diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index 422eab62..8543bf60 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -14,4 +14,5 @@ jobs: - uses: dtolnay/rust-toolchain@stable with: components: clippy - - run: cargo clippy --all-features -- --deny=warnings + - run: cargo clippy --workspace --exclude=embedded-io-adapters --all-features -- --deny=warnings + - run: cargo clippy --package=embedded-io-adapters --all-features -- --deny=warnings diff --git a/.github/workflows/rustdoc.yml b/.github/workflows/rustdoc.yml index 1a99f8d9..6f3a1941 100644 --- a/.github/workflows/rustdoc.yml +++ b/.github/workflows/rustdoc.yml @@ -15,4 +15,5 @@ jobs: with: toolchain: nightly-2024-07-26 # tokio/net required to workaround https://github.com/tokio-rs/tokio/issues/6165 - - run: RUSTDOCFLAGS="--deny=warnings --cfg=docsrs" cargo doc --all-features --features tokio/net + - run: RUSTDOCFLAGS="--deny=warnings --cfg=docsrs" cargo doc --workspace --exclude=embedded-io-adapters --all-features + - run: RUSTDOCFLAGS="--deny=warnings --cfg=docsrs" cargo doc --package=embedded-io-adapters --all-features --features tokio/net diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5b5ee297..3e637d97 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,13 +17,14 @@ jobs: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable - run: cargo test --workspace - + test-all-features: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable - - run: cargo test --workspace --all-features + - run: cargo test --workspace --exclude=embedded-io-adapters --all-features + - run: cargo test --package=embedded-io-adapters --all-features build-nostd: runs-on: ubuntu-latest @@ -43,4 +44,5 @@ jobs: steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@1.81 - - run: cargo test --workspace --all-features + - run: cargo test --workspace --exclude=embedded-io-adapters --all-features + - run: cargo test --package=embedded-io-adapters --all-features diff --git a/embedded-can/src/blocking.rs b/embedded-can/src/blocking.rs index d9998369..fa361128 100644 --- a/embedded-can/src/blocking.rs +++ b/embedded-can/src/blocking.rs @@ -6,6 +6,10 @@ pub trait Can { type Frame: crate::Frame; /// Associated error type. + #[cfg(feature = "defmt")] + type Error: crate::Error + defmt::Format; + /// Associated error type. + #[cfg(not(feature = "defmt"))] type Error: crate::Error; /// Puts a frame in the transmit buffer. Blocks until space is available in diff --git a/embedded-can/src/nb.rs b/embedded-can/src/nb.rs index 5010dc03..b63911a9 100644 --- a/embedded-can/src/nb.rs +++ b/embedded-can/src/nb.rs @@ -6,6 +6,10 @@ pub trait Can { type Frame: crate::Frame; /// Associated error type. + #[cfg(feature = "defmt")] + type Error: crate::Error + defmt::Format; + /// Associated error type. + #[cfg(not(feature = "defmt"))] type Error: crate::Error; /// Puts a frame in the transmit buffer to be sent on the bus. diff --git a/embedded-hal-bus/src/i2c/atomic.rs b/embedded-hal-bus/src/i2c/atomic.rs index b47b8c5e..544b032f 100644 --- a/embedded-hal-bus/src/i2c/atomic.rs +++ b/embedded-hal-bus/src/i2c/atomic.rs @@ -1,5 +1,7 @@ use embedded_hal::i2c::{Error, ErrorKind, ErrorType, I2c}; +#[cfg(feature = "defmt-03")] +use crate::defmt; use crate::util::AtomicCell; /// Atomics-based shared bus [`I2c`] implementation. @@ -30,6 +32,8 @@ use crate::util::AtomicCell; /// use embedded_hal_bus::i2c; /// use embedded_hal_bus::util::AtomicCell; /// # use embedded_hal::i2c::{self as hali2c, SevenBitAddress, TenBitAddress, I2c, Operation, ErrorKind}; +/// # #[cfg(feature = "defmt-03")] +/// # use embedded_hal::defmt; /// # pub struct Sensor { /// # i2c: I2C, /// # address: u8, @@ -42,6 +46,7 @@ use crate::util::AtomicCell; /// # type PressureSensor = Sensor; /// # type TemperatureSensor = Sensor; /// # pub struct I2c0; +/// # #[cfg_attr(feature = "defmt-03", derive(defmt::Format))] /// # #[derive(Debug, Copy, Clone, Eq, PartialEq)] /// # pub enum Error { } /// # impl hali2c::Error for Error { @@ -80,6 +85,7 @@ pub struct AtomicDevice<'a, T> { bus: &'a AtomicCell, } +#[cfg_attr(feature = "defmt-03", derive(defmt::Format))] #[derive(Debug, Copy, Clone)] /// Wrapper type for errors originating from the atomically-checked I2C bus manager. pub enum AtomicError { diff --git a/embedded-hal-bus/src/i2c/refcell.rs b/embedded-hal-bus/src/i2c/refcell.rs index 445b6b02..73dc1725 100644 --- a/embedded-hal-bus/src/i2c/refcell.rs +++ b/embedded-hal-bus/src/i2c/refcell.rs @@ -17,6 +17,8 @@ use embedded_hal::i2c::{ErrorType, I2c}; /// use embedded_hal_bus::i2c; /// use core::cell::RefCell; /// # use embedded_hal::i2c::{self as hali2c, SevenBitAddress, TenBitAddress, I2c, Operation, ErrorKind}; +/// # #[cfg(feature = "defmt-03")] +/// # use embedded_hal::defmt; /// # pub struct Sensor { /// # i2c: I2C, /// # address: u8, @@ -29,6 +31,7 @@ use embedded_hal::i2c::{ErrorType, I2c}; /// # type PressureSensor = Sensor; /// # type TemperatureSensor = Sensor; /// # pub struct I2c0; +/// # #[cfg_attr(feature = "defmt-03", derive(defmt::Format))] /// # #[derive(Debug, Copy, Clone, Eq, PartialEq)] /// # pub enum Error { } /// # impl hali2c::Error for Error { diff --git a/embedded-hal-bus/src/spi/atomic.rs b/embedded-hal-bus/src/spi/atomic.rs index b4a4208a..2f1a1594 100644 --- a/embedded-hal-bus/src/spi/atomic.rs +++ b/embedded-hal-bus/src/spi/atomic.rs @@ -3,6 +3,8 @@ use embedded_hal::digital::OutputPin; use embedded_hal::spi::{Error, ErrorKind, ErrorType, Operation, SpiBus, SpiDevice}; use super::DeviceError; +#[cfg(feature = "defmt-03")] +use crate::defmt; use crate::spi::shared::transaction; use crate::util::AtomicCell; @@ -36,12 +38,13 @@ pub struct AtomicDevice<'a, BUS, CS, D> { delay: D, } -#[derive(Debug, Copy, Clone)] /// Wrapper type for errors returned by [`AtomicDevice`]. +#[derive(Debug, Copy, Clone)] #[cfg_attr( docsrs, doc(cfg(any(feature = "portable-atomic", target_has_atomic = "8"))) )] +#[cfg_attr(feature = "defmt-03", derive(defmt::Format))] pub enum AtomicError { /// This error is returned if the SPI bus was already in use when an operation was attempted, /// which indicates that the driver requirements are not being met with regard to diff --git a/embedded-hal/src/digital.rs b/embedded-hal/src/digital.rs index 581f2ca3..849b4960 100644 --- a/embedded-hal/src/digital.rs +++ b/embedded-hal/src/digital.rs @@ -59,7 +59,11 @@ impl core::fmt::Display for ErrorKind { /// /// This just defines the error type, to be used by the other traits. pub trait ErrorType { - /// Error type + /// Error type. + #[cfg(feature = "defmt-03")] + type Error: Error + defmt::Format; + /// Error type. + #[cfg(not(feature = "defmt-03"))] type Error: Error; } diff --git a/embedded-hal/src/i2c.rs b/embedded-hal/src/i2c.rs index 8b99197e..45e04ac2 100644 --- a/embedded-hal/src/i2c.rs +++ b/embedded-hal/src/i2c.rs @@ -125,10 +125,13 @@ //! //! ``` //! use embedded_hal::i2c::{self, SevenBitAddress, TenBitAddress, I2c, Operation}; +//! #[cfg(feature = "defmt-03")] +//! use embedded_hal::defmt; //! //! /// I2C0 hardware peripheral which supports both 7-bit and 10-bit addressing. //! pub struct I2c0; //! +//! #[cfg_attr(feature = "defmt-03", derive(defmt::Format))] //! #[derive(Debug, Copy, Clone, Eq, PartialEq)] //! pub enum Error { //! // ... @@ -265,7 +268,11 @@ impl core::fmt::Display for NoAcknowledgeSource { /// /// This just defines the error type, to be used by the other traits. pub trait ErrorType { - /// Error type + /// Error type. + #[cfg(feature = "defmt-03")] + type Error: Error + defmt::Format; + /// Error type. + #[cfg(not(feature = "defmt-03"))] type Error: Error; } diff --git a/embedded-hal/src/lib.rs b/embedded-hal/src/lib.rs index f5eb76c3..3a025b24 100644 --- a/embedded-hal/src/lib.rs +++ b/embedded-hal/src/lib.rs @@ -18,4 +18,4 @@ 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; +pub use defmt_03 as defmt; diff --git a/embedded-hal/src/pwm.rs b/embedded-hal/src/pwm.rs index 4d4ff150..dc124cbd 100644 --- a/embedded-hal/src/pwm.rs +++ b/embedded-hal/src/pwm.rs @@ -58,7 +58,11 @@ impl core::fmt::Display for ErrorKind { /// /// This just defines the error type, to be used by the other traits. pub trait ErrorType { - /// Error type + /// Error type. + #[cfg(feature = "defmt-03")] + type Error: Error + defmt::Format; + /// Error type. + #[cfg(not(feature = "defmt-03"))] type Error: Error; } diff --git a/embedded-hal/src/spi.rs b/embedded-hal/src/spi.rs index 55fc7e9f..aa5e9a70 100644 --- a/embedded-hal/src/spi.rs +++ b/embedded-hal/src/spi.rs @@ -307,6 +307,10 @@ impl core::fmt::Display for ErrorKind { /// This just defines the error type, to be used by the other SPI traits. pub trait ErrorType { /// Error type. + #[cfg(feature = "defmt-03")] + type Error: Error + defmt::Format; + /// Error type. + #[cfg(not(feature = "defmt-03"))] type Error: Error; } diff --git a/embedded-io/src/lib.rs b/embedded-io/src/lib.rs index 7f56be6f..7529a166 100644 --- a/embedded-io/src/lib.rs +++ b/embedded-io/src/lib.rs @@ -218,6 +218,10 @@ impl Error for std::io::Error { /// which might be different types. pub trait ErrorType { /// Error type of all the IO operations on this type. + #[cfg(feature = "defmt")] + type Error: Error + defmt::Format; + /// Error type of all the IO operations on this type. + #[cfg(not(feature = "defmt"))] type Error: Error; }