pub trait SpiDevice: ErrorType {
    type Bus: ErrorType;

    fn transaction<R>(
        &mut self,
        f: impl FnOnce(&mut Self::Bus) -> Result<R, <Self::Bus as ErrorType>::Error>
    ) -> Result<R, Self::Error>; fn write<Word>(&mut self, buf: &[Word]) -> Result<(), Self::Error>
    where
        Self::Bus: SpiBusWrite<Word>,
        Word: Copy
, { ... } fn read<Word>(&mut self, buf: &mut [Word]) -> Result<(), Self::Error>
    where
        Self::Bus: SpiBusRead<Word>,
        Word: Copy
, { ... } fn transfer<Word>(
        &mut self,
        read: &mut [Word],
        write: &[Word]
    ) -> Result<(), Self::Error>
    where
        Self::Bus: SpiBus<Word>,
        Word: Copy
, { ... } fn transfer_in_place<Word>(
        &mut self,
        buf: &mut [Word]
    ) -> Result<(), Self::Error>
    where
        Self::Bus: SpiBus<Word>,
        Word: Copy
, { ... } }
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 Associated Types

SPI Bus type for this device.

Required Methods

Perform a transaction against the device.

  • Locks the bus
  • Asserts the CS (Chip Select) pin.
  • Calls f with an exclusive reference to the bus, which can then be used to do transfers against the device.
  • 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.

Provided Methods

Do a write within a transaction.

This is a convenience method equivalent to device.transaction(|bus| bus.write(buf)).

See also: SpiDevice::transaction, SpiBusWrite::write

Do a read within a transaction.

This is a convenience method equivalent to device.transaction(|bus| bus.read(buf)).

See also: SpiDevice::transaction, SpiBusRead::read

Do a transfer within a transaction.

This is a convenience method equivalent to device.transaction(|bus| bus.transfer(read, write)).

See also: SpiDevice::transaction, SpiBus::transfer

Do an in-place transfer within a transaction.

This is a convenience method equivalent to device.transaction(|bus| bus.transfer_in_place(buf)).

See also: SpiDevice::transaction, SpiBus::transfer_in_place

Implementations on Foreign Types

Implementors