Skip to content

Commit 1a2b6ea

Browse files
committed
Use overflow-workaround on delay_ms
1 parent cf5dbcd commit 1a2b6ea

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/delay.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ impl Delay {
3030
}
3131

3232
/// Delay using the Cortex-M systick for a certain duration, µs.
33+
#[inline]
3334
pub fn delay_us(&mut self, us: u32) {
3435
let ticks = (us as u64) * (self.ahb_frequency as u64) / 1_000_000;
3536

@@ -57,14 +58,8 @@ impl Delay {
5758
}
5859

5960
/// Delay using the Cortex-M systick for a certain duration, ms.
60-
pub fn delay_ms(&mut self, ms: u32) {
61-
self.delay_us(ms * 1_000);
62-
}
63-
}
64-
65-
impl DelayMs<u32> for Delay {
6661
#[inline]
67-
fn delay_ms(&mut self, mut ms: u32) {
62+
pub fn delay_ms(&mut self, mut ms: u32) {
6863
// 4294967 is the highest u32 value which you can multiply by 1000 without overflow
6964
while ms > 4294967 {
7065
Delay::delay_us(self, 4294967000u32);
@@ -74,6 +69,13 @@ impl DelayMs<u32> for Delay {
7469
}
7570
}
7671

72+
impl DelayMs<u32> for Delay {
73+
#[inline]
74+
fn delay_ms(&mut self, ms: u32) {
75+
Delay::delay_ms(self, ms);
76+
}
77+
}
78+
7779
// This is a workaround to allow `delay_ms(42)` construction without specifying a type.
7880
impl DelayMs<i32> for Delay {
7981
#[inline(always)]

0 commit comments

Comments
 (0)