Struct SpiHw

Source
pub struct SpiHw<'a> { /* private fields */ }
Expand description

Abstraction of the SPI Hardware

Implementations§

Source§

impl<'a> SpiHw<'a>

Source

pub const fn new(pm: &'a PowerManager) -> SpiHw<'a>

Creates a new SPI object, with peripheral 0 selected

Source

pub fn set_baud_rate(&self, rate: u32) -> u32

Sets the approximate baud rate for the active peripheral, and return the actual baud rate set.

Since the only supported baud rates are (system clock / n) where n is an integer from 1 to 255, the exact baud rate may not be available. In that case, the next lower baud rate will be selected.

The lowest available baud rate is 188235 baud. If the requested rate is lower, 188235 baud will be selected.

Source

pub fn set_dma(&self, read: &'static DMAChannel, write: &'static DMAChannel)

Set the DMA channels used for reading and writing.

Source

pub fn handle_interrupt(&self)

Trait Implementations§

Source§

impl DMAClient for SpiHw<'_>

Source§

impl PeripheralManagement<Clock> for SpiHw<'_>

Source§

type RegisterType = SpiRegisters

Source§

fn get_registers(&self) -> &SpiRegisters

How to get a reference to the physical hardware registers (the MMIO struct).
Source§

fn get_clock(&self) -> &Clock

Which clock feeds this peripheral. Read more
Source§

fn before_peripheral_access(&self, clock: &Clock, _: &SpiRegisters)

Called before peripheral access. Read more
Source§

fn after_peripheral_access(&self, clock: &Clock, registers: &SpiRegisters)

Called after peripheral access. Read more
Source§

impl<'a> SpiMaster<'a> for SpiHw<'a>

Source§

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

By default, initialize SPI to operate at 40KHz, clock is idle on low, and sample on the leading edge.

Source§

fn write_byte(&self, out_byte: u8) -> Result<(), ErrorCode>

Write a byte to the SPI and discard the read; if an asynchronous operation is outstanding, do nothing.

Source§

fn read_byte(&self) -> Result<u8, ErrorCode>

Write 0 to the SPI and return the read; if an asynchronous operation is outstanding, do nothing.

Source§

fn read_write_byte(&self, val: u8) -> Result<u8, ErrorCode>

Write a byte to the SPI and return the read; if an asynchronous operation is outstanding, do nothing.

Source§

fn read_write_bytes( &self, write_buffer: SubSliceMut<'static, u8>, read_buffer: Option<SubSliceMut<'static, u8>>, ) -> Result<(), (ErrorCode, SubSliceMut<'static, u8>, Option<SubSliceMut<'static, u8>>)>

Asynchronous buffer read/write of SPI. write_buffer must be present; read_buffer may be None. If read_buffer is present, then the length of the read/write is the minimum of two buffer lengths.

Returns:

  • Ok(()) if operation starts (will receive callback through SpiMasterClient)
  • BUSY if the operation does not start
Source§

type ChipSelect = Peripheral

Chip select is an associated type because different SPI buses may have different numbers of chip selects. This allows peripheral implementations to define their own type.
Source§

fn set_client(&self, client: &'a dyn SpiMasterClient)

Change the callback handler for SpiMaster::read_write_bytes calls.
Source§

fn is_busy(&self) -> bool

Return whether the SPI peripheral is busy with a SpiMaster::read_write_bytes operation.
Source§

fn set_rate(&self, rate: u32) -> Result<u32, ErrorCode>

Set the clock/data rate for the current chip select. Read more
Source§

fn get_rate(&self) -> u32

Return the current chip select’s clock rate.
Source§

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

Set the bus polarity (whether idle is high or low) for the current chip select. Read more
Source§

fn get_polarity(&self) -> ClockPolarity

Return the current bus polarity.
Source§

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

Set the bus phase for the current chip select (whether data is sent/received on leading or trailing edges). Read more
Source§

fn get_phase(&self) -> ClockPhase

Get the current bus phase for the current chip select.
Source§

fn hold_low(&self)

Hold the chip select line low after a SpiMaster::read_write_bytes completes. This allows a client to make one long SPI read/write with multiple calls to read_write_bytes.
Source§

fn release_low(&self)

Raise the chip select line after a SpiMaster::read_write_bytes completes. This will complete the SPI operation.
Source§

fn specify_chip_select(&self, cs: Self::ChipSelect) -> Result<(), ErrorCode>

Specify which chip select to use. Configuration settings (rate, polarity, phase) are chip-select specific and are stored for that chip select.
Source§

impl<'a> SpiSlave<'a> for SpiHw<'a>

Source§

fn set_write_byte(&self, write_byte: u8)

This sets the value in the TDR register, to be sent as soon as the chip select pin is low.

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

Setup buffers for a SPI transaction initiated by the master device.

Returns:

  • Ok(()) if the operation starts. A callback will be generated.
  • INVAL if neither the read or write buffer is provided.
Source§

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

Set the callback for slave operations, passing None to disable peripheral mode.
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 init(&self) -> Result<(), ErrorCode>

Initialize the SPI device to be in peripheral mode. Read more
Source§

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

Set the bus polarity (whether idle is high or low). Read more
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). Read more
Source§

fn get_phase(&self) -> ClockPhase

Return the current bus phase.

Auto Trait Implementations§

§

impl<'a> !Freeze for SpiHw<'a>

§

impl<'a> !RefUnwindSafe for SpiHw<'a>

§

impl<'a> !Send for SpiHw<'a>

§

impl<'a> !Sync for SpiHw<'a>

§

impl<'a> Unpin for SpiHw<'a>

§

impl<'a> !UnwindSafe for SpiHw<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.