@@ -123,16 +123,33 @@ pub enum ErrorKind {
123
123
Bus ,
124
124
/// The arbitration was lost, e.g. electrical problems with the clock signal
125
125
ArbitrationLoss ,
126
- /// The device did not acknowledge its address. The device may be missing.
127
- NoAcknowledgeAddress ,
128
- /// The device did not acknowled the data. It may not be ready to process requests at the moment.
129
- NoAcknowledgeData ,
126
+ /// A bus operation was not acknowledged, e.g. due to the addressed device not
127
+ /// being available on the bus or the device not being ready to process requests
128
+ /// at the moment
129
+ NoAcknowledge ( NoAcknowledgeSource ) ,
130
130
/// The peripheral receive buffer was overrun
131
131
Overrun ,
132
132
/// A different error occurred. The original error may contain more information.
133
133
Other ,
134
134
}
135
135
136
+ /// I2C no acknowledge error source
137
+ ///
138
+ /// In cases where it is possible, a device should indicate if a no acknowledge
139
+ /// response was received to an address versus a no acknowledge to a data byte.
140
+ /// Where it is not possible to differentiate, `Unknown` should be indicated.
141
+ #[ derive( Debug , Copy , Clone , Eq , PartialEq , Ord , PartialOrd , Hash ) ]
142
+ pub enum NoAcknowledgeSource {
143
+ /// The device did not acknowledge its address. The device may be missing.
144
+ Address ,
145
+ /// The device did not acknowledge the data. It may not be ready to process
146
+ /// requests at the moment.
147
+ Data ,
148
+ /// Either the device did not acknowledge its address or the data, but it is
149
+ /// unknown which.
150
+ Unknown ,
151
+ }
152
+
136
153
impl Error for ErrorKind {
137
154
fn kind ( & self ) -> ErrorKind {
138
155
* self
@@ -144,8 +161,7 @@ impl core::fmt::Display for ErrorKind {
144
161
match self {
145
162
Self :: Bus => write ! ( f, "Bus error occurred" ) ,
146
163
Self :: ArbitrationLoss => write ! ( f, "The arbitration was lost" ) ,
147
- Self :: NoAcknowledgeAddress => write ! ( f, "The device did not acknowledge its address" ) ,
148
- Self :: NoAcknowledgeData => write ! ( f, "The device did not acknowledge the data" ) ,
164
+ Self :: NoAcknowledge ( s) => s. fmt ( f) ,
149
165
Self :: Overrun => write ! ( f, "The peripheral receive buffer was overrun" ) ,
150
166
Self :: Other => write ! (
151
167
f,
@@ -155,6 +171,16 @@ impl core::fmt::Display for ErrorKind {
155
171
}
156
172
}
157
173
174
+ impl core:: fmt:: Display for NoAcknowledgeSource {
175
+ fn fmt ( & self , f : & mut core:: fmt:: Formatter < ' _ > ) -> core:: fmt:: Result {
176
+ match self {
177
+ Self :: Address => write ! ( f, "The device did not acknowledge its address" ) ,
178
+ Self :: Data => write ! ( f, "The device did not acknowledge the data" ) ,
179
+ Self :: Unknown => write ! ( f, "The device did not acknowledge its address or the data" ) ,
180
+ }
181
+ }
182
+ }
183
+
158
184
/// Address mode (7-bit / 10-bit)
159
185
///
160
186
/// Note: This trait is sealed and should not be implemented outside of this crate.
0 commit comments