Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion .github/workflows/rustdoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 5 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
4 changes: 4 additions & 0 deletions embedded-can/src/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions embedded-can/src/nb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions embedded-hal-bus/src/i2c/atomic.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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: I2C,
/// # address: u8,
Expand All @@ -42,6 +46,7 @@ use crate::util::AtomicCell;
/// # type PressureSensor<I2C> = Sensor<I2C>;
/// # type TemperatureSensor<I2C> = Sensor<I2C>;
/// # 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 {
Expand Down Expand Up @@ -80,6 +85,7 @@ pub struct AtomicDevice<'a, T> {
bus: &'a AtomicCell<T>,
}

#[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<T: Error> {
Expand Down
3 changes: 3 additions & 0 deletions embedded-hal-bus/src/i2c/refcell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: I2C,
/// # address: u8,
Expand All @@ -29,6 +31,7 @@ use embedded_hal::i2c::{ErrorType, I2c};
/// # type PressureSensor<I2C> = Sensor<I2C>;
/// # type TemperatureSensor<I2C> = Sensor<I2C>;
/// # 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 {
Expand Down
5 changes: 4 additions & 1 deletion embedded-hal-bus/src/spi/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<T: Error> {
/// 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
Expand Down
6 changes: 5 additions & 1 deletion embedded-hal/src/digital.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
9 changes: 8 additions & 1 deletion embedded-hal/src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
//! // ...
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion embedded-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
6 changes: 5 additions & 1 deletion embedded-hal/src/pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 4 additions & 0 deletions embedded-hal/src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 4 additions & 0 deletions embedded-io/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down