Skip to content

Commit

Permalink
simplify e-h 1.0 delay_ns implementation
Browse files Browse the repository at this point in the history
blatantly taken from rust-embedded/cortex-m#504

Co-Authored-By: Alex Martens <[email protected]>
  • Loading branch information
2 people authored and Rahix committed Jan 15, 2024
1 parent ab3e462 commit 403cf3b
Showing 1 changed file with 1 addition and 11 deletions.
12 changes: 1 addition & 11 deletions avr-hal-generic/src/delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,17 +284,7 @@ impl<SPEED> DelayNs for Delay<SPEED>
fn delay_ns(&mut self, ns: u32) {
// quick-win to get an initial implementation.
// note that the trait does not guarantee nanosecond-accuracy.

let mut us = ns / 1000;

// ensure that we wait _at least_ as long as specified.
// (we truncate the integer, so if we don't do this we'd wait 1us instead of 2us when specifying 1999ns).
let diff = ns - (us * 1000);
if diff > 0 {
us += 1;
}

delay_v0::DelayUs::<u32>::delay_us(self, us);
delay_v0::DelayUs::<u32>::delay_us(self, ns.saturating_add(999) / 1000)
}

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

0 comments on commit 403cf3b

Please sign in to comment.