diff options
| author | Jacob Rosenthal <[email protected]> | 2021-10-26 00:37:52 -0700 |
|---|---|---|
| committer | Jacob Rosenthal <[email protected]> | 2021-10-29 16:27:26 -0700 |
| commit | eb0bf1fd7a33330425a12420e5d948ca6e88d74f (patch) | |
| tree | d1d93ce868c98f6411b5fa6881a6f54c43a24f30 /examples | |
| parent | dfccb84fcbb9ab55c3d0f89d99d2049376bff901 (diff) | |
simple_playback api from nrf sdk
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/nrf/src/bin/pwm_sequence.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/examples/nrf/src/bin/pwm_sequence.rs b/examples/nrf/src/bin/pwm_sequence.rs new file mode 100644 index 000000000..93ee9f5b2 --- /dev/null +++ b/examples/nrf/src/bin/pwm_sequence.rs | |||
| @@ -0,0 +1,41 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | #[path = "../example_common.rs"] | ||
| 6 | mod example_common; | ||
| 7 | use defmt::*; | ||
| 8 | use embassy::executor::Spawner; | ||
| 9 | use embassy::time::{Duration, Timer}; | ||
| 10 | use embassy_nrf::gpio::NoPin; | ||
| 11 | use embassy_nrf::pwm::{CounterMode, LoopingConfig, Prescaler, Pwm, SequenceLoad}; | ||
| 12 | use embassy_nrf::Peripherals; | ||
| 13 | |||
| 14 | #[embassy::main] | ||
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 16 | let seq_values: [u16; 2] = [0, 0x8000]; | ||
| 17 | |||
| 18 | let config = LoopingConfig { | ||
| 19 | counter_mode: CounterMode::Up, | ||
| 20 | top: 31250, | ||
| 21 | prescaler: Prescaler::Div128, | ||
| 22 | sequence: &seq_values, | ||
| 23 | sequence_load: SequenceLoad::Common, | ||
| 24 | repeats: 1, | ||
| 25 | enddelay: 0, | ||
| 26 | }; | ||
| 27 | |||
| 28 | let pwm = unwrap!(Pwm::simple_playback( | ||
| 29 | p.PWM0, p.P0_13, NoPin, NoPin, NoPin, config, 1 | ||
| 30 | )); | ||
| 31 | info!("pwm started!"); | ||
| 32 | |||
| 33 | Timer::after(Duration::from_millis(10000)).await; | ||
| 34 | |||
| 35 | pwm.stop(); | ||
| 36 | info!("pwm stopped!"); | ||
| 37 | |||
| 38 | loop { | ||
| 39 | Timer::after(Duration::from_millis(1000)).await; | ||
| 40 | } | ||
| 41 | } | ||
