Skip to content

Commit

Permalink
Merge pull request #47 from caternuson/iss46_busio
Browse files Browse the repository at this point in the history
Convert to BusIO
  • Loading branch information
caternuson authored Oct 1, 2021
2 parents 017ce29 + 8877ef0 commit 879cd8e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 88 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/githubci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on: [pull_request, push, repository_dispatch]
jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/setup-python@v1
with:
Expand All @@ -23,7 +23,7 @@ jobs:
run: python3 ci/build_platform.py main_platforms

- name: clang
run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r .
run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r .

- name: doxygen
env:
Expand Down
94 changes: 15 additions & 79 deletions Adafruit_TCS34725.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,8 @@ float powf(const float x, const float y) {
* @param value
*/
void Adafruit_TCS34725::write8(uint8_t reg, uint32_t value) {
_wire->beginTransmission(_i2caddr);
#if ARDUINO >= 100
_wire->write(TCS34725_COMMAND_BIT | reg);
_wire->write(value & 0xFF);
#else
_wire->send(TCS34725_COMMAND_BIT | reg);
_wire->send(value & 0xFF);
#endif
_wire->endTransmission();
uint8_t buffer[2] = {TCS34725_COMMAND_BIT | reg, value & 0xFF};
i2c_dev->write(buffer, 2);
}

/*!
Expand All @@ -66,20 +59,9 @@ void Adafruit_TCS34725::write8(uint8_t reg, uint32_t value) {
* @return value
*/
uint8_t Adafruit_TCS34725::read8(uint8_t reg) {
_wire->beginTransmission(_i2caddr);
#if ARDUINO >= 100
_wire->write(TCS34725_COMMAND_BIT | reg);
#else
_wire->send(TCS34725_COMMAND_BIT | reg);
#endif
_wire->endTransmission();

_wire->requestFrom(_i2caddr, (uint8_t)1);
#if ARDUINO >= 100
return _wire->read();
#else
return _wire->receive();
#endif
uint8_t buffer[1] = {TCS34725_COMMAND_BIT | reg};
i2c_dev->write_then_read(buffer, 1, buffer, 1);
return buffer[0];
}

/*!
Expand All @@ -88,28 +70,9 @@ uint8_t Adafruit_TCS34725::read8(uint8_t reg) {
* @return value
*/
uint16_t Adafruit_TCS34725::read16(uint8_t reg) {
uint16_t x;
uint16_t t;

_wire->beginTransmission(_i2caddr);
#if ARDUINO >= 100
_wire->write(TCS34725_COMMAND_BIT | reg);
#else
_wire->send(TCS34725_COMMAND_BIT | reg);
#endif
_wire->endTransmission();

_wire->requestFrom(_i2caddr, (uint8_t)2);
#if ARDUINO >= 100
t = _wire->read();
x = _wire->read();
#else
t = _wire->receive();
x = _wire->receive();
#endif
x <<= 8;
x |= t;
return x;
uint8_t buffer[2] = {TCS34725_COMMAND_BIT | reg, 0};
i2c_dev->write_then_read(buffer, 1, buffer, 2);
return (uint16_t(buffer[1]) << 8) | (uint16_t(buffer[0]) & 0xFF);
}

/*!
Expand Down Expand Up @@ -152,19 +115,6 @@ Adafruit_TCS34725::Adafruit_TCS34725(uint8_t it, tcs34725Gain_t gain) {
_tcs34725Gain = gain;
}

/*!
* @brief Initializes I2C and configures the sensor
* @param addr
* i2c address
* @return True if initialization was successful, otherwise false.
*/
boolean Adafruit_TCS34725::begin(uint8_t addr) {
_i2caddr = addr;
_wire = &Wire;

return init();
}

/*!
* @brief Initializes I2C and configures the sensor
* @param addr
Expand All @@ -174,19 +124,9 @@ boolean Adafruit_TCS34725::begin(uint8_t addr) {
* @return True if initialization was successful, otherwise false.
*/
boolean Adafruit_TCS34725::begin(uint8_t addr, TwoWire *theWire) {
_i2caddr = addr;
_wire = theWire;

return init();
}

/*!
* @brief Initializes I2C and configures the sensor
* @return True if initialization was successful, otherwise false.
*/
boolean Adafruit_TCS34725::begin() {
_i2caddr = TCS34725_ADDRESS;
_wire = &Wire;
if (i2c_dev)
delete i2c_dev;
i2c_dev = new Adafruit_I2CDevice(addr, theWire);

return init();
}
Expand All @@ -196,7 +136,8 @@ boolean Adafruit_TCS34725::begin() {
* @return True if initialization was successful, otherwise false.
*/
boolean Adafruit_TCS34725::init() {
_wire->begin();
if (!i2c_dev->begin())
return false;

/* Make sure we're actually connected */
uint8_t x = read8(TCS34725_ID);
Expand Down Expand Up @@ -497,13 +438,8 @@ void Adafruit_TCS34725::setInterrupt(boolean i) {
* @brief Clears inerrupt for TCS34725
*/
void Adafruit_TCS34725::clearInterrupt() {
_wire->beginTransmission(_i2caddr);
#if ARDUINO >= 100
_wire->write(TCS34725_COMMAND_BIT | 0x66);
#else
_wire->send(TCS34725_COMMAND_BIT | 0x66);
#endif
_wire->endTransmission();
uint8_t buffer[1] = {TCS34725_COMMAND_BIT | 0x66};
i2c_dev->write(buffer, 1);
}

/*!
Expand Down
9 changes: 3 additions & 6 deletions Adafruit_TCS34725.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include <WProgram.h>
#endif

#include <Wire.h>
#include <Adafruit_I2CDevice.h>

#define TCS34725_ADDRESS (0x29) /**< I2C address **/
#define TCS34725_COMMAND_BIT (0x80) /**< Command bit **/
Expand Down Expand Up @@ -198,9 +198,7 @@ class Adafruit_TCS34725 {
Adafruit_TCS34725(uint8_t = TCS34725_INTEGRATIONTIME_2_4MS,
tcs34725Gain_t = TCS34725_GAIN_1X);

boolean begin(uint8_t addr, TwoWire *theWire);
boolean begin(uint8_t addr);
boolean begin();
boolean begin(uint8_t addr = TCS34725_ADDRESS, TwoWire *theWire = &Wire);
boolean init();

void setIntegrationTime(uint8_t it);
Expand All @@ -222,8 +220,7 @@ class Adafruit_TCS34725 {
void disable();

private:
TwoWire *_wire;
uint8_t _i2caddr;
Adafruit_I2CDevice *i2c_dev = NULL; ///< Pointer to I2C bus interface
boolean _tcs34725Initialised;
tcs34725Gain_t _tcs34725Gain;
uint8_t _tcs34725IntegrationTime;
Expand Down
3 changes: 2 additions & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name=Adafruit TCS34725
version=1.3.6
version=1.4.0
author=Adafruit
maintainer=Adafruit <[email protected]>
sentence=Driver for Adafruit's TCS34725 RGB Color Sensor Breakout
paragraph=Driver for Adafruit's TCS34725 RGB Color Sensor Breakout
category=Sensors
url=https://github.com/adafruit/Adafruit_TCS34725
architectures=*
depends=Adafruit BusIO

0 comments on commit 879cd8e

Please sign in to comment.