From 6a71b0c73d55d0756b358932ba8b10595a77c254 Mon Sep 17 00:00:00 2001 From: hibikiledo Date: Mon, 8 Aug 2016 13:52:57 +0700 Subject: [PATCH] Add support for Wire library for ESP-01 --- Adafruit_MCP23017.cpp | 20 +++++++++++++++++--- Adafruit_MCP23017.h | 13 ++++++++----- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/Adafruit_MCP23017.cpp b/Adafruit_MCP23017.cpp index ad96e8d..9df3810 100644 --- a/Adafruit_MCP23017.cpp +++ b/Adafruit_MCP23017.cpp @@ -1,4 +1,4 @@ -/*************************************************** +/*************************************************** This is a library for the MCP23017 i2c port expander These displays use I2C to communicate, 2 pins are required to @@ -124,6 +124,22 @@ void Adafruit_MCP23017::begin(uint8_t addr) { writeRegister(MCP23017_IODIRB,0xff); } +#ifdef ESP8266 + void Adafruit_MCP23017::begin(uint8_t addr, uint8_t sda, uint8_t sdc) { + if (addr > 7) { + addr = 7; + } + i2caddr = addr; + + Wire.begin(sda, sdc); + + // set defaults! + // all inputs on port A and B + writeRegister(MCP23017_IODIRA,0xff); + writeRegister(MCP23017_IODIRB,0xff); + } +#endif + /** * Initializes the default MCP23017, with 000 for the configurable part of the address */ @@ -287,5 +303,3 @@ uint8_t Adafruit_MCP23017::getLastInterruptPinValue(){ return MCP23017_INT_ERR; } - - diff --git a/Adafruit_MCP23017.h b/Adafruit_MCP23017.h index ef2ba01..af1fb14 100644 --- a/Adafruit_MCP23017.h +++ b/Adafruit_MCP23017.h @@ -1,13 +1,13 @@ -/*************************************************** +/*************************************************** This is a library for the MCP23017 i2c port expander - These displays use I2C to communicate, 2 pins are required to + These displays use I2C to communicate, 2 pins are required to interface - Adafruit invests time and resources providing this open source code, - please support Adafruit and open-source hardware by purchasing + Adafruit invests time and resources providing this open source code, + please support Adafruit and open-source hardware by purchasing products from Adafruit! - Written by Limor Fried/Ladyada for Adafruit Industries. + Written by Limor Fried/Ladyada for Adafruit Industries. BSD license, all text above must be included in any redistribution ****************************************************/ @@ -24,6 +24,9 @@ class Adafruit_MCP23017 { public: void begin(uint8_t addr); + #ifdef ESP8266 + void begin(uint8_t addr, uint8_t sda, uint8_t sdc); + #endif void begin(void); void pinMode(uint8_t p, uint8_t d);