Basic library of routines to interface to a Microchip MCP23017 16-bit I/O expander using an I2C interface.

Dependents:   AdaFruit_RGBLCD SX1276_GPS

Fork of MCP23017 by jim herd

Files at this revision

API Documentation at this revision

Comitter:
vtraveller
Date:
Tue Sep 02 07:11:53 2014 +0000
Parent:
15:164d420bcbcf
Commit message:
Changed to use shared I2C interface object

Changed in this revision

MCP23017.cpp Show annotated file Show diff for this revision Revisions of this file
MCP23017.h Show annotated file Show diff for this revision Revisions of this file
diff -r 164d420bcbcf -r 9b5a51117afe MCP23017.cpp
--- a/MCP23017.cpp	Thu Aug 07 19:59:32 2014 +0000
+++ b/MCP23017.cpp	Tue Sep 02 07:11:53 2014 +0000
@@ -27,10 +27,7 @@
 /*-----------------------------------------------------------------------------
  *
  */
-MCP23017::MCP23017(PinName sda, PinName scl, int i2cAddress, bool hispeed)  : _i2c(sda, scl) {
-    // I2C can handle two different frequencies - switch to high speed if asked
-    _i2c.frequency(hispeed ? 400000 : 100000);
-
+MCP23017::MCP23017(I2C & i2c, int i2cAddress)  : _i2c(i2c) {
     MCP23017_i2cAddress = i2cAddress;
     reset();                                  // initialise chip to power-on condition
 }
diff -r 164d420bcbcf -r 9b5a51117afe MCP23017.h
--- a/MCP23017.h	Thu Aug 07 19:59:32 2014 +0000
+++ b/MCP23017.h	Tue Sep 02 07:11:53 2014 +0000
@@ -57,11 +57,10 @@
      *
      * 16-bit I/O expander with I2C interface
      *
-     * @param   sda         I2C data pin
-     * @param   scl         I2C clock pin
+     * @param   i2c         I2C interface
      * @param   i2cAddress  I2C address
      */
-    MCP23017(PinName sda, PinName scl, int i2cAddress, bool hispeed = false);
+    MCP23017(I2C & i2c, int i2cAddress);
 
     /** Reset MCP23017 device to its power-on state
      */    
@@ -134,10 +133,10 @@
     void write(int data);
 
 protected:
-    I2C     _i2c;
+    I2C &   _i2c;
     int     MCP23017_i2cAddress;                        // physical I2C address
     unsigned short   shadow_GPIO, shadow_IODIR, shadow_GPPU, shadow_IPOL;     // Cached copies of the register values
     
 };
 
-#endif
\ No newline at end of file
+#endif