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>
impl<T: Copy + Default, const N: usize> DmaDoubleBuffer<T, N>
pub const HALF_SIZE: usize = N
pub const TOTAL_SIZE: usize
pub fn new() -> Self
pub const fn from_buffers(buf0: [T; N], buf1: [T; N]) -> Self
Sourcepub fn buffers_mut(&mut self) -> &mut [[T; N]; 2]
pub fn buffers_mut(&mut self) -> &mut [[T; N]; 2]
Get mutable reference to both half buffers.
Sourcepub fn current_half_mut(&mut self) -> &mut [T; N]
pub fn current_half_mut(&mut self) -> &mut [T; N]
Get current active half-buffer slice to fill with new samples.
Sourcepub fn current_half(&self) -> &[T; N]
pub fn current_half(&self) -> &[T; N]
Get current active half-buffer slice.
Sourcepub fn swap_and_get_next(&mut self) -> &mut [T; N]
pub fn swap_and_get_next(&mut self) -> &mut [T; N]
Swap active half-buffer index and return mutable slice for the next batch.
Sourcepub fn fill_and_swap<F>(&mut self, fill_fn: F) -> &mut [T; N]
pub fn fill_and_swap<F>(&mut self, fill_fn: F) -> &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>
impl<T: Clone, const N: usize> Clone for DmaDoubleBuffer<T, N>
Source§fn clone(&self) -> DmaDoubleBuffer<T, N>
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)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<T, const N: usize> Freeze for DmaDoubleBuffer<T, N>
impl<T, const N: usize> RefUnwindSafe for DmaDoubleBuffer<T, N>
impl<T, const N: usize> Send for DmaDoubleBuffer<T, N>
impl<T, const N: usize> Sync for DmaDoubleBuffer<T, N>
impl<T, const N: usize> Unpin for DmaDoubleBuffer<T, N>
impl<T, const N: usize> UnsafeUnpin for DmaDoubleBuffer<T, N>
impl<T, const N: usize> UnwindSafe for DmaDoubleBuffer<T, N>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more