We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
delay_ns
1 parent ab3e462 commit 403cf3bCopy full SHA for 403cf3b
avr-hal-generic/src/delay.rs
@@ -284,17 +284,7 @@ impl<SPEED> DelayNs for Delay<SPEED>
284
fn delay_ns(&mut self, ns: u32) {
285
// quick-win to get an initial implementation.
286
// 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);
+ delay_v0::DelayUs::<u32>::delay_us(self, ns.saturating_add(999) / 1000)
298
}
299
300
fn delay_us(&mut self, us: u32) {
0 commit comments