Accel
Dependencies: mbed PowerControl SDFileSystem
Fork of HeptaAccel by
hepta_sat/I2cBusDevice.h@1:63c3921c608c, 2016-12-13 (annotated)
- Committer:
- tomoya123
- Date:
- Tue Dec 13 07:51:40 2016 +0000
- Revision:
- 1:63c3921c608c
- Parent:
- 0:d721efd58e4e
Accel
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tomoya123 | 0:d721efd58e4e | 1 | #ifndef MBED_I2cBusDevice |
tomoya123 | 0:d721efd58e4e | 2 | #define MBED_I2cBusDevice |
tomoya123 | 0:d721efd58e4e | 3 | |
tomoya123 | 0:d721efd58e4e | 4 | #include "mbed.h" |
tomoya123 | 0:d721efd58e4e | 5 | |
tomoya123 | 0:d721efd58e4e | 6 | class I2cBusDevice { |
tomoya123 | 0:d721efd58e4e | 7 | public: |
tomoya123 | 0:d721efd58e4e | 8 | |
tomoya123 | 0:d721efd58e4e | 9 | I2cBusDevice( I2C *i2c, char dev_address ) { |
tomoya123 | 0:d721efd58e4e | 10 | bus = i2c; |
tomoya123 | 0:d721efd58e4e | 11 | device = dev_address; |
tomoya123 | 0:d721efd58e4e | 12 | } |
tomoya123 | 0:d721efd58e4e | 13 | |
tomoya123 | 0:d721efd58e4e | 14 | ~I2cBusDevice() { |
tomoya123 | 0:d721efd58e4e | 15 | } |
tomoya123 | 0:d721efd58e4e | 16 | |
tomoya123 | 0:d721efd58e4e | 17 | int write( char *data, int length ) { |
tomoya123 | 0:d721efd58e4e | 18 | return ( bus->write( device, data, length) ); |
tomoya123 | 0:d721efd58e4e | 19 | } |
tomoya123 | 0:d721efd58e4e | 20 | |
tomoya123 | 0:d721efd58e4e | 21 | int read( char *data, int length ) { |
tomoya123 | 0:d721efd58e4e | 22 | return ( bus->read( device, data, length) ); |
tomoya123 | 0:d721efd58e4e | 23 | } |
tomoya123 | 0:d721efd58e4e | 24 | |
tomoya123 | 0:d721efd58e4e | 25 | int read( char reg_ptr, char *data, int length ) { |
tomoya123 | 0:d721efd58e4e | 26 | if ( bus->write( device, ®_ptr, 1 ) ) |
tomoya123 | 0:d721efd58e4e | 27 | return ( 1 ); |
tomoya123 | 0:d721efd58e4e | 28 | |
tomoya123 | 0:d721efd58e4e | 29 | if ( bus->read( device, data, length ) ) |
tomoya123 | 0:d721efd58e4e | 30 | return ( 1 ); |
tomoya123 | 0:d721efd58e4e | 31 | |
tomoya123 | 0:d721efd58e4e | 32 | return ( 0 ); |
tomoya123 | 0:d721efd58e4e | 33 | } |
tomoya123 | 0:d721efd58e4e | 34 | |
tomoya123 | 0:d721efd58e4e | 35 | protected: |
tomoya123 | 0:d721efd58e4e | 36 | I2C *bus; |
tomoya123 | 0:d721efd58e4e | 37 | char device; |
tomoya123 | 0:d721efd58e4e | 38 | |
tomoya123 | 0:d721efd58e4e | 39 | private: |
tomoya123 | 0:d721efd58e4e | 40 | static char i2c_error; |
tomoya123 | 0:d721efd58e4e | 41 | } |
tomoya123 | 0:d721efd58e4e | 42 | ; |
tomoya123 | 0:d721efd58e4e | 43 | |
tomoya123 | 0:d721efd58e4e | 44 | #endif |