mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-21 22:32:29 +00:00
stm32: Use the updated LPTIM pac
This commit is contained in:
parent
b449e04a88
commit
37130f45e4
@ -28,16 +28,16 @@ pin_trait!(Channel1Pin, Instance);
|
||||
pin_trait!(Channel2Pin, Instance);
|
||||
|
||||
pub(crate) trait SealedInstance: RccPeripheral {
|
||||
fn regs() -> crate::pac::lptim::LptimAdv;
|
||||
fn regs() -> crate::pac::lptim::Lptim;
|
||||
}
|
||||
|
||||
/// LPTIM instance trait.
|
||||
#[allow(private_bounds)]
|
||||
pub trait Instance: SealedInstance + 'static {}
|
||||
foreach_interrupt! {
|
||||
($inst:ident, lptim, LPTIM_ADV, GLOBAL, $irq:ident) => {
|
||||
($inst:ident, lptim, LPTIM, UP, $irq:ident) => {
|
||||
impl SealedInstance for crate::peripherals::$inst {
|
||||
fn regs() -> crate::pac::lptim::LptimAdv {
|
||||
fn regs() -> crate::pac::lptim::Lptim {
|
||||
crate::pac::$inst
|
||||
}
|
||||
}
|
||||
|
@ -66,6 +66,7 @@ impl<'d, T: Instance> Pwm<'d, T> {
|
||||
this.inner.enable();
|
||||
this.set_frequency(freq);
|
||||
|
||||
#[cfg(any(lptim_v2a, lptim_v2b))]
|
||||
[Channel::Ch1, Channel::Ch2].iter().for_each(|&channel| {
|
||||
this.inner.set_channel_direction(channel, ChannelDirection::OutputPwm);
|
||||
});
|
||||
|
@ -8,6 +8,7 @@ use crate::rcc;
|
||||
use crate::time::Hertz;
|
||||
|
||||
/// Direction of a low-power timer channel
|
||||
#[cfg(any(lptim_v2a, lptim_v2b))]
|
||||
pub enum ChannelDirection {
|
||||
/// Use channel as a PWM output
|
||||
OutputPwm,
|
||||
@ -15,6 +16,7 @@ pub enum ChannelDirection {
|
||||
InputCapture,
|
||||
}
|
||||
|
||||
#[cfg(any(lptim_v2a, lptim_v2b))]
|
||||
impl From<ChannelDirection> for vals::Ccsel {
|
||||
fn from(direction: ChannelDirection) -> Self {
|
||||
match direction {
|
||||
@ -147,9 +149,10 @@ impl<'d, T: Instance> Timer<'d, T> {
|
||||
}
|
||||
|
||||
/// Set channel direction.
|
||||
#[cfg(any(lptim_v2a, lptim_v2b))]
|
||||
pub fn set_channel_direction(&self, channel: Channel, direction: ChannelDirection) {
|
||||
T::regs()
|
||||
.ccmr()
|
||||
.ccmr(0)
|
||||
.modify(|w| w.set_ccsel(channel.index(), direction.into()));
|
||||
}
|
||||
|
||||
@ -185,14 +188,14 @@ impl<'d, T: Instance> Timer<'d, T> {
|
||||
|
||||
/// Enable/disable a channel.
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
/// Get enable/disable state of a channel
|
||||
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.
|
||||
|
Loading…
Reference in New Issue
Block a user