diff options
| author | Rogan Morrow <[email protected]> | 2025-09-22 13:36:22 +1000 |
|---|---|---|
| committer | Rogan Morrow <[email protected]> | 2025-09-22 13:36:22 +1000 |
| commit | a0a204f586301ee4e014c3673c2ecd3ad90c504c (patch) | |
| tree | 520ba0ab08f0512c958d9342e4388d37f26b68c6 /embassy-time/src/duration.rs | |
| parent | 539837a7485381f83ef078595a4e248a0ea11436 (diff) | |
add as_nanos and from_nanos where missing
Diffstat (limited to 'embassy-time/src/duration.rs')
| -rw-r--r-- | embassy-time/src/duration.rs | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/embassy-time/src/duration.rs b/embassy-time/src/duration.rs index 5b140eeff..b3ea0468d 100644 --- a/embassy-time/src/duration.rs +++ b/embassy-time/src/duration.rs | |||
| @@ -37,6 +37,11 @@ impl Duration { | |||
| 37 | self.ticks * (1_000_000 / GCD_1M) / (TICK_HZ / GCD_1M) | 37 | self.ticks * (1_000_000 / GCD_1M) / (TICK_HZ / GCD_1M) |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | /// Convert the `Duration` to nanoseconds, rounding down. | ||
| 41 | pub const fn as_nanos(&self) -> u64 { | ||
| 42 | self.ticks * (1_000_000_000 / GCD_1G) / (TICK_HZ / GCD_1G) | ||
| 43 | } | ||
| 44 | |||
| 40 | /// Creates a duration from the specified number of clock ticks | 45 | /// Creates a duration from the specified number of clock ticks |
| 41 | pub const fn from_ticks(ticks: u64) -> Duration { | 46 | pub const fn from_ticks(ticks: u64) -> Duration { |
| 42 | Duration { ticks } | 47 | Duration { ticks } |
