From eeb1481413a5ce3cdadbbe0d47f4bec2586b9a37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Fri, 4 Feb 2022 12:20:31 +0100 Subject: [PATCH] [nfc] refactor set_compare to be more readable --- src/lib.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 42c7498..4d876c9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -103,19 +103,19 @@ impl Monotonic for DwtSystick { // We need to convert into its domain. let now = self.now(); - let max = 0x00ff_ffff; - - let dur = match val.checked_duration_since(now) { - None => 1, // In the past - + let reload = val + .checked_duration_since(now) + // Minimum reload value if `val` is in the past + .map_or(0, |t| t.ticks()) // ARM Architecture Reference Manual says: // "Setting SYST_RVR to zero has the effect of // disabling the SysTick counter independently // of the counter enable bit.", so the min is 1 - Some(x) => max.min(x.ticks()).max(1), - }; + .max(1) + // SysTick is a 24 bit counter. + .min(0xff_ffff) as u32; - self.systick.set_reload(dur as u32); + self.systick.set_reload(reload); self.systick.clear_current(); }