stm32: Use the updated LPTIM pac

This commit is contained in:
Romain Goyet 2024-09-05 11:39:09 -04:00 committed by Dario Nieuwenhuis
parent b449e04a88
commit 37130f45e4
3 changed files with 10 additions and 6 deletions

View File

@ -28,16 +28,16 @@ pin_trait!(Channel1Pin, Instance);
pin_trait!(Channel2Pin, Instance); pin_trait!(Channel2Pin, Instance);
pub(crate) trait SealedInstance: RccPeripheral { pub(crate) trait SealedInstance: RccPeripheral {
fn regs() -> crate::pac::lptim::LptimAdv; fn regs() -> crate::pac::lptim::Lptim;
} }
/// LPTIM instance trait. /// LPTIM instance trait.
#[allow(private_bounds)] #[allow(private_bounds)]
pub trait Instance: SealedInstance + 'static {} pub trait Instance: SealedInstance + 'static {}
foreach_interrupt! { foreach_interrupt! {
($inst:ident, lptim, LPTIM_ADV, GLOBAL, $irq:ident) => { ($inst:ident, lptim, LPTIM, UP, $irq:ident) => {
impl SealedInstance for crate::peripherals::$inst { impl SealedInstance for crate::peripherals::$inst {
fn regs() -> crate::pac::lptim::LptimAdv { fn regs() -> crate::pac::lptim::Lptim {
crate::pac::$inst crate::pac::$inst
} }
} }

View File

@ -66,6 +66,7 @@ impl<'d, T: Instance> Pwm<'d, T> {
this.inner.enable(); this.inner.enable();
this.set_frequency(freq); this.set_frequency(freq);
#[cfg(any(lptim_v2a, lptim_v2b))]
[Channel::Ch1, Channel::Ch2].iter().for_each(|&channel| { [Channel::Ch1, Channel::Ch2].iter().for_each(|&channel| {
this.inner.set_channel_direction(channel, ChannelDirection::OutputPwm); this.inner.set_channel_direction(channel, ChannelDirection::OutputPwm);
}); });

View File

@ -8,6 +8,7 @@ use crate::rcc;
use crate::time::Hertz; use crate::time::Hertz;
/// Direction of a low-power timer channel /// Direction of a low-power timer channel
#[cfg(any(lptim_v2a, lptim_v2b))]
pub enum ChannelDirection { pub enum ChannelDirection {
/// Use channel as a PWM output /// Use channel as a PWM output
OutputPwm, OutputPwm,
@ -15,6 +16,7 @@ pub enum ChannelDirection {
InputCapture, InputCapture,
} }
#[cfg(any(lptim_v2a, lptim_v2b))]
impl From<ChannelDirection> for vals::Ccsel { impl From<ChannelDirection> for vals::Ccsel {
fn from(direction: ChannelDirection) -> Self { fn from(direction: ChannelDirection) -> Self {
match direction { match direction {
@ -147,9 +149,10 @@ impl<'d, T: Instance> Timer<'d, T> {
} }
/// Set channel direction. /// Set channel direction.
#[cfg(any(lptim_v2a, lptim_v2b))]
pub fn set_channel_direction(&self, channel: Channel, direction: ChannelDirection) { pub fn set_channel_direction(&self, channel: Channel, direction: ChannelDirection) {
T::regs() T::regs()
.ccmr() .ccmr(0)
.modify(|w| w.set_ccsel(channel.index(), direction.into())); .modify(|w| w.set_ccsel(channel.index(), direction.into()));
} }
@ -185,14 +188,14 @@ impl<'d, T: Instance> Timer<'d, T> {
/// Enable/disable a channel. /// Enable/disable a channel.
pub fn enable_channel(&self, channel: Channel, enable: bool) { pub fn enable_channel(&self, channel: Channel, enable: bool) {
T::regs().ccmr().modify(|w| { T::regs().ccmr(0).modify(|w| {
w.set_cce(channel.index(), enable); w.set_cce(channel.index(), enable);
}); });
} }
/// Get enable/disable state of a channel /// Get enable/disable state of a channel
pub fn get_channel_enable_state(&self, channel: Channel) -> bool { pub fn get_channel_enable_state(&self, channel: Channel) -> bool {
T::regs().ccmr().read().cce(channel.index()) T::regs().ccmr(0).read().cce(channel.index())
} }
/// Set compare value for a channel. /// Set compare value for a channel.