drivers/l3g4200d: adapt to new I2C api
This commit is contained in:
parent
bca6868da6
commit
219277e884
@ -29,8 +29,6 @@
|
||||
#define ENABLE_DEBUG (0)
|
||||
#include "debug.h"
|
||||
|
||||
#define I2C_SPEED I2C_SPEED_FAST
|
||||
|
||||
#define MAX_VAL 0x7fff
|
||||
|
||||
#define DEV_I2C (dev->params.i2c)
|
||||
@ -62,20 +60,15 @@ int l3g4200d_init(l3g4200d_t *dev, const l3g4200d_params_t *params)
|
||||
|
||||
/* acquire exclusive access to the bus. */
|
||||
i2c_acquire(DEV_I2C);
|
||||
/* initialize the I2C bus */
|
||||
if (i2c_init_master(DEV_I2C, I2C_SPEED) < 0) {
|
||||
/* Release the bus for other threads. */
|
||||
i2c_release(DEV_I2C);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* configure CTRL_REG1 */
|
||||
tmp = ((DEV_MODE & 0xf) << L3G4200D_CTRL1_MODE_POS) | L3G4200D_CTRL1_ALLON;
|
||||
if (i2c_write_reg(DEV_I2C, DEV_ADDR, L3G4200D_REG_CTRL1, tmp) != 1) {
|
||||
if (i2c_write_reg(DEV_I2C, DEV_ADDR, L3G4200D_REG_CTRL1, tmp, 0) < 0) {
|
||||
i2c_release(DEV_I2C);
|
||||
return -1;
|
||||
}
|
||||
tmp = ((DEV_SCALE & 0x3) << L3G4200D_CTRL4_FS_POS) | L3G4200D_CTRL4_BDU;
|
||||
if (i2c_write_reg(DEV_I2C, DEV_ADDR, L3G4200D_REG_CTRL4, tmp) != 1) {
|
||||
if (i2c_write_reg(DEV_I2C, DEV_ADDR, L3G4200D_REG_CTRL4, tmp, 0) < 0) {
|
||||
i2c_release(DEV_I2C);
|
||||
return -1;
|
||||
}
|
||||
@ -90,7 +83,7 @@ int l3g4200d_read(const l3g4200d_t *dev, l3g4200d_data_t *data)
|
||||
|
||||
i2c_acquire(DEV_I2C);
|
||||
/* get acceleration in x direction */
|
||||
i2c_read_regs(DEV_I2C, DEV_ADDR, L3G4200D_REG_OUT_X_L | L3G4200D_AUTOINC, tmp, 6);
|
||||
i2c_read_regs(DEV_I2C, DEV_ADDR, L3G4200D_REG_OUT_X_L | L3G4200D_AUTOINC, tmp, 6, 0);
|
||||
i2c_release(DEV_I2C);
|
||||
|
||||
/* parse and normalize data into result vector */
|
||||
@ -109,13 +102,13 @@ int l3g4200d_enable(const l3g4200d_t *dev)
|
||||
int res;
|
||||
|
||||
i2c_acquire(DEV_I2C);
|
||||
res = i2c_read_reg(DEV_I2C, DEV_ADDR, L3G4200D_REG_CTRL1, &tmp);
|
||||
if (res < 1) {
|
||||
res = i2c_read_reg(DEV_I2C, DEV_ADDR, L3G4200D_REG_CTRL1, &tmp, 0);
|
||||
if (res < 0) {
|
||||
i2c_release(DEV_I2C);
|
||||
return res;
|
||||
}
|
||||
tmp |= L3G4200D_CTRL1_PD;
|
||||
if (i2c_write_reg(DEV_I2C, DEV_ADDR, L3G4200D_REG_CTRL1, tmp) != 1) {
|
||||
if (i2c_write_reg(DEV_I2C, DEV_ADDR, L3G4200D_REG_CTRL1, tmp, 0) < 0) {
|
||||
i2c_release(DEV_I2C);
|
||||
return -1;
|
||||
}
|
||||
@ -129,13 +122,13 @@ int l3g4200d_disable(const l3g4200d_t *dev)
|
||||
int res;
|
||||
|
||||
i2c_acquire(DEV_I2C);
|
||||
res = i2c_read_reg(DEV_I2C, DEV_ADDR, L3G4200D_REG_CTRL1, &tmp);
|
||||
if (res < 1) {
|
||||
res = i2c_read_reg(DEV_I2C, DEV_ADDR, L3G4200D_REG_CTRL1, &tmp, 0);
|
||||
if (res < 0) {
|
||||
i2c_release(DEV_I2C);
|
||||
return res;
|
||||
}
|
||||
tmp &= ~L3G4200D_CTRL1_PD;
|
||||
if (i2c_write_reg(DEV_I2C, DEV_ADDR, L3G4200D_REG_CTRL1, tmp) != 1) {
|
||||
if (i2c_write_reg(DEV_I2C, DEV_ADDR, L3G4200D_REG_CTRL1, tmp, 0) < 0) {
|
||||
i2c_release(DEV_I2C);
|
||||
return -1;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user