diff --git a/embedded-hal/src/adc.rs b/embedded-hal/src/adc.rs index 7a6c4c09..1ca677c8 100644 --- a/embedded-hal/src/adc.rs +++ b/embedded-hal/src/adc.rs @@ -1,6 +1,6 @@ //! Blocking analog-digital conversion traits. -use core::fmt::Debug; +use core::fmt::{Debug, Display}; #[cfg(feature = "defmt-03")] use crate::defmt; @@ -111,10 +111,21 @@ impl Error for core::convert::Infallible { #[cfg_attr(feature = "defmt-03", derive(defmt::Format))] #[non_exhaustive] pub enum ErrorKind { + /// Measurement was clipped. + Clip(Clip), /// A different error occurred. The original error may contain more information. Other, } +#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] +#[cfg_attr(feature = "defmt-03", derive(defmt::Format))] +pub enum Clip { + /// Measurement was clipped due to an undershoot of the measurement range. + Undershoot, + /// Measurement was clipped due to an overshoot of the measurement range. + Overshoot, +} + impl Error for ErrorKind { #[inline] fn kind(&self) -> ErrorKind { @@ -122,15 +133,23 @@ impl Error for ErrorKind { } } -impl core::fmt::Display for ErrorKind { +impl Display for ErrorKind { #[inline] fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - match self { - Self::Other => write!( - f, - "A different error occurred. The original error may contain more information" - ), - } + Display::fmt( + match self { + Self::Clip(Clip::Undershoot) => { + "Measurement was clipped due to an undershoot of the measurement range." + } + Self::Clip(Clip::Overshoot) => { + "Measurement was clipped due to an overshoot of the measurement range." + } + Self::Other => { + "A different error occurred. The original error may contain more information." + } + }, + f, + ) } }