embassy-stm32

Crates

git

Versions

stm32l476rg

Flavors

RingBufferedDacChannel

Struct RingBufferedDacChannel 

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

A DAC channel backed by a DMA ring buffer.

Allows continuous waveform streaming by writing new samples into the ring buffer while DMA is simultaneously consuming and outputting them. DMA runs in circular mode so output never stops between writes.

Obtain this from [DacChannel::into_ring_buffered_8bit] or [DacChannel::into_ring_buffered_12right].

Implementations§

Source§

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

Source

pub fn start(&mut self)

Start the DMA transfer.

Call this after creating the ring buffer (and optionally pre-filling it with write_immediate) to begin DAC output.

Source

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

Write samples directly into the raw DMA buffer without checking DMA position.

Useful for pre-filling the buffer before calling start. Writes at most capacity elements aligned to the end of the buffer.

Source

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

Write samples into the ring buffer.

Returns (written, remaining_space). Returns [Error::Overrun] if the DMA consumed data faster than the CPU supplied it; the ring buffer resets itself automatically in that case.

Source

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

Write an exact number of samples, waiting asynchronously until space is available.

Source

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

Wait for a ring buffer write error (underrun).

Source

pub fn capacity(&self) -> usize

Return the ring buffer capacity in samples.

Source

pub fn is_running(&mut self) -> bool

Return whether the DMA is currently running.

Source

pub fn request_reset(&mut self)

Request the DMA to stop, discarding the channel configuration.

Source

pub fn request_pause(&mut self)

Request the DMA to pause, preserving the channel configuration.

Resume with start.

Source

pub async fn stop(&mut self)

Stop the DMA transfer, waiting until all buffered samples have been output.

Trait Implementations§

Source§

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

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

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

§

impl<'d, W> !RefUnwindSafe for RingBufferedDacChannel<'d, W>

§

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

§

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

§

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

§

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