Skip to main content

SpiSlaveRing

Struct SpiSlaveRing 

Source
pub struct SpiSlaveRing<'d, T: Instance, W: Word> { /* private fields */ }
Expand description

SPI slave with RX and TX on circular DMA (see the module docs).

Implementations§

Source§

impl<'d, T: Instance, W: Word> SpiSlaveRing<'d, T, W>

Source

pub fn new<const REMAP: u8>( peri: Peri<'d, T>, sck: Peri<'d, impl SckPin<T, REMAP>>, mosi: Peri<'d, impl MosiPin<T, REMAP>>, miso: Peri<'d, impl MisoPin<T, REMAP>>, nss: Peri<'d, impl CsPin<T, REMAP>>, rx_dma: Peri<'d, impl RxDma<T>>, tx_dma: Peri<'d, impl TxDma<T>>, rx_buf: &'d mut [W], tx_buf: &'d mut [W], config: SlaveConfig, ) -> Self

rx_buf and tx_buf are the same length; each pass uses 2 x half_len words of them (all of them by default). Nothing runs until start.

Source

pub fn set_half_len(&mut self, words: usize)

Words per half. Safe to call while running: the halves keep their current length until the next start / restart.

Source

pub fn half_len(&self) -> usize

Words per half in use (since the last start).

Source

pub fn start(&mut self) -> Result<(), SlaveError>

Set up SPI and both DMA channels and enable the slave in a pause between bursts (NSS high). TX starts with whatever is in the TX buffer.

Source

pub fn stop(&mut self)

Stop both channels and the slave.

Source

pub fn restart(&mut self) -> Result<(), SlaveError>

After a slip or an error: stop, reset the peripheral (clears the shift register, the data register and OVR) and start again in a pause.

Source

pub async fn next_half(&mut self) -> Result<Half, SlaveError>

Wait for the next completed RX half.

Source

pub fn rx_half(&self, index: usize) -> &[W]

Received words of half index (complete once next_half returned it, until the DMA comes back to it one pass later).

Source

pub fn tx_half_mut(&mut self, index: usize) -> &mut [W]

TX half index, free to refill after next_half returned it.

Source

pub fn half_mut(&mut self, index: usize) -> (&[W], &mut [W])

rx_half and tx_half_mut of the same half, together.

Source

pub fn rx_position(&self) -> RingPositionReader<'d>

Reads the RX position from anywhere (e.g. a USB SOF interrupt measuring the master’s clock). It borrows the RX channel for 'd, so it can’t outlive it, but it reads the transfer set up by the last start / restart: take a new one after each.

Trait Implementations§

Source§

impl<'d, T: Instance, W: Word> Drop for SpiSlaveRing<'d, T, W>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<'d, T: Instance, W: Word + Send> Send for SpiSlaveRing<'d, T, W>

Auto Trait Implementations§

§

impl<'d, T, W> !Sync for SpiSlaveRing<'d, T, W>

§

impl<'d, T, W> !UnwindSafe for SpiSlaveRing<'d, T, W>

§

impl<'d, T, W> Freeze for SpiSlaveRing<'d, T, W>
where T: Freeze,

§

impl<'d, T, W> RefUnwindSafe for SpiSlaveRing<'d, T, W>
where T: RefUnwindSafe, W: RefUnwindSafe,

§

impl<'d, T, W> Unpin for SpiSlaveRing<'d, T, W>
where T: Unpin,

§

impl<'d, T, W> UnsafeUnpin for SpiSlaveRing<'d, T, W>
where T: UnsafeUnpin,

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.