aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorhuntc <[email protected]>2022-03-07 12:45:37 +1100
committerhuntc <[email protected]>2022-03-07 14:51:17 +1100
commit3990f09b2927ca8062482680f4caba04e0cb78a7 (patch)
tree37b8743495f27444477f790d2f2838b8ca31b169 /examples
parent98bdac51fe24c48ba097fcba3ec705f9da7df783 (diff)
Simplifies the API by taking in the TIMER and PPI channels
Diffstat (limited to 'examples')
-rw-r--r--examples/nrf/src/bin/saadc_continuous.rs26
1 files changed, 6 insertions, 20 deletions
diff --git a/examples/nrf/src/bin/saadc_continuous.rs b/examples/nrf/src/bin/saadc_continuous.rs
index 991adabad..bdf552fba 100644
--- a/examples/nrf/src/bin/saadc_continuous.rs
+++ b/examples/nrf/src/bin/saadc_continuous.rs
@@ -6,9 +6,8 @@
6mod example_common; 6mod example_common;
7use embassy::executor::Spawner; 7use embassy::executor::Spawner;
8use embassy::time::Duration; 8use embassy::time::Duration;
9use embassy_nrf::ppi::Ppi;
10use embassy_nrf::saadc::{ChannelConfig, Config, Saadc, SamplerState}; 9use embassy_nrf::saadc::{ChannelConfig, Config, Saadc, SamplerState};
11use embassy_nrf::timer::{Frequency, Timer}; 10use embassy_nrf::timer::Frequency;
12use embassy_nrf::{interrupt, Peripherals}; 11use embassy_nrf::{interrupt, Peripherals};
13use example_common::*; 12use example_common::*;
14 13
@@ -27,21 +26,6 @@ async fn main(_spawner: Spawner, mut p: Peripherals) {
27 [channel_1_config, channel_2_config, channel_3_config], 26 [channel_1_config, channel_2_config, channel_3_config],
28 ); 27 );
29 28
30 // We want the task start to effectively short with the last one ending so
31 // we don't miss any samples. The Saadc will trigger the initial TASKS_START.
32 let mut start_ppi = Ppi::new_one_to_one(p.PPI_CH0, saadc.event_end(), saadc.task_start());
33 start_ppi.enable();
34
35 let mut timer = Timer::new(p.TIMER0);
36 timer.set_frequency(Frequency::F1MHz);
37 timer.cc(0).write(1000); // We want to sample at 1KHz
38 timer.cc(0).short_compare_clear();
39
40 let mut sample_ppi =
41 Ppi::new_one_to_one(p.PPI_CH1, timer.cc(0).event_compare(), saadc.task_sample());
42
43 timer.start();
44
45 // This delay demonstrates that starting the timer prior to running 29 // This delay demonstrates that starting the timer prior to running
46 // the task sampler is benign given the calibration that follows. 30 // the task sampler is benign given the calibration that follows.
47 embassy::time::Timer::after(Duration::from_millis(500)).await; 31 embassy::time::Timer::after(Duration::from_millis(500)).await;
@@ -54,10 +38,12 @@ async fn main(_spawner: Spawner, mut p: Peripherals) {
54 38
55 saadc 39 saadc
56 .run_task_sampler( 40 .run_task_sampler(
41 &mut p.TIMER0,
42 &mut p.PPI_CH0,
43 &mut p.PPI_CH1,
44 Frequency::F1MHz,
45 1000, // We want to sample at 1KHz
57 &mut bufs, 46 &mut bufs,
58 || {
59 sample_ppi.enable();
60 },
61 move |buf| { 47 move |buf| {
62 // NOTE: It is important that the time spent within this callback 48 // NOTE: It is important that the time spent within this callback
63 // does not exceed the time taken to acquire the 1500 samples we 49 // does not exceed the time taken to acquire the 1500 samples we