From 00c7cd4f58aa277edb47e14a84f036e27b353306 Mon Sep 17 00:00:00 2001 From: Roman Valls Guimera Date: Thu, 27 Nov 2025 21:03:10 +1100 Subject: [PATCH 1/2] Fully migrate to defmt 1.x --- embedded-hal-async/Cargo.toml | 4 ++-- embedded-hal-bus/Cargo.toml | 4 ++-- embedded-hal-bus/src/lib.rs | 4 ++-- embedded-hal-bus/src/spi/mod.rs | 6 +++--- embedded-hal/Cargo.toml | 4 ++-- embedded-hal/src/digital.rs | 6 +++--- embedded-hal/src/i2c.rs | 8 ++++---- embedded-hal/src/lib.rs | 4 ++-- embedded-hal/src/pwm.rs | 4 ++-- embedded-hal/src/spi.rs | 12 ++++++------ 10 files changed, 28 insertions(+), 28 deletions(-) diff --git a/embedded-hal-async/Cargo.toml b/embedded-hal-async/Cargo.toml index 4d2679336..60e02a7f7 100644 --- a/embedded-hal-async/Cargo.toml +++ b/embedded-hal-async/Cargo.toml @@ -15,8 +15,8 @@ version = "1.0.0" rust-version = "1.75" [features] -defmt-03 = ["dep:defmt-03", "embedded-hal/defmt-03"] +defmt = ["dep:defmt", "embedded-hal/defmt"] [dependencies] embedded-hal = { version = "1.0.0", path = "../embedded-hal" } -defmt-03 = { package = "defmt", version = "0.3", optional = true } +defmt = { package = "defmt", version = "1", optional = true } diff --git a/embedded-hal-bus/Cargo.toml b/embedded-hal-bus/Cargo.toml index 7f404e3d6..c4d78ec0f 100644 --- a/embedded-hal-bus/Cargo.toml +++ b/embedded-hal-bus/Cargo.toml @@ -27,7 +27,7 @@ portable-atomic = ["dep:portable-atomic"] # Enable `embedded-hal-async` support. async = ["dep:embedded-hal-async"] # Derive `defmt::Format` from `defmt` 0.3 for enums and structs. See https://github.com/knurling-rs/defmt for more info -defmt-03 = ["dep:defmt-03", "embedded-hal/defmt-03", "embedded-hal-async?/defmt-03"] +defmt = ["dep:defmt", "embedded-hal/defmt", "embedded-hal-async?/defmt"] # Enables additional utilities requiring a global allocator. alloc = [] @@ -35,7 +35,7 @@ alloc = [] embedded-hal = { version = "1.0.0", path = "../embedded-hal" } embedded-hal-async = { version = "1.0.0", path = "../embedded-hal-async", optional = true } critical-section = { version = "1.0" } -defmt-03 = { package = "defmt", version = "0.3", optional = true } +defmt = { package = "defmt", version = "1", optional = true } portable-atomic = {version = "1.3", default-features = false, optional = true, features = ["require-cas"]} [package.metadata.docs.rs] diff --git a/embedded-hal-bus/src/lib.rs b/embedded-hal-bus/src/lib.rs index dfeca16e1..50bc4381d 100644 --- a/embedded-hal-bus/src/lib.rs +++ b/embedded-hal-bus/src/lib.rs @@ -4,8 +4,8 @@ #![cfg_attr(docsrs, feature(doc_cfg))] // needed to prevent defmt macros from breaking, since they emit code that does `defmt::blahblah`. -#[cfg(feature = "defmt-03")] -use defmt_03 as defmt; +#[cfg(feature = "defmt")] +use defmt; pub mod i2c; pub mod spi; diff --git a/embedded-hal-bus/src/spi/mod.rs b/embedded-hal-bus/src/spi/mod.rs index 659726288..b3a4725c5 100644 --- a/embedded-hal-bus/src/spi/mod.rs +++ b/embedded-hal-bus/src/spi/mod.rs @@ -25,12 +25,12 @@ pub use rc::*; pub use self::critical_section::*; -#[cfg(feature = "defmt-03")] +#[cfg(feature = "defmt")] use crate::defmt; /// Error type for [`ExclusiveDevice`] operations. #[derive(Copy, Clone, Eq, PartialEq, Debug)] -#[cfg_attr(feature = "defmt-03", derive(defmt::Format))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum DeviceError { /// An inner SPI bus operation failed. Spi(BUS), @@ -65,7 +65,7 @@ where /// Dummy [`DelayNs`](embedded_hal::delay::DelayNs) implementation that panics on use. #[derive(Copy, Clone, Eq, PartialEq, Debug)] -#[cfg_attr(feature = "defmt-03", derive(defmt::Format))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct NoDelay; #[cold] diff --git a/embedded-hal/Cargo.toml b/embedded-hal/Cargo.toml index 011f3cc9d..4dc4e011b 100644 --- a/embedded-hal/Cargo.toml +++ b/embedded-hal/Cargo.toml @@ -17,7 +17,7 @@ repository = "https://github.com/rust-embedded/embedded-hal" version = "1.0.0" [features] -defmt-03 = ["dep:defmt-03"] +defmt = ["dep:defmt"] [dependencies] -defmt-03 = { package = "defmt", version = "0.3", optional = true } +defmt = { package = "defmt", version = "1", optional = true } diff --git a/embedded-hal/src/digital.rs b/embedded-hal/src/digital.rs index 581f2ca38..3dee2f517 100644 --- a/embedded-hal/src/digital.rs +++ b/embedded-hal/src/digital.rs @@ -2,7 +2,7 @@ use core::ops::Not; -#[cfg(feature = "defmt-03")] +#[cfg(feature = "defmt")] use crate::defmt; /// Error. @@ -27,7 +27,7 @@ impl Error for core::convert::Infallible { /// free to define more specific or additional error types. However, by providing /// a mapping to these common errors, generic code can still react to them. #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] -#[cfg_attr(feature = "defmt-03", derive(defmt::Format))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[non_exhaustive] pub enum ErrorKind { /// A different error occurred. The original error may contain more information. @@ -82,7 +82,7 @@ impl ErrorType for &mut T { /// assert_eq!(!state, PinState::High); /// ``` #[derive(Debug, PartialEq, Eq, Clone, Copy)] -#[cfg_attr(feature = "defmt-03", derive(defmt::Format))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum PinState { /// Low pin state. Low, diff --git a/embedded-hal/src/i2c.rs b/embedded-hal/src/i2c.rs index 8b99197ef..c3c56cea3 100644 --- a/embedded-hal/src/i2c.rs +++ b/embedded-hal/src/i2c.rs @@ -163,7 +163,7 @@ use crate::private; -#[cfg(feature = "defmt-03")] +#[cfg(feature = "defmt")] use crate::defmt; /// I2C error. @@ -189,7 +189,7 @@ impl Error for core::convert::Infallible { /// free to define more specific or additional error types. However, by providing /// a mapping to these common I2C errors, generic code can still react to them. #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] -#[cfg_attr(feature = "defmt-03", derive(defmt::Format))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[non_exhaustive] pub enum ErrorKind { /// Bus error occurred. e.g. A START or a STOP condition is detected and is not @@ -213,7 +213,7 @@ pub enum ErrorKind { /// response was received to an address versus a no acknowledge to a data byte. /// Where it is not possible to differentiate, `Unknown` should be indicated. #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] -#[cfg_attr(feature = "defmt-03", derive(defmt::Format))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum NoAcknowledgeSource { /// The device did not acknowledge its address. The device may be missing. Address, @@ -303,7 +303,7 @@ impl AddressMode for TenBitAddress {} /// /// Several operations can be combined as part of a transaction. #[derive(Debug, PartialEq, Eq)] -#[cfg_attr(feature = "defmt-03", derive(defmt::Format))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum Operation<'a> { /// Read data into the provided buffer. Read(&'a mut [u8]), diff --git a/embedded-hal/src/lib.rs b/embedded-hal/src/lib.rs index f5eb76c32..bc39f96c8 100644 --- a/embedded-hal/src/lib.rs +++ b/embedded-hal/src/lib.rs @@ -17,5 +17,5 @@ mod private { } // needed to prevent defmt macros from breaking, since they emit code that does `defmt::blahblah`. -#[cfg(feature = "defmt-03")] -use defmt_03 as defmt; +#[cfg(feature = "defmt")] +use defmt; diff --git a/embedded-hal/src/pwm.rs b/embedded-hal/src/pwm.rs index 4d4ff1508..3b589dfd1 100644 --- a/embedded-hal/src/pwm.rs +++ b/embedded-hal/src/pwm.rs @@ -1,6 +1,6 @@ //! Pulse Width Modulation (PWM) traits. -#[cfg(feature = "defmt-03")] +#[cfg(feature = "defmt")] use crate::defmt; /// Error @@ -26,7 +26,7 @@ impl Error for core::convert::Infallible { /// free to define more specific or additional error types. However, by providing /// a mapping to these common errors, generic code can still react to them. #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] -#[cfg_attr(feature = "defmt-03", derive(defmt::Format))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[non_exhaustive] pub enum ErrorKind { /// A different error occurred. The original error may contain more information. diff --git a/embedded-hal/src/spi.rs b/embedded-hal/src/spi.rs index 55fc7e9fb..b6bdfb841 100644 --- a/embedded-hal/src/spi.rs +++ b/embedded-hal/src/spi.rs @@ -173,12 +173,12 @@ use core::fmt::Debug; -#[cfg(feature = "defmt-03")] +#[cfg(feature = "defmt")] use crate::defmt; /// Clock polarity. #[derive(Clone, Copy, Debug, PartialEq, Eq)] -#[cfg_attr(feature = "defmt-03", derive(defmt::Format))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum Polarity { /// Clock signal low when idle. IdleLow, @@ -188,7 +188,7 @@ pub enum Polarity { /// Clock phase. #[derive(Clone, Copy, Debug, PartialEq, Eq)] -#[cfg_attr(feature = "defmt-03", derive(defmt::Format))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum Phase { /// Data in "captured" on the first clock transition. CaptureOnFirstTransition, @@ -198,7 +198,7 @@ pub enum Phase { /// SPI mode. #[derive(Clone, Copy, Debug, PartialEq, Eq)] -#[cfg_attr(feature = "defmt-03", derive(defmt::Format))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct Mode { /// Clock polarity. pub polarity: Polarity, @@ -253,7 +253,7 @@ impl Error for core::convert::Infallible { /// free to define more specific or additional error types. However, by providing /// a mapping to these common SPI errors, generic code can still react to them. #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] -#[cfg_attr(feature = "defmt-03", derive(defmt::Format))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[non_exhaustive] pub enum ErrorKind { /// The peripheral receive buffer was overrun. @@ -318,7 +318,7 @@ impl ErrorType for &mut T { /// /// This allows composition of SPI operations into a single bus transaction. #[derive(Debug, PartialEq, Eq)] -#[cfg_attr(feature = "defmt-03", derive(defmt::Format))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum Operation<'a, Word: 'static> { /// Read data into the provided buffer. /// From 967379336d9e6f0921ad8c3282104c8eac521a86 Mon Sep 17 00:00:00 2001 From: Roman Valls Guimera Date: Mon, 1 Dec 2025 09:16:31 +1100 Subject: [PATCH 2/2] Remove last traces of defmt-03 --- .github/workflows/test.yml | 2 +- embedded-hal-bus/src/lib.rs | 4 ---- embedded-hal-bus/src/spi/mod.rs | 2 +- embedded-hal/src/digital.rs | 2 +- embedded-hal/src/i2c.rs | 2 +- embedded-hal/src/lib.rs | 4 ---- embedded-hal/src/pwm.rs | 2 +- embedded-hal/src/spi.rs | 2 +- 8 files changed, 6 insertions(+), 14 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5b5ee297d..8a9299e90 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -36,7 +36,7 @@ jobs: cargo build --workspace --target thumbv7m-none-eabi - --features async,defmt-03,embedded-io/defmt,embedded-io-async/defmt + --features async,defmt,embedded-io/defmt,embedded-io-async/defmt msrv-1-81: runs-on: ubuntu-latest diff --git a/embedded-hal-bus/src/lib.rs b/embedded-hal-bus/src/lib.rs index 50bc4381d..7545480b8 100644 --- a/embedded-hal-bus/src/lib.rs +++ b/embedded-hal-bus/src/lib.rs @@ -3,10 +3,6 @@ #![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(docsrs, feature(doc_cfg))] -// needed to prevent defmt macros from breaking, since they emit code that does `defmt::blahblah`. -#[cfg(feature = "defmt")] -use defmt; - pub mod i2c; pub mod spi; pub mod util; diff --git a/embedded-hal-bus/src/spi/mod.rs b/embedded-hal-bus/src/spi/mod.rs index b3a4725c5..bf8b5a3bc 100644 --- a/embedded-hal-bus/src/spi/mod.rs +++ b/embedded-hal-bus/src/spi/mod.rs @@ -26,7 +26,7 @@ pub use rc::*; pub use self::critical_section::*; #[cfg(feature = "defmt")] -use crate::defmt; +use defmt; /// Error type for [`ExclusiveDevice`] operations. #[derive(Copy, Clone, Eq, PartialEq, Debug)] diff --git a/embedded-hal/src/digital.rs b/embedded-hal/src/digital.rs index 3dee2f517..cff6e2cd6 100644 --- a/embedded-hal/src/digital.rs +++ b/embedded-hal/src/digital.rs @@ -3,7 +3,7 @@ use core::ops::Not; #[cfg(feature = "defmt")] -use crate::defmt; +use defmt; /// Error. pub trait Error: core::fmt::Debug { diff --git a/embedded-hal/src/i2c.rs b/embedded-hal/src/i2c.rs index c3c56cea3..c7b64d574 100644 --- a/embedded-hal/src/i2c.rs +++ b/embedded-hal/src/i2c.rs @@ -164,7 +164,7 @@ use crate::private; #[cfg(feature = "defmt")] -use crate::defmt; +use defmt; /// I2C error. pub trait Error: core::fmt::Debug { diff --git a/embedded-hal/src/lib.rs b/embedded-hal/src/lib.rs index bc39f96c8..c195bb2a1 100644 --- a/embedded-hal/src/lib.rs +++ b/embedded-hal/src/lib.rs @@ -15,7 +15,3 @@ mod private { impl Sealed for SevenBitAddress {} impl Sealed for TenBitAddress {} } - -// needed to prevent defmt macros from breaking, since they emit code that does `defmt::blahblah`. -#[cfg(feature = "defmt")] -use defmt; diff --git a/embedded-hal/src/pwm.rs b/embedded-hal/src/pwm.rs index 3b589dfd1..8952b15b8 100644 --- a/embedded-hal/src/pwm.rs +++ b/embedded-hal/src/pwm.rs @@ -1,7 +1,7 @@ //! Pulse Width Modulation (PWM) traits. #[cfg(feature = "defmt")] -use crate::defmt; +use defmt; /// Error pub trait Error: core::fmt::Debug { diff --git a/embedded-hal/src/spi.rs b/embedded-hal/src/spi.rs index b6bdfb841..9b19d9953 100644 --- a/embedded-hal/src/spi.rs +++ b/embedded-hal/src/spi.rs @@ -174,7 +174,7 @@ use core::fmt::Debug; #[cfg(feature = "defmt")] -use crate::defmt; +use defmt; /// Clock polarity. #[derive(Clone, Copy, Debug, PartialEq, Eq)]