Skip to content

Commit b20c29a

Browse files
committed
Stopwatch: simplify counter reading
1 parent 82728fa commit b20c29a

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

src/timer/stopwatch.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub struct Stopwatch<TIM> {
1212
}
1313

1414
macro_rules! stopwatches {
15-
($($TIM:ident: ($tim:ident, $timXen:ident, $timXrst:ident, $apbenr:ident, $apbrstr:ident, $cnt:ident $(,$cnt_h:ident)*),)+) => {
15+
($($TIM:ident: ($tim:ident, $timXen:ident, $timXrst:ident, $apbenr:ident, $apbrstr:ident ),)+) => {
1616
$(
1717
impl Stopwatch<$TIM> {
1818
pub fn $tim(tim: $TIM, rcc: &mut Rcc) -> Self {
@@ -65,12 +65,7 @@ macro_rules! stopwatches {
6565
}
6666

6767
pub fn now(&self) -> Instant {
68-
let _high = 0;
69-
$(
70-
let _high = self.tim.cnt.read().$cnt_h().bits() as u32;
71-
)*
72-
let low = self.tim.cnt.read().$cnt().bits() as u32;
73-
Instant(low | (_high << 16))
68+
Instant(self.tim.cnt.read().bits())
7469
}
7570

7671
pub fn elapsed(&self, ts: Instant) -> MicroSecond {
@@ -100,21 +95,21 @@ macro_rules! stopwatches {
10095
}
10196

10297
stopwatches! {
103-
TIM1: (tim1, tim1en, tim1rst, apbenr2, apbrstr2, cnt),
104-
TIM3: (tim3, tim3en, tim3rst, apbenr1, apbrstr1, cnt_l, cnt_h),
105-
TIM14: (tim14, tim14en, tim14rst, apbenr2, apbrstr2, cnt),
106-
TIM16: (tim16, tim16en, tim16rst, apbenr2, apbrstr2, cnt),
107-
TIM17: (tim17, tim17en, tim17rst, apbenr2, apbrstr2, cnt),
98+
TIM1: (tim1, tim1en, tim1rst, apbenr2, apbrstr2),
99+
TIM3: (tim3, tim3en, tim3rst, apbenr1, apbrstr1),
100+
TIM14: (tim14, tim14en, tim14rst, apbenr2, apbrstr2),
101+
TIM16: (tim16, tim16en, tim16rst, apbenr2, apbrstr2),
102+
TIM17: (tim17, tim17en, tim17rst, apbenr2, apbrstr2),
108103
}
109104

110105
#[cfg(feature = "stm32g0x1")]
111106
stopwatches! {
112-
TIM2: (tim2, tim2en, tim2rst, apbenr1, apbrstr1, cnt_l, cnt_h),
107+
TIM2: (tim2, tim2en, tim2rst, apbenr1, apbrstr1),
113108
}
114109

115110
#[cfg(any(feature = "stm32g070", feature = "stm32g071", feature = "stm32g081"))]
116111
stopwatches! {
117-
TIM6: (tim6, tim6en, tim6rst, apbenr1, apbrstr1, cnt),
118-
TIM7: (tim7, tim7en, tim7rst, apbenr1, apbrstr1, cnt),
119-
TIM15: (tim15, tim15en, tim15rst, apbenr2, apbrstr2, cnt),
112+
TIM6: (tim6, tim6en, tim6rst, apbenr1, apbrstr1),
113+
TIM7: (tim7, tim7en, tim7rst, apbenr1, apbrstr1),
114+
TIM15: (tim15, tim15en, tim15rst, apbenr2, apbrstr2),
120115
}

0 commit comments

Comments
 (0)