Trait kernel::hil::spi::SpiSlave

source ·
pub trait SpiSlave<'a> {
    // Required methods
    fn init(&self) -> Result<(), ErrorCode>;
    fn has_client(&self) -> bool;
    fn set_client(&self, client: Option<&'a dyn SpiSlaveClient>);
    fn set_write_byte(&self, write_byte: u8);
    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

Trait for SPI peripherals (slaves) to exchange data with a contoller (master). This is a low-level trait typically implemented by hardware: higher level software typically uses the SpiSlaveDevice trait, which is provided by a virtualizing/multiplexing layer.

Required Methods§

source

fn init(&self) -> Result<(), ErrorCode>

Initialize the SPI device to be in peripheral mode. Return values:

  • Ok(()): the device is in peripheral mode
  • Err(BUSY): the device is busy with an operation and cannot be initialized
  • Err(FAIL): other failure condition
source

fn has_client(&self) -> bool

Returns true if there is a client. Useful for verifying that two software drivers do not both try to take control of the device.

source

fn set_client(&self, client: Option<&'a dyn SpiSlaveClient>)

Set the callback for slave operations, passing None to disable peripheral mode.

source

fn set_write_byte(&self, write_byte: u8)

Set a single byte to write in response to a read/write operation from a controller. Useful for devices that always send a status code in their first byte.

source

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]>)>

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.

source

fn set_polarity(&self, polarity: ClockPolarity) -> Result<(), ErrorCode>

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
source

fn get_polarity(&self) -> ClockPolarity

Return the current bus polarity.

source

fn set_phase(&self, phase: ClockPhase) -> Result<(), ErrorCode>

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
source

fn get_phase(&self) -> ClockPhase

Return the current bus phase.

Implementors§