diff options
| author | Dario Nieuwenhuis <[email protected]> | 2021-10-11 00:45:49 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-10-11 00:45:49 +0200 |
| commit | 902f566b9a338f80520b4f1110f09f9401109b81 (patch) | |
| tree | e1d39b0c383098d8b77b85e5e94c7ebb624494f3 /examples | |
| parent | 1c4c813255d39c9b517a0b6c5cc905df1c6aa565 (diff) | |
| parent | 8c9e50b37871368c31ed23208329fbe28bcc0a7e (diff) | |
Merge pull request #417 from huntc/extend-saadc
Extend SAADC one shot support
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/nrf/src/bin/saadc.rs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/examples/nrf/src/bin/saadc.rs b/examples/nrf/src/bin/saadc.rs index c4d23360e..d12717c04 100644 --- a/examples/nrf/src/bin/saadc.rs +++ b/examples/nrf/src/bin/saadc.rs | |||
| @@ -7,18 +7,20 @@ mod example_common; | |||
| 7 | use defmt::panic; | 7 | use defmt::panic; |
| 8 | use embassy::executor::Spawner; | 8 | use embassy::executor::Spawner; |
| 9 | use embassy::time::{Duration, Timer}; | 9 | use embassy::time::{Duration, Timer}; |
| 10 | use embassy_nrf::saadc::{Config, OneShot}; | 10 | use embassy_nrf::saadc::{ChannelConfig, Config, OneShot}; |
| 11 | use embassy_nrf::{interrupt, Peripherals}; | 11 | use embassy_nrf::{interrupt, Peripherals}; |
| 12 | use example_common::*; | 12 | use example_common::*; |
| 13 | 13 | ||
| 14 | #[embassy::main] | 14 | #[embassy::main] |
| 15 | async fn main(_spawner: Spawner, mut p: Peripherals) { | 15 | async fn main(_spawner: Spawner, mut p: Peripherals) { |
| 16 | let config = Config::default(); | 16 | let config = Config::default(); |
| 17 | let mut saadc = OneShot::new(p.SAADC, interrupt::take!(SAADC), config); | 17 | let channel_config = ChannelConfig::single_ended(&mut p.P0_02); |
| 18 | let mut saadc = OneShot::new(p.SAADC, interrupt::take!(SAADC), config, [channel_config]); | ||
| 18 | 19 | ||
| 19 | loop { | 20 | loop { |
| 20 | let sample = saadc.sample(&mut p.P0_02).await; | 21 | let mut buf = [0; 1]; |
| 21 | info!("sample: {=i16}", sample); | 22 | saadc.sample(&mut buf).await; |
| 23 | info!("sample: {=i16}", &buf[0]); | ||
| 22 | Timer::after(Duration::from_millis(100)).await; | 24 | Timer::after(Duration::from_millis(100)).await; |
| 23 | } | 25 | } |
| 24 | } | 26 | } |
