aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2025-07-24 21:53:10 +0000
committerGitHub <[email protected]>2025-07-24 21:53:10 +0000
commit7d657ac16b72104fd137ef08d4a8f09e1137f9d6 (patch)
tree671b3b7f45175377e0dc4b470691847f583a4811 /embassy-stm32
parent1baf918319fa772174e68fe0fc6f3b748ff7e463 (diff)
parent09967b71f509bdebaf23ab11e3c362e447722240 (diff)
Merge pull request #4302 from Jacke-debug/get_max_duty_off_by_one
Get max duty off by one for Center-aligned mode
Diffstat (limited to 'embassy-stm32')
-rw-r--r--embassy-stm32/src/timer/complementary_pwm.rs12
1 files changed, 10 insertions, 2 deletions
diff --git a/embassy-stm32/src/timer/complementary_pwm.rs b/embassy-stm32/src/timer/complementary_pwm.rs
index 2bc8ceb5a..b00cc18ad 100644
--- a/embassy-stm32/src/timer/complementary_pwm.rs
+++ b/embassy-stm32/src/timer/complementary_pwm.rs
@@ -111,7 +111,11 @@ impl<'d, T: AdvancedInstance4Channel> ComplementaryPwm<'d, T> {
111 /// 111 ///
112 /// This value depends on the configured frequency and the timer's clock rate from RCC. 112 /// This value depends on the configured frequency and the timer's clock rate from RCC.
113 pub fn get_max_duty(&self) -> u16 { 113 pub fn get_max_duty(&self) -> u16 {
114 self.inner.get_max_compare_value() as u16 + 1 114 if self.inner.get_counting_mode().is_center_aligned() {
115 self.inner.get_max_compare_value() as u16
116 } else {
117 self.inner.get_max_compare_value() as u16 + 1
118 }
115 } 119 }
116 120
117 /// Set the duty for a given channel. 121 /// Set the duty for a given channel.
@@ -161,7 +165,11 @@ impl<'d, T: AdvancedInstance4Channel> embedded_hal_02::Pwm for ComplementaryPwm<
161 } 165 }
162 166
163 fn get_max_duty(&self) -> Self::Duty { 167 fn get_max_duty(&self) -> Self::Duty {
164 self.inner.get_max_compare_value() as u16 + 1 168 if self.inner.get_counting_mode().is_center_aligned() {
169 self.inner.get_max_compare_value() as u16
170 } else {
171 self.inner.get_max_compare_value() as u16 + 1
172 }
165 } 173 }
166 174
167 fn set_duty(&mut self, channel: Self::Channel, duty: Self::Duty) { 175 fn set_duty(&mut self, channel: Self::Channel, duty: Self::Duty) {