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

Revision:
9:e08c29541bc4
Parent:
8:460f7a57725d
Child:
12:6d9d2b277f26
--- a/MCP23017.cpp	Mon Nov 29 10:55:29 2010 +0000
+++ b/MCP23017.cpp	Mon Nov 29 11:17:30 2010 +0000
@@ -32,7 +32,7 @@
     reset();                                  // initialise chip to power-on condition
 }
 
-/*-----------------------------------------------------------------------------
+/* -----------------------------------------------------------------------------
  * reset
  * Set configuration (IOCON) and direction(IODIR) registers to initial state
  */
@@ -46,7 +46,7 @@
 //
     writeRegister(IODIR, (unsigned short)0xFFFF);
 //
-// set all other registers to zero (last od 10 registers is OLAT)
+// set all other registers to zero (last of 10 registers is OLAT)
 //
     for (int reg_addr = 2 ; reg_addr <= OLAT ; reg_addr+=2) {
         writeRegister(reg_addr, (unsigned short)0x0000);
@@ -60,7 +60,7 @@
     shadow_IPOL  = 0;
 }
 
-/*-----------------------------------------------------------------------------
+/* -----------------------------------------------------------------------------
  * pinMode
  */
 void MCP23017::pinMode(int pin, int mode) {
@@ -72,7 +72,7 @@
     writeRegister(IODIR, (unsigned short)shadow_IODIR);
 }
 
-/*-----------------------------------------------------------------------------
+/* -----------------------------------------------------------------------------
  * digitalRead
  */
 int MCP23017::digitalRead(int pin) {
@@ -84,7 +84,7 @@
     }
 }
 
-/*-----------------------------------------------------------------------------
+/* -----------------------------------------------------------------------------
  * write_bit
  * Write a 1/0 to a single bit of the 16-bit port
  */
@@ -97,7 +97,7 @@
     writeRegister(GPIO, (unsigned short)shadow_GPIO);
 }
 
-/*-----------------------------------------------------------------------------
+/* -----------------------------------------------------------------------------
  * Write a combination of bits to the 16-bit port
  */
 void MCP23017::write_mask(unsigned short data, unsigned short mask) {
@@ -105,7 +105,7 @@
     writeRegister(GPIO, (unsigned short)shadow_GPIO);
 }
 
-/*-----------------------------------------------------------------------------
+/* -----------------------------------------------------------------------------
  * read_bit
  * Read a single bit from the 16-bit port
  */
@@ -114,7 +114,7 @@
     return  ((shadow_GPIO >> bit_number) & 0x0001);
 }
 
-/*-----------------------------------------------------------------------------
+/* -----------------------------------------------------------------------------
  * read_mask
  */
 int  MCP23017::read_mask(unsigned short mask) {
@@ -122,7 +122,7 @@
     return (shadow_GPIO & mask);
 }
 
-/*-----------------------------------------------------------------------------
+/* -----------------------------------------------------------------------------
  * Config
  * set direction and pull-up registers
  */
@@ -135,7 +135,7 @@
     writeRegister(IPOL, (unsigned short)shadow_IPOL);
 }
 
-/*-----------------------------------------------------------------------------
+/* -----------------------------------------------------------------------------
  * digitalWrite
  */
 void MCP23017::digitalWrite(int pin, int val) {
@@ -161,7 +161,7 @@
     }
 }
 
-/*-----------------------------------------------------------------------------
+/* -----------------------------------------------------------------------------
  * digitalWordRead
  */
 unsigned short MCP23017::digitalWordRead() {
@@ -169,7 +169,7 @@
     return shadow_GPIO;
 }
 
-/*-----------------------------------------------------------------------------
+/* -----------------------------------------------------------------------------
  * digitalWordWrite
  */
 void MCP23017::digitalWordWrite(unsigned short w) {
@@ -177,14 +177,14 @@
     writeRegister(GPIO, (unsigned short)shadow_GPIO);
 }
 
-/*-----------------------------------------------------------------------------
+/* -----------------------------------------------------------------------------
  * inputPolarityMask
  */
 void MCP23017::inputPolarityMask(unsigned short mask) {
     writeRegister(IPOL, mask);
 }
 
-/*-----------------------------------------------------------------------------
+/* -----------------------------------------------------------------------------
  * inputoutputMask
  */
 void MCP23017::inputOutputMask(unsigned short mask) {
@@ -192,7 +192,7 @@
     writeRegister(IODIR, (unsigned short)shadow_IODIR);
 }
 
-/*-----------------------------------------------------------------------------
+/* -----------------------------------------------------------------------------
  * internalPullupMask
  */
 void MCP23017::internalPullupMask(unsigned short mask) {
@@ -200,10 +200,8 @@
     writeRegister(GPPU, (unsigned short)shadow_GPPU);
 }
 
-
-
 //PRIVATE
-/*-----------------------------------------------------------------------------
+/* -----------------------------------------------------------------------------
  * writeRegister
  * write a byte
  */
@@ -215,7 +213,7 @@
     _i2c.write(MCP23017_i2cAddress, buffer, 2);
 }
 
-/*-----------------------------------------------------------------------------
+/* -----------------------------------------------------------------------------
  * writeRegister
  * write two bytes
  */
@@ -230,7 +228,7 @@
     _i2c.write(MCP23017_i2cAddress, buffer, 3);
 }
 
-/*-----------------------------------------------------------------------------
+/* -----------------------------------------------------------------------------
  * readRegister
  */
 int MCP23017::readRegister(int regAddress) {