From 98595f659c309703aab411b6b3be7579b6e93c5d Mon Sep 17 00:00:00 2001 From: Ralph Ursprung Date: Mon, 28 Jul 2025 15:37:34 +0200 Subject: `embassy-time`: add missing `Debug` & `defmt::Format` derives `defmt::Format` is *not* implemented for `MockDriver` and `InnerMockDriver` because the former contains the latter and the latter is using `Queue` from `embassy-time-queue-utils` which so far does not have a `defmt` dependency. since this is just a mock driver it shouldn't be relevant if it has no `defmt::Format` impl. --- embassy-executor/src/raw/mod.rs | 2 +- embassy-time-queue-utils/src/lib.rs | 1 + embassy-time-queue-utils/src/queue_generic.rs | 2 ++ embassy-time-queue-utils/src/queue_integrated.rs | 1 + embassy-time/src/delay.rs | 3 ++- embassy-time/src/driver_mock.rs | 2 ++ embassy-time/src/driver_std.rs | 6 ++++++ embassy-time/src/driver_wasm.rs | 6 ++++++ embassy-time/src/lib.rs | 1 + embassy-time/src/timer.rs | 6 ++++++ 10 files changed, 28 insertions(+), 2 deletions(-) diff --git a/embassy-executor/src/raw/mod.rs b/embassy-executor/src/raw/mod.rs index 913da2e25..c8f1f46c2 100644 --- a/embassy-executor/src/raw/mod.rs +++ b/embassy-executor/src/raw/mod.rs @@ -98,7 +98,7 @@ pub(crate) struct TaskHeader { } /// This is essentially a `&'static TaskStorage` where the type of the future has been erased. -#[derive(Clone, Copy, PartialEq)] +#[derive(Debug, Clone, Copy, PartialEq)] pub struct TaskRef { ptr: NonNull, } diff --git a/embassy-time-queue-utils/src/lib.rs b/embassy-time-queue-utils/src/lib.rs index a6f66913f..08e186432 100644 --- a/embassy-time-queue-utils/src/lib.rs +++ b/embassy-time-queue-utils/src/lib.rs @@ -1,6 +1,7 @@ #![no_std] #![doc = include_str!("../README.md")] #![warn(missing_docs)] +#![deny(missing_debug_implementations)] #[cfg(feature = "_generic-queue")] pub mod queue_generic; diff --git a/embassy-time-queue-utils/src/queue_generic.rs b/embassy-time-queue-utils/src/queue_generic.rs index 232035bc6..bff7a4735 100644 --- a/embassy-time-queue-utils/src/queue_generic.rs +++ b/embassy-time-queue-utils/src/queue_generic.rs @@ -34,6 +34,7 @@ impl Ord for Timer { } /// A timer queue with a pre-determined capacity. +#[derive(Debug)] pub struct ConstGenericQueue { queue: Vec, } @@ -119,6 +120,7 @@ const QUEUE_SIZE: usize = 128; const QUEUE_SIZE: usize = 64; /// A timer queue with a pre-determined capacity. +#[derive(Debug)] pub struct Queue { queue: ConstGenericQueue, } diff --git a/embassy-time-queue-utils/src/queue_integrated.rs b/embassy-time-queue-utils/src/queue_integrated.rs index 246cf1d63..748cd7843 100644 --- a/embassy-time-queue-utils/src/queue_integrated.rs +++ b/embassy-time-queue-utils/src/queue_integrated.rs @@ -6,6 +6,7 @@ use core::task::Waker; use embassy_executor::raw::TaskRef; /// A timer queue, with items integrated into tasks. +#[derive(Debug)] pub struct Queue { head: Cell>, } diff --git a/embassy-time/src/delay.rs b/embassy-time/src/delay.rs index f77859d4a..67345f726 100644 --- a/embassy-time/src/delay.rs +++ b/embassy-time/src/delay.rs @@ -13,7 +13,8 @@ pub fn block_for(duration: Duration) { /// the amount provided, but accuracy can be affected by many factors, including interrupt usage. /// Make sure to use a suitable tick rate for your use case. The tick rate is defined by the currently /// active driver. -#[derive(Clone)] +#[derive(Clone, Debug)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct Delay; impl embedded_hal_1::delay::DelayNs for Delay { 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}; /// assert_eq!(true, has_a_second_passed(reference)); /// } /// ``` +#[derive(Debug)] pub struct MockDriver(CsMutex>); embassy_time_driver::time_driver_impl!(static DRIVER: MockDriver = MockDriver::new()); @@ -80,6 +81,7 @@ impl Driver for MockDriver { } } +#[derive(Debug)] struct InnerMockDriver { now: Instant, queue: Queue, diff --git a/embassy-time/src/driver_std.rs b/embassy-time/src/driver_std.rs index 87d7ef7eb..a77eed75e 100644 --- a/embassy-time/src/driver_std.rs +++ b/embassy-time/src/driver_std.rs @@ -5,11 +5,15 @@ use std::time::{Duration as StdDuration, Instant as StdInstant}; use embassy_time_driver::Driver; use embassy_time_queue_utils::Queue; +#[derive(Debug)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] struct TimeDriver { signaler: Signaler, inner: Mutex, } +#[derive(Debug)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] struct Inner { zero_instant: Option, queue: Queue, @@ -64,6 +68,8 @@ fn alarm_thread() { } } +#[derive(Debug)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] struct Signaler { mutex: Mutex, 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; use wasm_bindgen::prelude::*; use wasm_timer::Instant as StdInstant; +#[derive(Debug)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] struct AlarmState { token: Option, } @@ -21,10 +23,14 @@ extern "C" { fn clearTimeout(token: f64); } +#[derive(Debug)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] struct TimeDriver { inner: Mutex, } +#[derive(Debug)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] struct Inner { alarm: AlarmState, zero_instant: Option, 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 @@ #![doc = include_str!("../README.md")] #![allow(clippy::new_without_default)] #![warn(missing_docs)] +#![deny(missing_debug_implementations)] //! ## Feature flags #![doc = document_features::document_features!(feature_label = r#"{feature}"#)] diff --git a/embassy-time/src/timer.rs b/embassy-time/src/timer.rs index d3f1e1621..54bb9b6d8 100644 --- a/embassy-time/src/timer.rs +++ b/embassy-time/src/timer.rs @@ -66,6 +66,8 @@ impl WithTimeout for F { /// Future for the [`with_timeout`] and [`with_deadline`] functions. #[must_use = "futures do nothing unless you `.await` or poll them"] +#[derive(Debug)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct TimeoutFuture { timer: Timer, fut: F, @@ -92,6 +94,8 @@ impl Future for TimeoutFuture { /// A future that completes at a specified [Instant](struct.Instant.html). #[must_use = "futures do nothing unless you `.await` or poll them"] +#[derive(Debug)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct Timer { expires_at: Instant, yielded_once: bool, @@ -227,6 +231,8 @@ impl Future for Timer { /// ## Cancel safety /// It is safe to cancel waiting for the next tick, /// meaning no tick is lost if the Future is dropped. +#[derive(Debug)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct Ticker { expires_at: Instant, duration: Duration, -- cgit