Skip to content

Commit 29d5d76

Browse files
committed
Add ADC Clip error.
1 parent 902ee78 commit 29d5d76

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

embedded-hal/src/adc.rs

Lines changed: 27 additions & 8 deletions
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,45 @@ 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+
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
121+
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
122+
pub enum Clip {
123+
/// Measurement was clipped due to an undershoot of the measurement range.
124+
Undershoot,
125+
/// Measurement was clipped due to an overshoot of the measurement range.
126+
Overshoot,
127+
}
128+
118129
impl Error for ErrorKind {
119130
#[inline]
120131
fn kind(&self) -> ErrorKind {
121132
*self
122133
}
123134
}
124135

125-
impl core::fmt::Display for ErrorKind {
136+
impl Display for ErrorKind {
126137
#[inline]
127138
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-
}
139+
Display::fmt(
140+
match self {
141+
Self::Clip(Clip::Undershoot) => {
142+
"Measurement was clipped due to an undershoot of the measurement range."
143+
}
144+
Self::Clip(Clip::Overshoot) => {
145+
"Measurement was clipped due to an overshoot of the measurement range."
146+
}
147+
Self::Other => {
148+
"A different error occurred. The original error may contain more information."
149+
}
150+
},
151+
f,
152+
)
134153
}
135154
}
136155

0 commit comments

Comments
 (0)