From 6d8198a46ae20be24c84fbb07d474d4eb507ac4d Mon Sep 17 00:00:00 2001 From: Jacob Rosenthal Date: Sat, 30 Oct 2021 11:33:10 -0700 Subject: [PATCH] move psel back out of if --- embassy-nrf/src/pwm.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/embassy-nrf/src/pwm.rs b/embassy-nrf/src/pwm.rs index 64b5e5478..d834b1303 100644 --- a/embassy-nrf/src/pwm.rs +++ b/embassy-nrf/src/pwm.rs @@ -167,24 +167,28 @@ impl<'d, T: Instance> Pwm<'d, T> { if let Some(pin) = ch0.pin_mut() { pin.set_low(); pin.conf().write(|w| w.dir().output()); - r.psel.out[0].write(|w| unsafe { w.bits(ch0.psel_bits()) }); } + if let Some(pin) = ch1.pin_mut() { pin.set_low(); pin.conf().write(|w| w.dir().output()); - r.psel.out[1].write(|w| unsafe { w.bits(ch1.psel_bits()) }); } if let Some(pin) = ch2.pin_mut() { pin.set_low(); pin.conf().write(|w| w.dir().output()); - r.psel.out[2].write(|w| unsafe { w.bits(ch2.psel_bits()) }); } if let Some(pin) = ch3.pin_mut() { pin.set_low(); pin.conf().write(|w| w.dir().output()); - r.psel.out[3].write(|w| unsafe { w.bits(ch3.psel_bits()) }); } + // if NoPin provided writes disconnected (top bit 1) 0x80000000 else + // writes pin number ex 13 (0x0D) which is connected (top bit 0) + r.psel.out[0].write(|w| unsafe { w.bits(ch0.psel_bits()) }); + r.psel.out[1].write(|w| unsafe { w.bits(ch1.psel_bits()) }); + r.psel.out[2].write(|w| unsafe { w.bits(ch2.psel_bits()) }); + r.psel.out[3].write(|w| unsafe { w.bits(ch3.psel_bits()) }); + r.enable.write(|w| w.enable().enabled()); r.mode @@ -323,6 +327,7 @@ impl<'d, T: Instance> Pwm<'d, T> { impl<'a, T: Instance> Drop for Pwm<'a, T> { fn drop(&mut self) { let r = T::regs(); + r.enable.write(|w| w.enable().disabled()); info!("pwm drop: done");