diff options
| author | Caleb Jamison <[email protected]> | 2023-02-09 19:22:06 -0500 |
|---|---|---|
| committer | Caleb Jamison <[email protected]> | 2023-02-09 19:22:06 -0500 |
| commit | a4371e9544f284927aae3b0de0ff5318f81acc80 (patch) | |
| tree | 2011e1e813eee61c8c1d4409ec283ce3ef79df2d /embassy-time/src/duration.rs | |
| parent | e1a0df7d46419962b92c36d8efd8c4840eef7349 (diff) | |
Add from_hz function for Duration.
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 d3c6f42a9..846a9c3d5 100644 --- a/embassy-time/src/duration.rs +++ b/embassy-time/src/duration.rs | |||
| @@ -81,6 +81,11 @@ impl Duration { | |||
| 81 | } | 81 | } |
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | /// Creates a duration corresponding to the specified Hz. | ||
| 85 | pub const fn from_hz(hz: u64) -> Duration { | ||
| 86 | Duration { ticks: TICK_HZ / hz } | ||
| 87 | } | ||
| 88 | |||
| 84 | /// Adds one Duration to another, returning a new Duration or None in the event of an overflow. | 89 | /// Adds one Duration to another, returning a new Duration or None in the event of an overflow. |
| 85 | pub fn checked_add(self, rhs: Duration) -> Option<Duration> { | 90 | pub fn checked_add(self, rhs: Duration) -> Option<Duration> { |
| 86 | self.ticks.checked_add(rhs.ticks).map(|ticks| Duration { ticks }) | 91 | self.ticks.checked_add(rhs.ticks).map(|ticks| Duration { ticks }) |
