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>
impl<'d, W: Word> RingBufferedSpiRx<'d, W>
Sourcepub fn start(&mut self)
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.
Sourcepub async fn read(&mut self, buf: &mut [W]) -> Result<usize, Error>
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.
Sourcepub fn blocking_read(&mut self, buf: &mut [W]) -> Result<usize, Error>
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>
impl<W: Word> Drop for RingBufferedSpiRx<'_, W>
Source§impl<W: Word> ErrorType for RingBufferedSpiRx<'_, W>
impl<W: Word> ErrorType for RingBufferedSpiRx<'_, W>
Source§impl Read for RingBufferedSpiRx<'_, u8>
impl Read for RingBufferedSpiRx<'_, u8>
Source§async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>
async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>
Source§async fn read_exact(
&mut self,
buf: &mut [u8],
) -> Result<(), ReadExactError<Self::Error>>
async fn read_exact( &mut self, buf: &mut [u8], ) -> Result<(), ReadExactError<Self::Error>>
buf. Read moreSource§impl<W: Word> ReadReady for RingBufferedSpiRx<'_, W>
impl<W: Word> ReadReady for RingBufferedSpiRx<'_, W>
Source§impl<'d, W: Word> SetConfig for RingBufferedSpiRx<'d, W>
impl<'d, W: Word> SetConfig for RingBufferedSpiRx<'d, W>
Source§type ConfigError = ()
type ConfigError = ()
set_config fails.