Skip to content

Commit 4acbc55

Browse files
committed
Add defmt::Format bound to error types
1 parent b8fd20d commit 4acbc55

8 files changed

Lines changed: 34 additions & 4 deletions

File tree

embedded-can/src/blocking.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ pub trait Can {
66
type Frame: crate::Frame;
77

88
/// Associated error type.
9+
#[cfg(feature = "defmt")]
10+
type Error: crate::Error + defmt::Format;
11+
/// Associated error type.
12+
#[cfg(not(feature = "defmt"))]
913
type Error: crate::Error;
1014

1115
/// Puts a frame in the transmit buffer. Blocks until space is available in

embedded-can/src/nb.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ pub trait Can {
66
type Frame: crate::Frame;
77

88
/// Associated error type.
9+
#[cfg(feature = "defmt")]
10+
type Error: crate::Error + defmt::Format;
11+
/// Associated error type.
12+
#[cfg(not(feature = "defmt"))]
913
type Error: crate::Error;
1014

1115
/// Puts a frame in the transmit buffer to be sent on the bus.

embedded-hal-bus/src/i2c/atomic.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use embedded_hal::i2c::{Error, ErrorKind, ErrorType, I2c};
22

3+
#[cfg(feature = "defmt-03")]
4+
use crate::defmt;
35
use crate::util::AtomicCell;
46

57
/// Atomics-based shared bus [`I2c`] implementation.
@@ -80,6 +82,7 @@ pub struct AtomicDevice<'a, T> {
8082
bus: &'a AtomicCell<T>,
8183
}
8284

85+
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
8386
#[derive(Debug, Copy, Clone)]
8487
/// Wrapper type for errors originating from the atomically-checked I2C bus manager.
8588
pub enum AtomicError<T: Error> {

embedded-hal-bus/src/spi/atomic.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use embedded_hal::digital::OutputPin;
33
use embedded_hal::spi::{Error, ErrorKind, ErrorType, Operation, SpiBus, SpiDevice};
44

55
use super::DeviceError;
6+
#[cfg(feature = "defmt-03")]
7+
use crate::defmt;
68
use crate::spi::shared::transaction;
79
use crate::util::AtomicCell;
810

@@ -36,12 +38,13 @@ pub struct AtomicDevice<'a, BUS, CS, D> {
3638
delay: D,
3739
}
3840

39-
#[derive(Debug, Copy, Clone)]
4041
/// Wrapper type for errors returned by [`AtomicDevice`].
42+
#[derive(Debug, Copy, Clone)]
4143
#[cfg_attr(
4244
docsrs,
4345
doc(cfg(any(feature = "portable-atomic", target_has_atomic = "8")))
4446
)]
47+
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
4548
pub enum AtomicError<T: Error> {
4649
/// This error is returned if the SPI bus was already in use when an operation was attempted,
4750
/// which indicates that the driver requirements are not being met with regard to

embedded-hal/src/digital.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ impl core::fmt::Display for ErrorKind {
5959
///
6060
/// This just defines the error type, to be used by the other traits.
6161
pub trait ErrorType {
62-
/// Error type
62+
/// Error type.
63+
#[cfg(feature = "defmt-03")]
64+
type Error: Error + defmt::Format;
65+
/// Error type.
66+
#[cfg(not(feature = "defmt-03"))]
6367
type Error: Error;
6468
}
6569

embedded-hal/src/i2c.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,11 @@ impl core::fmt::Display for NoAcknowledgeSource {
265265
///
266266
/// This just defines the error type, to be used by the other traits.
267267
pub trait ErrorType {
268-
/// Error type
268+
/// Error type.
269+
#[cfg(feature = "defmt-03")]
270+
type Error: Error + defmt::Format;
271+
/// Error type.
272+
#[cfg(not(feature = "defmt-03"))]
269273
type Error: Error;
270274
}
271275

embedded-hal/src/pwm.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ impl core::fmt::Display for ErrorKind {
5858
///
5959
/// This just defines the error type, to be used by the other traits.
6060
pub trait ErrorType {
61-
/// Error type
61+
/// Error type.
62+
#[cfg(feature = "defmt-03")]
63+
type Error: Error + defmt::Format;
64+
/// Error type.
65+
#[cfg(not(feature = "defmt-03"))]
6266
type Error: Error;
6367
}
6468

embedded-hal/src/spi.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@ impl core::fmt::Display for ErrorKind {
307307
/// This just defines the error type, to be used by the other SPI traits.
308308
pub trait ErrorType {
309309
/// Error type.
310+
#[cfg(feature = "defmt-03")]
311+
type Error: Error + defmt::Format;
312+
/// Error type.
313+
#[cfg(not(feature = "defmt-03"))]
310314
type Error: Error;
311315
}
312316

0 commit comments

Comments
 (0)