pub struct Pdm<'d, T: Instance> { /* private fields */ }
Expand description
PDM microphone interface
Implementations§
Source§impl<'d, T: Instance> Pdm<'d, T>
impl<'d, T: Instance> Pdm<'d, T>
Sourcepub fn new(
pdm: impl Peripheral<P = T> + 'd,
_irq: impl Binding<T::Interrupt, InterruptHandler<T>> + 'd,
clk: impl Peripheral<P = impl GpioPin> + 'd,
din: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
) -> Self
pub fn new( pdm: impl Peripheral<P = T> + 'd, _irq: impl Binding<T::Interrupt, InterruptHandler<T>> + 'd, clk: impl Peripheral<P = impl GpioPin> + 'd, din: impl Peripheral<P = impl GpioPin> + 'd, config: Config, ) -> Self
Create PDM driver
Sourcepub fn set_gain(&mut self, gain_left: I7F1, gain_right: I7F1)
pub fn set_gain(&mut self, gain_left: I7F1, gain_right: I7F1)
Adjust the gain of the PDM microphone on the fly
Sourcepub async fn start(&mut self)
pub async fn start(&mut self)
Start sampling microphone data into a dummy buffer. Useful to start the microphone and keep it active between recording samples.
Sourcepub async fn sample(&mut self, buffer: &mut [i16]) -> Result<(), Error>
pub async fn sample(&mut self, buffer: &mut [i16]) -> Result<(), Error>
Sample data into the given buffer
Sourcepub async fn run_task_sampler<S, const N: usize>(
&mut self,
bufs: &mut [[i16; N]; 2],
sampler: S,
) -> Result<(), Error>
pub async fn run_task_sampler<S, const N: usize>( &mut self, bufs: &mut [[i16; N]; 2], sampler: S, ) -> Result<(), Error>
Continuous sampling with double buffers.
A sampler closure is provided that receives the buffer of samples, noting that the size of this buffer can be less than the original buffer’s size. A command is return from the closure that indicates whether the sampling should continue or stop.
NOTE: The time spent within the callback supplied should not exceed the time taken to acquire the samples into a single buffer. You should measure the time taken by the callback and set the sample buffer size accordingly. Exceeding this time can lead to samples becoming dropped.