From 90b25e70d799b78a20693c37be10dd99d9a0792f Mon Sep 17 00:00:00 2001 From: Thales Fragoso Date: Sun, 23 May 2021 16:15:24 -0300 Subject: [PATCH] timer-rtc: Already ask for the timer frequency --- embassy-stm32/src/rtc.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/embassy-stm32/src/rtc.rs b/embassy-stm32/src/rtc.rs index d7987b1b3..05e22cd1b 100644 --- a/embassy-stm32/src/rtc.rs +++ b/embassy-stm32/src/rtc.rs @@ -76,13 +76,13 @@ impl RTC { } } - pub fn start(&'static self, pfreq: Hertz, ppre: u8) { + pub fn start(&'static self, timer_freq: Hertz) { let inner = T::inner(); // NOTE(unsafe) Critical section to use the unsafe methods critical_section::with(|_| { unsafe { - inner.prepare(pfreq, ppre); + inner.prepare(timer_freq); } self.irq.set_handler_context(self as *const _ as *mut _); @@ -245,12 +245,10 @@ impl embassy::time::Alarm for Alarm { pub struct TimerInner(pub(crate) TimGp16); impl TimerInner { - unsafe fn prepare(&self, pfreq: Hertz, ppre: u8) { + unsafe fn prepare(&self, timer_freq: Hertz) { self.stop_and_reset(); - let multiplier = if ppre == 1 { 1 } else { 2 }; - let freq = pfreq.0 * multiplier; - let psc = freq / TICKS_PER_SECOND as u32 - 1; + let psc = timer_freq.0 / TICKS_PER_SECOND as u32 - 1; let psc: u16 = psc.try_into().unwrap(); self.set_psc_arr(psc, u16::MAX);