Skip to content

Commit 4be95a4

Browse files
committed
Refactor bit manipulation in getRegister() function
Obtain the same outcome by using bitwise operations
1 parent 540acfc commit 4be95a4

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/Adafruit_MCP23XXX.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,8 @@ uint16_t Adafruit_MCP23XXX::getRegister(uint8_t baseAddress, uint8_t port) {
292292
uint16_t reg = baseAddress;
293293
// MCP23x17 BANK=0
294294
if (pinCount > 8) {
295-
reg *= 2;
296-
// Port B
297-
if (port)
298-
reg++;
295+
reg <<= 1;
296+
reg |= port;
299297
}
300298
// for SPI, add opcode as high byte
301299
return (spi_dev) ? (0x4000 | (hw_addr << 9) | reg) : reg;

0 commit comments

Comments
 (0)