Skip to content

spi_bus

SPI bus abstraction.

Wraps a [PhysicalTransfer] impl and exposes the [Bus] trait as a list of [Op]s run in order. MAX_TRANSFER is the controller’s data buffer; a write-only or read-only op longer than that is clocked in buffer-sized pieces, and an exchange is handed to the physical driver whole (it chunks through the FIFO or uses DMA). No length is ever silently cut short.

The physical driver is held by value (SpiBus<P>), not behind a &'static dyn — so one Once<SpiBus<Esp32Spi>> holds the whole stack rather than a driver static plus a bus static that borrows it. A caller that already has a &'static driver can still pass it: &T is itself a [PhysicalTransfer] (the blanket impl in hal::bus), so SpiBus<&Esp32Spi> works unchanged.

[Bus::transfer] holds an [api::mutex] lock for the whole op list, so a multi-op transaction cannot be split by another task once a board hands the same &'static SpiBus to more than one of them. The lock is the kernel’s priority-inheritance mutex, a syscall that the kernel refuses from interrupt context — so transfer must not be called from an ISR. An interrupt that has to touch the peripheral should own the physical driver directly (exchange is &self) and coordinate with the task side through a CsCell, not through this wrapper.

struct SpiBus<P> { /* private fields */ }

SPI bus abstraction owning its physical driver P.

Implements: Bus