Skip to content

Commit

Permalink
Merge pull request #783 from jannic/div_ceil
Browse files Browse the repository at this point in the history
Simplify ceiling division in delay calculation
  • Loading branch information
ithinuel authored Mar 25, 2024
2 parents 413420a + 4a677a6 commit 50865b7
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions rp2040-hal/src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 50865b7

Please sign in to comment.