diff options
| author | xoviat <[email protected]> | 2023-06-30 18:20:33 -0500 |
|---|---|---|
| committer | xoviat <[email protected]> | 2023-06-30 18:22:02 -0500 |
| commit | c07854fed8f6ba38d418ef63853769a9af109bff (patch) | |
| tree | f68a796f0aecdc2103073c97c54c4c6589233f02 | |
| parent | 8c4997c5fcd8c25d68865b9e7537e0add50eac24 (diff) | |
stm32/hrtim: minor fixes
| -rw-r--r-- | embassy-stm32/src/pwm/advanced_pwm.rs | 49 |
1 files changed, 38 insertions, 11 deletions
diff --git a/embassy-stm32/src/pwm/advanced_pwm.rs b/embassy-stm32/src/pwm/advanced_pwm.rs index 228899c0c..7e595421c 100644 --- a/embassy-stm32/src/pwm/advanced_pwm.rs +++ b/embassy-stm32/src/pwm/advanced_pwm.rs | |||
| @@ -43,12 +43,12 @@ pub struct ChE<T: HighResolutionCaptureCompare16bitInstance> { | |||
| 43 | mod sealed { | 43 | mod sealed { |
| 44 | use crate::pwm::HighResolutionCaptureCompare16bitInstance; | 44 | use crate::pwm::HighResolutionCaptureCompare16bitInstance; |
| 45 | 45 | ||
| 46 | pub trait AdvancedChannel<T: HighResolutionCaptureCompare16bitInstance> {} | 46 | pub trait AdvancedChannel<T: HighResolutionCaptureCompare16bitInstance> { |
| 47 | fn raw() -> usize; | ||
| 48 | } | ||
| 47 | } | 49 | } |
| 48 | 50 | ||
| 49 | pub trait AdvancedChannel<T: HighResolutionCaptureCompare16bitInstance>: sealed::AdvancedChannel<T> { | 51 | pub trait AdvancedChannel<T: HighResolutionCaptureCompare16bitInstance>: sealed::AdvancedChannel<T> {} |
| 50 | fn raw() -> usize; | ||
| 51 | } | ||
| 52 | 52 | ||
| 53 | pub struct PwmPin<'d, Perip, Channel> { | 53 | pub struct PwmPin<'d, Perip, Channel> { |
| 54 | _pin: PeripheralRef<'d, AnyPin>, | 54 | _pin: PeripheralRef<'d, AnyPin>, |
| @@ -94,12 +94,12 @@ macro_rules! advanced_channel_impl { | |||
| 94 | } | 94 | } |
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | impl<T: HighResolutionCaptureCompare16bitInstance> sealed::AdvancedChannel<T> for $channel<T> {} | 97 | impl<T: HighResolutionCaptureCompare16bitInstance> sealed::AdvancedChannel<T> for $channel<T> { |
| 98 | impl<T: HighResolutionCaptureCompare16bitInstance> AdvancedChannel<T> for $channel<T> { | ||
| 99 | fn raw() -> usize { | 98 | fn raw() -> usize { |
| 100 | $ch_num | 99 | $ch_num |
| 101 | } | 100 | } |
| 102 | } | 101 | } |
| 102 | impl<T: HighResolutionCaptureCompare16bitInstance> AdvancedChannel<T> for $channel<T> {} | ||
| 103 | }; | 103 | }; |
| 104 | } | 104 | } |
| 105 | 105 | ||
| @@ -158,8 +158,8 @@ impl<'d, T: HighResolutionCaptureCompare16bitInstance> AdvancedPwm<'d, T> { | |||
| 158 | } | 158 | } |
| 159 | 159 | ||
| 160 | impl<T: HighResolutionCaptureCompare16bitInstance> BurstController<T> { | 160 | impl<T: HighResolutionCaptureCompare16bitInstance> BurstController<T> { |
| 161 | pub fn set_source(&mut self, source: Source) { | 161 | pub fn set_source(&mut self, _source: Source) { |
| 162 | let regs = T::regs(); | 162 | todo!("burst mode control registers not implemented") |
| 163 | } | 163 | } |
| 164 | } | 164 | } |
| 165 | 165 | ||
| @@ -229,6 +229,32 @@ impl<T: HighResolutionCaptureCompare16bitInstance, C: AdvancedChannel<T>> Bridge | |||
| 229 | T::regs().mcr().modify(|w| w.set_tcen(C::raw(), false)); | 229 | T::regs().mcr().modify(|w| w.set_tcen(C::raw(), false)); |
| 230 | } | 230 | } |
| 231 | 231 | ||
| 232 | pub fn enable_burst_mode(&mut self) { | ||
| 233 | use crate::pac::hrtim::vals::{Idlem, Idles}; | ||
| 234 | |||
| 235 | // TODO: fix metapac | ||
| 236 | T::regs().tim(C::raw()).outr().modify(|w| { | ||
| 237 | w.set_idlem(0, Idlem(1)); | ||
| 238 | w.set_idlem(1, Idlem(1)); | ||
| 239 | |||
| 240 | w.set_idles(0, Idles(1)); | ||
| 241 | w.set_idles(1, Idles(1)); | ||
| 242 | }) | ||
| 243 | } | ||
| 244 | |||
| 245 | pub fn disable_burst_mode(&mut self) { | ||
| 246 | use crate::pac::hrtim::vals::{Idlem, Idles}; | ||
| 247 | |||
| 248 | // TODO: fix metapac | ||
| 249 | T::regs().tim(C::raw()).outr().modify(|w| { | ||
| 250 | w.set_idlem(0, Idlem(0)); | ||
| 251 | w.set_idlem(1, Idlem(0)); | ||
| 252 | |||
| 253 | w.set_idles(0, Idles(0)); | ||
| 254 | w.set_idles(1, Idles(0)); | ||
| 255 | }) | ||
| 256 | } | ||
| 257 | |||
| 232 | /// Set the dead time as a proportion of the maximum compare value | 258 | /// Set the dead time as a proportion of the maximum compare value |
| 233 | pub fn set_dead_time(&mut self, value: u16) { | 259 | pub fn set_dead_time(&mut self, value: u16) { |
| 234 | T::set_channel_dead_time(C::raw(), value); | 260 | T::set_channel_dead_time(C::raw(), value); |
| @@ -282,11 +308,12 @@ impl<T: HighResolutionCaptureCompare16bitInstance, C: AdvancedChannel<T>> Resona | |||
| 282 | w.set_half(true); | 308 | w.set_half(true); |
| 283 | }); | 309 | }); |
| 284 | 310 | ||
| 285 | // TODO: compute min period value | 311 | let max_period = T::regs().tim(C::raw()).per().read().per(); |
| 312 | let min_period = max_period * (min_frequency.0 / max_frequency.0) as u16; | ||
| 286 | 313 | ||
| 287 | Self { | 314 | Self { |
| 288 | min_period: 0, | 315 | min_period: min_period, |
| 289 | max_period: T::regs().tim(C::raw()).per().read().per(), | 316 | max_period: max_period, |
| 290 | phantom: PhantomData, | 317 | phantom: PhantomData, |
| 291 | ch: channel, | 318 | ch: channel, |
| 292 | } | 319 | } |
