diff --git a/embassy-nrf/src/pwm.rs b/embassy-nrf/src/pwm.rs index ccab6f48..64b5e547 100644 --- a/embassy-nrf/src/pwm.rs +++ b/embassy-nrf/src/pwm.rs @@ -153,7 +153,6 @@ impl<'d, T: Instance> Pwm<'d, T> { ch2: impl Unborrow + 'd, ch3: impl Unborrow + 'd, config: LoopingConfig, - count: u16, ) -> Result { slice_in_ram_or(config.sequence, Error::DMABufferNotInDataMemory)?; @@ -163,8 +162,6 @@ impl<'d, T: Instance> Pwm<'d, T> { unborrow!(ch0, ch1, ch2, ch3); - let odd: bool = count & 1 == 1; - let r = T::regs(); if let Some(pin) = ch0.pin_mut() { @@ -224,25 +221,12 @@ impl<'d, T: Instance> Pwm<'d, T> { .enddelay .write(|w| unsafe { w.bits(config.enddelay) }); - let mut loop_: u16 = count / 2; - if odd { - loop_ += 1; - } + r.loop_.write(|w| unsafe { w.cnt().bits(0x1) }); - r.loop_.write(|w| unsafe { w.cnt().bits(loop_) }); - - if odd { - r.shorts.write(|w| w.loopsdone_seqstart1().set_bit()); - } else { - r.shorts.write(|w| w.loopsdone_seqstart0().set_bit()); - } + r.shorts.write(|w| w.loopsdone_seqstart1().set_bit()); // tasks_seqstart doesnt exist in all svds so write its bit instead - if odd { - r.tasks_seqstart[1].write(|w| unsafe { w.bits(0x01) }); - } else { - r.tasks_seqstart[0].write(|w| unsafe { w.bits(0x01) }); - } + r.tasks_seqstart[1].write(|w| unsafe { w.bits(0x01) }); Ok(Self { phantom: PhantomData, diff --git a/examples/nrf/src/bin/pwm_sequence.rs b/examples/nrf/src/bin/pwm_sequence.rs index 93ee9f5b..bc356c28 100644 --- a/examples/nrf/src/bin/pwm_sequence.rs +++ b/examples/nrf/src/bin/pwm_sequence.rs @@ -7,26 +7,26 @@ mod example_common; use defmt::*; use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; -use embassy_nrf::gpio::NoPin; use embassy_nrf::pwm::{CounterMode, LoopingConfig, Prescaler, Pwm, SequenceLoad}; use embassy_nrf::Peripherals; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { - let seq_values: [u16; 2] = [0, 0x8000]; - + let seq_values: [u16; 16] = [ + 0x8000, 0, 0, 0, 0, 0x8000, 0, 0, 0, 0, 0x8000, 0, 0, 0, 0, 0x8000, + ]; let config = LoopingConfig { counter_mode: CounterMode::Up, - top: 31250, + top: 15625, prescaler: Prescaler::Div128, sequence: &seq_values, - sequence_load: SequenceLoad::Common, - repeats: 1, + sequence_load: SequenceLoad::Individual, + repeats: 0, enddelay: 0, }; let pwm = unwrap!(Pwm::simple_playback( - p.PWM0, p.P0_13, NoPin, NoPin, NoPin, config, 1 + p.PWM0, p.P0_13, p.P0_15, p.P0_16, p.P0_14, config )); info!("pwm started!");