1use core::fmt::Debug;
2
3use embedded_hal::digital::{Error as DigitalError, ErrorKind as DigitalErrorKind};
4use embedded_hal::i2c::ErrorType;
5use embedded_hal_bus::i2c::AtomicError;
6use thiserror::Error;
7
8#[derive(Error)]
10pub enum Error<S: ErrorType> {
11 Communication(S::Error),
13}
14
15impl<S: ErrorType<Error = impl Debug>> Debug for Error<S> {
16 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
17 match self {
18 Self::Communication(e) => f.debug_tuple("Communication").field(e).finish(),
19 }
20 }
21}
22
23impl<S: ErrorType<Error = E>, E: Debug> DigitalError for Error<S> {
24 fn kind(&self) -> DigitalErrorKind {
25 DigitalErrorKind::Other
26 }
27}
28
29impl<S: ErrorType> From<AtomicError<S::Error>> for Error<S> {
30 fn from(value: AtomicError<S::Error>) -> Self {
31 match value {
32 AtomicError::Busy => unreachable!(),
33 AtomicError::Other(error) => Self::Communication(error),
34 }
35 }
36}