Skip to content

Commit cb86eb0

Browse files
committed
Add ADC Clip error.
1 parent f0db02e commit cb86eb0

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

embedded-hal/src/adc.rs

+28-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Blocking analog-digital conversion traits.
22
3-
use core::fmt::Debug;
3+
use core::fmt::{Debug, Display};
44

55
#[cfg(feature = "defmt-03")]
66
use crate::defmt;
@@ -111,26 +111,46 @@ impl Error for core::convert::Infallible {
111111
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
112112
#[non_exhaustive]
113113
pub enum ErrorKind {
114+
/// Measurement was clipped.
115+
Clip(Clip),
114116
/// A different error occurred. The original error may contain more information.
115117
Other,
116118
}
117119

120+
/// ADC clip error.
121+
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
122+
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
123+
pub enum Clip {
124+
/// An undershoot of the measurement range occured.
125+
Undershoot,
126+
/// An overshoot of the measurement range occured.
127+
Overshoot,
128+
}
129+
118130
impl Error for ErrorKind {
119131
#[inline]
120132
fn kind(&self) -> ErrorKind {
121133
*self
122134
}
123135
}
124136

125-
impl core::fmt::Display for ErrorKind {
137+
impl Display for ErrorKind {
126138
#[inline]
127139
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
128-
match self {
129-
Self::Other => write!(
130-
f,
131-
"A different error occurred. The original error may contain more information"
132-
),
133-
}
140+
Display::fmt(
141+
match self {
142+
Self::Clip(Clip::Undershoot) => {
143+
"An undershoot of the measurement range occured."
144+
}
145+
Self::Clip(Clip::Overshoot) => {
146+
"An overshoot of the measurement range occured."
147+
}
148+
Self::Other => {
149+
"A different error occurred. The original error may contain more information."
150+
}
151+
},
152+
f,
153+
)
134154
}
135155
}
136156

0 commit comments

Comments
 (0)