diff options
author | 2021-06-12 16:17:48 -0400 | |
---|---|---|
committer | 2021-06-12 16:17:48 -0400 | |
commit | 1a2b6eaaf65e09688a16e00c4ccd1ad1c9c32a70 (patch) | |
tree | 6a6c2ec14c9275614ca144f3a384d977cd91e2c6 /src/delay.rs | |
parent | cf5dbcd90229a33fd6a2cedd3069cf66625d297f (diff) | |
download | cortex-m-1a2b6eaaf65e09688a16e00c4ccd1ad1c9c32a70.tar.gz cortex-m-1a2b6eaaf65e09688a16e00c4ccd1ad1c9c32a70.tar.zst cortex-m-1a2b6eaaf65e09688a16e00c4ccd1ad1c9c32a70.zip |
Use overflow-workaround on delay_ms
Diffstat (limited to 'src/delay.rs')
-rw-r--r-- | src/delay.rs | 16 |
1 files changed, 9 insertions, 7 deletions
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<u32> 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<u32> for Delay { } } +impl DelayMs<u32> 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<i32> for Delay { #[inline(always)] |