diff options
| author | Dario Nieuwenhuis <[email protected]> | 2025-04-08 14:25:33 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-04-08 14:25:33 +0000 |
| commit | 5158482eb95d2ec5c25d0d65991e7df2d5733e10 (patch) | |
| tree | 45f2c2a46ad57825237e56f607cac067a6c295dd | |
| parent | 0313089991870357f47ba92f42373b6e7a7160c7 (diff) | |
| parent | 4239a43810f55f2e35b313c5bb9cc59ad432fcc7 (diff) | |
Merge pull request #4064 from bugadani/hz
Hand-roll defmt::Format for Hertz
| -rw-r--r-- | embassy-stm32/src/time.rs | 8 |
1 files changed, 7 insertions, 1 deletions
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}; | |||
| 5 | 5 | ||
| 6 | /// Hertz | 6 | /// Hertz |
| 7 | #[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Debug)] | 7 | #[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Debug)] |
| 8 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 9 | pub struct Hertz(pub u32); | 8 | pub struct Hertz(pub u32); |
| 10 | 9 | ||
| 11 | impl Display for Hertz { | 10 | impl Display for Hertz { |
| @@ -14,6 +13,13 @@ impl Display for Hertz { | |||
| 14 | } | 13 | } |
| 15 | } | 14 | } |
| 16 | 15 | ||
| 16 | #[cfg(feature = "defmt")] | ||
| 17 | impl defmt::Format for Hertz { | ||
| 18 | fn format(&self, f: defmt::Formatter) { | ||
| 19 | defmt::write!(f, "{=u32} Hz", self.0) | ||
| 20 | } | ||
| 21 | } | ||
| 22 | |||
| 17 | impl Hertz { | 23 | impl Hertz { |
| 18 | /// Create a `Hertz` from the given hertz. | 24 | /// Create a `Hertz` from the given hertz. |
| 19 | pub const fn hz(hertz: u32) -> Self { | 25 | pub const fn hz(hertz: u32) -> Self { |
