aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src
diff options
context:
space:
mode:
authorJakob <[email protected]>2025-08-08 11:43:51 +0200
committerJakob <[email protected]>2025-08-10 08:57:15 +0200
commitb6ee237fb1c59eaa0c0aa1bf876d1caf7888e940 (patch)
tree9a149ca604f4ec9d0ea169ec86a9f0ef342a6524 /embassy-stm32/src
parentc46cae734f3566a1e77d59b37d8bd714e542fd21 (diff)
Add enum for IdlePolarity to make interface clearer for set_output_idle_state method
Diffstat (limited to 'embassy-stm32/src')
-rw-r--r--embassy-stm32/src/timer/complementary_pwm.rs24
1 files changed, 17 insertions, 7 deletions
diff --git a/embassy-stm32/src/timer/complementary_pwm.rs b/embassy-stm32/src/timer/complementary_pwm.rs
index dcfe8f5dd..4d83875f5 100644
--- a/embassy-stm32/src/timer/complementary_pwm.rs
+++ b/embassy-stm32/src/timer/complementary_pwm.rs
@@ -43,6 +43,15 @@ pub struct ComplementaryPwm<'d, T: AdvancedInstance4Channel> {
43 inner: Timer<'d, T>, 43 inner: Timer<'d, T>,
44} 44}
45 45
46#[derive(Copy, Clone, Debug, PartialEq, Eq)]
47/// Determines which outputs are active when PWM is in idle mode
48pub enum IdlePolarity {
49 /// Normal channels are forced active and complementary channels are forced inactive
50 OisActive,
51 /// Normal channels are forced inactive and complementary channels are forced active
52 OisnActive,
53}
54
46impl<'d, T: AdvancedInstance4Channel> ComplementaryPwm<'d, T> { 55impl<'d, T: AdvancedInstance4Channel> ComplementaryPwm<'d, T> {
47 /// Create a new complementary PWM driver. 56 /// Create a new complementary PWM driver.
48 #[allow(clippy::too_many_arguments)] 57 #[allow(clippy::too_many_arguments)]
@@ -82,16 +91,17 @@ impl<'d, T: AdvancedInstance4Channel> ComplementaryPwm<'d, T> {
82 this 91 this
83 } 92 }
84 93
85 /// Set output idle state for all channels 94 /// Sets the idle output state for all channels.
86 /// - `output_high_when_idle` - true if the output for the normal channels should 95 pub fn set_output_idle_state(&self, polarity: IdlePolarity) {
87 /// be high when idle, which means that the complementary channels are low. Opposite 96 let ois_active = match polarity {
88 /// for `false`. 97 IdlePolarity::OisActive => true,
89 pub fn set_output_idle_state(&self, output_high_when_idle: bool) { 98 IdlePolarity::OisnActive => false,
99 };
90 [Channel::Ch1, Channel::Ch2, Channel::Ch3, Channel::Ch4] 100 [Channel::Ch1, Channel::Ch2, Channel::Ch3, Channel::Ch4]
91 .iter() 101 .iter()
92 .for_each(|&channel| { 102 .for_each(|&channel| {
93 self.inner.set_ois(channel, output_high_when_idle); 103 self.inner.set_ois(channel, ois_active);
94 self.inner.set_oisn(channel, !output_high_when_idle); 104 self.inner.set_oisn(channel, !ois_active);
95 }); 105 });
96 } 106 }
97 107