aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/lptim
diff options
context:
space:
mode:
authorRomain Goyet <[email protected]>2024-09-05 11:39:09 -0400
committerDario Nieuwenhuis <[email protected]>2024-09-11 01:18:52 +0200
commit37130f45e4f74f7b4faeb7cac017c4588e5b422a (patch)
treeb78a487a6058d285f03039a5632da8ed13787d76 /embassy-stm32/src/lptim
parentb449e04a88d76b41aae91d98bd66bf2754637d03 (diff)
stm32: Use the updated LPTIM pac
Diffstat (limited to 'embassy-stm32/src/lptim')
-rw-r--r--embassy-stm32/src/lptim/mod.rs6
-rw-r--r--embassy-stm32/src/lptim/pwm.rs1
-rw-r--r--embassy-stm32/src/lptim/timer.rs9
3 files changed, 10 insertions, 6 deletions
diff --git a/embassy-stm32/src/lptim/mod.rs b/embassy-stm32/src/lptim/mod.rs
index 327a1d44b..dc5f1d5bb 100644
--- a/embassy-stm32/src/lptim/mod.rs
+++ b/embassy-stm32/src/lptim/mod.rs
@@ -28,16 +28,16 @@ pin_trait!(Channel1Pin, Instance);
28pin_trait!(Channel2Pin, Instance); 28pin_trait!(Channel2Pin, Instance);
29 29
30pub(crate) trait SealedInstance: RccPeripheral { 30pub(crate) trait SealedInstance: RccPeripheral {
31 fn regs() -> crate::pac::lptim::LptimAdv; 31 fn regs() -> crate::pac::lptim::Lptim;
32} 32}
33 33
34/// LPTIM instance trait. 34/// LPTIM instance trait.
35#[allow(private_bounds)] 35#[allow(private_bounds)]
36pub trait Instance: SealedInstance + 'static {} 36pub trait Instance: SealedInstance + 'static {}
37foreach_interrupt! { 37foreach_interrupt! {
38 ($inst:ident, lptim, LPTIM_ADV, GLOBAL, $irq:ident) => { 38 ($inst:ident, lptim, LPTIM, UP, $irq:ident) => {
39 impl SealedInstance for crate::peripherals::$inst { 39 impl SealedInstance for crate::peripherals::$inst {
40 fn regs() -> crate::pac::lptim::LptimAdv { 40 fn regs() -> crate::pac::lptim::Lptim {
41 crate::pac::$inst 41 crate::pac::$inst
42 } 42 }
43 } 43 }
diff --git a/embassy-stm32/src/lptim/pwm.rs b/embassy-stm32/src/lptim/pwm.rs
index 725aa676e..24725f625 100644
--- a/embassy-stm32/src/lptim/pwm.rs
+++ b/embassy-stm32/src/lptim/pwm.rs
@@ -66,6 +66,7 @@ impl<'d, T: Instance> Pwm<'d, T> {
66 this.inner.enable(); 66 this.inner.enable();
67 this.set_frequency(freq); 67 this.set_frequency(freq);
68 68
69 #[cfg(any(lptim_v2a, lptim_v2b))]
69 [Channel::Ch1, Channel::Ch2].iter().for_each(|&channel| { 70 [Channel::Ch1, Channel::Ch2].iter().for_each(|&channel| {
70 this.inner.set_channel_direction(channel, ChannelDirection::OutputPwm); 71 this.inner.set_channel_direction(channel, ChannelDirection::OutputPwm);
71 }); 72 });
diff --git a/embassy-stm32/src/lptim/timer.rs b/embassy-stm32/src/lptim/timer.rs
index 06392b2e7..b354c1f61 100644
--- a/embassy-stm32/src/lptim/timer.rs
+++ b/embassy-stm32/src/lptim/timer.rs
@@ -8,6 +8,7 @@ use crate::rcc;
8use crate::time::Hertz; 8use crate::time::Hertz;
9 9
10/// Direction of a low-power timer channel 10/// Direction of a low-power timer channel
11#[cfg(any(lptim_v2a, lptim_v2b))]
11pub enum ChannelDirection { 12pub enum ChannelDirection {
12 /// Use channel as a PWM output 13 /// Use channel as a PWM output
13 OutputPwm, 14 OutputPwm,
@@ -15,6 +16,7 @@ pub enum ChannelDirection {
15 InputCapture, 16 InputCapture,
16} 17}
17 18
19#[cfg(any(lptim_v2a, lptim_v2b))]
18impl From<ChannelDirection> for vals::Ccsel { 20impl From<ChannelDirection> for vals::Ccsel {
19 fn from(direction: ChannelDirection) -> Self { 21 fn from(direction: ChannelDirection) -> Self {
20 match direction { 22 match direction {
@@ -147,9 +149,10 @@ impl<'d, T: Instance> Timer<'d, T> {
147 } 149 }
148 150
149 /// Set channel direction. 151 /// Set channel direction.
152 #[cfg(any(lptim_v2a, lptim_v2b))]
150 pub fn set_channel_direction(&self, channel: Channel, direction: ChannelDirection) { 153 pub fn set_channel_direction(&self, channel: Channel, direction: ChannelDirection) {
151 T::regs() 154 T::regs()
152 .ccmr() 155 .ccmr(0)
153 .modify(|w| w.set_ccsel(channel.index(), direction.into())); 156 .modify(|w| w.set_ccsel(channel.index(), direction.into()));
154 } 157 }
155 158
@@ -185,14 +188,14 @@ impl<'d, T: Instance> Timer<'d, T> {
185 188
186 /// Enable/disable a channel. 189 /// Enable/disable a channel.
187 pub fn enable_channel(&self, channel: Channel, enable: bool) { 190 pub fn enable_channel(&self, channel: Channel, enable: bool) {
188 T::regs().ccmr().modify(|w| { 191 T::regs().ccmr(0).modify(|w| {
189 w.set_cce(channel.index(), enable); 192 w.set_cce(channel.index(), enable);
190 }); 193 });
191 } 194 }
192 195
193 /// Get enable/disable state of a channel 196 /// Get enable/disable state of a channel
194 pub fn get_channel_enable_state(&self, channel: Channel) -> bool { 197 pub fn get_channel_enable_state(&self, channel: Channel) -> bool {
195 T::regs().ccmr().read().cce(channel.index()) 198 T::regs().ccmr(0).read().cce(channel.index())
196 } 199 }
197 200
198 /// Set compare value for a channel. 201 /// Set compare value for a channel.