diff --git a/ublox-cellular/src/error.rs b/ublox-cellular/src/error.rs index 57e6999..dd7b684 100644 --- a/ublox-cellular/src/error.rs +++ b/ublox-cellular/src/error.rs @@ -30,6 +30,23 @@ pub enum Error { _Unknown, } +#[cfg(feature = "defmt")] +impl defmt::Format for Error { + fn format(&self, f: defmt::Formatter<'_>) { + match self { + Self::BaudDetection => defmt::write!(f, "BaudDetection"), + Self::Busy => defmt::write!(f, "Busy"), + Self::Uninitialized => defmt::write!(f, "Uninitialized"), + Self::StateTimeout => defmt::write!(f, "StateTimeout"), + Self::Network(e) => defmt::write!(f, "Network({:?})", e), + Self::DataService(e) => defmt::write!(f, "DataService({:?})", e), + Self::Generic(e) => defmt::write!(f, "Generic({:?})", e), + Self::_Unknown => defmt::write!(f, "_Unknown"), + _ => defmt::write!(f, "non_exhaustive"), + } + } +} + impl From for Error { fn from(e: DataServiceError) -> Self { // Unwrap generic and network errors diff --git a/ublox-cellular/src/services/data/error.rs b/ublox-cellular/src/services/data/error.rs index 4a6c557..63468e5 100644 --- a/ublox-cellular/src/services/data/error.rs +++ b/ublox-cellular/src/services/data/error.rs @@ -3,6 +3,7 @@ use crate::network::Error as NetworkError; use ublox_sockets::Error as SocketError; #[derive(Debug, PartialEq)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum Error { InvalidApn, SocketMemory,