1313
1414#ifndef _Adafruit_MCP23017_H_
1515#define _Adafruit_MCP23017_H_
16+
17+ #if defined (SPARK)
1618#include " application.h"
19+
20+ #define bitRead (value, bit ) (((value) >> (bit)) & 0x01 )
21+ #define bitSet (value, bit ) ((value) |= (1UL << (bit)))
22+ #define bitClear (value, bit ) ((value) &= ~(1UL << (bit)))
23+ #define bitWrite (value, bit, bitvalue ) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
24+
25+ #endif
26+
1727// Don't forget the Wire library
1828class Adafruit_MCP23017 {
1929public:
@@ -27,9 +37,28 @@ class Adafruit_MCP23017 {
2737
2838 void writeGPIOAB (uint16_t );
2939 uint16_t readGPIOAB ();
40+ uint8_t readGPIO (uint8_t b);
41+
42+ void setupInterrupts (uint8_t mirroring, uint8_t open, uint8_t polarity);
43+ void setupInterruptPin (uint8_t p, uint8_t mode);
44+ uint8_t getLastInterruptPin ();
45+ uint8_t getLastInterruptPinValue ();
3046
3147 private:
3248 uint8_t i2caddr;
49+
50+ uint8_t bitForPin (uint8_t pin);
51+ uint8_t regForPin (uint8_t pin, uint8_t portAaddr, uint8_t portBaddr);
52+
53+ uint8_t readRegister (uint8_t addr);
54+ void writeRegister (uint8_t addr, uint8_t value);
55+
56+ /* *
57+ * Utility private method to update a register associated with a pin (whether port A/B)
58+ * reads its value, updates the particular bit, and writes its value.
59+ */
60+ void updateRegisterBit (uint8_t p, uint8_t pValue, uint8_t portAaddr, uint8_t portBaddr);
61+
3362};
3463
3564#define MCP23017_ADDRESS 0x20
@@ -60,4 +89,7 @@ class Adafruit_MCP23017 {
6089#define MCP23017_GPIOB 0x13
6190#define MCP23017_OLATB 0x15
6291
92+ #define MCP23017_INT_ERR 255
93+
6394#endif
95+
0 commit comments