Trait embedded_hal::spi::SpiDevice
source · pub trait SpiDevice<Word: Copy + 'static = u8>: ErrorType {
// Required method
fn transaction(
&mut self,
operations: &mut [Operation<'_, Word>],
) -> Result<(), Self::Error>;
// Provided methods
fn read(&mut self, buf: &mut [Word]) -> Result<(), Self::Error> { ... }
fn write(&mut self, buf: &[Word]) -> Result<(), Self::Error> { ... }
fn transfer(
&mut self,
read: &mut [Word],
write: &[Word],
) -> Result<(), Self::Error> { ... }
fn transfer_in_place(&mut self, buf: &mut [Word]) -> Result<(), Self::Error> { ... }
}
Expand description
SPI device trait
SpiDevice
represents ownership over a single SPI device on a (possibly shared) bus, selected
with a CS (Chip Select) pin.
See the module-level documentation for important usage information.
Required Methods§
sourcefn transaction(
&mut self,
operations: &mut [Operation<'_, Word>],
) -> Result<(), Self::Error>
fn transaction( &mut self, operations: &mut [Operation<'_, Word>], ) -> Result<(), Self::Error>
Perform a transaction against the device.
- Locks the bus
- Asserts the CS (Chip Select) pin.
- Performs all the operations.
- Flushes the bus.
- Deasserts the CS pin.
- Unlocks the bus.
The locking mechanism is implementation-defined. The only requirement is it must prevent two transactions from executing concurrently against the same bus. Examples of implementations are: critical sections, blocking mutexes, returning an error or panicking if the bus is already busy.
On bus errors the implementation should try to deassert CS. If an error occurs while deasserting CS the bus error should take priority as the return value.
Provided Methods§
sourcefn read(&mut self, buf: &mut [Word]) -> Result<(), Self::Error>
fn read(&mut self, buf: &mut [Word]) -> Result<(), Self::Error>
Do a read within a transaction.
This is a convenience method equivalent to device.transaction(&mut [Operation::Read(buf)])
.
See also: SpiDevice::transaction
, SpiBus::read
sourcefn write(&mut self, buf: &[Word]) -> Result<(), Self::Error>
fn write(&mut self, buf: &[Word]) -> Result<(), Self::Error>
Do a write within a transaction.
This is a convenience method equivalent to device.transaction(&mut [Operation::Write(buf)])
.
See also: SpiDevice::transaction
, SpiBus::write
sourcefn transfer(
&mut self,
read: &mut [Word],
write: &[Word],
) -> Result<(), Self::Error>
fn transfer( &mut self, read: &mut [Word], write: &[Word], ) -> Result<(), Self::Error>
Do a transfer within a transaction.
This is a convenience method equivalent to device.transaction(&mut [Operation::Transfer(read, write)]
.
See also: SpiDevice::transaction
, SpiBus::transfer
sourcefn transfer_in_place(&mut self, buf: &mut [Word]) -> Result<(), Self::Error>
fn transfer_in_place(&mut self, buf: &mut [Word]) -> Result<(), Self::Error>
Do an in-place transfer within a transaction.
This is a convenience method equivalent to device.transaction(&mut [Operation::TransferInPlace(buf)]
.
See also: SpiDevice::transaction
, SpiBus::transfer_in_place