embassy-stm32

Crates

git

Versions

stm32l496ag

Flavors

RingBufferedSpiRx

Struct RingBufferedSpiRx 

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

Rx-only Ring-buffered SPI Driver

Created with Spi::into_ring_buffered

§Notes on ‘waiting for bytes’

The read(buf) (but not read()) function may need to wait for bytes to arrive, if the ring buffer does not contain enough bytes to fill the buffer passed by the caller of the function, or is empty.

Waiting for bytes operates in one of two modes, depending on the behavior of the sender, the size of the buffer passed to the function:

  • If the slave is deselected (either rising or falling edge on NSS pin depending on SPI configuration), then any bytes in the ring buffer will be returned. If there are no bytes in the buffer, the check will be repeated each time the NSS deselect edge is detected, so if the sender sends just a single byte, it will be returned once the NSS deselect edge is detected.

  • If the sender sends continuously, the call will wait until the DMA controller indicates that it has written to either the middle byte or last byte of the ring buffer (‘half transfer’ or ‘transfer complete’, respectively). This does not indicate the buffer is half-full or full, though, because the DMA controller does not detect those conditions; it sends an interrupt when those specific buffer addresses have been written.

Implementations§

Source§

impl<'d, W: Word> RingBufferedSpiRx<'d, W>

Source

pub fn set_config(&mut self, config: &Config) -> Result<(), ()>

Reconfigure the driver

Source

pub fn start(&mut self)

Configure and start the DMA backed SPI receiver

Note: This is also done automatically by the read functions if required.

Source

pub async fn read(&mut self, buf: &mut [W]) -> Result<usize, Error>

Read bytes that are available in the ring buffer.

Background reception is started if necessary (if start() had not previously been called, or if an error was detected which caused background reception to be stopped).

Background reception is terminated when an error is returned. It must be started again by calling start() or by calling a read function again.

Source

pub fn blocking_read(&mut self, buf: &mut [W]) -> Result<usize, Error>

Read bytes that are readily available in the ring buffer. If no bytes are currently available in the buffer the call waits until the some bytes are available (at least one byte and at most half the buffer size)

Background receive is started if start() has not been previously called.

Receive in the background is terminated if an error is returned. It must then manually be started again by calling start() or by re-calling blocking_read().

Trait Implementations§

Source§

impl<W: Word> Drop for RingBufferedSpiRx<'_, W>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<W: Word> ErrorType for RingBufferedSpiRx<'_, W>

Source§

type Error = Error

Error type of all the IO operations on this type.
Source§

impl Read for RingBufferedSpiRx<'_, u8>

Source§

async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>

Read some bytes from this source into the specified buffer, returning how many bytes were read. Read more
Source§

async fn read_exact( &mut self, buf: &mut [u8], ) -> Result<(), ReadExactError<Self::Error>>

Read the exact number of bytes required to fill buf. Read more
Source§

impl<W: Word> ReadReady for RingBufferedSpiRx<'_, W>

Source§

fn read_ready(&mut self) -> Result<bool, Self::Error>

Get whether the reader is ready for immediately reading. Read more
Source§

impl<'d, W: Word> SetConfig for RingBufferedSpiRx<'d, W>

Source§

type Config = Config

The configuration type used by this driver.
Source§

type ConfigError = ()

The error type that can occur if set_config fails.
Source§

fn set_config(&mut self, config: &Self::Config) -> Result<(), Self::ConfigError>

Set the configuration of the driver.

Auto Trait Implementations§

§

impl<'d, W> Freeze for RingBufferedSpiRx<'d, W>

§

impl<'d, W> RefUnwindSafe for RingBufferedSpiRx<'d, W>
where W: RefUnwindSafe,

§

impl<'d, W> Send for RingBufferedSpiRx<'d, W>
where W: Send,

§

impl<'d, W> Sync for RingBufferedSpiRx<'d, W>
where W: Sync,

§

impl<'d, W> Unpin for RingBufferedSpiRx<'d, W>

§

impl<'d, W> !UnwindSafe for RingBufferedSpiRx<'d, W>

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> ToMutAligned for T
where T: ?Sized,

Source§

type Element = T

Element
Source§

fn to_mut_aligned<A>(&mut self) -> &mut Aligned<A, <T as ToMutAligned>::Element>
where A: Alignment,

Create a type-checked aligned value from a value that is aligned.
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.