@@ -44,7 +44,8 @@ bool Adafruit_MCP23XXX::begin_I2C(uint8_t i2c_addr, TwoWire *wire) {
44
44
*/
45
45
/* *************************************************************************/
46
46
bool Adafruit_MCP23XXX::begin_SPI (uint8_t cs_pin, SPIClass *theSPI) {
47
- spi_dev = new Adafruit_SPIDevice (cs_pin, 1000000 , SPI_BITORDER_MSBFIRST, SPI_MODE0, theSPI);
47
+ spi_dev = new Adafruit_SPIDevice (cs_pin, 1000000 , SPI_BITORDER_MSBFIRST,
48
+ SPI_MODE0, theSPI);
48
49
return spi_dev->begin ();
49
50
}
50
51
@@ -58,8 +59,8 @@ bool Adafruit_MCP23XXX::begin_SPI(uint8_t cs_pin, SPIClass *theSPI) {
58
59
@return true if initialization successful, otherwise false.
59
60
*/
60
61
/* *************************************************************************/
61
- bool Adafruit_MCP23XXX::begin_SPI (int8_t cs_pin, int8_t sck_pin, int8_t miso_pin,
62
- int8_t mosi_pin) {
62
+ bool Adafruit_MCP23XXX::begin_SPI (int8_t cs_pin, int8_t sck_pin,
63
+ int8_t miso_pin, int8_t mosi_pin) {
63
64
spi_dev = new Adafruit_SPIDevice (cs_pin, sck_pin, miso_pin, mosi_pin);
64
65
return spi_dev->begin ();
65
66
}
@@ -105,7 +106,8 @@ void Adafruit_MCP23XXX::pinMode(uint8_t pin, uint8_t mode) {
105
106
*/
106
107
/* *************************************************************************/
107
108
uint8_t Adafruit_MCP23XXX::digitalRead (uint8_t pin) {
108
- if (pin >= pinCount) return 0 ;
109
+ if (pin >= pinCount)
110
+ return 0 ;
109
111
return ((readGPIO (PORT (pin)) & MASK (pin)) == 0 ) ? LOW : HIGH;
110
112
}
111
113
@@ -156,11 +158,21 @@ void Adafruit_MCP23XXX::writeGPIO(uint8_t value, uint8_t port) {
156
158
@param polarity HIGH or LOW
157
159
*/
158
160
/* *************************************************************************/
159
- void Adafruit_MCP23XXX::setupInterrupts (bool mirroring, bool openDrain, uint8_t polarity) {
161
+ void Adafruit_MCP23XXX::setupInterrupts (bool mirroring, bool openDrain,
162
+ uint8_t polarity) {
160
163
uint8_t iocon = readRegister (getRegister (MCP23XXX_IOCON));
161
- if (mirroring) iocon |= 1 << 6 ; else iocon &= ~(1 << 6 );
162
- if (openDrain) iocon |= 1 << 2 ; else iocon &= ~(1 << 2 );
163
- if (polarity == HIGH) iocon |= 1 << 1 ; else iocon &= ~(1 << 1 );
164
+ if (mirroring)
165
+ iocon |= 1 << 6 ;
166
+ else
167
+ iocon &= ~(1 << 6 );
168
+ if (openDrain)
169
+ iocon |= 1 << 2 ;
170
+ else
171
+ iocon &= ~(1 << 2 );
172
+ if (polarity == HIGH)
173
+ iocon |= 1 << 1 ;
174
+ else
175
+ iocon &= ~(1 << 1 );
164
176
writeRegister (getRegister (MCP23XXX_IOCON), iocon);
165
177
}
166
178
@@ -191,7 +203,10 @@ void Adafruit_MCP23XXX::setupInterruptPin(uint8_t pin, uint8_t mode) {
191
203
// set DEFVAL to 1=LOW or 0=HIGH
192
204
reg = getRegister (MCP23XXX_DEFVAL, PORT (pin));
193
205
uint8_t defval = readRegister (reg);
194
- if (mode == LOW) defval |= MASK (pin); else defval &= ~MASK (pin);
206
+ if (mode == LOW)
207
+ defval |= MASK (pin);
208
+ else
209
+ defval &= ~MASK (pin);
195
210
writeRegister (reg, defval);
196
211
}
197
212
}
@@ -334,7 +349,8 @@ uint8_t Adafruit_MCP23XXX::getRegister(uint8_t baseAddress, uint8_t port) {
334
349
if (pinCount > 8 ) {
335
350
reg *= 2 ;
336
351
// Port B
337
- if (port) reg++;
352
+ if (port)
353
+ reg++;
338
354
}
339
355
return reg;
340
356
}
0 commit comments