diff options
| author | Thales Fragoso <[email protected]> | 2021-05-23 16:15:24 -0300 |
|---|---|---|
| committer | Thales Fragoso <[email protected]> | 2021-05-23 16:15:24 -0300 |
| commit | 90b25e70d799b78a20693c37be10dd99d9a0792f (patch) | |
| tree | c250a45d93294e4ad2af0e84750b5f06f3fa2c7e | |
| parent | e501932cb58fbc1e68e7d6542877fcad1e220979 (diff) | |
timer-rtc: Already ask for the timer frequency
| -rw-r--r-- | embassy-stm32/src/rtc.rs | 10 |
1 files 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<T: Instance> RTC<T> { | |||
| 76 | } | 76 | } |
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | pub fn start(&'static self, pfreq: Hertz, ppre: u8) { | 79 | pub fn start(&'static self, timer_freq: Hertz) { |
| 80 | let inner = T::inner(); | 80 | let inner = T::inner(); |
| 81 | 81 | ||
| 82 | // NOTE(unsafe) Critical section to use the unsafe methods | 82 | // NOTE(unsafe) Critical section to use the unsafe methods |
| 83 | critical_section::with(|_| { | 83 | critical_section::with(|_| { |
| 84 | unsafe { | 84 | unsafe { |
| 85 | inner.prepare(pfreq, ppre); | 85 | inner.prepare(timer_freq); |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | self.irq.set_handler_context(self as *const _ as *mut _); | 88 | self.irq.set_handler_context(self as *const _ as *mut _); |
| @@ -245,12 +245,10 @@ impl<T: Instance> embassy::time::Alarm for Alarm<T> { | |||
| 245 | pub struct TimerInner(pub(crate) TimGp16); | 245 | pub struct TimerInner(pub(crate) TimGp16); |
| 246 | 246 | ||
| 247 | impl TimerInner { | 247 | impl TimerInner { |
| 248 | unsafe fn prepare(&self, pfreq: Hertz, ppre: u8) { | 248 | unsafe fn prepare(&self, timer_freq: Hertz) { |
| 249 | self.stop_and_reset(); | 249 | self.stop_and_reset(); |
| 250 | 250 | ||
| 251 | let multiplier = if ppre == 1 { 1 } else { 2 }; | 251 | let psc = timer_freq.0 / TICKS_PER_SECOND as u32 - 1; |
| 252 | let freq = pfreq.0 * multiplier; | ||
| 253 | let psc = freq / TICKS_PER_SECOND as u32 - 1; | ||
| 254 | let psc: u16 = psc.try_into().unwrap(); | 252 | let psc: u16 = psc.try_into().unwrap(); |
| 255 | 253 | ||
| 256 | self.set_psc_arr(psc, u16::MAX); | 254 | self.set_psc_arr(psc, u16::MAX); |
