Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/MCP23017.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ MCP23017::MCP23017(uint8_t address, TwoWire& bus) {
_bus = &bus;
}

MCP23017::MCP23017(TwoWire& bus) {
_deviceAddr = MCP23017_I2C_ADDRESS;
_bus = &bus;
}

MCP23017::~MCP23017() {}

void MCP23017::init()
Expand All @@ -25,6 +30,17 @@ void MCP23017::init()
writeRegister(MCP23017Register::GPPU_A, 0xFF, 0xFF);
}

void MCP23017::begin()
{
init();
}

void MCP23017::begin(uint8_t address)
{
_deviceAddr = address;
begin();
}

void MCP23017::portMode(MCP23017Port port, uint8_t directions, uint8_t pullups, uint8_t inverted)
{
writeRegister(MCP23017Register::IODIR_A + port, directions);
Expand Down
17 changes: 16 additions & 1 deletion src/MCP23017.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <Arduino.h>
#include <Wire.h>

#define MCP23017_I2C_ADDRESS 0x20 ///< The default I2C address of MCP23017.
#define _MCP23017_INTERRUPT_SUPPORT_ ///< Enables support for MCP23017 interrupts.

enum class MCP23017Port : uint8_t
Expand Down Expand Up @@ -65,10 +66,24 @@ class MCP23017
* Instantiates a new instance to interact with a MCP23017 at the specified address.
*/
MCP23017(uint8_t address, TwoWire& bus = Wire);
/**
* Instantiates a new instance to interact with a MCP23017 at the
* MCP23017_I2C_ADDRESS default.
*/
MCP23017(TwoWire& bus = Wire);
~MCP23017();
#ifdef _DEBUG
void debug();
#endif
/**
* Uses the I2C address set during construction. Implicitly calls init().
*/
void begin();
/**
* Overrides the I2C address set by the constructor. Implicitly calls begin().

*/
void begin(uint8_t address);
/**
* Initializes the chip with the default configuration.
* Enables Byte mode (IOCON.BANK = 0 and IOCON.SEQOP = 1).
Expand Down Expand Up @@ -221,4 +236,4 @@ class MCP23017
void clearInterrupts(uint8_t& portA, uint8_t& portB);

#endif
};
};