diff options
| author | 1-rafael-1 <[email protected]> | 2025-09-15 20:07:18 +0200 |
|---|---|---|
| committer | 1-rafael-1 <[email protected]> | 2025-09-15 20:07:18 +0200 |
| commit | 6bb3d2c0720fa082f27d3cdb70f516058497ec87 (patch) | |
| tree | 5a1e255cff999b00800f203b91a759c720c973e5 /embassy-time | |
| parent | eb685574601d98c44faed9a3534d056199b46e20 (diff) | |
| parent | 92a6fd2946f2cbb15359290f68aa360953da2ff7 (diff) | |
Merge branch 'main' into rp2040-rtc-alarm
Diffstat (limited to 'embassy-time')
| -rw-r--r-- | embassy-time/CHANGELOG.md | 14 | ||||
| -rw-r--r-- | embassy-time/Cargo.toml | 19 | ||||
| -rw-r--r-- | embassy-time/src/delay.rs | 17 | ||||
| -rw-r--r-- | embassy-time/src/driver_mock.rs | 2 | ||||
| -rw-r--r-- | embassy-time/src/driver_std.rs | 3 | ||||
| -rw-r--r-- | embassy-time/src/driver_wasm.rs | 6 | ||||
| -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 | 11 |
9 files changed, 67 insertions, 15 deletions
diff --git a/embassy-time/CHANGELOG.md b/embassy-time/CHANGELOG.md index 09e951ce4..572571215 100644 --- a/embassy-time/CHANGELOG.md +++ b/embassy-time/CHANGELOG.md | |||
| @@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file. | |||
| 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), |
| 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). |
| 7 | 7 | ||
| 8 | <!-- next-header --> | ||
| 9 | ## Unreleased - ReleaseDate | ||
| 10 | |||
| 11 | ## 0.5.0 - 2025-08-26 | ||
| 12 | |||
| 13 | - Allow inlining on time driver boundary | ||
| 14 | - Add `saturating_add` and `saturating_sub` to `Instant` | ||
| 15 | - Add `Instant::try_from_*` constructor functions | ||
| 16 | - Add `Duration::try_from_*` constructor functions | ||
| 17 | - Don't select `critical-section` impl for `std` | ||
| 18 | - Manually implement the future for `with_timeout` | ||
| 19 | - Add 133MHz tick rate to support PR2040 @ 133MHz when `TIMERx`'s `SOURCE` is set to `SYSCLK` | ||
| 20 | - Implement Sum for Duration | ||
| 21 | |||
| 8 | ## 0.4.0 - 2025-01-02 | 22 | ## 0.4.0 - 2025-01-02 |
| 9 | 23 | ||
| 10 | - `embassy-time-driver` updated from v0.1 to v0.2. | 24 | - `embassy-time-driver` updated from v0.1 to v0.2. |
diff --git a/embassy-time/Cargo.toml b/embassy-time/Cargo.toml index dc144ec3c..2d7c3c1fa 100644 --- a/embassy-time/Cargo.toml +++ b/embassy-time/Cargo.toml | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | [package] | 1 | [package] |
| 2 | name = "embassy-time" | 2 | name = "embassy-time" |
| 3 | version = "0.4.0" | 3 | version = "0.5.0" |
| 4 | edition = "2021" | 4 | edition = "2021" |
| 5 | description = "Instant and Duration for embedded no-std systems, with async timer support" | 5 | description = "Instant and Duration for embedded no-std systems, with async timer support" |
| 6 | repository = "https://github.com/embassy-rs/embassy" | 6 | repository = "https://github.com/embassy-rs/embassy" |
| @@ -14,6 +14,13 @@ categories = [ | |||
| 14 | "asynchronous", | 14 | "asynchronous", |
| 15 | ] | 15 | ] |
| 16 | 16 | ||
| 17 | [package.metadata.embassy] | ||
| 18 | build = [ | ||
| 19 | {target = "thumbv6m-none-eabi", features = ["defmt", "defmt-timestamp-uptime", "mock-driver"]}, | ||
| 20 | # Xtensa builds | ||
| 21 | {group = "xtensa", build-std = ["core", "alloc"], target = "xtensa-esp32s2-none-elf", features = ["defmt", "defmt-timestamp-uptime", "mock-driver"]}, | ||
| 22 | ] | ||
| 23 | |||
| 17 | [package.metadata.embassy_docs] | 24 | [package.metadata.embassy_docs] |
| 18 | src_base = "https://github.com/embassy-rs/embassy/blob/embassy-time-v$VERSION/embassy-time/src/" | 25 | src_base = "https://github.com/embassy-rs/embassy/blob/embassy-time-v$VERSION/embassy-time/src/" |
| 19 | src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-time/src/" | 26 | src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-time/src/" |
| @@ -417,17 +424,17 @@ tick-hz-5_242_880_000 = ["embassy-time-driver/tick-hz-5_242_880_000"] | |||
| 417 | #! </details> | 424 | #! </details> |
| 418 | 425 | ||
| 419 | [dependencies] | 426 | [dependencies] |
| 420 | embassy-time-driver = { version = "0.2", path = "../embassy-time-driver" } | 427 | embassy-time-driver = { version = "0.2.1", path = "../embassy-time-driver" } |
| 421 | embassy-time-queue-utils = { version = "0.1", path = "../embassy-time-queue-utils", optional = true} | 428 | embassy-time-queue-utils = { version = "0.3.0", path = "../embassy-time-queue-utils", optional = true} |
| 422 | 429 | ||
| 423 | defmt = { version = "0.3", optional = true } | 430 | defmt = { version = "1.0.1", optional = true } |
| 424 | log = { version = "0.4.14", optional = true } | 431 | log = { version = "0.4.14", optional = true } |
| 425 | 432 | ||
| 426 | embedded-hal-02 = { package = "embedded-hal", version = "0.2.6" } | 433 | embedded-hal-02 = { package = "embedded-hal", version = "0.2.6" } |
| 427 | embedded-hal-1 = { package = "embedded-hal", version = "1.0" } | 434 | embedded-hal-1 = { package = "embedded-hal", version = "1.0" } |
| 428 | embedded-hal-async = { version = "1.0" } | 435 | embedded-hal-async = { version = "1.0" } |
| 429 | 436 | ||
| 430 | futures-util = { version = "0.3.17", default-features = false } | 437 | futures-core = { version = "0.3.31", default-features = false } |
| 431 | critical-section = "1.1" | 438 | critical-section = "1.1" |
| 432 | cfg-if = "1.0.0" | 439 | cfg-if = "1.0.0" |
| 433 | 440 | ||
| @@ -441,4 +448,4 @@ wasm-timer = { version = "0.2.5", optional = true } | |||
| 441 | [dev-dependencies] | 448 | [dev-dependencies] |
| 442 | serial_test = "0.9" | 449 | serial_test = "0.9" |
| 443 | critical-section = { version = "1.1", features = ["std"] } | 450 | critical-section = { version = "1.1", features = ["std"] } |
| 444 | embassy-executor = { version = "0.7.0", path = "../embassy-executor" } | 451 | embassy-executor = { version = "0.9.0", path = "../embassy-executor" } |
diff --git a/embassy-time/src/delay.rs b/embassy-time/src/delay.rs index f77859d4a..11b54b098 100644 --- a/embassy-time/src/delay.rs +++ b/embassy-time/src/delay.rs | |||
| @@ -1,3 +1,5 @@ | |||
| 1 | use core::future::Future; | ||
| 2 | |||
| 1 | use super::{Duration, Instant}; | 3 | use super::{Duration, Instant}; |
| 2 | use crate::Timer; | 4 | use crate::Timer; |
| 3 | 5 | ||
| @@ -13,7 +15,8 @@ pub fn block_for(duration: Duration) { | |||
| 13 | /// the amount provided, but accuracy can be affected by many factors, including interrupt usage. | 15 | /// the amount provided, but accuracy can be affected by many factors, including interrupt usage. |
| 14 | /// Make sure to use a suitable tick rate for your use case. The tick rate is defined by the currently | 16 | /// Make sure to use a suitable tick rate for your use case. The tick rate is defined by the currently |
| 15 | /// active driver. | 17 | /// active driver. |
| 16 | #[derive(Clone)] | 18 | #[derive(Clone, Debug)] |
| 19 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 17 | pub struct Delay; | 20 | pub struct Delay; |
| 18 | 21 | ||
| 19 | impl embedded_hal_1::delay::DelayNs for Delay { | 22 | impl embedded_hal_1::delay::DelayNs for Delay { |
| @@ -31,16 +34,16 @@ impl embedded_hal_1::delay::DelayNs for Delay { | |||
| 31 | } | 34 | } |
| 32 | 35 | ||
| 33 | impl embedded_hal_async::delay::DelayNs for Delay { | 36 | impl embedded_hal_async::delay::DelayNs for Delay { |
| 34 | async fn delay_ns(&mut self, ns: u32) { | 37 | fn delay_ns(&mut self, ns: u32) -> impl Future<Output = ()> { |
| 35 | Timer::after_nanos(ns as _).await | 38 | Timer::after_nanos(ns as _) |
| 36 | } | 39 | } |
| 37 | 40 | ||
| 38 | async fn delay_us(&mut self, us: u32) { | 41 | fn delay_us(&mut self, us: u32) -> impl Future<Output = ()> { |
| 39 | Timer::after_micros(us as _).await | 42 | Timer::after_micros(us as _) |
| 40 | } | 43 | } |
| 41 | 44 | ||
| 42 | async fn delay_ms(&mut self, ms: u32) { | 45 | fn delay_ms(&mut self, ms: u32) -> impl Future<Output = ()> { |
| 43 | Timer::after_millis(ms as _).await | 46 | Timer::after_millis(ms as _) |
| 44 | } | 47 | } |
| 45 | } | 48 | } |
| 46 | 49 | ||
diff --git a/embassy-time/src/driver_mock.rs b/embassy-time/src/driver_mock.rs index bb1961bf2..bcde2a6c9 100644 --- a/embassy-time/src/driver_mock.rs +++ b/embassy-time/src/driver_mock.rs | |||
| @@ -28,6 +28,7 @@ use crate::{Duration, Instant}; | |||
| 28 | /// assert_eq!(true, has_a_second_passed(reference)); | 28 | /// assert_eq!(true, has_a_second_passed(reference)); |
| 29 | /// } | 29 | /// } |
| 30 | /// ``` | 30 | /// ``` |
| 31 | #[derive(Debug)] | ||
| 31 | pub struct MockDriver(CsMutex<RefCell<InnerMockDriver>>); | 32 | pub struct MockDriver(CsMutex<RefCell<InnerMockDriver>>); |
| 32 | 33 | ||
| 33 | embassy_time_driver::time_driver_impl!(static DRIVER: MockDriver = MockDriver::new()); | 34 | embassy_time_driver::time_driver_impl!(static DRIVER: MockDriver = MockDriver::new()); |
| @@ -80,6 +81,7 @@ impl Driver for MockDriver { | |||
| 80 | } | 81 | } |
| 81 | } | 82 | } |
| 82 | 83 | ||
| 84 | #[derive(Debug)] | ||
| 83 | struct InnerMockDriver { | 85 | struct InnerMockDriver { |
| 84 | now: Instant, | 86 | now: Instant, |
| 85 | queue: Queue, | 87 | queue: Queue, |
diff --git a/embassy-time/src/driver_std.rs b/embassy-time/src/driver_std.rs index 87d7ef7eb..0cdb8f4ac 100644 --- a/embassy-time/src/driver_std.rs +++ b/embassy-time/src/driver_std.rs | |||
| @@ -5,11 +5,13 @@ use std::time::{Duration as StdDuration, Instant as StdInstant}; | |||
| 5 | use embassy_time_driver::Driver; | 5 | use embassy_time_driver::Driver; |
| 6 | use embassy_time_queue_utils::Queue; | 6 | use embassy_time_queue_utils::Queue; |
| 7 | 7 | ||
| 8 | #[derive(Debug)] | ||
| 8 | struct TimeDriver { | 9 | struct TimeDriver { |
| 9 | signaler: Signaler, | 10 | signaler: Signaler, |
| 10 | inner: Mutex<Inner>, | 11 | inner: Mutex<Inner>, |
| 11 | } | 12 | } |
| 12 | 13 | ||
| 14 | #[derive(Debug)] | ||
| 13 | struct Inner { | 15 | struct Inner { |
| 14 | zero_instant: Option<StdInstant>, | 16 | zero_instant: Option<StdInstant>, |
| 15 | queue: Queue, | 17 | queue: Queue, |
| @@ -64,6 +66,7 @@ fn alarm_thread() { | |||
| 64 | } | 66 | } |
| 65 | } | 67 | } |
| 66 | 68 | ||
| 69 | #[derive(Debug)] | ||
| 67 | struct Signaler { | 70 | struct Signaler { |
| 68 | mutex: Mutex<bool>, | 71 | mutex: Mutex<bool>, |
| 69 | condvar: Condvar, | 72 | condvar: Condvar, |
diff --git a/embassy-time/src/driver_wasm.rs b/embassy-time/src/driver_wasm.rs index e3207691a..646ce170e 100644 --- a/embassy-time/src/driver_wasm.rs +++ b/embassy-time/src/driver_wasm.rs | |||
| @@ -5,6 +5,8 @@ use embassy_time_queue_utils::Queue; | |||
| 5 | use wasm_bindgen::prelude::*; | 5 | use wasm_bindgen::prelude::*; |
| 6 | use wasm_timer::Instant as StdInstant; | 6 | use wasm_timer::Instant as StdInstant; |
| 7 | 7 | ||
| 8 | #[derive(Debug)] | ||
| 9 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 8 | struct AlarmState { | 10 | struct AlarmState { |
| 9 | token: Option<f64>, | 11 | token: Option<f64>, |
| 10 | } | 12 | } |
| @@ -21,10 +23,14 @@ extern "C" { | |||
| 21 | fn clearTimeout(token: f64); | 23 | fn clearTimeout(token: f64); |
| 22 | } | 24 | } |
| 23 | 25 | ||
| 26 | #[derive(Debug)] | ||
| 27 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 24 | struct TimeDriver { | 28 | struct TimeDriver { |
| 25 | inner: Mutex<Inner>, | 29 | inner: Mutex<Inner>, |
| 26 | } | 30 | } |
| 27 | 31 | ||
| 32 | #[derive(Debug)] | ||
| 33 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 28 | struct Inner { | 34 | struct Inner { |
| 29 | alarm: AlarmState, | 35 | alarm: AlarmState, |
| 30 | zero_instant: Option<StdInstant>, | 36 | zero_instant: Option<StdInstant>, |
diff --git a/embassy-time/src/duration.rs b/embassy-time/src/duration.rs index dcda705d3..5b140eeff 100644 --- a/embassy-time/src/duration.rs +++ b/embassy-time/src/duration.rs | |||
| @@ -293,3 +293,12 @@ impl From<Duration> for core::time::Duration { | |||
| 293 | core::time::Duration::from_micros(value.as_micros()) | 293 | core::time::Duration::from_micros(value.as_micros()) |
| 294 | } | 294 | } |
| 295 | } | 295 | } |
| 296 | |||
| 297 | impl core::iter::Sum for Duration { | ||
| 298 | fn sum<I>(iter: I) -> Self | ||
| 299 | where | ||
| 300 | I: Iterator<Item = Duration>, | ||
| 301 | { | ||
| 302 | Duration::from_ticks(iter.map(|d| d.as_ticks()).sum()) | ||
| 303 | } | ||
| 304 | } | ||
diff --git a/embassy-time/src/lib.rs b/embassy-time/src/lib.rs index 80a359413..77f4b344d 100644 --- a/embassy-time/src/lib.rs +++ b/embassy-time/src/lib.rs | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | #![doc = include_str!("../README.md")] | 3 | #![doc = include_str!("../README.md")] |
| 4 | #![allow(clippy::new_without_default)] | 4 | #![allow(clippy::new_without_default)] |
| 5 | #![warn(missing_docs)] | 5 | #![warn(missing_docs)] |
| 6 | #![deny(missing_debug_implementations)] | ||
| 6 | 7 | ||
| 7 | //! ## Feature flags | 8 | //! ## Feature flags |
| 8 | #![doc = document_features::document_features!(feature_label = r#"<span class="stab portability"><code>{feature}</code></span>"#)] | 9 | #![doc = document_features::document_features!(feature_label = r#"<span class="stab portability"><code>{feature}</code></span>"#)] |
diff --git a/embassy-time/src/timer.rs b/embassy-time/src/timer.rs index d1162eadd..fcf79f58e 100644 --- a/embassy-time/src/timer.rs +++ b/embassy-time/src/timer.rs | |||
| @@ -2,8 +2,8 @@ use core::future::{poll_fn, Future}; | |||
| 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_util::stream::FusedStream; | 5 | use futures_core::stream::FusedStream; |
| 6 | use futures_util::Stream; | 6 | use futures_core::Stream; |
| 7 | 7 | ||
| 8 | use crate::{Duration, Instant}; | 8 | use crate::{Duration, Instant}; |
| 9 | 9 | ||
| @@ -66,6 +66,8 @@ impl<F: Future> WithTimeout for F { | |||
| 66 | 66 | ||
| 67 | /// Future for the [`with_timeout`] and [`with_deadline`] functions. | 67 | /// Future for the [`with_timeout`] and [`with_deadline`] functions. |
| 68 | #[must_use = "futures do nothing unless you `.await` or poll them"] | 68 | #[must_use = "futures do nothing unless you `.await` or poll them"] |
| 69 | #[derive(Debug)] | ||
| 70 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 69 | pub struct TimeoutFuture<F> { | 71 | pub struct TimeoutFuture<F> { |
| 70 | timer: Timer, | 72 | timer: Timer, |
| 71 | fut: F, | 73 | fut: F, |
| @@ -92,6 +94,8 @@ impl<F: Future> Future for TimeoutFuture<F> { | |||
| 92 | 94 | ||
| 93 | /// A future that completes at a specified [Instant](struct.Instant.html). | 95 | /// A future that completes at a specified [Instant](struct.Instant.html). |
| 94 | #[must_use = "futures do nothing unless you `.await` or poll them"] | 96 | #[must_use = "futures do nothing unless you `.await` or poll them"] |
| 97 | #[derive(Debug)] | ||
| 98 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 95 | pub struct Timer { | 99 | pub struct Timer { |
| 96 | expires_at: Instant, | 100 | expires_at: Instant, |
| 97 | yielded_once: bool, | 101 | yielded_once: bool, |
| @@ -99,6 +103,7 @@ pub struct Timer { | |||
| 99 | 103 | ||
| 100 | impl Timer { | 104 | impl Timer { |
| 101 | /// Expire at specified [Instant](struct.Instant.html) | 105 | /// Expire at specified [Instant](struct.Instant.html) |
| 106 | /// Will expire immediately if the Instant is in the past. | ||
| 102 | pub fn at(expires_at: Instant) -> Self { | 107 | pub fn at(expires_at: Instant) -> Self { |
| 103 | Self { | 108 | Self { |
| 104 | expires_at, | 109 | expires_at, |
| @@ -227,6 +232,8 @@ impl Future for Timer { | |||
| 227 | /// ## Cancel safety | 232 | /// ## Cancel safety |
| 228 | /// It is safe to cancel waiting for the next tick, | 233 | /// It is safe to cancel waiting for the next tick, |
| 229 | /// meaning no tick is lost if the Future is dropped. | 234 | /// meaning no tick is lost if the Future is dropped. |
| 235 | #[derive(Debug)] | ||
| 236 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 230 | pub struct Ticker { | 237 | pub struct Ticker { |
| 231 | expires_at: Instant, | 238 | expires_at: Instant, |
| 232 | duration: Duration, | 239 | duration: Duration, |
