diff --git a/esp-hal/src/i2c/master/mod.rs b/esp-hal/src/i2c/master/mod.rs index dcdf8437b6..0fcc09af86 100644 --- a/esp-hal/src/i2c/master/mod.rs +++ b/esp-hal/src/i2c/master/mod.rs @@ -106,12 +106,38 @@ pub enum Error { InvalidZeroLength, } +impl core::error::Error for Error {} + +impl core::fmt::Display for Error { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Error::ExceedingFifo => write!(f, "The transmission exceeded the FIFO size"), + Error::AckCheckFailed => write!(f, "The acknowledgment check failed"), + Error::TimeOut => write!(f, "A timeout occurred during transmission"), + Error::ArbitrationLost => write!(f, "The arbitration for the bus was lost"), + Error::ExecIncomplete => write!(f, "The execution of the I2C command was incomplete"), + Error::CommandNrExceeded => { + write!(f, "The number of commands issued exceeded the limit") + } + Error::InvalidZeroLength => write!(f, "Zero length read or write operation"), + } + } +} + /// I2C-specific configuration errors #[derive(Debug, Clone, Copy, PartialEq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[non_exhaustive] pub enum ConfigError {} +impl core::error::Error for ConfigError {} + +impl core::fmt::Display for ConfigError { + fn fmt(&self, _f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + Ok(()) + } +} + // This enum is used to keep track of the last/next operation that was/will be // performed in an embedded-hal(-async) I2c::transaction. It is used to // determine whether a START condition should be issued at the start of the diff --git a/esp-hal/src/uart.rs b/esp-hal/src/uart.rs index 3c464cb648..cdd1e4db5a 100644 --- a/esp-hal/src/uart.rs +++ b/esp-hal/src/uart.rs @@ -287,6 +287,20 @@ pub enum Error { RxParityError, } +impl core::error::Error for Error {} + +impl core::fmt::Display for Error { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Error::InvalidArgument => write!(f, "An invalid configuration argument was provided"), + Error::RxFifoOvf => write!(f, "The RX FIFO overflowed"), + Error::RxGlitchDetected => write!(f, "A glitch was detected on the RX line"), + Error::RxFrameError => write!(f, "A framing error was detected on the RX line"), + Error::RxParityError => write!(f, "A parity error was detected on the RX line"), + } + } +} + impl embedded_hal_nb::serial::Error for Error { fn kind(&self) -> embedded_hal_nb::serial::ErrorKind { embedded_hal_nb::serial::ErrorKind::Other @@ -621,10 +635,23 @@ pub struct UartRx<'d, Dm, T = AnyUart> { pub enum ConfigError { /// The requested timeout is not supported. UnsupportedTimeout, - /// The requested fifo threshold is not supported. + /// The requested FIFO threshold is not supported. UnsupportedFifoThreshold, } +impl core::error::Error for ConfigError {} + +impl core::fmt::Display for ConfigError { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + ConfigError::UnsupportedTimeout => write!(f, "The requested timeout is not supported"), + ConfigError::UnsupportedFifoThreshold => { + write!(f, "The requested FIFO threshold is not supported") + } + } + } +} + #[cfg(any(doc, feature = "unstable"))] #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))] impl SetConfig for Uart<'_, Dm, T>