aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaarten de Vries <[email protected]>2025-10-15 11:59:42 +0200
committerMaarten de Vries <[email protected]>2025-10-15 14:42:08 +0200
commitb2dce7a67e0dc18c568da5758190e23778d025ef (patch)
tree728163fde4b21282db07672232189c5a9d0210cb
parent5be0e0e7f9d453fc695c1a3c5b8b8148d7a4852a (diff)
embassy_nrf::pwm: allow setting all duty cycles of SimplePwm at once
-rw-r--r--embassy-nrf/src/pwm.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/embassy-nrf/src/pwm.rs b/embassy-nrf/src/pwm.rs
index e47922e5a..7fbe9be9d 100644
--- a/embassy-nrf/src/pwm.rs
+++ b/embassy-nrf/src/pwm.rs
@@ -781,7 +781,23 @@ impl<'d> SimplePwm<'d> {
781 /// Sets duty cycle (15 bit) and polarity for a PWM channel. 781 /// Sets duty cycle (15 bit) and polarity for a PWM channel.
782 pub fn set_duty(&mut self, channel: usize, duty: DutyCycle) { 782 pub fn set_duty(&mut self, channel: usize, duty: DutyCycle) {
783 self.duty[channel] = duty; 783 self.duty[channel] = duty;
784 self.sync_duty_cyles_to_peripheral();
785 }
786
787 /// Sets the duty cycle (15 bit) and polarity for all PWM channels.
788 ///
789 /// You can safely set the duty cycle of disabled PWM channels.
790 ///
791 /// When using this function, a single DMA transfer sets all the duty cycles.
792 /// If you call [`Self::set_duty()`] multiple times,
793 /// each duty cycle will be set by a separate DMA transfer.
794 pub fn set_all_duties(&mut self, duty: [DutyCycle; 4]) {
795 self.duty = duty;
796 self.sync_duty_cyles_to_peripheral();
797 }
784 798
799 /// Transfer the duty cycles from `self` to the peripheral.
800 fn sync_duty_cyles_to_peripheral(&self) {
785 // reload ptr in case self was moved 801 // reload ptr in case self was moved
786 self.r.seq(0).ptr().write_value((self.duty).as_ptr() as u32); 802 self.r.seq(0).ptr().write_value((self.duty).as_ptr() as u32);
787 803