From 403cf3b4b712c1f5a1183f708dc2dd7b35e97b13 Mon Sep 17 00:00:00 2001 From: Ralph Ursprung Date: Mon, 15 Jan 2024 12:15:44 +0100 Subject: [PATCH] simplify e-h 1.0 `delay_ns` implementation blatantly taken from rust-embedded/cortex-m#504 Co-Authored-By: Alex Martens --- avr-hal-generic/src/delay.rs | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/avr-hal-generic/src/delay.rs b/avr-hal-generic/src/delay.rs index 61c1f6cf96..59f5de34af 100644 --- a/avr-hal-generic/src/delay.rs +++ b/avr-hal-generic/src/delay.rs @@ -284,17 +284,7 @@ impl DelayNs for Delay 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::::delay_us(self, us); + delay_v0::DelayUs::::delay_us(self, ns.saturating_add(999) / 1000) } fn delay_us(&mut self, us: u32) {