From 1a2b6eaaf65e09688a16e00c4ccd1ad1c9c32a70 Mon Sep 17 00:00:00 2001 From: David O'Connor Date: Sat, 12 Jun 2021 16:17:48 -0400 Subject: Use overflow-workaround on delay_ms --- src/delay.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/delay.rs b/src/delay.rs index 8d3e00c..17dc654 100644 --- a/src/delay.rs +++ b/src/delay.rs @@ -30,6 +30,7 @@ impl Delay { } /// Delay using the Cortex-M systick for a certain duration, µs. + #[inline] pub fn delay_us(&mut self, us: u32) { let ticks = (us as u64) * (self.ahb_frequency as u64) / 1_000_000; @@ -57,14 +58,8 @@ impl Delay { } /// Delay using the Cortex-M systick for a certain duration, ms. - pub fn delay_ms(&mut self, ms: u32) { - self.delay_us(ms * 1_000); - } -} - -impl DelayMs for Delay { #[inline] - fn delay_ms(&mut self, mut ms: u32) { + pub fn delay_ms(&mut self, mut ms: u32) { // 4294967 is the highest u32 value which you can multiply by 1000 without overflow while ms > 4294967 { Delay::delay_us(self, 4294967000u32); @@ -74,6 +69,13 @@ impl DelayMs for Delay { } } +impl DelayMs for Delay { + #[inline] + fn delay_ms(&mut self, ms: u32) { + Delay::delay_ms(self, ms); + } +} + // This is a workaround to allow `delay_ms(42)` construction without specifying a type. impl DelayMs for Delay { #[inline(always)] -- cgit v1.2.3