diff options
Diffstat (limited to 'embassy-time/src')
| -rw-r--r-- | embassy-time/src/duration.rs | 8 | ||||
| -rw-r--r-- | embassy-time/src/lib.rs | 11 | ||||
| -rw-r--r-- | embassy-time/src/timer.rs | 6 |
3 files changed, 8 insertions, 17 deletions
diff --git a/embassy-time/src/duration.rs b/embassy-time/src/duration.rs index b3ea0468d..b2bfd6de9 100644 --- a/embassy-time/src/duration.rs +++ b/embassy-time/src/duration.rs | |||
| @@ -175,13 +175,7 @@ impl Duration { | |||
| 175 | /// NOTE: Giving this function a hz >= the TICK_HZ of your platform will clamp the Duration to 1 | 175 | /// NOTE: Giving this function a hz >= the TICK_HZ of your platform will clamp the Duration to 1 |
| 176 | /// tick. Doing so will not deadlock, but will certainly not produce the desired output. | 176 | /// tick. Doing so will not deadlock, but will certainly not produce the desired output. |
| 177 | pub const fn from_hz(hz: u64) -> Duration { | 177 | pub const fn from_hz(hz: u64) -> Duration { |
| 178 | let ticks = { | 178 | let ticks = { if hz >= TICK_HZ { 1 } else { (TICK_HZ + hz / 2) / hz } }; |
| 179 | if hz >= TICK_HZ { | ||
| 180 | 1 | ||
| 181 | } else { | ||
| 182 | (TICK_HZ + hz / 2) / hz | ||
| 183 | } | ||
| 184 | }; | ||
| 185 | Duration { ticks } | 179 | Duration { ticks } |
| 186 | } | 180 | } |
| 187 | 181 | ||
diff --git a/embassy-time/src/lib.rs b/embassy-time/src/lib.rs index 77f4b344d..e375fe93e 100644 --- a/embassy-time/src/lib.rs +++ b/embassy-time/src/lib.rs | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | #![cfg_attr(not(any(feature = "std", feature = "wasm", test)), no_std)] | 1 | #![cfg_attr(not(any(feature = "std", feature = "wasm", test)), no_std)] |
| 2 | #![allow(async_fn_in_trait)] | 2 | #![allow(async_fn_in_trait)] |
| 3 | #![allow(unsafe_op_in_unsafe_fn)] | ||
| 3 | #![doc = include_str!("../README.md")] | 4 | #![doc = include_str!("../README.md")] |
| 4 | #![allow(clippy::new_without_default)] | 5 | #![allow(clippy::new_without_default)] |
| 5 | #![warn(missing_docs)] | 6 | #![warn(missing_docs)] |
| @@ -27,18 +28,14 @@ mod driver_std; | |||
| 27 | #[cfg(feature = "wasm")] | 28 | #[cfg(feature = "wasm")] |
| 28 | mod driver_wasm; | 29 | mod driver_wasm; |
| 29 | 30 | ||
| 30 | pub use delay::{block_for, Delay}; | 31 | pub use delay::{Delay, block_for}; |
| 31 | pub use duration::Duration; | 32 | pub use duration::Duration; |
| 32 | pub use embassy_time_driver::TICK_HZ; | 33 | pub use embassy_time_driver::TICK_HZ; |
| 33 | pub use instant::Instant; | 34 | pub use instant::Instant; |
| 34 | pub use timer::{with_deadline, with_timeout, Ticker, TimeoutError, Timer, WithTimeout}; | 35 | pub use timer::{Ticker, TimeoutError, Timer, WithTimeout, with_deadline, with_timeout}; |
| 35 | 36 | ||
| 36 | const fn gcd(a: u64, b: u64) -> u64 { | 37 | const fn gcd(a: u64, b: u64) -> u64 { |
| 37 | if b == 0 { | 38 | if b == 0 { a } else { gcd(b, a % b) } |
| 38 | a | ||
| 39 | } else { | ||
| 40 | gcd(b, a % b) | ||
| 41 | } | ||
| 42 | } | 39 | } |
| 43 | 40 | ||
| 44 | pub(crate) const GCD_1K: u64 = gcd(TICK_HZ, 1_000); | 41 | pub(crate) const GCD_1K: u64 = gcd(TICK_HZ, 1_000); |
diff --git a/embassy-time/src/timer.rs b/embassy-time/src/timer.rs index fcf79f58e..e6d1aed84 100644 --- a/embassy-time/src/timer.rs +++ b/embassy-time/src/timer.rs | |||
| @@ -1,9 +1,9 @@ | |||
| 1 | use core::future::{poll_fn, Future}; | 1 | use core::future::{Future, poll_fn}; |
| 2 | use core::pin::Pin; | 2 | use core::pin::Pin; |
| 3 | use core::task::{Context, Poll}; | 3 | use core::task::{Context, Poll}; |
| 4 | 4 | ||
| 5 | use futures_core::stream::FusedStream; | ||
| 6 | use futures_core::Stream; | 5 | use futures_core::Stream; |
| 6 | use futures_core::stream::FusedStream; | ||
| 7 | 7 | ||
| 8 | use crate::{Duration, Instant}; | 8 | use crate::{Duration, Instant}; |
| 9 | 9 | ||
| @@ -253,7 +253,7 @@ impl Ticker { | |||
| 253 | } | 253 | } |
| 254 | 254 | ||
| 255 | /// Reset the ticker at the deadline. | 255 | /// Reset the ticker at the deadline. |
| 256 | /// If the deadline is in the past, the ticker will fire instantly. | 256 | /// If the deadline is in the past, the ticker will fire before the next scheduled tick. |
| 257 | pub fn reset_at(&mut self, deadline: Instant) { | 257 | pub fn reset_at(&mut self, deadline: Instant) { |
| 258 | self.expires_at = deadline + self.duration; | 258 | self.expires_at = deadline + self.duration; |
| 259 | } | 259 | } |
