ERC1602-4 i2c Text LCD library for East Rising COG display in i2c mode using the ST7032i controller IC.
I2cBusDevice.h@0:5b8f0de660ec, 2014-05-04 (annotated)
- Committer:
- star297
- Date:
- Sun May 04 11:31:31 2014 +0000
- Revision:
- 0:5b8f0de660ec
v1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
star297 | 0:5b8f0de660ec | 1 | #include "mbed.h" |
star297 | 0:5b8f0de660ec | 2 | |
star297 | 0:5b8f0de660ec | 3 | class I2cBusDevice { |
star297 | 0:5b8f0de660ec | 4 | public: |
star297 | 0:5b8f0de660ec | 5 | |
star297 | 0:5b8f0de660ec | 6 | I2cBusDevice( I2C *LCD, char dev_address ) { |
star297 | 0:5b8f0de660ec | 7 | bus = LCD; |
star297 | 0:5b8f0de660ec | 8 | device = dev_address; |
star297 | 0:5b8f0de660ec | 9 | } |
star297 | 0:5b8f0de660ec | 10 | |
star297 | 0:5b8f0de660ec | 11 | ~I2cBusDevice() { |
star297 | 0:5b8f0de660ec | 12 | } |
star297 | 0:5b8f0de660ec | 13 | |
star297 | 0:5b8f0de660ec | 14 | int write( char *data, int length ) { |
star297 | 0:5b8f0de660ec | 15 | return ( bus->write( device, data, length) ); |
star297 | 0:5b8f0de660ec | 16 | } |
star297 | 0:5b8f0de660ec | 17 | |
star297 | 0:5b8f0de660ec | 18 | int read( char *data, int length ) { |
star297 | 0:5b8f0de660ec | 19 | return ( bus->read( device, data, length) ); |
star297 | 0:5b8f0de660ec | 20 | } |
star297 | 0:5b8f0de660ec | 21 | |
star297 | 0:5b8f0de660ec | 22 | int read( char reg_ptr, char *data, int length ) { |
star297 | 0:5b8f0de660ec | 23 | if ( bus->write( device, ®_ptr, 1 ) ) |
star297 | 0:5b8f0de660ec | 24 | return ( 1 ); |
star297 | 0:5b8f0de660ec | 25 | if ( bus->read( device, data, length ) ) |
star297 | 0:5b8f0de660ec | 26 | return ( 1 ); |
star297 | 0:5b8f0de660ec | 27 | return ( 0 ); |
star297 | 0:5b8f0de660ec | 28 | } |
star297 | 0:5b8f0de660ec | 29 | |
star297 | 0:5b8f0de660ec | 30 | protected: |
star297 | 0:5b8f0de660ec | 31 | I2C *bus; |
star297 | 0:5b8f0de660ec | 32 | char device; |
star297 | 0:5b8f0de660ec | 33 | } |
star297 | 0:5b8f0de660ec | 34 | ; |
star297 | 0:5b8f0de660ec | 35 | |
star297 | 0:5b8f0de660ec | 36 |