aboutsummaryrefslogtreecommitdiff
path: root/examples/nrf/src/bin/pwm_sequence.rs
diff options
context:
space:
mode:
authorhuntc <[email protected]>2022-01-30 16:21:23 +1100
committerhuntc <[email protected]>2022-01-30 16:21:23 +1100
commit1c67bd46433734d9280e976da33975cf5beb773e (patch)
treea832657ca21a0446769a6c39faedce33045ce9ee /examples/nrf/src/bin/pwm_sequence.rs
parent482389a6911d8d3505872e6ad03d5b0af565eaf9 (diff)
Revert "Own the sequence buffer"
This reverts commit 482389a6911d8d3505872e6ad03d5b0af565eaf9.
Diffstat (limited to 'examples/nrf/src/bin/pwm_sequence.rs')
-rw-r--r--examples/nrf/src/bin/pwm_sequence.rs22
1 files changed, 14 insertions, 8 deletions
diff --git a/examples/nrf/src/bin/pwm_sequence.rs b/examples/nrf/src/bin/pwm_sequence.rs
index 6fe957d24..6fb861e8f 100644
--- a/examples/nrf/src/bin/pwm_sequence.rs
+++ b/examples/nrf/src/bin/pwm_sequence.rs
@@ -8,13 +8,14 @@ use defmt::*;
8use embassy::executor::Spawner; 8use embassy::executor::Spawner;
9use embassy::time::{Duration, Timer}; 9use embassy::time::{Duration, Timer};
10use embassy_nrf::gpio::NoPin; 10use embassy_nrf::gpio::NoPin;
11use embassy_nrf::pwm::{ 11use embassy_nrf::pwm::{Config, Prescaler, Sequence, SequenceConfig, SequenceMode, SequencePwm};
12 Config, Prescaler, Sequence, SequenceConfig, SequenceMode, SequencePwm, EMPTY_SEQ,
13};
14use embassy_nrf::Peripherals; 12use embassy_nrf::Peripherals;
15 13
16#[embassy::main] 14#[embassy::main]
17async fn main(_spawner: Spawner, p: Peripherals) { 15async fn main(_spawner: Spawner, p: Peripherals) {
16 let mut seq_words_1: [u16; 5] = [1000, 250, 100, 50, 0];
17 let mut seq_words_2: [u16; 5] = [0, 50, 100, 250, 1000];
18
18 let mut config = Config::default(); 19 let mut config = Config::default();
19 config.prescaler = Prescaler::Div128; 20 config.prescaler = Prescaler::Div128;
20 // 1 period is 1000 * (128/16mhz = 0.000008s = 0.008ms) = 8us 21 // 1 period is 1000 * (128/16mhz = 0.000008s = 0.008ms) = 8us
@@ -25,20 +26,25 @@ async fn main(_spawner: Spawner, p: Peripherals) {
25 seq_config.refresh = 624; 26 seq_config.refresh = 624;
26 // thus our sequence takes 5 * 5000ms or 25 seconds 27 // thus our sequence takes 5 * 5000ms or 25 seconds
27 28
28 let seq_1 = Sequence::new([1000, 250, 100, 50, 0], seq_config.clone());
29 let seq_2 = Sequence::new([0, 50, 100, 250, 1000], seq_config);
30
31 let mut pwm = unwrap!(SequencePwm::new( 29 let mut pwm = unwrap!(SequencePwm::new(
32 p.PWM0, p.P0_13, NoPin, NoPin, NoPin, config, 30 p.PWM0, p.P0_13, NoPin, NoPin, NoPin, config,
33 )); 31 ));
34 unwrap!(pwm.start(seq_1, EMPTY_SEQ, SequenceMode::Times(1))); 32 let _ = pwm.start(
33 Sequence::new(&mut seq_words_1, seq_config.clone()),
34 None,
35 SequenceMode::Infinite,
36 );
35 37
36 info!("pwm started!"); 38 info!("pwm started!");
37 39
38 Timer::after(Duration::from_millis(20000)).await; 40 Timer::after(Duration::from_millis(20000)).await;
39 info!("pwm starting with another sequence!"); 41 info!("pwm starting with another sequence!");
40 42
41 unwrap!(pwm.start(seq_2, EMPTY_SEQ, SequenceMode::Times(1))); 43 let _ = pwm.start(
44 Sequence::new(&mut seq_words_2, seq_config),
45 None,
46 SequenceMode::Infinite,
47 );
42 48
43 // we can abort a sequence if we need to before its complete with pwm.stop() 49 // we can abort a sequence if we need to before its complete with pwm.stop()
44 // or stop is also implicitly called when the pwm peripheral is dropped 50 // or stop is also implicitly called when the pwm peripheral is dropped