pub struct Saadc<'d, const N: usize> { /* private fields */ }
Expand description
One-shot and continuous SAADC.
Implementations§
Source§impl<'d, const N: usize> Saadc<'d, N>
impl<'d, const N: usize> Saadc<'d, N>
Sourcepub fn new(
saadc: impl Peripheral<P = SAADC> + 'd,
_irq: impl Binding<SAADC, InterruptHandler> + 'd,
config: Config,
channel_configs: [ChannelConfig<'_>; N],
) -> Self
pub fn new( saadc: impl Peripheral<P = SAADC> + 'd, _irq: impl Binding<SAADC, InterruptHandler> + 'd, config: Config, channel_configs: [ChannelConfig<'_>; N], ) -> Self
Create a new SAADC driver.
Sourcepub async fn sample(&mut self, buf: &mut [i16; N])
pub async fn sample(&mut self, buf: &mut [i16; N])
One shot sampling. The buffer must be the same size as the number of channels configured. The sampling is stopped prior to returning in order to reduce power consumption (power consumption remains higher if sampling is not stopped explicitly). Cancellation will also cause the sampling to be stopped.
Sourcepub async fn run_task_sampler<F, T: TimerInstance, const N0: usize>(
&mut self,
timer: &mut T,
ppi_ch1: &mut impl ConfigurableChannel,
ppi_ch2: &mut impl ConfigurableChannel,
frequency: Frequency,
sample_counter: u32,
bufs: &mut [[[i16; N]; N0]; 2],
callback: F,
)
pub async fn run_task_sampler<F, T: TimerInstance, const N0: usize>( &mut self, timer: &mut T, ppi_ch1: &mut impl ConfigurableChannel, ppi_ch2: &mut impl ConfigurableChannel, frequency: Frequency, sample_counter: u32, bufs: &mut [[[i16; N]; N0]; 2], callback: F, )
Continuous sampling with double buffers.
A TIMER and two PPI peripherals are passed in so that precise sampling can be attained. The sampling interval is expressed by selecting a timer clock frequency to use along with a counter threshold to be reached. For example, 1KHz can be achieved using a frequency of 1MHz and a counter threshold of 1000.
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.
The sampling is stopped prior to returning in order to reduce power consumption (power consumption remains higher if sampling is not stopped explicitly), and to free the buffers from being used by the peripheral. Cancellation will also cause the sampling to be stopped.
Source§impl<'d> Saadc<'d, 1>
impl<'d> Saadc<'d, 1>
Sourcepub async fn run_timer_sampler<I, S, const N0: usize>(
&mut self,
bufs: &mut [[[i16; 1]; N0]; 2],
sample_rate_divisor: u16,
sampler: S,
)
pub async fn run_timer_sampler<I, S, const N0: usize>( &mut self, bufs: &mut [[[i16; 1]; N0]; 2], sample_rate_divisor: u16, sampler: S, )
Continuous sampling on a single channel with double buffers.
The internal clock is to be used with a sample rate expressed as a divisor of 16MHz, ranging from 80..2047. For example, 1600 represents a sample rate of 10KHz given 16_000_000 / 10_000_000 = 1600.
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.