aboutsummaryrefslogtreecommitdiff
path: root/examples/nrf/src/bin/pwm_sequence_ppi.rs
diff options
context:
space:
mode:
authorhuntc <[email protected]>2022-02-04 16:26:23 +1100
committerhuntc <[email protected]>2022-02-04 16:26:23 +1100
commitfe5501293f39307fbfa419d6f882f4a2cd10c115 (patch)
tree301798af1dbcb2fe7d9296c1ba1a79ca1890831a /examples/nrf/src/bin/pwm_sequence_ppi.rs
parent25be00878c44550a7ecbb6f6501490dba770c20e (diff)
Expose PWM
Diffstat (limited to 'examples/nrf/src/bin/pwm_sequence_ppi.rs')
-rw-r--r--examples/nrf/src/bin/pwm_sequence_ppi.rs19
1 files changed, 10 insertions, 9 deletions
diff --git a/examples/nrf/src/bin/pwm_sequence_ppi.rs b/examples/nrf/src/bin/pwm_sequence_ppi.rs
index f5d734bb1..593e7590d 100644
--- a/examples/nrf/src/bin/pwm_sequence_ppi.rs
+++ b/examples/nrf/src/bin/pwm_sequence_ppi.rs
@@ -11,12 +11,14 @@ use embassy::executor::Spawner;
11use embassy_nrf::gpio::{Input, NoPin, Pull}; 11use embassy_nrf::gpio::{Input, NoPin, Pull};
12use embassy_nrf::gpiote::{InputChannel, InputChannelPolarity}; 12use embassy_nrf::gpiote::{InputChannel, InputChannelPolarity};
13use embassy_nrf::ppi::Ppi; 13use embassy_nrf::ppi::Ppi;
14use embassy_nrf::pwm::{Config, Prescaler, Sequence, SequenceConfig, SequenceMode, SequencePwm}; 14use embassy_nrf::pwm::{
15 Config, Prescaler, Sequence, SequenceConfig, SequenceMode, SequencePwm, Sequences,
16};
15use embassy_nrf::Peripherals; 17use embassy_nrf::Peripherals;
16 18
17#[embassy::main] 19#[embassy::main]
18async fn main(_spawner: Spawner, p: Peripherals) { 20async fn main(_spawner: Spawner, p: Peripherals) {
19 let mut seq_words: [u16; 5] = [1000, 250, 100, 50, 0]; 21 let seq_words: [u16; 5] = [1000, 250, 100, 50, 0];
20 22
21 let mut config = Config::default(); 23 let mut config = Config::default();
22 config.prescaler = Prescaler::Div128; 24 config.prescaler = Prescaler::Div128;
@@ -31,11 +33,10 @@ async fn main(_spawner: Spawner, p: Peripherals) {
31 p.PWM0, p.P0_13, NoPin, NoPin, NoPin, config, 33 p.PWM0, p.P0_13, NoPin, NoPin, NoPin, config,
32 )); 34 ));
33 35
34 let _ = pwm.start( 36 let sequence0 = Sequence::new(&seq_words, seq_config);
35 Sequence::new(&mut seq_words, seq_config), 37 let sequences = Sequences::new(&mut pwm, sequence0, None);
36 None, 38 unwrap!(sequences.start(SequenceMode::Infinite));
37 SequenceMode::Infinite, 39
38 );
39 // pwm.stop() deconfigures pins, and then the task_start_seq0 task cant work 40 // pwm.stop() deconfigures pins, and then the task_start_seq0 task cant work
40 // so its going to have to start running in order load the configuration 41 // so its going to have to start running in order load the configuration
41 42
@@ -53,8 +54,8 @@ async fn main(_spawner: Spawner, p: Peripherals) {
53 54
54 // messing with the pwm tasks is ill advised 55 // messing with the pwm tasks is ill advised
55 // Times::Ininite and Times even are seq0, Times odd is seq1 56 // Times::Ininite and Times even are seq0, Times odd is seq1
56 let start = unsafe { pwm.task_start_seq0() }; 57 let start = unsafe { sequences.pwm.task_start_seq0() };
57 let stop = unsafe { pwm.task_stop() }; 58 let stop = unsafe { sequences.pwm.task_stop() };
58 59
59 let mut ppi = Ppi::new_one_to_one(p.PPI_CH1, button1.event_in(), start); 60 let mut ppi = Ppi::new_one_to_one(p.PPI_CH1, button1.event_in(), start);
60 ppi.enable(); 61 ppi.enable();