Skip to main content

Interface

Struct Interface 

Source
pub struct Interface<'a, S: InterfaceState> { /* private fields */ }
Expand description

decides when and how you start audio callback at runtime. It enforces a two-state model:

  • Idle – peripherals configured but SAI not started.
  • Running – SAI started, ready to execute audio callbacks.

Transition from Idle to Running by calling start_interface(), which performs codec register writes, waits for codec timing, and starts the SAI receiver and transmitter. Once Running, invoke start_callback() to enter a continuous read→process→write loop. Any SAI errors are returned to the caller for custom handling.

Interface<'a, S> manages the setup and runtime of an SAI-based audio stream. It drives codec initialization (over I2C if required), configures SAI TX/RX, and enforces a two-state model:

  • Idle – peripherals configured but SAI not started.
  • Running – SAI started, ready to execute audio callbacks.

Transition from Idle to Running by calling start_interface(), which performs codec register writes, waits for codec timing, and starts the SAI receiver and transmitter. Once Running, invoke start_callback() to enter a continuous read→process→write loop. Any SAI errors are returned to the caller for custom handling.

§Example

// 1. Configure peripherals into Idle state
let idle: Interface<Idle> = board
    .audio_peripherals
    .prepare_interface(Default::default())
    .await;

// ... initialize your DSP or other resources ...

// 2. Start interface and transition to Running
let mut audio: Interface<Running> = idle
    .start_interface()
    .await
    .unwrap();

// 3. Audio processing loop with error handling
loop {
    // Runs until an SAI error occurs, then returns Err(e)
    if let Err(e) = audio
        .start_callback(|input, output| {
            // process `input` samples into `output` buffer
        })
        .await
    {
        // handle SAI error e (be quick to avoid overrun)
    }

    // ... optionally reset or reinitialize DSP ...
}

§Notes

  • Always call start_interface() before start_callback().
  • Keep callback and error-handling routines short to prevent SAI overruns.

Implementations§

Source§

impl<'a> Interface<'a, Idle>

Source

pub async fn start_interface(self) -> Result<Interface<'a, Running>, Error>

This has to be called before Interface::start_callback can be used to ensure proper setup of the interface. Interface::start_callback should be called immediately afterwards otherwise overruns of the SAI can occur.

Source

pub async fn setup_and_release( self, ) -> Result<(Sai<'a, SAI1, u32>, Sai<'a, SAI1, u32>, I2c<'a, Blocking, Master>), Error>

Source§

impl Interface<'_, Running>

Source

pub async fn start_callback( &mut self, callback: impl FnMut(&[u32], &mut [u32]), ) -> Result<Infallible, Error>

Source§

impl<S: InterfaceState> Interface<'_, S>

Source

pub fn sai_rx_config(&self) -> &Config

Source

pub fn sai_tx_config(&self) -> &Config

Auto Trait Implementations§

§

impl<'a, S> !RefUnwindSafe for Interface<'a, S>

§

impl<'a, S> !UnwindSafe for Interface<'a, S>

§

impl<'a, S> Freeze for Interface<'a, S>

§

impl<'a, S> Send for Interface<'a, S>
where S: Send,

§

impl<'a, S> Sync for Interface<'a, S>
where S: Sync,

§

impl<'a, S> Unpin for Interface<'a, S>
where S: Unpin,

§

impl<'a, S> UnsafeUnpin for Interface<'a, S>

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.