Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed PowerControl SDFileSystem
Fork of HeptaBattery_SDFilesystem_Q by
hepta_sat/I2cBusDevice.h@0:9eb94b338772, 2016-12-09 (annotated)
- Committer:
- tomoya123
- Date:
- Fri Dec 09 04:53:49 2016 +0000
- Revision:
- 0:9eb94b338772
Battery and SDcard Q
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| tomoya123 | 0:9eb94b338772 | 1 | #ifndef MBED_I2cBusDevice |
| tomoya123 | 0:9eb94b338772 | 2 | #define MBED_I2cBusDevice |
| tomoya123 | 0:9eb94b338772 | 3 | |
| tomoya123 | 0:9eb94b338772 | 4 | #include "mbed.h" |
| tomoya123 | 0:9eb94b338772 | 5 | |
| tomoya123 | 0:9eb94b338772 | 6 | class I2cBusDevice { |
| tomoya123 | 0:9eb94b338772 | 7 | public: |
| tomoya123 | 0:9eb94b338772 | 8 | |
| tomoya123 | 0:9eb94b338772 | 9 | I2cBusDevice( I2C *i2c, char dev_address ) { |
| tomoya123 | 0:9eb94b338772 | 10 | bus = i2c; |
| tomoya123 | 0:9eb94b338772 | 11 | device = dev_address; |
| tomoya123 | 0:9eb94b338772 | 12 | } |
| tomoya123 | 0:9eb94b338772 | 13 | |
| tomoya123 | 0:9eb94b338772 | 14 | ~I2cBusDevice() { |
| tomoya123 | 0:9eb94b338772 | 15 | } |
| tomoya123 | 0:9eb94b338772 | 16 | |
| tomoya123 | 0:9eb94b338772 | 17 | int write( char *data, int length ) { |
| tomoya123 | 0:9eb94b338772 | 18 | return ( bus->write( device, data, length) ); |
| tomoya123 | 0:9eb94b338772 | 19 | } |
| tomoya123 | 0:9eb94b338772 | 20 | |
| tomoya123 | 0:9eb94b338772 | 21 | int read( char *data, int length ) { |
| tomoya123 | 0:9eb94b338772 | 22 | return ( bus->read( device, data, length) ); |
| tomoya123 | 0:9eb94b338772 | 23 | } |
| tomoya123 | 0:9eb94b338772 | 24 | |
| tomoya123 | 0:9eb94b338772 | 25 | int read( char reg_ptr, char *data, int length ) { |
| tomoya123 | 0:9eb94b338772 | 26 | if ( bus->write( device, ®_ptr, 1 ) ) |
| tomoya123 | 0:9eb94b338772 | 27 | return ( 1 ); |
| tomoya123 | 0:9eb94b338772 | 28 | |
| tomoya123 | 0:9eb94b338772 | 29 | if ( bus->read( device, data, length ) ) |
| tomoya123 | 0:9eb94b338772 | 30 | return ( 1 ); |
| tomoya123 | 0:9eb94b338772 | 31 | |
| tomoya123 | 0:9eb94b338772 | 32 | return ( 0 ); |
| tomoya123 | 0:9eb94b338772 | 33 | } |
| tomoya123 | 0:9eb94b338772 | 34 | |
| tomoya123 | 0:9eb94b338772 | 35 | protected: |
| tomoya123 | 0:9eb94b338772 | 36 | I2C *bus; |
| tomoya123 | 0:9eb94b338772 | 37 | char device; |
| tomoya123 | 0:9eb94b338772 | 38 | |
| tomoya123 | 0:9eb94b338772 | 39 | private: |
| tomoya123 | 0:9eb94b338772 | 40 | static char i2c_error; |
| tomoya123 | 0:9eb94b338772 | 41 | } |
| tomoya123 | 0:9eb94b338772 | 42 | ; |
| tomoya123 | 0:9eb94b338772 | 43 | |
| tomoya123 | 0:9eb94b338772 | 44 | #endif |
