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@0:d829b4edd564, 2016-06-03 (annotated)
- Committer:
- wbeaumont
- Date:
- Fri Jun 03 12:40:49 2016 +0000
- Revision:
- 0:d829b4edd564
- Child:
- 1:9146d773a5a3
initial version not tested with hw
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wbeaumont | 0:d829b4edd564 | 1 | #ifndef MCP_23009_H |
wbeaumont | 0:d829b4edd564 | 2 | #define MCP_23009_H |
wbeaumont | 0:d829b4edd564 | 3 | #include "getVersion.h" |
wbeaumont | 0:d829b4edd564 | 4 | |
wbeaumont | 0:d829b4edd564 | 5 | #include "stdbool.h" |
wbeaumont | 0:d829b4edd564 | 6 | |
wbeaumont | 0:d829b4edd564 | 7 | |
wbeaumont | 0:d829b4edd564 | 8 | #include "dev_interface_def.h" |
wbeaumont | 0:d829b4edd564 | 9 | #include "I2CInterface.h" |
wbeaumont | 0:d829b4edd564 | 10 | #include "DACInterface.h" |
wbeaumont | 0:d829b4edd564 | 11 | |
wbeaumont | 0:d829b4edd564 | 12 | #define VERSION_MCP23009_HDR "0.1" |
wbeaumont | 0:d829b4edd564 | 13 | |
wbeaumont | 0:d829b4edd564 | 14 | /** MCP23009 class. |
wbeaumont | 0:d829b4edd564 | 15 | * Used for interfacing with a mcp23009 8 bit io expander |
wbeaumont | 0:d829b4edd564 | 16 | * |
wbeaumont | 0:d829b4edd564 | 17 | * It has to be used with the https://developer.mbed.org/users/wbeaumont/code/DevInterfaces/ package |
wbeaumont | 0:d829b4edd564 | 18 | * This includes the "virtual" I2CInterface class that is the interface to the I2C device |
wbeaumont | 0:d829b4edd564 | 19 | * An implementation of the I2Cinterface class for the MBED can be found at |
wbeaumont | 0:d829b4edd564 | 20 | * interrupt is not supported (yet ) |
wbeaumont | 0:d829b4edd564 | 21 | * |
wbeaumont | 0:d829b4edd564 | 22 | * (C) Wim Beaumont Universiteit Antwerpen 2016 |
wbeaumont | 0:d829b4edd564 | 23 | * |
wbeaumont | 0:d829b4edd564 | 24 | */ |
wbeaumont | 0:d829b4edd564 | 25 | class MCP23009 : public virtual getVersion { |
wbeaumont | 0:d829b4edd564 | 26 | |
wbeaumont | 0:d829b4edd564 | 27 | public: |
wbeaumont | 0:d829b4edd564 | 28 | |
wbeaumont | 0:d829b4edd564 | 29 | |
wbeaumont | 0:d829b4edd564 | 30 | |
wbeaumont | 0:d829b4edd564 | 31 | |
wbeaumont | 0:d829b4edd564 | 32 | |
wbeaumont | 0:d829b4edd564 | 33 | /** Create an mcp23009 I2C interface |
wbeaumont | 0:d829b4edd564 | 34 | * |
wbeaumont | 0:d829b4edd564 | 35 | * @param i2cinterface pointer to the I2C interface (proto type) |
wbeaumont | 0:d829b4edd564 | 36 | * @param device_address_bits The 3bit address bits of the device ( set via an analogue value on the addresspin) |
wbeaumont | 0:d829b4edd564 | 37 | */ |
wbeaumont | 0:d829b4edd564 | 38 | MCP23009(I2CInterface* i2cinterface, int device_address_bits ); |
wbeaumont | 0:d829b4edd564 | 39 | |
wbeaumont | 0:d829b4edd564 | 40 | |
wbeaumont | 0:d829b4edd564 | 41 | /** set IO pin to input or all , also set the pullup and poloarity ( default = no change |
wbeaumont | 0:d829b4edd564 | 42 | * @param pinnr range 0 .. 8 if 8 all pins are set as input |
wbeaumont | 0:d829b4edd564 | 43 | * @param pullup if positive pull up will be enabled 0 pull up will be disabled if negative no change |
wbeaumont | 0:d829b4edd564 | 44 | * @param polarity if positive polaritye will be inverted 0 std polarity if negative no change |
wbeaumont | 0:d829b4edd564 | 45 | * @return none zero in case of error |
wbeaumont | 0:d829b4edd564 | 46 | */ |
wbeaumont | 0:d829b4edd564 | 47 | int set_as_input(int pinnr,int pullup, int polarity=-1 ); |
wbeaumont | 0:d829b4edd564 | 48 | |
wbeaumont | 0:d829b4edd564 | 49 | /** set IO pin to output |
wbeaumont | 0:d829b4edd564 | 50 | * @param pinnr range 0 .. if 8 all pins are set as output |
wbeaumont | 0:d829b4edd564 | 51 | * @param pullup if true pull up is enabled |
wbeaumont | 0:d829b4edd564 | 52 | * @param polarity if true inverted polarity not yet tested if the polarity bit has effect on the output |
wbeaumont | 0:d829b4edd564 | 53 | * @return none zero in case of error |
wbeaumont | 0:d829b4edd564 | 54 | */ |
wbeaumont | 0:d829b4edd564 | 55 | int set_as_output(int pinnr ,int pullup,int polarity=-1 ); |
wbeaumont | 0:d829b4edd564 | 56 | |
wbeaumont | 0:d829b4edd564 | 57 | int status( int pinnr=8); |
wbeaumont | 0:d829b4edd564 | 58 | int set( int pinnr , int value); |
wbeaumont | 0:d829b4edd564 | 59 | protected: |
wbeaumont | 0:d829b4edd564 | 60 | /** pointer to the I2C interface driver. */ |
wbeaumont | 0:d829b4edd564 | 61 | I2CInterface* _i2c_interface; |
wbeaumont | 0:d829b4edd564 | 62 | /** The full i2c device address. */ |
wbeaumont | 0:d829b4edd564 | 63 | int _device_address; |
wbeaumont | 0:d829b4edd564 | 64 | private : |
wbeaumont | 0:d829b4edd564 | 65 | char data[5]; |
wbeaumont | 0:d829b4edd564 | 66 | int set_io_pin(bool input ,int pinnr,int pullup, int polarity ); |
wbeaumont | 0:d829b4edd564 | 67 | int pinmanipulation ( bool active , int pinnr ); |
wbeaumont | 0:d829b4edd564 | 68 | }; |
wbeaumont | 0:d829b4edd564 | 69 | |
wbeaumont | 0:d829b4edd564 | 70 | #endif |