MCP23009 is a general IO I2C chip . This lib provide higher level interface ( set pin value, set io modes etc ) without need to have knowledge of the I2C registers
mcp23009.h
- Committer:
- wbeaumont
- Date:
- 2016-06-03
- Revision:
- 0:d829b4edd564
- Child:
- 1:9146d773a5a3
File content as of revision 0:d829b4edd564:
#ifndef MCP_23009_H #define MCP_23009_H #include "getVersion.h" #include "stdbool.h" #include "dev_interface_def.h" #include "I2CInterface.h" #include "DACInterface.h" #define VERSION_MCP23009_HDR "0.1" /** MCP23009 class. * Used for interfacing with a mcp23009 8 bit io expander * * It has to be used with the https://developer.mbed.org/users/wbeaumont/code/DevInterfaces/ package * This includes the "virtual" I2CInterface class that is the interface to the I2C device * An implementation of the I2Cinterface class for the MBED can be found at * interrupt is not supported (yet ) * * (C) Wim Beaumont Universiteit Antwerpen 2016 * */ class MCP23009 : public virtual getVersion { public: /** Create an mcp23009 I2C interface * * @param i2cinterface pointer to the I2C interface (proto type) * @param device_address_bits The 3bit address bits of the device ( set via an analogue value on the addresspin) */ MCP23009(I2CInterface* i2cinterface, int device_address_bits ); /** set IO pin to input or all , also set the pullup and poloarity ( default = no change * @param pinnr range 0 .. 8 if 8 all pins are set as input * @param pullup if positive pull up will be enabled 0 pull up will be disabled if negative no change * @param polarity if positive polaritye will be inverted 0 std polarity if negative no change * @return none zero in case of error */ int set_as_input(int pinnr,int pullup, int polarity=-1 ); /** set IO pin to output * @param pinnr range 0 .. if 8 all pins are set as output * @param pullup if true pull up is enabled * @param polarity if true inverted polarity not yet tested if the polarity bit has effect on the output * @return none zero in case of error */ int set_as_output(int pinnr ,int pullup,int polarity=-1 ); int status( int pinnr=8); int set( int pinnr , int value); protected: /** pointer to the I2C interface driver. */ I2CInterface* _i2c_interface; /** The full i2c device address. */ int _device_address; private : char data[5]; int set_io_pin(bool input ,int pinnr,int pullup, int polarity ); int pinmanipulation ( bool active , int pinnr ); }; #endif