diff options
| -rw-r--r-- | embassy-time/src/duration.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/embassy-time/src/duration.rs b/embassy-time/src/duration.rs index 846a9c3d5..9d0bab2dd 100644 --- a/embassy-time/src/duration.rs +++ b/embassy-time/src/duration.rs | |||
| @@ -82,8 +82,17 @@ impl Duration { | |||
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | /// Creates a duration corresponding to the specified Hz. | 84 | /// Creates a duration corresponding to the specified Hz. |
| 85 | /// NOTE: Giving this function a hz >= the TICK_HZ of your platform will clamp the Duration to 1 | ||
| 86 | /// tick. Doing so will not deadlock, but will certainly not produce the desired output. | ||
| 85 | pub const fn from_hz(hz: u64) -> Duration { | 87 | pub const fn from_hz(hz: u64) -> Duration { |
| 86 | Duration { ticks: TICK_HZ / hz } | 88 | let ticks = { |
| 89 | if hz >= TICK_HZ { | ||
| 90 | 1 | ||
| 91 | } else { | ||
| 92 | (TICK_HZ + hz / 2) / hz | ||
| 93 | } | ||
| 94 | }; | ||
| 95 | Duration { ticks } | ||
| 87 | } | 96 | } |
| 88 | 97 | ||
| 89 | /// Adds one Duration to another, returning a new Duration or None in the event of an overflow. | 98 | /// Adds one Duration to another, returning a new Duration or None in the event of an overflow. |
