diff options
| author | Jacob Rosenthal <[email protected]> | 2021-11-01 08:54:07 -0700 |
|---|---|---|
| committer | Jacob Rosenthal <[email protected]> | 2021-11-01 08:54:07 -0700 |
| commit | 12b2c5d5f70b836c853c000f036df2bdc255098d (patch) | |
| tree | 682111848ac6e510789c6739d56d60b31891d3dd /examples | |
| parent | 90be851e4b52703b4297615253bc7a89fdd03b9f (diff) | |
better not as a constructor?
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/nrf/src/bin/pwm_sequence.rs | 11 | ||||
| -rw-r--r-- | examples/nrf/src/bin/pwm_simple_sin.rs | 11 |
2 files changed, 10 insertions, 12 deletions
diff --git a/examples/nrf/src/bin/pwm_sequence.rs b/examples/nrf/src/bin/pwm_sequence.rs index 40ba7ab1c..066ab3c03 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, LoopMode, LoopingConfig, Prescaler, Pwm, SequenceLoad}; | 10 | use embassy_nrf::pwm::{CounterMode, Prescaler, Pwm, SequenceConfig, SequenceLoad, SequenceMode}; |
| 11 | use embassy_nrf::Peripherals; | 11 | use embassy_nrf::Peripherals; |
| 12 | 12 | ||
| 13 | #[embassy::main] | 13 | #[embassy::main] |
| @@ -16,7 +16,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 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 | ||
| 19 | let config = LoopingConfig { | 19 | let config = SequenceConfig { |
| 20 | counter_mode: CounterMode::Up, | 20 | counter_mode: CounterMode::Up, |
| 21 | top: 15625, | 21 | top: 15625, |
| 22 | prescaler: Prescaler::Div128, | 22 | prescaler: Prescaler::Div128, |
| @@ -24,12 +24,11 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 24 | sequence_load: SequenceLoad::Individual, | 24 | sequence_load: SequenceLoad::Individual, |
| 25 | refresh: 0, | 25 | refresh: 0, |
| 26 | end_delay: 0, | 26 | end_delay: 0, |
| 27 | times: LoopMode::Times(5), | 27 | times: SequenceMode::Times(5), |
| 28 | }; | 28 | }; |
| 29 | 29 | ||
| 30 | let _pwm = unwrap!(Pwm::simple_playback( | 30 | let pwm = Pwm::new(p.PWM0, p.P0_13, p.P0_15, p.P0_16, p.P0_14); |
| 31 | p.PWM0, p.P0_13, p.P0_15, p.P0_16, p.P0_14, config | 31 | unwrap!(pwm.play_sequence(config)); |
| 32 | )); | ||
| 33 | info!("pwm started!"); | 32 | info!("pwm started!"); |
| 34 | 33 | ||
| 35 | loop { | 34 | loop { |
diff --git a/examples/nrf/src/bin/pwm_simple_sin.rs b/examples/nrf/src/bin/pwm_simple_sin.rs index c1af0db8c..3c1bddbc7 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, LoopMode, LoopingConfig, Prescaler, Pwm, SequenceLoad}; | 12 | use embassy_nrf::pwm::{CounterMode, Prescaler, Pwm, SequenceConfig, SequenceLoad, SequenceMode}; |
| 13 | use embassy_nrf::Peripherals; | 13 | use embassy_nrf::Peripherals; |
| 14 | use micromath::F32Ext; | 14 | use micromath::F32Ext; |
| 15 | 15 | ||
| @@ -20,7 +20,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 20 | // probably not best use of resources to create the table at runtime, but makes testing fast | 20 | // probably not best use of resources to create the table at runtime, but makes testing fast |
| 21 | let seq_values: [u16; 220] = core::array::from_fn(|n| ((W1 * n as f32).sin() * 10000.0) as u16); | 21 | let seq_values: [u16; 220] = core::array::from_fn(|n| ((W1 * n as f32).sin() * 10000.0) as u16); |
| 22 | 22 | ||
| 23 | let config = LoopingConfig { | 23 | let config = SequenceConfig { |
| 24 | counter_mode: CounterMode::UpAndDown, | 24 | counter_mode: CounterMode::UpAndDown, |
| 25 | top: 12000, | 25 | top: 12000, |
| 26 | prescaler: Prescaler::Div16, | 26 | prescaler: Prescaler::Div16, |
| @@ -28,12 +28,11 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 28 | sequence_load: SequenceLoad::Common, | 28 | sequence_load: SequenceLoad::Common, |
| 29 | refresh: 0, | 29 | refresh: 0, |
| 30 | end_delay: 0, | 30 | end_delay: 0, |
| 31 | times: LoopMode::Infinite, | 31 | times: SequenceMode::Infinite, |
| 32 | }; | 32 | }; |
| 33 | 33 | ||
| 34 | let pwm = unwrap!(Pwm::simple_playback( | 34 | let pwm = Pwm::new(p.PWM0, p.P0_13, NoPin, NoPin, NoPin); |
| 35 | p.PWM0, p.P0_13, NoPin, NoPin, NoPin, config | 35 | unwrap!(pwm.play_sequence(config)); |
| 36 | )); | ||
| 37 | info!("pwm started!"); | 36 | info!("pwm started!"); |
| 38 | 37 | ||
| 39 | Timer::after(Duration::from_millis(20000)).await; | 38 | Timer::after(Duration::from_millis(20000)).await; |
