aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/timer/complementary_pwm.rs
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-stm32/src/timer/complementary_pwm.rs')
-rw-r--r--embassy-stm32/src/timer/complementary_pwm.rs55
1 files changed, 54 insertions, 1 deletions
diff --git a/embassy-stm32/src/timer/complementary_pwm.rs b/embassy-stm32/src/timer/complementary_pwm.rs
index b00cc18ad..b291fc155 100644
--- a/embassy-stm32/src/timer/complementary_pwm.rs
+++ b/embassy-stm32/src/timer/complementary_pwm.rs
@@ -2,7 +2,7 @@
2 2
3use core::marker::PhantomData; 3use core::marker::PhantomData;
4 4
5use stm32_metapac::timer::vals::Ckd; 5pub use stm32_metapac::timer::vals::{Ckd, Ossi, Ossr};
6 6
7use super::low_level::{CountingMode, OutputPolarity, Timer}; 7use super::low_level::{CountingMode, OutputPolarity, Timer};
8use super::simple_pwm::PwmPin; 8use super::simple_pwm::PwmPin;
@@ -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,6 +91,50 @@ impl<'d, T: AdvancedInstance4Channel> ComplementaryPwm<'d, T> {
82 this 91 this
83 } 92 }
84 93
94 /// Sets the idle output state for the given channels.
95 pub fn set_output_idle_state(&mut self, channels: &[Channel], polarity: IdlePolarity) {
96 let ois_active = matches!(polarity, IdlePolarity::OisActive);
97 for &channel in channels {
98 self.inner.set_ois(channel, ois_active);
99 self.inner.set_oisn(channel, !ois_active);
100 }
101 }
102
103 /// Set state of OSSI-bit in BDTR register
104 pub fn set_off_state_selection_idle(&mut self, val: Ossi) {
105 self.inner.set_ossi(val);
106 }
107
108 /// Get state of OSSI-bit in BDTR register
109 pub fn get_off_state_selection_idle(&self) -> Ossi {
110 self.inner.get_ossi()
111 }
112
113 /// Set state of OSSR-bit in BDTR register
114 pub fn set_off_state_selection_run(&mut self, val: Ossr) {
115 self.inner.set_ossr(val);
116 }
117
118 /// Get state of OSSR-bit in BDTR register
119 pub fn get_off_state_selection_run(&self) -> Ossr {
120 self.inner.get_ossr()
121 }
122
123 /// Trigger break input from software
124 pub fn trigger_software_break(&mut self, n: usize) {
125 self.inner.trigger_software_break(n);
126 }
127
128 /// Set Master Output Enable
129 pub fn set_master_output_enable(&mut self, enable: bool) {
130 self.inner.set_moe(enable);
131 }
132
133 /// Get Master Output Enable
134 pub fn get_master_output_enable(&self) -> bool {
135 self.inner.get_moe()
136 }
137
85 /// Enable the given channel. 138 /// Enable the given channel.
86 pub fn enable(&mut self, channel: Channel) { 139 pub fn enable(&mut self, channel: Channel) {
87 self.inner.enable_channel(channel, true); 140 self.inner.enable_channel(channel, true);