embassy-stm32

Crates

git

Versions

stm32h730vb

Flavors

embassy_stm32::dma

Struct ReadableRingBuffer

source
pub struct ReadableRingBuffer<'a, W: Word> { /* private fields */ }
Expand description

Ringbuffer for receiving data using DMA circular mode.

Implementations§

source§

impl<'a, W: Word> ReadableRingBuffer<'a, W>

source

pub unsafe fn new( channel: impl Peripheral<P = impl Channel> + 'a, _request: Request, peri_addr: *mut W, buffer: &'a mut [W], options: TransferOptions, ) -> Self

Create a new ring buffer.

source

pub fn start(&mut self)

Start the ring buffer operation.

You must call this after creating it for it to work.

source

pub fn clear(&mut self)

Clear all data in the ring buffer.

source

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

Read elements from the ring buffer Return a tuple of the length read and the length remaining in the buffer If not all of the elements were read, then there will be some elements in the buffer remaining The length remaining is the capacity, ring_buf.len(), less the elements remaining after the read Error is returned if the portion to be read was overwritten by the DMA controller.

source

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

Read an exact number of elements from the ringbuffer.

Returns the remaining number of elements available for immediate reading. Error is returned if the portion to be read was overwritten by the DMA controller.

Async/Wake Behavior: The underlying DMA peripheral only can wake us when its buffer pointer has reached the halfway point, and when it wraps around. This means that when called with a buffer of length ‘M’, when this ring buffer was created with a buffer of size ‘N’:

  • If M equals N/2 or N/2 divides evenly into M, this function will return every N/2 elements read on the DMA source.
  • Otherwise, this function may need up to N/2 extra elements to arrive before returning.
source

pub fn len(&mut self) -> Result<usize, Error>

The current length of the ringbuffer

source

pub const fn capacity(&self) -> usize

The capacity of the ringbuffer

source

pub fn set_waker(&mut self, waker: &Waker)

Set a waker to be woken when at least one byte is received.

source

pub fn request_stop(&mut self)

Request the DMA to stop. The configuration for this channel will not be preserved. If you need to restart the transfer at a later point with the same configuration, see request_pause instead.

This doesn’t immediately stop the transfer, you have to wait until is_running returns false.

source

pub fn request_pause(&mut self)

Request the transfer to pause, keeping the existing configuration for this channel. To restart the transfer, call start again.

This doesn’t immediately stop the transfer, you have to wait until is_running returns false.

source

pub fn is_running(&mut self) -> bool

Return whether DMA is still running.

If this returns false, it can be because either the transfer finished, or it was requested to stop early with request_stop.

source

pub async fn stop(&mut self)

Stop the DMA transfer and await until the buffer is full.

This disables the DMA transfer’s circular mode so that the transfer stops when the buffer is full.

This is designed to be used with streaming input data such as the I2S/SAI or ADC.

When using the UART, you probably want request_stop().

Trait Implementations§

source§

impl<'a, W: Word> Drop for ReadableRingBuffer<'a, W>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a, W> Freeze for ReadableRingBuffer<'a, W>

§

impl<'a, W> RefUnwindSafe for ReadableRingBuffer<'a, W>
where W: RefUnwindSafe,

§

impl<'a, W> Send for ReadableRingBuffer<'a, W>
where W: Send,

§

impl<'a, W> Sync for ReadableRingBuffer<'a, W>
where W: Sync,

§

impl<'a, W> Unpin for ReadableRingBuffer<'a, W>

§

impl<'a, W> !UnwindSafe for ReadableRingBuffer<'a, 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, 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.