diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-11-29 17:12:30 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-11-29 17:12:30 +0100 |
| commit | 384bad7bfaa1f2415baf2cd3b69ebf36dc0a02d7 (patch) | |
| tree | 1992bf003d6afcdeae926db2308f369bccfc42ea /embassy-time | |
| parent | b4bc9ac028568dfb3896dfb00cbd1e181863fd64 (diff) | |
| parent | 4634316749c41dd5d8cc2f316033c9098369ed2f (diff) | |
Merge pull request #2231 from embassy-rs/stable3
Update embedded-(hal,io,nal).
Diffstat (limited to 'embassy-time')
| -rw-r--r-- | embassy-time/CHANGELOG.md | 4 | ||||
| -rw-r--r-- | embassy-time/Cargo.toml | 4 | ||||
| -rw-r--r-- | embassy-time/src/delay.rs | 20 | ||||
| -rw-r--r-- | embassy-time/src/duration.rs | 9 | ||||
| -rw-r--r-- | embassy-time/src/lib.rs | 1 | ||||
| -rw-r--r-- | embassy-time/src/timer.rs | 9 |
6 files changed, 37 insertions, 10 deletions
diff --git a/embassy-time/CHANGELOG.md b/embassy-time/CHANGELOG.md index 1421d76a9..9625b8909 100644 --- a/embassy-time/CHANGELOG.md +++ b/embassy-time/CHANGELOG.md | |||
| @@ -22,8 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |||
| 22 | 22 | ||
| 23 | ## 0.1.3 - 2023-08-28 | 23 | ## 0.1.3 - 2023-08-28 |
| 24 | 24 | ||
| 25 | - Update `embedded-hal-async` to `1.0.0-rc.1` | 25 | - Update `embedded-hal-async` to `1.0.0-rc.2` |
| 26 | - Update `embedded-hal v1` to `1.0.0-rc.1` | 26 | - Update `embedded-hal v1` to `1.0.0-rc.2` |
| 27 | 27 | ||
| 28 | ## 0.1.2 - 2023-07-05 | 28 | ## 0.1.2 - 2023-07-05 |
| 29 | 29 | ||
diff --git a/embassy-time/Cargo.toml b/embassy-time/Cargo.toml index 3cabb2371..570e0efa7 100644 --- a/embassy-time/Cargo.toml +++ b/embassy-time/Cargo.toml | |||
| @@ -242,8 +242,8 @@ defmt = { version = "0.3", optional = true } | |||
| 242 | log = { version = "0.4.14", optional = true } | 242 | log = { version = "0.4.14", optional = true } |
| 243 | 243 | ||
| 244 | embedded-hal-02 = { package = "embedded-hal", version = "0.2.6" } | 244 | embedded-hal-02 = { package = "embedded-hal", version = "0.2.6" } |
| 245 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1", optional = true} | 245 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2", optional = true} |
| 246 | embedded-hal-async = { version = "=1.0.0-rc.1", optional = true} | 246 | embedded-hal-async = { version = "=1.0.0-rc.2", optional = true} |
| 247 | 247 | ||
| 248 | futures-util = { version = "0.3.17", default-features = false } | 248 | futures-util = { version = "0.3.17", default-features = false } |
| 249 | critical-section = "1.1" | 249 | critical-section = "1.1" |
diff --git a/embassy-time/src/delay.rs b/embassy-time/src/delay.rs index be962747c..aab56b1f1 100644 --- a/embassy-time/src/delay.rs +++ b/embassy-time/src/delay.rs | |||
| @@ -18,7 +18,11 @@ pub struct Delay; | |||
| 18 | mod eh1 { | 18 | mod eh1 { |
| 19 | use super::*; | 19 | use super::*; |
| 20 | 20 | ||
| 21 | impl embedded_hal_1::delay::DelayUs for Delay { | 21 | impl embedded_hal_1::delay::DelayNs for Delay { |
| 22 | fn delay_ns(&mut self, ns: u32) { | ||
| 23 | block_for(Duration::from_nanos(ns as u64)) | ||
| 24 | } | ||
| 25 | |||
| 22 | fn delay_us(&mut self, us: u32) { | 26 | fn delay_us(&mut self, us: u32) { |
| 23 | block_for(Duration::from_micros(us as u64)) | 27 | block_for(Duration::from_micros(us as u64)) |
| 24 | } | 28 | } |
| @@ -34,13 +38,17 @@ mod eha { | |||
| 34 | use super::*; | 38 | use super::*; |
| 35 | use crate::Timer; | 39 | use crate::Timer; |
| 36 | 40 | ||
| 37 | impl embedded_hal_async::delay::DelayUs for Delay { | 41 | impl embedded_hal_async::delay::DelayNs for Delay { |
| 38 | async fn delay_us(&mut self, micros: u32) { | 42 | async fn delay_ns(&mut self, ns: u32) { |
| 39 | Timer::after_micros(micros as _).await | 43 | Timer::after_nanos(ns as _).await |
| 44 | } | ||
| 45 | |||
| 46 | async fn delay_us(&mut self, us: u32) { | ||
| 47 | Timer::after_micros(us as _).await | ||
| 40 | } | 48 | } |
| 41 | 49 | ||
| 42 | async fn delay_ms(&mut self, millis: u32) { | 50 | async fn delay_ms(&mut self, ms: u32) { |
| 43 | Timer::after_millis(millis as _).await | 51 | Timer::after_millis(ms as _).await |
| 44 | } | 52 | } |
| 45 | } | 53 | } |
| 46 | } | 54 | } |
diff --git a/embassy-time/src/duration.rs b/embassy-time/src/duration.rs index 8366455be..647d208e3 100644 --- a/embassy-time/src/duration.rs +++ b/embassy-time/src/duration.rs | |||
| @@ -2,6 +2,7 @@ use core::fmt; | |||
| 2 | use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; | 2 | use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; |
| 3 | 3 | ||
| 4 | use super::{GCD_1K, GCD_1M, TICK_HZ}; | 4 | use super::{GCD_1K, GCD_1M, TICK_HZ}; |
| 5 | use crate::GCD_1G; | ||
| 5 | 6 | ||
| 6 | #[derive(Debug, Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] | 7 | #[derive(Debug, Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] |
| 7 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 8 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| @@ -61,6 +62,14 @@ impl Duration { | |||
| 61 | } | 62 | } |
| 62 | } | 63 | } |
| 63 | 64 | ||
| 65 | /// Creates a duration from the specified number of nanoseconds, rounding up. | ||
| 66 | /// NOTE: Delays this small may be inaccurate. | ||
| 67 | pub const fn from_nanos(micros: u64) -> Duration { | ||
| 68 | Duration { | ||
| 69 | ticks: div_ceil(micros * (TICK_HZ / GCD_1G), 1_000_000_000 / GCD_1G), | ||
| 70 | } | ||
| 71 | } | ||
| 72 | |||
| 64 | /// Creates a duration from the specified number of seconds, rounding down. | 73 | /// Creates a duration from the specified number of seconds, rounding down. |
| 65 | pub const fn from_secs_floor(secs: u64) -> Duration { | 74 | pub const fn from_secs_floor(secs: u64) -> Duration { |
| 66 | Duration { ticks: secs * TICK_HZ } | 75 | Duration { ticks: secs * TICK_HZ } |
diff --git a/embassy-time/src/lib.rs b/embassy-time/src/lib.rs index a90368d59..a0f6e3824 100644 --- a/embassy-time/src/lib.rs +++ b/embassy-time/src/lib.rs | |||
| @@ -52,6 +52,7 @@ const fn gcd(a: u64, b: u64) -> u64 { | |||
| 52 | 52 | ||
| 53 | pub(crate) const GCD_1K: u64 = gcd(TICK_HZ, 1_000); | 53 | pub(crate) const GCD_1K: u64 = gcd(TICK_HZ, 1_000); |
| 54 | pub(crate) const GCD_1M: u64 = gcd(TICK_HZ, 1_000_000); | 54 | pub(crate) const GCD_1M: u64 = gcd(TICK_HZ, 1_000_000); |
| 55 | pub(crate) const GCD_1G: u64 = gcd(TICK_HZ, 1_000_000_000); | ||
| 55 | 56 | ||
| 56 | #[cfg(feature = "defmt-timestamp-uptime")] | 57 | #[cfg(feature = "defmt-timestamp-uptime")] |
| 57 | defmt::timestamp! {"{=u64:us}", Instant::now().as_micros() } | 58 | defmt::timestamp! {"{=u64:us}", Instant::now().as_micros() } |
diff --git a/embassy-time/src/timer.rs b/embassy-time/src/timer.rs index ee2423daf..574d715da 100644 --- a/embassy-time/src/timer.rs +++ b/embassy-time/src/timer.rs | |||
| @@ -74,6 +74,15 @@ impl Timer { | |||
| 74 | Self::after(Duration::from_ticks(ticks)) | 74 | Self::after(Duration::from_ticks(ticks)) |
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | /// Expire after the specified number of nanoseconds. | ||
| 78 | /// | ||
| 79 | /// This method is a convenience wrapper for calling `Timer::after(Duration::from_nanos())`. | ||
| 80 | /// For more details, refer to [`Timer::after()`] and [`Duration::from_nanos()`]. | ||
| 81 | #[inline] | ||
| 82 | pub fn after_nanos(nanos: u64) -> Self { | ||
| 83 | Self::after(Duration::from_nanos(nanos)) | ||
| 84 | } | ||
| 85 | |||
| 77 | /// Expire after the specified number of microseconds. | 86 | /// Expire after the specified number of microseconds. |
| 78 | /// | 87 | /// |
| 79 | /// This method is a convenience wrapper for calling `Timer::after(Duration::from_micros())`. | 88 | /// This method is a convenience wrapper for calling `Timer::after(Duration::from_micros())`. |
