pub trait SpiSlaveDevice {
    fn set_client(&self, client: &'static dyn SpiSlaveClient);
    fn configure(
        &self,
        cpol: ClockPolarity,
        cpal: ClockPhase
    ) -> Result<(), ErrorCode>; fn read_write_bytes(
        &self,
        write_buffer: Option<&'static mut [u8]>,
        read_buffer: Option<&'static mut [u8]>,
        len: usize
    ) -> Result<(), (ErrorCode, Option<&'static mut [u8]>, Option<&'static mut [u8]>)>; fn set_polarity(&self, polarity: ClockPolarity) -> Result<(), ErrorCode>; fn get_polarity(&self) -> ClockPolarity; fn set_phase(&self, phase: ClockPhase) -> Result<(), ErrorCode>; fn get_phase(&self) -> ClockPhase; }
Expand description

SPISlaveDevice is an interface to a SPI bus in peripheral mode. It is the standard trait used by services within the kernel: SpiSlave is for lower-level access responsible for initializing hardware.

Required Methods

Specify the callback of read_write_bytes operations:

Setup the SPI settings and speed of the bus.

Provide buffers for the peripheral to write from and read into when a controller performs a read_write_bytes operation. The device will issue a callback when one of four things occurs:

  • The controller completes the operation by bringing the chip select high.
  • A Some write buffer is written.
  • A Some read buffer is filled.
  • len bytes are read/written Return values:
  • Ok(()): the SPI bus will read/write the provided buffers on the next SPI operation requested by the controller.
  • Err(BUSY): the device is busy with an existing read_write_bytes operation.
  • Err(INVAL): the len parameter is 0

Err return values return the passed buffer Options.

Set the bus polarity (whether idle is high or low). Return values:

  • Ok(()): the polarity was set.
  • Err(BUSY): the SPI bus is busy with a read_write_bytes operation whose callback hasn’t been called yet.
  • Err(FAIL): other failure

Return the current bus polarity.

Set the bus phase (whether data is sent/received on leading or trailing edges).

  • Ok(()): the phase was set.
  • Err(BUSY): the SPI bus is busy with a read_write_bytes operation whose callback hasn’t been called yet.
  • Err(FAIL): other failure

Return the current bus phase.

Implementors