From f2cfbe42629c74fd53f709ad7187d00b21d7030a Mon Sep 17 00:00:00 2001 From: Jacob Rosenthal <jacobrosenthal@gmail.com> Date: Mon, 1 Nov 2021 13:00:50 -0700 Subject: [PATCH] align pwm.set_duty with embedded hal to not be one shot --- embassy-nrf/src/pwm.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/embassy-nrf/src/pwm.rs b/embassy-nrf/src/pwm.rs index 31e8a3b6..3594e6af 100644 --- a/embassy-nrf/src/pwm.rs +++ b/embassy-nrf/src/pwm.rs @@ -282,8 +282,15 @@ impl<'d, T: Instance> Pwm<'d, T> { let s = T::state(); unsafe { (*s.duty.get())[channel] = duty & 0x7FFF }; + // todo justify? should i fence elsehwere we task start? or compiler_fence(Ordering::SeqCst); - T::regs().tasks_seqstart[0].write(|w| unsafe { w.bits(1) }); + + // play duty cycle infinitely + let r = T::regs(); + r.loop_.write(|w| unsafe { w.cnt().bits(0x1) }); + r.shorts.write(|w| w.loopsdone_seqstart0().enabled()); + // tasks_seqstart doesnt exist in all svds so write its bit instead + r.tasks_seqstart[0].write(|w| unsafe { w.bits(1) }); } /// Sets the PWM clock prescaler.