From 05bfbacee55207f8065b6e9bbbc0d5454e77668f Mon Sep 17 00:00:00 2001 From: Ralph Ursprung Date: Thu, 15 May 2025 18:36:51 +0200 Subject: [PATCH 1/2] `embassy-nxp`: make `defmt` optional also enable it on all dependencies (where available). this is needed because in a next commit we'll add code to `embassy-hal-internal` which uses the feature in a macro, as it expects `defmt` to be optional in all embassy HALs. this was the only HAL where that wasn't the case. note that this is a breaking change for consumers! if you wish to use `defmt` in `embassy-nxp` you now need to enable the feature. --- embassy-nxp/Cargo.toml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/embassy-nxp/Cargo.toml b/embassy-nxp/Cargo.toml index cf36a67ec..031cd4aba 100644 --- a/embassy-nxp/Cargo.toml +++ b/embassy-nxp/Cargo.toml @@ -10,8 +10,11 @@ critical-section = "1.1.2" embassy-hal-internal = { version = "0.2.0", path = "../embassy-hal-internal", features = ["cortex-m", "prio-bits-2"] } embassy-sync = { version = "0.6.2", path = "../embassy-sync" } lpc55-pac = "0.5.0" -defmt = "0.3.8" +defmt = { version = "0.3.8", optional = true } [features] default = ["rt"] -rt = ["lpc55-pac/rt"] \ No newline at end of file +rt = ["lpc55-pac/rt"] + +## Enable [defmt support](https://docs.rs/defmt) and enables `defmt` debug-log messages and formatting in embassy drivers. +defmt = ["dep:defmt", "embassy-hal-internal/defmt", "embassy-sync/defmt"] From 4a089fe2455f22f956455548816fcd96735e38d8 Mon Sep 17 00:00:00 2001 From: Ralph Ursprung Date: Thu, 15 May 2025 17:29:23 +0200 Subject: [PATCH 2/2] rp: add missing `Debug` and `defmt::Format` `derive`s for ADC this doesn't cover every `struct` & co. in `embassy-rp`, but at least it adds those needed for `Adc` and `adc::Channel`. --- embassy-hal-internal/src/macros.rs | 2 ++ embassy-hal-internal/src/peripheral.rs | 2 ++ embassy-rp/src/adc.rs | 2 ++ embassy-rp/src/gpio.rs | 2 ++ 4 files changed, 8 insertions(+) diff --git a/embassy-hal-internal/src/macros.rs b/embassy-hal-internal/src/macros.rs index cd2bc3cab..ce72ded5c 100644 --- a/embassy-hal-internal/src/macros.rs +++ b/embassy-hal-internal/src/macros.rs @@ -8,6 +8,8 @@ macro_rules! peripherals_definition { $(#[$cfg])? #[allow(non_camel_case_types)] #[doc = concat!(stringify!($name), " peripheral")] + #[derive(Debug)] + #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct $name { _private: () } $(#[$cfg])? diff --git a/embassy-hal-internal/src/peripheral.rs b/embassy-hal-internal/src/peripheral.rs index 803259bb8..b1868caf6 100644 --- a/embassy-hal-internal/src/peripheral.rs +++ b/embassy-hal-internal/src/peripheral.rs @@ -14,6 +14,8 @@ use core::ops::Deref; /// the driver code would be monomorphized two times. With Peri, the driver is generic /// over a lifetime only. `SPI4` becomes `Peri<'static, SPI4>`, and `&mut SPI4` becomes /// `Peri<'a, SPI4>`. Lifetimes don't cause monomorphization. +#[derive(Debug)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct Peri<'a, T: PeripheralType> { inner: T, _lifetime: PhantomData<&'a mut T>, diff --git a/embassy-rp/src/adc.rs b/embassy-rp/src/adc.rs index ec0c8c46c..2db8e63d7 100644 --- a/embassy-rp/src/adc.rs +++ b/embassy-rp/src/adc.rs @@ -21,6 +21,8 @@ static WAKER: AtomicWaker = AtomicWaker::new(); #[derive(Default)] pub struct Config {} +#[derive(Debug)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] enum Source<'p> { Pin(Peri<'p, AnyPin>), TempSensor(Peri<'p, ADC_TEMP_SENSOR>), diff --git a/embassy-rp/src/gpio.rs b/embassy-rp/src/gpio.rs index af0837f6a..2fb2d65c2 100644 --- a/embassy-rp/src/gpio.rs +++ b/embassy-rp/src/gpio.rs @@ -932,6 +932,8 @@ pub trait Pin: PeripheralType + Into + SealedPin + Sized + 'static { } /// Type-erased GPIO pin +#[derive(Debug)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct AnyPin { pin_bank: u8, }