1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum AD7124CoreError {
8 InvalidParameter,
10 InvalidConfiguration,
12 DeviceNotResponding,
14 InvalidDeviceId,
16 UnsupportedOperation,
18 DataCorruption,
20 BufferOverflow,
22 ValueOutOfRange,
24 NotInitialized,
26 Timeout,
28 CrcError,
30 CalibrationFailed,
32 ConversionError,
34 ChannelNotEnabled,
36 ReferenceVoltageError,
38 PowerSupplyFault,
40}
41
42#[derive(Debug)]
44pub enum AD7124Error<TransportE = (), PinE = ()> {
45 Core(AD7124CoreError),
47 Transport(TransportE),
49 Pin(PinE),
51 Timeout,
53}
54
55impl<TransportE, PinE> From<AD7124CoreError> for AD7124Error<TransportE, PinE> {
56 fn from(err: AD7124CoreError) -> Self {
57 AD7124Error::Core(err)
58 }
59}
60
61impl<TransportE, PinE> core::fmt::Display for AD7124Error<TransportE, PinE>
65where
66 TransportE: core::fmt::Display,
67 PinE: core::fmt::Display,
68{
69 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
70 match self {
71 AD7124Error::Core(err) => match err {
72 AD7124CoreError::InvalidParameter => write!(f, "Invalid parameter"),
73 AD7124CoreError::InvalidConfiguration => write!(f, "Invalid configuration"),
74 AD7124CoreError::DeviceNotResponding => write!(f, "Device not responding"),
75 AD7124CoreError::InvalidDeviceId => write!(f, "Invalid device ID"),
76 AD7124CoreError::UnsupportedOperation => write!(f, "Unsupported operation"),
77 AD7124CoreError::DataCorruption => write!(f, "Data corruption detected"),
78 AD7124CoreError::BufferOverflow => write!(f, "Buffer overflow"),
79 AD7124CoreError::ValueOutOfRange => write!(f, "Value out of range"),
80 AD7124CoreError::NotInitialized => write!(f, "Device not initialized"),
81 AD7124CoreError::Timeout => write!(f, "Communication timeout"),
82 AD7124CoreError::CrcError => write!(f, "CRC validation failed"),
83 AD7124CoreError::CalibrationFailed => write!(f, "ADC calibration failed"),
84 AD7124CoreError::ConversionError => write!(f, "ADC conversion error"),
85 AD7124CoreError::ChannelNotEnabled => write!(f, "Channel not enabled"),
86 AD7124CoreError::ReferenceVoltageError => write!(f, "Reference voltage error"),
87 AD7124CoreError::PowerSupplyFault => write!(f, "Power supply fault"),
88 },
89 AD7124Error::Transport(err) => write!(f, "Transport error: {}", err),
90 AD7124Error::Pin(err) => write!(f, "Pin error: {}", err),
91 AD7124Error::Timeout => write!(f, "Operation timeout"),
92 }
93 }
94}
95
96#[cfg(feature = "defmt")]
97impl<TransportE, PinE> defmt::Format for AD7124Error<TransportE, PinE>
98where
99 TransportE: defmt::Format,
100 PinE: defmt::Format,
101{
102 fn format(&self, f: defmt::Formatter<'_>) {
103 match self {
104 AD7124Error::Core(err) => match err {
105 AD7124CoreError::InvalidParameter => defmt::write!(f, "Invalid parameter"),
106 AD7124CoreError::InvalidConfiguration => defmt::write!(f, "Invalid configuration"),
107 AD7124CoreError::DeviceNotResponding => defmt::write!(f, "Device not responding"),
108 AD7124CoreError::InvalidDeviceId => defmt::write!(f, "Invalid device ID"),
109 AD7124CoreError::UnsupportedOperation => defmt::write!(f, "Unsupported operation"),
110 AD7124CoreError::DataCorruption => defmt::write!(f, "Data corruption detected"),
111 AD7124CoreError::BufferOverflow => defmt::write!(f, "Buffer overflow"),
112 AD7124CoreError::ValueOutOfRange => defmt::write!(f, "Value out of range"),
113 AD7124CoreError::NotInitialized => defmt::write!(f, "Device not initialized"),
114 AD7124CoreError::Timeout => defmt::write!(f, "Communication timeout"),
115 AD7124CoreError::CrcError => defmt::write!(f, "CRC validation failed"),
116 AD7124CoreError::CalibrationFailed => defmt::write!(f, "ADC calibration failed"),
117 AD7124CoreError::ConversionError => defmt::write!(f, "ADC conversion error"),
118 AD7124CoreError::ChannelNotEnabled => defmt::write!(f, "Channel not enabled"),
119 AD7124CoreError::ReferenceVoltageError => {
120 defmt::write!(f, "Reference voltage error")
121 }
122 AD7124CoreError::PowerSupplyFault => defmt::write!(f, "Power supply fault"),
123 },
124 AD7124Error::Transport(err) => defmt::write!(f, "Transport error: {:?}", err),
125 AD7124Error::Pin(err) => defmt::write!(f, "Pin error: {:?}", err),
126 AD7124Error::Timeout => defmt::write!(f, "Operation timeout"),
127 }
128 }
129}