Skip to content

Commit

Permalink
Add ADC Clip error.
Browse files Browse the repository at this point in the history
  • Loading branch information
reitermarkus committed Jan 19, 2024
1 parent f0db02e commit cb86eb0
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions embedded-hal/src/adc.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -111,26 +111,46 @@ 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,
}

/// ADC clip error.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
pub enum Clip {
/// An undershoot of the measurement range occured.
Undershoot,
/// An overshoot of the measurement range occured.
Overshoot,
}

impl Error for ErrorKind {
#[inline]
fn kind(&self) -> ErrorKind {
*self
}
}

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) => {
"An undershoot of the measurement range occured."
}
Self::Clip(Clip::Overshoot) => {
"An overshoot of the measurement range occured."
}
Self::Other => {
"A different error occurred. The original error may contain more information."
}
},
f,
)
}
}

Expand Down

0 comments on commit cb86eb0

Please sign in to comment.