diff options
| author | Jacob Rosenthal <[email protected]> | 2021-10-30 16:16:10 -0700 |
|---|---|---|
| committer | Jacob Rosenthal <[email protected]> | 2021-10-30 16:16:10 -0700 |
| commit | 763e250dfea4425912674ed68d77c3291b0505e0 (patch) | |
| tree | dc6acf87b672b30c2866760b99267bc7bb0043c4 /examples | |
| parent | ee8f76537b2dd8e886f44bd7e43d4ba9fd767778 (diff) | |
add ability to configure loop count from 1 to infinite
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/nrf/src/bin/pwm_sequence.rs | 13 | ||||
| -rw-r--r-- | examples/nrf/src/bin/pwm_simple_sin.rs | 12 |
2 files changed, 14 insertions, 11 deletions
diff --git a/examples/nrf/src/bin/pwm_sequence.rs b/examples/nrf/src/bin/pwm_sequence.rs index bc356c28b..8b7aeddcd 100644 --- a/examples/nrf/src/bin/pwm_sequence.rs +++ b/examples/nrf/src/bin/pwm_sequence.rs | |||
| @@ -7,7 +7,7 @@ mod example_common; | |||
| 7 | use defmt::*; | 7 | use defmt::*; |
| 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::pwm::{CounterMode, LoopingConfig, Prescaler, Pwm, SequenceLoad}; | 10 | use embassy_nrf::pwm::{CounterMode, LoopMode, LoopingConfig, Prescaler, Pwm, SequenceLoad}; |
| 11 | use embassy_nrf::Peripherals; | 11 | use embassy_nrf::Peripherals; |
| 12 | 12 | ||
| 13 | #[embassy::main] | 13 | #[embassy::main] |
| @@ -15,26 +15,23 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 15 | let seq_values: [u16; 16] = [ | 15 | let seq_values: [u16; 16] = [ |
| 16 | 0x8000, 0, 0, 0, 0, 0x8000, 0, 0, 0, 0, 0x8000, 0, 0, 0, 0, 0x8000, | 16 | 0x8000, 0, 0, 0, 0, 0x8000, 0, 0, 0, 0, 0x8000, 0, 0, 0, 0, 0x8000, |
| 17 | ]; | 17 | ]; |
| 18 | |||
| 18 | let config = LoopingConfig { | 19 | let config = LoopingConfig { |
| 19 | counter_mode: CounterMode::Up, | 20 | counter_mode: CounterMode::Up, |
| 20 | top: 15625, | 21 | top: 15625, |
| 21 | prescaler: Prescaler::Div128, | 22 | prescaler: Prescaler::Div128, |
| 22 | sequence: &seq_values, | 23 | sequence: &seq_values, |
| 23 | sequence_load: SequenceLoad::Individual, | 24 | sequence_load: SequenceLoad::Individual, |
| 24 | repeats: 0, | 25 | refresh: 0, |
| 25 | enddelay: 0, | 26 | enddelay: 0, |
| 27 | additional_loops: LoopMode::Additional(5), | ||
| 26 | }; | 28 | }; |
| 27 | 29 | ||
| 28 | let pwm = unwrap!(Pwm::simple_playback( | 30 | let _pwm = unwrap!(Pwm::simple_playback( |
| 29 | p.PWM0, p.P0_13, p.P0_15, p.P0_16, p.P0_14, config | 31 | p.PWM0, p.P0_13, p.P0_15, p.P0_16, p.P0_14, config |
| 30 | )); | 32 | )); |
| 31 | info!("pwm started!"); | 33 | info!("pwm started!"); |
| 32 | 34 | ||
| 33 | Timer::after(Duration::from_millis(10000)).await; | ||
| 34 | |||
| 35 | pwm.stop(); | ||
| 36 | info!("pwm stopped!"); | ||
| 37 | |||
| 38 | loop { | 35 | loop { |
| 39 | Timer::after(Duration::from_millis(1000)).await; | 36 | Timer::after(Duration::from_millis(1000)).await; |
| 40 | } | 37 | } |
diff --git a/examples/nrf/src/bin/pwm_simple_sin.rs b/examples/nrf/src/bin/pwm_simple_sin.rs index 866202a4c..3fbfc960f 100644 --- a/examples/nrf/src/bin/pwm_simple_sin.rs +++ b/examples/nrf/src/bin/pwm_simple_sin.rs | |||
| @@ -9,7 +9,7 @@ use defmt::*; | |||
| 9 | use embassy::executor::Spawner; | 9 | use embassy::executor::Spawner; |
| 10 | use embassy::time::{Duration, Timer}; | 10 | use embassy::time::{Duration, Timer}; |
| 11 | use embassy_nrf::gpio::NoPin; | 11 | use embassy_nrf::gpio::NoPin; |
| 12 | use embassy_nrf::pwm::{CounterMode, LoopingConfig, Prescaler, Pwm, SequenceLoad}; | 12 | use embassy_nrf::pwm::{CounterMode, LoopMode, LoopingConfig, Prescaler, Pwm, SequenceLoad}; |
| 13 | use embassy_nrf::Peripherals; | 13 | use embassy_nrf::Peripherals; |
| 14 | use micromath::F32Ext; | 14 | use micromath::F32Ext; |
| 15 | 15 | ||
| @@ -26,15 +26,21 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 26 | prescaler: Prescaler::Div16, | 26 | prescaler: Prescaler::Div16, |
| 27 | sequence: &seq_values, | 27 | sequence: &seq_values, |
| 28 | sequence_load: SequenceLoad::Common, | 28 | sequence_load: SequenceLoad::Common, |
| 29 | repeats: 0, | 29 | refresh: 0, |
| 30 | enddelay: 0, | 30 | enddelay: 0, |
| 31 | additional_loops: LoopMode::Infinite, | ||
| 31 | }; | 32 | }; |
| 32 | 33 | ||
| 33 | let _pwm = unwrap!(Pwm::simple_playback( | 34 | let pwm = unwrap!(Pwm::simple_playback( |
| 34 | p.PWM0, p.P0_13, NoPin, NoPin, NoPin, config | 35 | p.PWM0, p.P0_13, NoPin, NoPin, NoPin, config |
| 35 | )); | 36 | )); |
| 36 | info!("pwm started!"); | 37 | info!("pwm started!"); |
| 37 | 38 | ||
| 39 | Timer::after(Duration::from_millis(20000)).await; | ||
| 40 | |||
| 41 | pwm.stop(); | ||
| 42 | info!("pwm stopped!"); | ||
| 43 | |||
| 38 | loop { | 44 | loop { |
| 39 | Timer::after(Duration::from_millis(1000)).await; | 45 | Timer::after(Duration::from_millis(1000)).await; |
| 40 | } | 46 | } |
