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.
Dependents: openwear-lifelogger-example
Fork of TCS3472_I2C by
Revision 7:fbc4c6f3be5b, committed 2014-09-04
- Comitter:
- janekm
- Date:
- Thu Sep 04 21:18:50 2014 +0000
- Parent:
- 6:6d5bb4ad7d6e
- Child:
- 8:2a240f6ca27a
- Commit message:
- Fixup
Changed in this revision
| TCS3472_I2C.cpp | Show annotated file Show diff for this revision Revisions of this file |
| TCS3472_I2C.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/TCS3472_I2C.cpp Thu Apr 24 09:14:25 2014 +0000
+++ b/TCS3472_I2C.cpp Thu Sep 04 21:18:50 2014 +0000
@@ -1,7 +1,8 @@
#include "TCS3472_I2C.h"
-TCS3472_I2C::TCS3472_I2C( PinName sda, PinName scl ) : i2c( sda, scl ){
- i2c.frequency(100000);
+TCS3472_I2C::TCS3472_I2C( I2C *i2c, uint8_t deviceAddress ) : _i2c( i2c ){
+ _slaveAddress = deviceAddress;
+
enablePowerAndRGBC();
}
@@ -11,7 +12,7 @@
int TCS3472_I2C::writeSingleRegister( char address, char data ){
char tx[2] = { address | 160, data }; //0d160 = 0b10100000
- int ack = i2c.write( SLAVE_ADDRESS << 1, tx, 2 );
+ int ack = _i2c->write( _slaveAddress << 1, tx, 2 );
return ack;
}
@@ -21,22 +22,22 @@
for ( int i = 1; i <= quantity; i++ ){
tx[ i ] = data[ i - 1 ];
}
- int ack = i2c.write( SLAVE_ADDRESS << 1, tx, quantity + 1 );
+ int ack = _i2c->write( _slaveAddress << 1, tx, quantity + 1 );
return ack;
}
char TCS3472_I2C::readSingleRegister( char address ){
char output = 255;
char command = address | 160; //0d160 = 0b10100000
- i2c.write( SLAVE_ADDRESS << 1, &command, 1, true );
- i2c.read( SLAVE_ADDRESS << 1, &output, 1 );
+ _i2c->write( _slaveAddress << 1, &command, 1, true );
+ _i2c->read( _slaveAddress << 1, &output, 1 );
return output;
}
int TCS3472_I2C::readMultipleRegisters( char address, char* output, int quantity ){
char command = address | 160; //0d160 = 0b10100000
- i2c.write( SLAVE_ADDRESS << 1, &command, 1, true );
- int ack = i2c.read( SLAVE_ADDRESS << 1, output, quantity );
+ _i2c->write( _slaveAddress << 1, &command, 1, true );
+ int ack = _i2c->read( _slaveAddress << 1, output, quantity );
return ack;
}
@@ -376,7 +377,7 @@
int TCS3472_I2C::clearInterrupt(){
char tx = 230;
- int ack = i2c.write( SLAVE_ADDRESS << 1, &tx, 1 );
+ int ack = _i2c->write( _slaveAddress << 1, &tx, 1 );
return ack;
}
--- a/TCS3472_I2C.h Thu Apr 24 09:14:25 2014 +0000
+++ b/TCS3472_I2C.h Thu Sep 04 21:18:50 2014 +0000
@@ -50,7 +50,7 @@
* @param sda sda pin for I2C
* @param scl scl pin for I2C
*/
- TCS3472_I2C( PinName sda, PinName scl );
+ TCS3472_I2C( I2C *i2c, uint8_t deviceAddress = SLAVE_ADDRESS );
/** Destructor
*/
@@ -336,7 +336,8 @@
char readStatusRegister();
private:
- I2C i2c;
+ I2C *_i2c;
+ uint8_t _slaveAddress;
int writeSingleRegister( char address, char data );
int writeMultipleRegisters( char address, char* data, int quantity );
