mirror of
https://github.com/italicsjenga/rp-hal-boards.git
synced 2024-12-23 20:51:31 +11:00
Make the i2c error render as text if eh1_0_alpha is on.
This commit is contained in:
parent
6ef6838132
commit
6a29b3bb73
|
@ -65,8 +65,11 @@ pub mod peripheral;
|
|||
|
||||
/// I2C error
|
||||
#[non_exhaustive]
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||
#[cfg_attr(not(feature = "eh1_0_alpha"), derive(Debug))]
|
||||
#[cfg_attr(
|
||||
all(feature = "defmt", not(feature = "eh1_0_alpha")),
|
||||
derive(defmt::Format)
|
||||
)]
|
||||
pub enum Error {
|
||||
/// I2C abort with error
|
||||
Abort(u32),
|
||||
|
@ -80,6 +83,38 @@ pub enum Error {
|
|||
AddressReserved(u16),
|
||||
}
|
||||
|
||||
#[cfg(feature = "eh1_0_alpha")]
|
||||
impl core::fmt::Debug for Error {
|
||||
fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
use eh1_0_alpha::i2c::Error as _;
|
||||
match self {
|
||||
Error::InvalidReadBufferLength => write!(fmt, "InvalidReadBufferLength"),
|
||||
Error::InvalidWriteBufferLength => write!(fmt, "InvalidWriteBufferLength"),
|
||||
Error::AddressOutOfRange(addr) => write!(fmt, "AddressOutOfRange({:x})", addr),
|
||||
Error::AddressReserved(addr) => write!(fmt, "AddressReserved({:x})", addr),
|
||||
Error::Abort(_) => {
|
||||
write!(fmt, "{:?}", self.kind())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "defmt", feature = "eh1_0_alpha"))]
|
||||
impl defmt::Format for Error {
|
||||
fn format(&self, fmt: defmt::Formatter) {
|
||||
use eh1_0_alpha::i2c::Error as _;
|
||||
match self {
|
||||
Error::InvalidReadBufferLength => defmt::write!(fmt, "InvalidReadBufferLength"),
|
||||
Error::InvalidWriteBufferLength => defmt::write!(fmt, "InvalidWriteBufferLength"),
|
||||
Error::AddressOutOfRange(addr) => defmt::write!(fmt, "AddressOutOfRange({:x})", addr),
|
||||
Error::AddressReserved(addr) => defmt::write!(fmt, "AddressReserved({:x})", addr),
|
||||
Error::Abort(_) => {
|
||||
defmt::write!(fmt, "{}", defmt::Debug2Format(&self.kind()))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "eh1_0_alpha")]
|
||||
impl eh1_0_alpha::i2c::Error for Error {
|
||||
fn kind(&self) -> eh1_0_alpha::i2c::ErrorKind {
|
||||
|
|
Loading…
Reference in a new issue