@@ -207,12 +207,25 @@ void Adafruit_MCP23XXX::disableInterruptPin(uint8_t pin) {
207
207
208
208
/* *************************************************************************/
209
209
/* !
210
- @brief Gets the last interrupt pin.
211
- @returns Pin that caused last interrupt.
210
+ @brief Clear interrupts. NOTE:If using DEFVAL, INT clears only if interrupt
211
+ condition does not exist. See Fig 1-7 in datasheet.
212
+ */
213
+ /* *************************************************************************/
214
+ void Adafruit_MCP23XXX::clearInterrupts () {
215
+ // reading INTCAP register(s) clears interrupts
216
+ // just call this and ignore return
217
+ getCapturedInterrupt ();
218
+ }
219
+
220
+ /* *************************************************************************/
221
+ /* !
222
+ @brief Gets the pin that caused the latest interrupt, from INTF, without
223
+ clearing any interrupt flags.
224
+ @returns Pin that caused lastest interrupt.
212
225
*/
213
226
/* *************************************************************************/
214
227
uint8_t Adafruit_MCP23XXX::getLastInterruptPin () {
215
- uint8_t intpin = 255 ;
228
+ uint8_t intpin = MCP23XXX_INT_ERR ;
216
229
uint8_t intf;
217
230
218
231
// Port A
@@ -227,7 +240,7 @@ uint8_t Adafruit_MCP23XXX::getLastInterruptPin() {
227
240
}
228
241
229
242
// Port B and still not found?
230
- if ((pinCount > 8 ) && (intpin == 255 )) {
243
+ if ((pinCount > 8 ) && (intpin == MCP23XXX_INT_ERR )) {
231
244
Adafruit_BusIO_Register INTFB (i2c_dev, spi_dev, MCP23XXX_SPIREG,
232
245
getRegister (MCP23XXX_INTF, 1 ));
233
246
INTFB.read (&intf);
@@ -239,15 +252,34 @@ uint8_t Adafruit_MCP23XXX::getLastInterruptPin() {
239
252
}
240
253
}
241
254
242
- // clear if found
243
- if (intpin != 255 ) {
244
- Adafruit_BusIO_Register INTCAP (
245
- i2c_dev, spi_dev, MCP23XXX_SPIREG,
246
- getRegister (MCP23XXX_INTCAP, MCP_PORT (intpin)));
247
- INTCAP.read ();
255
+ return intpin;
256
+ }
257
+
258
+ /* *************************************************************************/
259
+ /* !
260
+ @brief Get pin states captured at time of interrupt.
261
+ @returns Mutli-bit value representing pin states.
262
+ */
263
+ /* *************************************************************************/
264
+ uint16_t Adafruit_MCP23XXX::getCapturedInterrupt () {
265
+ uint16_t intcap;
266
+ uint8_t intf;
267
+
268
+ // Port A
269
+ Adafruit_BusIO_Register INTCAPA (i2c_dev, spi_dev, MCP23XXX_SPIREG,
270
+ getRegister (MCP23XXX_INTCAP, 0 ));
271
+ INTCAPA.read (&intf);
272
+ intcap = intf;
273
+
274
+ // Port B ?
275
+ if (pinCount > 8 ) {
276
+ Adafruit_BusIO_Register INTCAPB (i2c_dev, spi_dev, MCP23XXX_SPIREG,
277
+ getRegister (MCP23XXX_INTCAP, 1 ));
278
+ INTCAPB.read (&intf);
279
+ intcap |= (uint16_t )intf << 8 ;
248
280
}
249
281
250
- return intpin ;
282
+ return intcap ;
251
283
}
252
284
253
285
/* *************************************************************************/
0 commit comments