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()beforestart_callback(). - Keep callback and error-handling routines short to prevent SAI overruns.
Implementations§
Source§impl<'a> Interface<'a, Idle>
impl<'a> Interface<'a, Idle>
Sourcepub async fn start_interface(self) -> Result<Interface<'a, Running>, Error>
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.