Skip to content

Commit 403cf3b

Browse files
rursprungnewAM
authored andcommitted
simplify e-h 1.0 delay_ns implementation
blatantly taken from rust-embedded/cortex-m#504 Co-Authored-By: Alex Martens <[email protected]>
1 parent ab3e462 commit 403cf3b

File tree

1 file changed

+1
-11
lines changed

1 file changed

+1
-11
lines changed

avr-hal-generic/src/delay.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -284,17 +284,7 @@ impl<SPEED> DelayNs for Delay<SPEED>
284284
fn delay_ns(&mut self, ns: u32) {
285285
// quick-win to get an initial implementation.
286286
// note that the trait does not guarantee nanosecond-accuracy.
287-
288-
let mut us = ns / 1000;
289-
290-
// ensure that we wait _at least_ as long as specified.
291-
// (we truncate the integer, so if we don't do this we'd wait 1us instead of 2us when specifying 1999ns).
292-
let diff = ns - (us * 1000);
293-
if diff > 0 {
294-
us += 1;
295-
}
296-
297-
delay_v0::DelayUs::<u32>::delay_us(self, us);
287+
delay_v0::DelayUs::<u32>::delay_us(self, ns.saturating_add(999) / 1000)
298288
}
299289

300290
fn delay_us(&mut self, us: u32) {

0 commit comments

Comments
 (0)