diff options
| -rw-r--r-- | embassy-stm32/src/timer/complementary_pwm.rs | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/embassy-stm32/src/timer/complementary_pwm.rs b/embassy-stm32/src/timer/complementary_pwm.rs index 4d83875f5..1f049cb32 100644 --- a/embassy-stm32/src/timer/complementary_pwm.rs +++ b/embassy-stm32/src/timer/complementary_pwm.rs | |||
| @@ -91,22 +91,21 @@ impl<'d, T: AdvancedInstance4Channel> ComplementaryPwm<'d, T> { | |||
| 91 | this | 91 | this |
| 92 | } | 92 | } |
| 93 | 93 | ||
| 94 | /// Sets the idle output state for all channels. | 94 | /// Sets the idle output state for the given channels. |
| 95 | pub fn set_output_idle_state(&self, polarity: IdlePolarity) { | 95 | pub fn set_output_idle_state( |
| 96 | let ois_active = match polarity { | 96 | &mut self, |
| 97 | IdlePolarity::OisActive => true, | 97 | channels: &[Channel], |
| 98 | IdlePolarity::OisnActive => false, | 98 | polarity: IdlePolarity, |
| 99 | }; | 99 | ) { |
| 100 | [Channel::Ch1, Channel::Ch2, Channel::Ch3, Channel::Ch4] | 100 | let ois_active = matches!(polarity, IdlePolarity::OisActive); |
| 101 | .iter() | 101 | for &channel in channels { |
| 102 | .for_each(|&channel| { | 102 | self.inner.set_ois(channel, ois_active); |
| 103 | self.inner.set_ois(channel, ois_active); | 103 | self.inner.set_oisn(channel, !ois_active); |
| 104 | self.inner.set_oisn(channel, !ois_active); | 104 | } |
| 105 | }); | ||
| 106 | } | 105 | } |
| 107 | 106 | ||
| 108 | /// Set state of OSSI-bit in BDTR register | 107 | /// Set state of OSSI-bit in BDTR register |
| 109 | pub fn set_off_state_selection_idle(&self, val: Ossi) { | 108 | pub fn set_off_state_selection_idle(&mut self, val: Ossi) { |
| 110 | self.inner.set_ossi(val); | 109 | self.inner.set_ossi(val); |
| 111 | } | 110 | } |
| 112 | 111 | ||
| @@ -116,7 +115,7 @@ impl<'d, T: AdvancedInstance4Channel> ComplementaryPwm<'d, T> { | |||
| 116 | } | 115 | } |
| 117 | 116 | ||
| 118 | /// Set state of OSSR-bit in BDTR register | 117 | /// Set state of OSSR-bit in BDTR register |
| 119 | pub fn set_off_state_selection_run(&self, val: Ossr) { | 118 | pub fn set_off_state_selection_run(&mut self, val: Ossr) { |
| 120 | self.inner.set_ossr(val); | 119 | self.inner.set_ossr(val); |
| 121 | } | 120 | } |
| 122 | 121 | ||
| @@ -126,12 +125,12 @@ impl<'d, T: AdvancedInstance4Channel> ComplementaryPwm<'d, T> { | |||
| 126 | } | 125 | } |
| 127 | 126 | ||
| 128 | /// Trigger break input from software | 127 | /// Trigger break input from software |
| 129 | pub fn trigger_software_break(&self, n: usize) { | 128 | pub fn trigger_software_break(&mut self, n: usize) { |
| 130 | self.inner.trigger_software_break(n); | 129 | self.inner.trigger_software_break(n); |
| 131 | } | 130 | } |
| 132 | 131 | ||
| 133 | /// Set Master Output Enable | 132 | /// Set Master Output Enable |
| 134 | pub fn set_master_output_enable(&self, enable: bool) { | 133 | pub fn set_master_output_enable(&mut self, enable: bool) { |
| 135 | self.inner.set_moe(enable); | 134 | self.inner.set_moe(enable); |
| 136 | } | 135 | } |
| 137 | 136 | ||
| @@ -146,18 +145,18 @@ impl<'d, T: AdvancedInstance4Channel> ComplementaryPwm<'d, T> { | |||
| 146 | } | 145 | } |
| 147 | 146 | ||
| 148 | /// Set Repetition Counter | 147 | /// Set Repetition Counter |
| 149 | pub fn set_repetition_counter(&self, val: u16) { | 148 | pub fn set_repetition_counter(&mut self, val: u16) { |
| 150 | self.inner.set_repetition_counter(val); | 149 | self.inner.set_repetition_counter(val); |
| 151 | } | 150 | } |
| 152 | 151 | ||
| 153 | /// Enable the given channel. | 152 | /// Enable the given channel. |
| 154 | pub fn enable(&self, channel: Channel) { | 153 | pub fn enable(&mut self, channel: Channel) { |
| 155 | self.inner.enable_channel(channel, true); | 154 | self.inner.enable_channel(channel, true); |
| 156 | self.inner.enable_complementary_channel(channel, true); | 155 | self.inner.enable_complementary_channel(channel, true); |
| 157 | } | 156 | } |
| 158 | 157 | ||
| 159 | /// Disable the given channel. | 158 | /// Disable the given channel. |
| 160 | pub fn disable(&self, channel: Channel) { | 159 | pub fn disable(&mut self, channel: Channel) { |
| 161 | self.inner.enable_complementary_channel(channel, false); | 160 | self.inner.enable_complementary_channel(channel, false); |
| 162 | self.inner.enable_channel(channel, false); | 161 | self.inner.enable_channel(channel, false); |
| 163 | } | 162 | } |
