From 4a677a69ae07cbb52881bbda86e4947afc5fa14d Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Sun, 24 Mar 2024 20:35:33 +0000 Subject: [PATCH] Simplify ceiling division in delay calculation Our MSRV is 1.75, and div_ceil is available since 1.73 --- rp2040-hal/src/timer.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/rp2040-hal/src/timer.rs b/rp2040-hal/src/timer.rs index 2a3272a91..a834b427b 100644 --- a/rp2040-hal/src/timer.rs +++ b/rp2040-hal/src/timer.rs @@ -171,9 +171,7 @@ impl embedded_hal::delay::DelayNs for Timer { // For now, just use microsecond delay, internally. Of course, this // might cause a much longer delay than necessary. So a more advanced // implementation would be desirable for sub-microsecond delays. - let us = ns / 1000 + if ns % 1000 == 0 { 0 } else { 1 }; - // With rustc 1.73, this can be replaced by: - // let us = ns.div_ceil(1000); + let us = ns.div_ceil(1000); self.delay_us_internal(us) }