@@ -123,16 +123,34 @@ 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
+
137
+ /// I2C no acknowledge error source
138
+ ///
139
+ /// In cases where it is possible, a device should indicate if a no acknowledge
140
+ /// response was received to an address versus a no acknowledge to a data byte.
141
+ /// Where it is not possible to differentiate, `Unknown` should be indicated.
142
+ #[ derive( Debug , Copy , Clone , Eq , PartialEq , Ord , PartialOrd , Hash ) ]
143
+ pub enum NoAcknowledgeSource {
144
+ /// The device did not acknowledge its address. The device may be missing.
145
+ Address ,
146
+ /// The device did not acknowledge the data. It may not be ready to process
147
+ /// requests at the moment.
148
+ Data ,
149
+ /// Either the device did not acknowledge its address or the data, but it is
150
+ /// unknown which.
151
+ Unknown ,
152
+ }
153
+
136
154
impl Error for ErrorKind {
137
155
fn kind ( & self ) -> ErrorKind {
138
156
* self
@@ -144,8 +162,7 @@ impl core::fmt::Display for ErrorKind {
144
162
match self {
145
163
Self :: Bus => write ! ( f, "Bus error occurred" ) ,
146
164
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" ) ,
165
+ Self :: NoAcknowledge ( s) => s. fmt ( f) ,
149
166
Self :: Overrun => write ! ( f, "The peripheral receive buffer was overrun" ) ,
150
167
Self :: Other => write ! (
151
168
f,
@@ -155,6 +172,16 @@ impl core::fmt::Display for ErrorKind {
155
172
}
156
173
}
157
174
175
+ impl core:: fmt:: Display for NoAcknowledgeSource {
176
+ fn fmt ( & self , f : & mut core:: fmt:: Formatter < ' _ > ) -> core:: fmt:: Result {
177
+ match self {
178
+ Self :: Address => write ! ( f, "The device did not acknowledge its address" ) ,
179
+ Self :: Data => write ! ( f, "The device did not acknowledge the data" ) ,
180
+ Self :: Unknown => write ! ( f, "The device did not acknowledge its address or the data" ) ,
181
+ }
182
+ }
183
+ }
184
+
158
185
/// Address mode (7-bit / 10-bit)
159
186
///
160
187
/// Note: This trait is sealed and should not be implemented outside of this crate.
0 commit comments