Skip to content

Commit fd9f5e3

Browse files
committed
TIM2 is 32bit
1 parent 8f083c1 commit fd9f5e3

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

src/timer/mod.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,10 @@ pub(super) mod private {
188188
}
189189

190190
macro_rules! timers {
191-
($($TIM:ident: ($tim:ident, $cnt:ident $(,$cnt_h:ident)*),)+) => {
191+
($($TIM:ident: $width:ty, ($tim:ident, $cnt:ident $(,$cnt_h:ident)*),)+) => {
192192
$(
193193
impl private::TimerCommon for $TIM {
194-
type Width = u16; // TODO: Are there any with 32 bits?
194+
type Width = $width;
195195

196196
fn init(&mut self, rcc: &mut Rcc) {
197197
$TIM::enable(rcc);
@@ -273,7 +273,7 @@ macro_rules! timers {
273273
fn set_freq_settings(&mut self, freq_settings: TimerFrequencySettings) {
274274
unsafe {
275275
self.psc().write(|w| w.psc().bits(freq_settings.psc as u16));
276-
self.arr().write(|w| w.arr().bits((freq_settings.arr as u16).into()));
276+
self.arr().write(|w| w.arr().bits(freq_settings.arr as $width));
277277
}
278278
}
279279

@@ -443,21 +443,21 @@ timers_external_clocks! {
443443
}
444444

445445
timers! {
446-
TIM1: (tim1, cnt),
447-
TIM3: (tim3, cnt),
448-
TIM14: (tim14, cnt),
449-
TIM16: (tim16, cnt),
450-
TIM17: (tim17, cnt),
446+
TIM1: u16, (tim1, cnt),
447+
TIM3: u16, (tim3, cnt),
448+
TIM14: u16, (tim14, cnt),
449+
TIM16: u16, (tim16, cnt),
450+
TIM17: u16, (tim17, cnt),
451451
}
452452

453453
#[cfg(feature = "stm32g0x1")]
454454
timers! {
455-
TIM2: (tim2, cnt),
455+
TIM2: u32, (tim2, cnt),
456456
}
457457

458458
#[cfg(any(feature = "stm32g070", feature = "stm32g071", feature = "stm32g081"))]
459459
timers! {
460-
TIM6: (tim6, cnt),
461-
TIM7: (tim7, cnt),
462-
TIM15: (tim15, cnt),
460+
TIM6: u16, (tim6, cnt),
461+
TIM7: u16, (tim7, cnt),
462+
TIM15: u16, (tim15, cnt),
463463
}

src/timer/pwm.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,16 @@ macro_rules! pwm_hal {
163163
}
164164

165165

166-
pub fn get_duty(&self) -> u32 {
167-
unsafe { (*$TIMX::ptr()).$ccrx().read().bits() }
166+
pub fn get_duty(&self) -> <$TIMX as super::private::TimerCommon>::Width {
167+
unsafe { (*$TIMX::ptr()).$ccrx().read().ccr().bits() }
168168
}
169169

170-
pub fn get_max_duty(&self) -> u32 {
171-
unsafe { (*$TIMX::ptr()).arr().read().bits() }
172-
170+
pub fn get_max_duty(&self) -> <$TIMX as super::private::TimerCommon>::Width {
171+
unsafe { (*$TIMX::ptr()).arr().read().arr().bits() }
173172
}
174173

175-
pub fn set_duty(&mut self, duty: u32) {
176-
unsafe { (*$TIMX::ptr()).$ccrx().write(|w| w.bits(duty)); }
174+
pub fn set_duty(&mut self, duty: <$TIMX as super::private::TimerCommon>::Width) {
175+
unsafe { (*$TIMX::ptr()).$ccrx().write(|w| w.ccr().bits(duty)); }
177176
}
178177
}
179178

@@ -187,7 +186,7 @@ macro_rules! pwm_hal {
187186
}
188187

189188
fn set_duty_cycle(&mut self, duty: u16) -> Result<(), Self::Error> {
190-
self.set_duty(duty as u32);
189+
self.set_duty(duty.into());
191190
Ok(())
192191
}
193192
}

0 commit comments

Comments
 (0)