Extend SAADC one shot support

One-shot mode now permits the sampling of differential pins, and the sampling of multiple pins simultaneously.

A new ChannelConfig structure has been introduced so that multiple channels can be configured individually. Further, the `sample` method now accepts a buffer into which samples are written.

Along the way, I've reset some default configuration to align with Nordic's settings in their nrfx saadc driver. Specifically, the channel gain defaults to 6 (from 4) and the time defaults to 10us (from 20us).
This commit is contained in:
huntc
2021-10-07 18:00:03 +11:00
parent 009b77c1b9
commit cef6158c31
3 changed files with 145 additions and 44 deletions

View File

@ -7,18 +7,20 @@ mod example_common;
use defmt::panic;
use embassy::executor::Spawner;
use embassy::time::{Duration, Timer};
use embassy_nrf::saadc::{Config, OneShot};
use embassy_nrf::saadc::{ChannelConfig, Config, OneShot};
use embassy_nrf::{interrupt, Peripherals};
use example_common::*;
#[embassy::main]
async fn main(_spawner: Spawner, mut p: Peripherals) {
let config = Config::default();
let mut saadc = OneShot::new(p.SAADC, interrupt::take!(SAADC), config);
let channel_config = ChannelConfig::single_ended(&mut p.P0_02);
let mut saadc = OneShot::new(p.SAADC, interrupt::take!(SAADC), config, [channel_config]);
loop {
let sample = saadc.sample(&mut p.P0_02).await;
info!("sample: {=i16}", sample);
let mut buf = [0; 1];
saadc.sample(&mut buf).await;
info!("sample: {=i16}", &buf[0]);
Timer::after(Duration::from_millis(100)).await;
}
}