From 4239a43810f55f2e35b313c5bb9cc59ad432fcc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Tue, 8 Apr 2025 16:21:41 +0200 Subject: [PATCH] Hand-roll defmt::Format for Hertz --- embassy-stm32/src/time.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/embassy-stm32/src/time.rs b/embassy-stm32/src/time.rs index 71fe668a9..532877f70 100644 --- a/embassy-stm32/src/time.rs +++ b/embassy-stm32/src/time.rs @@ -5,7 +5,6 @@ use core::ops::{Div, Mul}; /// Hertz #[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Debug)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct Hertz(pub u32); impl Display for Hertz { @@ -14,6 +13,13 @@ impl Display for Hertz { } } +#[cfg(feature = "defmt")] +impl defmt::Format for Hertz { + fn format(&self, f: defmt::Formatter) { + defmt::write!(f, "{=u32} Hz", self.0) + } +} + impl Hertz { /// Create a `Hertz` from the given hertz. pub const fn hz(hertz: u32) -> Self {