diff options
| author | Jacob Rosenthal <[email protected]> | 2021-10-29 16:39:41 -0700 |
|---|---|---|
| committer | Jacob Rosenthal <[email protected]> | 2021-10-29 16:39:41 -0700 |
| commit | 1d1d8a848e165e2754720fa442571782616cb822 (patch) | |
| tree | 8d01fee0ec241df0e6ff4de6eabbfba61dcba25d | |
| parent | eb0bf1fd7a33330425a12420e5d948ca6e88d74f (diff) | |
simplify api, more interesting example
| -rw-r--r-- | embassy-nrf/src/pwm.rs | 22 | ||||
| -rw-r--r-- | examples/nrf/src/bin/pwm_sequence.rs | 14 |
2 files changed, 10 insertions, 26 deletions
diff --git a/embassy-nrf/src/pwm.rs b/embassy-nrf/src/pwm.rs index ccab6f48d..64b5e5478 100644 --- a/embassy-nrf/src/pwm.rs +++ b/embassy-nrf/src/pwm.rs | |||
| @@ -153,7 +153,6 @@ impl<'d, T: Instance> Pwm<'d, T> { | |||
| 153 | ch2: impl Unborrow<Target = impl GpioOptionalPin> + 'd, | 153 | ch2: impl Unborrow<Target = impl GpioOptionalPin> + 'd, |
| 154 | ch3: impl Unborrow<Target = impl GpioOptionalPin> + 'd, | 154 | ch3: impl Unborrow<Target = impl GpioOptionalPin> + 'd, |
| 155 | config: LoopingConfig, | 155 | config: LoopingConfig, |
| 156 | count: u16, | ||
| 157 | ) -> Result<Self, Error> { | 156 | ) -> Result<Self, Error> { |
| 158 | slice_in_ram_or(config.sequence, Error::DMABufferNotInDataMemory)?; | 157 | slice_in_ram_or(config.sequence, Error::DMABufferNotInDataMemory)?; |
| 159 | 158 | ||
| @@ -163,8 +162,6 @@ impl<'d, T: Instance> Pwm<'d, T> { | |||
| 163 | 162 | ||
| 164 | unborrow!(ch0, ch1, ch2, ch3); | 163 | unborrow!(ch0, ch1, ch2, ch3); |
| 165 | 164 | ||
| 166 | let odd: bool = count & 1 == 1; | ||
| 167 | |||
| 168 | let r = T::regs(); | 165 | let r = T::regs(); |
| 169 | 166 | ||
| 170 | if let Some(pin) = ch0.pin_mut() { | 167 | if let Some(pin) = ch0.pin_mut() { |
| @@ -224,25 +221,12 @@ impl<'d, T: Instance> Pwm<'d, T> { | |||
| 224 | .enddelay | 221 | .enddelay |
| 225 | .write(|w| unsafe { w.bits(config.enddelay) }); | 222 | .write(|w| unsafe { w.bits(config.enddelay) }); |
| 226 | 223 | ||
| 227 | let mut loop_: u16 = count / 2; | 224 | r.loop_.write(|w| unsafe { w.cnt().bits(0x1) }); |
| 228 | if odd { | ||
| 229 | loop_ += 1; | ||
| 230 | } | ||
| 231 | 225 | ||
| 232 | r.loop_.write(|w| unsafe { w.cnt().bits(loop_) }); | 226 | r.shorts.write(|w| w.loopsdone_seqstart1().set_bit()); |
| 233 | |||
| 234 | if odd { | ||
| 235 | r.shorts.write(|w| w.loopsdone_seqstart1().set_bit()); | ||
| 236 | } else { | ||
| 237 | r.shorts.write(|w| w.loopsdone_seqstart0().set_bit()); | ||
| 238 | } | ||
| 239 | 227 | ||
| 240 | // tasks_seqstart doesnt exist in all svds so write its bit instead | 228 | // tasks_seqstart doesnt exist in all svds so write its bit instead |
| 241 | if odd { | 229 | r.tasks_seqstart[1].write(|w| unsafe { w.bits(0x01) }); |
| 242 | r.tasks_seqstart[1].write(|w| unsafe { w.bits(0x01) }); | ||
| 243 | } else { | ||
| 244 | r.tasks_seqstart[0].write(|w| unsafe { w.bits(0x01) }); | ||
| 245 | } | ||
| 246 | 230 | ||
| 247 | Ok(Self { | 231 | Ok(Self { |
| 248 | phantom: PhantomData, | 232 | phantom: PhantomData, |
diff --git a/examples/nrf/src/bin/pwm_sequence.rs b/examples/nrf/src/bin/pwm_sequence.rs index 93ee9f5b2..bc356c28b 100644 --- a/examples/nrf/src/bin/pwm_sequence.rs +++ b/examples/nrf/src/bin/pwm_sequence.rs | |||
| @@ -7,26 +7,26 @@ 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::gpio::NoPin; | ||
| 11 | use embassy_nrf::pwm::{CounterMode, LoopingConfig, Prescaler, Pwm, SequenceLoad}; | 10 | use embassy_nrf::pwm::{CounterMode, LoopingConfig, Prescaler, Pwm, SequenceLoad}; |
| 12 | use embassy_nrf::Peripherals; | 11 | use embassy_nrf::Peripherals; |
| 13 | 12 | ||
| 14 | #[embassy::main] | 13 | #[embassy::main] |
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | 14 | async fn main(_spawner: Spawner, p: Peripherals) { |
| 16 | let seq_values: [u16; 2] = [0, 0x8000]; | 15 | let seq_values: [u16; 16] = [ |
| 17 | 16 | 0x8000, 0, 0, 0, 0, 0x8000, 0, 0, 0, 0, 0x8000, 0, 0, 0, 0, 0x8000, | |
| 17 | ]; | ||
| 18 | let config = LoopingConfig { | 18 | let config = LoopingConfig { |
| 19 | counter_mode: CounterMode::Up, | 19 | counter_mode: CounterMode::Up, |
| 20 | top: 31250, | 20 | top: 15625, |
| 21 | prescaler: Prescaler::Div128, | 21 | prescaler: Prescaler::Div128, |
| 22 | sequence: &seq_values, | 22 | sequence: &seq_values, |
| 23 | sequence_load: SequenceLoad::Common, | 23 | sequence_load: SequenceLoad::Individual, |
| 24 | repeats: 1, | 24 | repeats: 0, |
| 25 | enddelay: 0, | 25 | enddelay: 0, |
| 26 | }; | 26 | }; |
| 27 | 27 | ||
| 28 | let pwm = unwrap!(Pwm::simple_playback( | 28 | let pwm = unwrap!(Pwm::simple_playback( |
| 29 | p.PWM0, p.P0_13, NoPin, NoPin, NoPin, config, 1 | 29 | p.PWM0, p.P0_13, p.P0_15, p.P0_16, p.P0_14, config |
| 30 | )); | 30 | )); |
| 31 | info!("pwm started!"); | 31 | info!("pwm started!"); |
| 32 | 32 | ||
