Skip to main content

DmaDoubleBuffer

Struct DmaDoubleBuffer 

Source
pub struct DmaDoubleBuffer<T, const N: usize> { /* private fields */ }
Expand description

Double-buffer ping-pong manager for DMA audio streaming.

Designed to work seamlessly with async DMA drivers (e.g. Embassy dac.write(), sai.write(), timer.write_dma(), etc.) or IRQ-driven DMA half-transfer callbacks.

Implementations§

Source§

impl<T: Copy + Default, const N: usize> DmaDoubleBuffer<T, N>

Source

pub const HALF_SIZE: usize = N

Source

pub const TOTAL_SIZE: usize

Source

pub fn new() -> Self

Source

pub const fn from_buffers(buf0: [T; N], buf1: [T; N]) -> Self

Source

pub fn buffers(&self) -> &[[T; N]; 2]

Get reference to both half buffers.

Source

pub fn buffers_mut(&mut self) -> &mut [[T; N]; 2]

Get mutable reference to both half buffers.

Source

pub fn current_half_mut(&mut self) -> &mut [T; N]

Get current active half-buffer slice to fill with new samples.

Source

pub fn current_half(&self) -> &[T; N]

Get current active half-buffer slice.

Source

pub fn swap_and_get_next(&mut self) -> &mut [T; N]

Swap active half-buffer index and return mutable slice for the next batch.

Source

pub fn fill_and_swap<F>(&mut self, fill_fn: F) -> &mut [T; N]
where F: FnMut(&mut [T; N]),

Fill the inactive buffer half using fill_fn, then swap to make it active and return its slice.

Trait Implementations§

Source§

impl<T: Clone, const N: usize> Clone for DmaDoubleBuffer<T, N>

Source§

fn clone(&self) -> DmaDoubleBuffer<T, N>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug, const N: usize> Debug for DmaDoubleBuffer<T, N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Copy + Default, const N: usize> Default for DmaDoubleBuffer<T, N>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T, const N: usize> Freeze for DmaDoubleBuffer<T, N>
where [[T; N]; 2]: Freeze,

§

impl<T, const N: usize> RefUnwindSafe for DmaDoubleBuffer<T, N>

§

impl<T, const N: usize> Send for DmaDoubleBuffer<T, N>
where [[T; N]; 2]: Send,

§

impl<T, const N: usize> Sync for DmaDoubleBuffer<T, N>
where [[T; N]; 2]: Sync,

§

impl<T, const N: usize> Unpin for DmaDoubleBuffer<T, N>
where [[T; N]; 2]: Unpin,

§

impl<T, const N: usize> UnsafeUnpin for DmaDoubleBuffer<T, N>
where [[T; N]; 2]: UnsafeUnpin,

§

impl<T, const N: usize> UnwindSafe for DmaDoubleBuffer<T, N>
where [[T; N]; 2]: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.