mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
drivers/tcs37727: adapt to new I2C api
This commit is contained in:
parent
a85fbd2c75
commit
78c5b46eac
@ -33,7 +33,6 @@
|
||||
#define ENABLE_DEBUG (0)
|
||||
#include "debug.h"
|
||||
|
||||
#define I2C_SPEED I2C_SPEED_FAST
|
||||
#define BUS (dev->p.i2c)
|
||||
#define ADR (dev->p.addr)
|
||||
|
||||
@ -49,14 +48,9 @@ int tcs37727_init(tcs37727_t *dev, const tcs37727_params_t *params)
|
||||
|
||||
/* setup the I2C bus */
|
||||
i2c_acquire(BUS);
|
||||
if (i2c_init_master(BUS, I2C_SPEED) < 0) {
|
||||
i2c_release(BUS);
|
||||
LOG_ERROR("[tcs37727] init: error initializing I2C bus\n");
|
||||
return TCS37727_NOBUS;
|
||||
}
|
||||
|
||||
/* check if we can communicate with the device */
|
||||
i2c_read_reg(BUS, ADR, TCS37727_ID, &tmp);
|
||||
i2c_read_reg(BUS, ADR, TCS37727_ID, &tmp, 0);
|
||||
if (tmp != TCS37727_ID_VALUE) {
|
||||
i2c_release(BUS);
|
||||
LOG_ERROR("[tcs37727] init: error while reading ID register\n");
|
||||
@ -64,13 +58,14 @@ int tcs37727_init(tcs37727_t *dev, const tcs37727_params_t *params)
|
||||
}
|
||||
|
||||
/* configure gain and conversion time */
|
||||
i2c_write_reg(BUS, ADR, TCS37727_ATIME, TCS37727_ATIME_TO_REG(dev->p.atime));
|
||||
i2c_write_reg(BUS, ADR, TCS37727_CONTROL, TCS37727_CONTROL_AGAIN_4);
|
||||
i2c_write_reg(BUS, ADR, TCS37727_ATIME,
|
||||
TCS37727_ATIME_TO_REG(dev->p.atime), 0);
|
||||
i2c_write_reg(BUS, ADR, TCS37727_CONTROL, TCS37727_CONTROL_AGAIN_4, 0);
|
||||
dev->again = 4;
|
||||
|
||||
/* enable the device */
|
||||
tmp = (TCS37727_ENABLE_AEN | TCS37727_ENABLE_PON);
|
||||
i2c_write_reg(BUS, ADR, TCS37727_ENABLE, tmp);
|
||||
i2c_write_reg(BUS, ADR, TCS37727_ENABLE, tmp, 0);
|
||||
|
||||
i2c_release(BUS);
|
||||
|
||||
@ -84,9 +79,9 @@ void tcs37727_set_rgbc_active(const tcs37727_t *dev)
|
||||
assert(dev);
|
||||
|
||||
i2c_acquire(BUS);
|
||||
i2c_read_reg(BUS, ADR, TCS37727_ENABLE, ®);
|
||||
i2c_read_reg(BUS, ADR, TCS37727_ENABLE, ®, 0);
|
||||
reg |= (TCS37727_ENABLE_AEN | TCS37727_ENABLE_PON);
|
||||
i2c_write_reg(BUS, ADR, TCS37727_ENABLE, reg);
|
||||
i2c_write_reg(BUS, ADR, TCS37727_ENABLE, reg, 0);
|
||||
i2c_release(BUS);
|
||||
}
|
||||
|
||||
@ -97,12 +92,12 @@ void tcs37727_set_rgbc_standby(const tcs37727_t *dev)
|
||||
assert(dev);
|
||||
|
||||
i2c_acquire(BUS);
|
||||
i2c_read_reg(BUS, ADR, TCS37727_ENABLE, ®);
|
||||
i2c_read_reg(BUS, ADR, TCS37727_ENABLE, ®, 0);
|
||||
reg &= ~TCS37727_ENABLE_AEN;
|
||||
if (!(reg & TCS37727_ENABLE_PEN)) {
|
||||
reg &= ~TCS37727_ENABLE_PON;
|
||||
}
|
||||
i2c_write_reg(BUS, ADR, TCS37727_ENABLE, reg);
|
||||
i2c_write_reg(BUS, ADR, TCS37727_ENABLE, reg, 0);
|
||||
i2c_release(BUS);
|
||||
}
|
||||
|
||||
@ -161,13 +156,13 @@ static uint8_t tcs37727_trim_gain(tcs37727_t *dev, int32_t rawc)
|
||||
|
||||
i2c_acquire(BUS);
|
||||
uint8_t reg = 0;
|
||||
if (i2c_read_reg(BUS, ADR, TCS37727_CONTROL, ®) != 1) {
|
||||
if (i2c_read_reg(BUS, ADR, TCS37727_CONTROL, ®, 0) < 0) {
|
||||
i2c_release(BUS);
|
||||
return -2;
|
||||
}
|
||||
reg &= ~TCS37727_CONTROL_AGAIN_MASK;
|
||||
reg |= reg_again;
|
||||
if (i2c_write_reg(BUS, ADR, TCS37727_CONTROL, reg) != 1) {
|
||||
if (i2c_write_reg(BUS, ADR, TCS37727_CONTROL, reg, 0) < 0) {
|
||||
i2c_release(BUS);
|
||||
return -2;
|
||||
}
|
||||
@ -184,7 +179,7 @@ void tcs37727_read(const tcs37727_t *dev, tcs37727_data_t *data)
|
||||
assert(dev && data);
|
||||
|
||||
i2c_acquire(BUS);
|
||||
i2c_read_regs(BUS, ADR, (TCS37727_INC_TRANS | TCS37727_CDATA), buf, 8);
|
||||
i2c_read_regs(BUS, ADR, (TCS37727_INC_TRANS | TCS37727_CDATA), buf, 8, 0);
|
||||
i2c_release(BUS);
|
||||
|
||||
int32_t tmpc = ((uint16_t)buf[1] << 8) | buf[0];
|
||||
|
Loading…
Reference in New Issue
Block a user