Trait embedded_hal_async::spi::SpiBus
source · pub trait SpiBus<Word: 'static + Copy = u8>: ErrorType {
// Required methods
async fn read(&mut self, words: &mut [Word]) -> Result<(), Self::Error>;
async fn write(&mut self, words: &[Word]) -> Result<(), Self::Error>;
async fn transfer(
&mut self,
read: &mut [Word],
write: &[Word],
) -> Result<(), Self::Error>;
async fn transfer_in_place(
&mut self,
words: &mut [Word],
) -> Result<(), Self::Error>;
async fn flush(&mut self) -> Result<(), Self::Error>;
}
Expand description
SPI bus.
SpiBus
represents exclusive ownership over the whole SPI bus, with SCK, MOSI and MISO pins.
See the docs on embedded-hal for important information on SPI Bus vs Device traits.
Required Methods§
sourceasync fn read(&mut self, words: &mut [Word]) -> Result<(), Self::Error>
async fn read(&mut self, words: &mut [Word]) -> Result<(), Self::Error>
Read words
from the slave.
The word value sent on MOSI during reading is implementation-defined,
typically 0x00
, 0xFF
, or configurable.
Implementations are allowed to return before the operation is complete. See the docs on embedded-hal for details on flushing.
sourceasync fn write(&mut self, words: &[Word]) -> Result<(), Self::Error>
async fn write(&mut self, words: &[Word]) -> Result<(), Self::Error>
Write words
to the slave, ignoring all the incoming words.
Implementations are allowed to return before the operation is complete. See the docs on embedded-hal for details on flushing.
sourceasync fn transfer(
&mut self,
read: &mut [Word],
write: &[Word],
) -> Result<(), Self::Error>
async fn transfer( &mut self, read: &mut [Word], write: &[Word], ) -> Result<(), Self::Error>
Write and read simultaneously. write
is written to the slave on MOSI and
words received on MISO are stored in read
.
It is allowed for read
and write
to have different lengths, even zero length.
The transfer runs for max(read.len(), write.len())
words. If read
is shorter,
incoming words after read
has been filled will be discarded. If write
is shorter,
the value of words sent in MOSI after all write
has been sent is implementation-defined,
typically 0x00
, 0xFF
, or configurable.
Implementations are allowed to return before the operation is complete. See the docs on embedded-hal for details on flushing.
sourceasync fn transfer_in_place(
&mut self,
words: &mut [Word],
) -> Result<(), Self::Error>
async fn transfer_in_place( &mut self, words: &mut [Word], ) -> Result<(), Self::Error>
Write and read simultaneously. The contents of words
are
written to the slave, and the received words are stored into the same
words
buffer, overwriting it.
Implementations are allowed to return before the operation is complete. See the docs on embedded-hal for details on flushing.
sourceasync fn flush(&mut self) -> Result<(), Self::Error>
async fn flush(&mut self) -> Result<(), Self::Error>
Wait until all operations have completed and the bus is idle.
See the docs on embedded-hal for information on flushing.