From c07854fed8f6ba38d418ef63853769a9af109bff Mon Sep 17 00:00:00 2001 From: xoviat Date: Fri, 30 Jun 2023 18:20:33 -0500 Subject: [PATCH] stm32/hrtim: minor fixes --- embassy-stm32/src/pwm/advanced_pwm.rs | 49 +++++++++++++++++++++------ 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/embassy-stm32/src/pwm/advanced_pwm.rs b/embassy-stm32/src/pwm/advanced_pwm.rs index 228899c0..7e595421 100644 --- a/embassy-stm32/src/pwm/advanced_pwm.rs +++ b/embassy-stm32/src/pwm/advanced_pwm.rs @@ -43,12 +43,12 @@ pub struct ChE { mod sealed { use crate::pwm::HighResolutionCaptureCompare16bitInstance; - pub trait AdvancedChannel {} + pub trait AdvancedChannel { + fn raw() -> usize; + } } -pub trait AdvancedChannel: sealed::AdvancedChannel { - fn raw() -> usize; -} +pub trait AdvancedChannel: sealed::AdvancedChannel {} pub struct PwmPin<'d, Perip, Channel> { _pin: PeripheralRef<'d, AnyPin>, @@ -94,12 +94,12 @@ macro_rules! advanced_channel_impl { } } - impl sealed::AdvancedChannel for $channel {} - impl AdvancedChannel for $channel { + impl sealed::AdvancedChannel for $channel { fn raw() -> usize { $ch_num } } + impl AdvancedChannel for $channel {} }; } @@ -158,8 +158,8 @@ impl<'d, T: HighResolutionCaptureCompare16bitInstance> AdvancedPwm<'d, T> { } impl BurstController { - pub fn set_source(&mut self, source: Source) { - let regs = T::regs(); + pub fn set_source(&mut self, _source: Source) { + todo!("burst mode control registers not implemented") } } @@ -229,6 +229,32 @@ impl> Bridge T::regs().mcr().modify(|w| w.set_tcen(C::raw(), false)); } + pub fn enable_burst_mode(&mut self) { + use crate::pac::hrtim::vals::{Idlem, Idles}; + + // TODO: fix metapac + T::regs().tim(C::raw()).outr().modify(|w| { + w.set_idlem(0, Idlem(1)); + w.set_idlem(1, Idlem(1)); + + w.set_idles(0, Idles(1)); + w.set_idles(1, Idles(1)); + }) + } + + pub fn disable_burst_mode(&mut self) { + use crate::pac::hrtim::vals::{Idlem, Idles}; + + // TODO: fix metapac + T::regs().tim(C::raw()).outr().modify(|w| { + w.set_idlem(0, Idlem(0)); + w.set_idlem(1, Idlem(0)); + + w.set_idles(0, Idles(0)); + w.set_idles(1, Idles(0)); + }) + } + /// Set the dead time as a proportion of the maximum compare value pub fn set_dead_time(&mut self, value: u16) { T::set_channel_dead_time(C::raw(), value); @@ -282,11 +308,12 @@ impl> Resona w.set_half(true); }); - // TODO: compute min period value + let max_period = T::regs().tim(C::raw()).per().read().per(); + let min_period = max_period * (min_frequency.0 / max_frequency.0) as u16; Self { - min_period: 0, - max_period: T::regs().tim(C::raw()).per().read().per(), + min_period: min_period, + max_period: max_period, phantom: PhantomData, ch: channel, }