diff options
| -rw-r--r-- | embassy-stm32/src/pwm/mod.rs | 73 | ||||
| -rw-r--r-- | embassy-stm32/src/timer/mod.rs | 10 |
2 files changed, 68 insertions, 15 deletions
diff --git a/embassy-stm32/src/pwm/mod.rs b/embassy-stm32/src/pwm/mod.rs index b62a14668..1cb191a95 100644 --- a/embassy-stm32/src/pwm/mod.rs +++ b/embassy-stm32/src/pwm/mod.rs | |||
| @@ -62,9 +62,7 @@ impl From<OutputCompareMode> for stm32_metapac::timer::vals::Ocm { | |||
| 62 | pub(crate) mod sealed { | 62 | pub(crate) mod sealed { |
| 63 | use super::*; | 63 | use super::*; |
| 64 | 64 | ||
| 65 | pub trait CaptureCompareCapable16bitInstance: | 65 | pub trait CaptureCompareCapable16bitInstance: crate::timer::sealed::Basic16bitInstance { |
| 66 | crate::timer::sealed::GeneralPurpose16bitInstance | ||
| 67 | { | ||
| 68 | unsafe fn set_output_compare_mode(&mut self, channel: Channel, mode: OutputCompareMode); | 66 | unsafe fn set_output_compare_mode(&mut self, channel: Channel, mode: OutputCompareMode); |
| 69 | 67 | ||
| 70 | unsafe fn enable_channel(&mut self, channel: Channel, enable: bool); | 68 | unsafe fn enable_channel(&mut self, channel: Channel, enable: bool); |
| @@ -88,7 +86,7 @@ pub(crate) mod sealed { | |||
| 88 | } | 86 | } |
| 89 | 87 | ||
| 90 | pub trait CaptureCompareCapable16bitInstance: | 88 | pub trait CaptureCompareCapable16bitInstance: |
| 91 | sealed::CaptureCompareCapable16bitInstance + crate::timer::GeneralPurpose16bitInstance + 'static | 89 | sealed::CaptureCompareCapable16bitInstance + crate::timer::Basic16bitInstance + 'static |
| 92 | { | 90 | { |
| 93 | } | 91 | } |
| 94 | pub trait CaptureCompareCapable32bitInstance: | 92 | pub trait CaptureCompareCapable32bitInstance: |
| @@ -136,7 +134,38 @@ macro_rules! impl_compare_capable_16bit { | |||
| 136 | 134 | ||
| 137 | crate::pac::interrupts! { | 135 | crate::pac::interrupts! { |
| 138 | ($inst:ident, timer, TIM_GP16, UP, $irq:ident) => { | 136 | ($inst:ident, timer, TIM_GP16, UP, $irq:ident) => { |
| 139 | impl_compare_capable_16bit!($inst); | 137 | impl crate::pwm::sealed::CaptureCompareCapable16bitInstance for crate::peripherals::$inst { |
| 138 | unsafe fn set_output_compare_mode( | ||
| 139 | &mut self, | ||
| 140 | channel: crate::pwm::Channel, | ||
| 141 | mode: OutputCompareMode, | ||
| 142 | ) { | ||
| 143 | use crate::timer::sealed::GeneralPurpose16bitInstance; | ||
| 144 | let r = self.regs_gp16(); | ||
| 145 | let raw_channel: usize = channel.raw(); | ||
| 146 | r.ccmr_output(raw_channel / 2) | ||
| 147 | .modify(|w| w.set_ocm(raw_channel % 2, mode.into())); | ||
| 148 | } | ||
| 149 | |||
| 150 | unsafe fn enable_channel(&mut self, channel: Channel, enable: bool) { | ||
| 151 | use crate::timer::sealed::GeneralPurpose16bitInstance; | ||
| 152 | self.regs_gp16() | ||
| 153 | .ccer() | ||
| 154 | .modify(|w| w.set_cce(channel.raw(), enable)); | ||
| 155 | } | ||
| 156 | |||
| 157 | unsafe fn set_compare_value(&mut self, channel: Channel, value: u16) { | ||
| 158 | use crate::timer::sealed::GeneralPurpose16bitInstance; | ||
| 159 | self.regs_gp16() | ||
| 160 | .ccr(channel.raw()) | ||
| 161 | .modify(|w| w.set_ccr(value)); | ||
| 162 | } | ||
| 163 | |||
| 164 | unsafe fn get_max_compare_value(&self) -> u16 { | ||
| 165 | use crate::timer::sealed::GeneralPurpose16bitInstance; | ||
| 166 | self.regs_gp16().arr().read().arr() | ||
| 167 | } | ||
| 168 | } | ||
| 140 | 169 | ||
| 141 | impl CaptureCompareCapable16bitInstance for crate::peripherals::$inst { | 170 | impl CaptureCompareCapable16bitInstance for crate::peripherals::$inst { |
| 142 | 171 | ||
| @@ -180,7 +209,39 @@ crate::pac::interrupts! { | |||
| 180 | }; | 209 | }; |
| 181 | 210 | ||
| 182 | ($inst:ident, timer, TIM_ADV, UP, $irq:ident) => { | 211 | ($inst:ident, timer, TIM_ADV, UP, $irq:ident) => { |
| 183 | impl_compare_capable_16bit!($inst); | 212 | impl crate::pwm::sealed::CaptureCompareCapable16bitInstance for crate::peripherals::$inst { |
| 213 | unsafe fn set_output_compare_mode( | ||
| 214 | &mut self, | ||
| 215 | channel: crate::pwm::Channel, | ||
| 216 | mode: OutputCompareMode, | ||
| 217 | ) { | ||
| 218 | use crate::timer::sealed::AdvancedControlInstance; | ||
| 219 | let r = self.regs_advanced(); | ||
| 220 | let raw_channel: usize = channel.raw(); | ||
| 221 | r.ccmr_output(raw_channel / 2) | ||
| 222 | .modify(|w| w.set_ocm(raw_channel % 2, mode.into())); | ||
| 223 | } | ||
| 224 | |||
| 225 | unsafe fn enable_channel(&mut self, channel: Channel, enable: bool) { | ||
| 226 | use crate::timer::sealed::AdvancedControlInstance; | ||
| 227 | self.regs_advanced() | ||
| 228 | .ccer() | ||
| 229 | .modify(|w| w.set_cce(channel.raw(), enable)); | ||
| 230 | } | ||
| 231 | |||
| 232 | unsafe fn set_compare_value(&mut self, channel: Channel, value: u16) { | ||
| 233 | use crate::timer::sealed::AdvancedControlInstance; | ||
| 234 | self.regs_advanced() | ||
| 235 | .ccr(channel.raw()) | ||
| 236 | .modify(|w| w.set_ccr(value)); | ||
| 237 | } | ||
| 238 | |||
| 239 | unsafe fn get_max_compare_value(&self) -> u16 { | ||
| 240 | use crate::timer::sealed::AdvancedControlInstance; | ||
| 241 | self.regs_advanced().arr().read().arr() | ||
| 242 | } | ||
| 243 | } | ||
| 244 | |||
| 184 | impl CaptureCompareCapable16bitInstance for crate::peripherals::$inst { | 245 | impl CaptureCompareCapable16bitInstance for crate::peripherals::$inst { |
| 185 | 246 | ||
| 186 | } | 247 | } |
diff --git a/embassy-stm32/src/timer/mod.rs b/embassy-stm32/src/timer/mod.rs index ed2cb2d97..e3389fbad 100644 --- a/embassy-stm32/src/timer/mod.rs +++ b/embassy-stm32/src/timer/mod.rs | |||
| @@ -39,7 +39,7 @@ pub(crate) mod sealed { | |||
| 39 | fn set_frequency<F: Into<Hertz>>(&mut self, frequency: F); | 39 | fn set_frequency<F: Into<Hertz>>(&mut self, frequency: F); |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | pub trait AdvancedControlInstance: GeneralPurpose16bitInstance { | 42 | pub trait AdvancedControlInstance: Basic16bitInstance { |
| 43 | fn regs_advanced(&self) -> crate::pac::timer::TimAdv; | 43 | fn regs_advanced(&self) -> crate::pac::timer::TimAdv; |
| 44 | } | 44 | } |
| 45 | } | 45 | } |
| @@ -205,14 +205,6 @@ crate::pac::interrupts! { | |||
| 205 | impl Basic16bitInstance for crate::peripherals::$inst { | 205 | impl Basic16bitInstance for crate::peripherals::$inst { |
| 206 | } | 206 | } |
| 207 | 207 | ||
| 208 | impl sealed::GeneralPurpose16bitInstance for crate::peripherals::$inst { | ||
| 209 | fn regs_gp16(&self) -> crate::pac::timer::TimGp16 { | ||
| 210 | crate::pac::timer::TimGp16(crate::pac::$inst.0) | ||
| 211 | } | ||
| 212 | } | ||
| 213 | |||
| 214 | impl GeneralPurpose16bitInstance for crate::peripherals::$inst { | ||
| 215 | } | ||
| 216 | impl sealed::AdvancedControlInstance for crate::peripherals::$inst { | 208 | impl sealed::AdvancedControlInstance for crate::peripherals::$inst { |
| 217 | fn regs_advanced(&self) -> crate::pac::timer::TimAdv { | 209 | fn regs_advanced(&self) -> crate::pac::timer::TimAdv { |
| 218 | crate::pac::$inst | 210 | crate::pac::$inst |
