diff options
| -rw-r--r-- | embassy-time/src/instant.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/embassy-time/src/instant.rs b/embassy-time/src/instant.rs index 4e6670032..de5ebebf8 100644 --- a/embassy-time/src/instant.rs +++ b/embassy-time/src/instant.rs | |||
| @@ -57,6 +57,17 @@ impl Instant { | |||
| 57 | } | 57 | } |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | /// Try to create an Instant from a nanosecond count since system boot. | ||
| 61 | /// Fails if the number of nanoseconds is too large. | ||
| 62 | pub const fn try_from_nanos(nanos: u64) -> Option<Self> { | ||
| 63 | let Some(value) = nanos.checked_mul(TICK_HZ / GCD_1G) else { | ||
| 64 | return None; | ||
| 65 | }; | ||
| 66 | Some(Self { | ||
| 67 | ticks: value / (1_000_000_000 / GCD_1G), | ||
| 68 | }) | ||
| 69 | } | ||
| 70 | |||
| 60 | /// Try to create an Instant from a microsecond count since system boot. | 71 | /// Try to create an Instant from a microsecond count since system boot. |
| 61 | /// Fails if the number of microseconds is too large. | 72 | /// Fails if the number of microseconds is too large. |
| 62 | pub const fn try_from_micros(micros: u64) -> Option<Self> { | 73 | pub const fn try_from_micros(micros: u64) -> Option<Self> { |
