Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR provides an abstraction layer for SPI support, in main mode.
It focuses on providing non-DMA-enabled drivers, which still provide an async interface, with timeouts—e.g., to avoid indefinitely blocking when the target is not connected.
The drivers implement
embedded_hal_async::spi::SpiBus
, and can thus easily be used by any device driver relying on that trait.It provides ways to either select frequencies which all MCUs are expected to support (up to 8 MHz), or to request the highest available frequency within a range, resolved at compile-time using
highest_freq_in
.Issues/PRs references
Open Questions
Frequency
be renamed toBitrate
?highest_freq_in
or directly using the arch-independent enum, is only precisely respected on a best-effort basis by Embassy: as the SPI frequency is sometimes configured based on an input frequency divided by a prescaler, which only has a limited number of possible values, the exact frequency actually used can be different from the one selected by the user. I suppose it would be useful to document this. As the documentation of the manufacturer-specific crates is not currently rendered (where I think this should be mentioned), I'm opting for documenting this as part of a follow-up PR.Limitations
DMA-enabled drivers are out-of-scope of this PR as the number of DMA channels is limited on some architectures and non-DMA-enabled drivers are therefore useful when no channels are left. Moreover, setting up DMA incurs some overhead, and is thus not relevant for small operations as it is the case with sensors, which was the initial motivation for adding support for SPI.
Future work
dma
module insidespi::main
.Change checklist