aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2024-01-29 14:18:25 +0000
committerGitHub <[email protected]>2024-01-29 14:18:25 +0000
commit681393150dcb9704e55bcb315cb7793e0f56607e (patch)
tree05671d3b7521cb7d7a52bd99772e6852ddf88ebc
parent415050516b34689a4c349a78816ad6a70ae7cbdf (diff)
parent319b0fe3d78c60aa123a8cbdfac850d61f1478b0 (diff)
Merge pull request #2487 from Murmele/pwm
PWM Improvements
-rw-r--r--embassy-nrf/src/pwm.rs9
1 files changed, 8 insertions, 1 deletions
diff --git a/embassy-nrf/src/pwm.rs b/embassy-nrf/src/pwm.rs
index 856e12024..e0583b770 100644
--- a/embassy-nrf/src/pwm.rs
+++ b/embassy-nrf/src/pwm.rs
@@ -736,6 +736,11 @@ impl<'d, T: Instance> SimplePwm<'d, T> {
736 r.enable.write(|w| w.enable().disabled()); 736 r.enable.write(|w| w.enable().disabled());
737 } 737 }
738 738
739 /// Returns the current duty of the channel
740 pub fn duty(&self, channel: usize) -> u16 {
741 self.duty[channel]
742 }
743
739 /// Sets duty cycle (15 bit) for a PWM channel. 744 /// Sets duty cycle (15 bit) for a PWM channel.
740 pub fn set_duty(&mut self, channel: usize, duty: u16) { 745 pub fn set_duty(&mut self, channel: usize, duty: u16) {
741 let r = T::regs(); 746 let r = T::regs();
@@ -755,7 +760,9 @@ impl<'d, T: Instance> SimplePwm<'d, T> {
755 760
756 // defensive wait until waveform is loaded after seqstart so set_duty 761 // defensive wait until waveform is loaded after seqstart so set_duty
757 // can't be called again while dma is still reading 762 // can't be called again while dma is still reading
758 while r.events_seqend[0].read().bits() == 0 {} 763 if self.is_enabled() {
764 while r.events_seqend[0].read().bits() == 0 {}
765 }
759 } 766 }
760 767
761 /// Sets the PWM clock prescaler. 768 /// Sets the PWM clock prescaler.