Cs4272

Struct Cs4272 

Source
pub struct Cs4272<const BUFFER_SIZE: usize, Pio, ChA, ChB, P0, P1, P2, P3, P4, P5>
where Pio: PIOExt, ChA: SingleChannel, ChB: SingleChannel, P0: OutputPin, P1: AnyPin, P2: AnyPin, P3: AnyPin, P4: AnyPin, P5: AnyPin,
{ /* private fields */ }
Expand description

Main driver struct, keeps ownership of all necessary resources while the driver is running

Implementations§

Source§

impl<const BUFFER_SIZE: usize, Pio, ChA, ChB, P0, P1, P2, P3, P4, P5> Cs4272<BUFFER_SIZE, Pio, ChA, ChB, P0, P1, P2, P3, P4, P5>
where Pio: PIOExt, ChA: SingleChannel, ChB: SingleChannel, P0: OutputPin, P1: AnyPin<Function = Pio::PinFunction>, P2: AnyPin<Function = Pio::PinFunction>, P3: AnyPin<Function = Pio::PinFunction>, P4: AnyPin<Function = Pio::PinFunction>, P5: AnyPin<Function = Pio::PinFunction>,

Source

pub fn handle_irq(&mut self)

Required method for restarting the DMA and swapping the buffers internally.

#[interrupt]
fn DMA_IRQ_0() {
    cortex_m::interrupt::free(|cs| {
        let mut cs4272 = CS4272.borrow(cs).borrow_mut();
        cs4272.as_mut().unwrap().handle_irq();
    });
}
Source

pub fn poll(&self) -> bool

Check if the current free output buffer has already been written to.

This makes it easy to periodically check when the driver is ready for new input.

if cs4272.poll() {
    // buffer is ready for new input
}
Source

pub fn get_input_buffer<'a>( &'a self, ) -> Ref<'a, &'static mut [u32; BUFFER_SIZE]>

Get a reference to the currently free input buffer.

If you are using the driver from a mutex getting to the data requires a cs from an interrupt::free callback for memory safety. Consider cloning the buffer to process it without blocking any other interrupts:

let buffer = cortex_m::interrupt::free(|cs| {
    CS4272.borrow(cs).borrow_mut().as_ref().unwrap().get_input_buffer().clone()
});
Source

pub fn set_output_buffer(&mut self, buffer: &[u32; BUFFER_SIZE])

Sets the current free output buffer for the next buffer switch.

// Output silence
let buffer: [u32; BUFFER_SIZE] = [0; BUFFER_SIZE];

cortex_m::interrupt::free(|cs| {
    CS4272.borrow(cs).borrow_mut().as_mut().unwrap().set_output_buffer(&buffer).clone()
});

Auto Trait Implementations§

§

impl<const BUFFER_SIZE: usize, Pio, ChA, ChB, P0, P1, P2, P3, P4, P5> !Freeze for Cs4272<BUFFER_SIZE, Pio, ChA, ChB, P0, P1, P2, P3, P4, P5>

§

impl<const BUFFER_SIZE: usize, Pio, ChA, ChB, P0, P1, P2, P3, P4, P5> !RefUnwindSafe for Cs4272<BUFFER_SIZE, Pio, ChA, ChB, P0, P1, P2, P3, P4, P5>

§

impl<const BUFFER_SIZE: usize, Pio, ChA, ChB, P0, P1, P2, P3, P4, P5> Send for Cs4272<BUFFER_SIZE, Pio, ChA, ChB, P0, P1, P2, P3, P4, P5>
where P0: Send, <P5 as AnyPin>::Id: Send, <P5 as AnyPin>::Function: Send, <P5 as AnyPin>::Pull: Send, <P2 as AnyPin>::Id: Send, <P2 as AnyPin>::Function: Send, <P2 as AnyPin>::Pull: Send, <P1 as AnyPin>::Id: Send, <P1 as AnyPin>::Function: Send, <P1 as AnyPin>::Pull: Send, <P3 as AnyPin>::Id: Send, <P3 as AnyPin>::Function: Send, <P3 as AnyPin>::Pull: Send, <P4 as AnyPin>::Id: Send, <P4 as AnyPin>::Function: Send, <P4 as AnyPin>::Pull: Send, ChB: Send, ChA: Send,

§

impl<const BUFFER_SIZE: usize, Pio, ChA, ChB, P0, P1, P2, P3, P4, P5> !Sync for Cs4272<BUFFER_SIZE, Pio, ChA, ChB, P0, P1, P2, P3, P4, P5>

§

impl<const BUFFER_SIZE: usize, Pio, ChA, ChB, P0, P1, P2, P3, P4, P5> Unpin for Cs4272<BUFFER_SIZE, Pio, ChA, ChB, P0, P1, P2, P3, P4, P5>
where P0: Unpin, <P5 as AnyPin>::Id: Unpin, <P5 as AnyPin>::Function: Unpin, <P5 as AnyPin>::Pull: Unpin, <P2 as AnyPin>::Id: Unpin, <P2 as AnyPin>::Function: Unpin, <P2 as AnyPin>::Pull: Unpin, <P1 as AnyPin>::Id: Unpin, <P1 as AnyPin>::Function: Unpin, <P1 as AnyPin>::Pull: Unpin, <P3 as AnyPin>::Id: Unpin, <P3 as AnyPin>::Function: Unpin, <P3 as AnyPin>::Pull: Unpin, <P4 as AnyPin>::Id: Unpin, <P4 as AnyPin>::Function: Unpin, <P4 as AnyPin>::Pull: Unpin, Pio: Unpin, ChB: Unpin, ChA: Unpin,

§

impl<const BUFFER_SIZE: usize, Pio, ChA, ChB, P0, P1, P2, P3, P4, P5> !UnwindSafe for Cs4272<BUFFER_SIZE, Pio, ChA, ChB, P0, P1, P2, P3, P4, P5>

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<Choices> CoproductSubsetter<CNil, HNil> for Choices

Source§

type Remainder = Choices

Source§

fn subset( self, ) -> Result<CNil, <Choices as CoproductSubsetter<CNil, HNil>>::Remainder>

Extract a subset of the possible types in a coproduct (or get the remaining possibilities) 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U, I> LiftInto<U, I> for T
where U: LiftFrom<T, I>,

Source§

fn lift_into(self) -> U

Performs the indexed conversion.
Source§

impl<Source> Sculptor<HNil, HNil> for Source

Source§

type Remainder = Source

Source§

fn sculpt(self) -> (HNil, <Source as Sculptor<HNil, HNil>>::Remainder)

Consumes the current HList and returns an HList with the requested shape. Read more
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.