Basic library of routines to interface to a Microchip MCP23017 16-bit I/O expander using an I2C interface.
Dependents: acd52832_beep_buzzer_ints
Fork of MCP23017 by
Revision 6:1144e6353b50, committed 2010-11-28
- Comitter:
- jimherd
- Date:
- Sun Nov 28 22:20:59 2010 +0000
- Parent:
- 5:79b8535dc5ac
- Child:
- 7:c282ea90cdb5
- Commit message:
Changed in this revision
MCP23017.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/MCP23017.cpp Sun Nov 28 22:13:12 2010 +0000 +++ b/MCP23017.cpp Sun Nov 28 22:20:59 2010 +0000 @@ -32,7 +32,7 @@ reset(); // initialise chip to power-on condition } -/* ****************************************************************************** +/*----------------------------------------------------------------------------- * reset * Set configuration (IOCON) and direction(IODIR) registers to initial state */ @@ -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) { @@ -203,7 +203,7 @@ //PRIVATE -/* ****************************************************************************** +/*----------------------------------------------------------------------------- * writeRegister * write a byte */ @@ -215,7 +215,7 @@ _i2c.write(MCP23017_i2cAddress, buffer, 2); } -/* ****************************************************************************** +/*----------------------------------------------------------------------------- * writeRegister * write two bytes */ @@ -230,7 +230,7 @@ _i2c.write(MCP23017_i2cAddress, buffer, 3); } -/* ****************************************************************************** +/*----------------------------------------------------------------------------- * readRegister */ int MCP23017::readRegister(int regAddress) {