mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
drivers/lsm303dlhc: adapt to new I2C api
This commit is contained in:
parent
b5750c5671
commit
ec25c1f7b0
@ -44,11 +44,10 @@ int lsm303dlhc_init(lsm303dlhc_t *dev, const lsm303dlhc_params_t *params)
|
||||
|
||||
/* Acquire exclusive access to the bus. */
|
||||
i2c_acquire(DEV_I2C);
|
||||
i2c_init_master(DEV_I2C, I2C_SPEED_NORMAL);
|
||||
|
||||
DEBUG("lsm303dlhc reboot...");
|
||||
res = i2c_write_reg(DEV_I2C, DEV_ACC_ADDR,
|
||||
LSM303DLHC_REG_CTRL5_A, LSM303DLHC_REG_CTRL5_A_BOOT);
|
||||
LSM303DLHC_REG_CTRL5_A, LSM303DLHC_REG_CTRL5_A_BOOT, 0);
|
||||
/* Release the bus for other threads. */
|
||||
i2c_release(DEV_I2C);
|
||||
DEBUG("[OK]\n");
|
||||
@ -61,14 +60,14 @@ int lsm303dlhc_init(lsm303dlhc_t *dev, const lsm303dlhc_params_t *params)
|
||||
| DEV_ACC_RATE);
|
||||
i2c_acquire(DEV_I2C);
|
||||
res += i2c_write_reg(DEV_I2C, DEV_ACC_ADDR,
|
||||
LSM303DLHC_REG_CTRL1_A, tmp);
|
||||
LSM303DLHC_REG_CTRL1_A, tmp, 0);
|
||||
/* update on read, MSB @ low address, scale and high-resolution */
|
||||
tmp = (DEV_ACC_SCALE | LSM303DLHC_CTRL4_A_HR);
|
||||
res += i2c_write_reg(DEV_I2C, DEV_ACC_ADDR,
|
||||
LSM303DLHC_REG_CTRL4_A, tmp);
|
||||
LSM303DLHC_REG_CTRL4_A, tmp, 0);
|
||||
/* no interrupt generation */
|
||||
res += i2c_write_reg(DEV_I2C, DEV_ACC_ADDR,
|
||||
LSM303DLHC_REG_CTRL3_A, LSM303DLHC_CTRL3_A_I1_NONE);
|
||||
LSM303DLHC_REG_CTRL3_A, LSM303DLHC_CTRL3_A_I1_NONE, 0);
|
||||
/* configure acc data ready pin */
|
||||
gpio_init(DEV_ACC_PIN, GPIO_IN);
|
||||
|
||||
@ -76,18 +75,18 @@ int lsm303dlhc_init(lsm303dlhc_t *dev, const lsm303dlhc_params_t *params)
|
||||
/* enable temperature output and set sample rate */
|
||||
tmp = LSM303DLHC_TEMP_EN | DEV_MAG_RATE;
|
||||
res += i2c_write_reg(DEV_I2C, DEV_MAG_ADDR,
|
||||
LSM303DLHC_REG_CRA_M, tmp);
|
||||
LSM303DLHC_REG_CRA_M, tmp, 0);
|
||||
/* configure z-axis gain */
|
||||
res += i2c_write_reg(DEV_I2C, DEV_MAG_ADDR,
|
||||
LSM303DLHC_REG_CRB_M, DEV_MAG_GAIN);
|
||||
LSM303DLHC_REG_CRB_M, DEV_MAG_GAIN, 0);
|
||||
/* set continuous mode */
|
||||
res += i2c_write_reg(DEV_I2C, DEV_MAG_ADDR,
|
||||
LSM303DLHC_REG_MR_M, LSM303DLHC_MAG_MODE_CONTINUOUS);
|
||||
LSM303DLHC_REG_MR_M, LSM303DLHC_MAG_MODE_CONTINUOUS, 0);
|
||||
i2c_release(DEV_I2C);
|
||||
/* configure mag data ready pin */
|
||||
gpio_init(DEV_MAG_PIN, GPIO_IN);
|
||||
|
||||
return (res < 7) ? -1 : 0;
|
||||
return (res < 0) ? -1 : 0;
|
||||
}
|
||||
|
||||
int lsm303dlhc_read_acc(const lsm303dlhc_t *dev, lsm303dlhc_3d_data_t *data)
|
||||
@ -96,27 +95,27 @@ int lsm303dlhc_read_acc(const lsm303dlhc_t *dev, lsm303dlhc_3d_data_t *data)
|
||||
uint8_t tmp;
|
||||
|
||||
i2c_acquire(DEV_I2C);
|
||||
i2c_read_reg(DEV_I2C, DEV_ACC_ADDR, LSM303DLHC_REG_STATUS_A, &tmp);
|
||||
i2c_read_reg(DEV_I2C, DEV_ACC_ADDR, LSM303DLHC_REG_STATUS_A, &tmp, 0);
|
||||
DEBUG("lsm303dlhc status: %x\n", tmp);
|
||||
DEBUG("lsm303dlhc: wait for acc values ... ");
|
||||
|
||||
res = i2c_read_reg(DEV_I2C, DEV_ACC_ADDR,
|
||||
LSM303DLHC_REG_OUT_X_L_A, &tmp);
|
||||
LSM303DLHC_REG_OUT_X_L_A, &tmp, 0);
|
||||
data->x_axis = tmp;
|
||||
res += i2c_read_reg(DEV_I2C, DEV_ACC_ADDR,
|
||||
LSM303DLHC_REG_OUT_X_H_A, &tmp);
|
||||
LSM303DLHC_REG_OUT_X_H_A, &tmp, 0);
|
||||
data->x_axis |= tmp<<8;
|
||||
res += i2c_read_reg(DEV_I2C, DEV_ACC_ADDR,
|
||||
LSM303DLHC_REG_OUT_Y_L_A, &tmp);
|
||||
LSM303DLHC_REG_OUT_Y_L_A, &tmp, 0);
|
||||
data->y_axis = tmp;
|
||||
res += i2c_read_reg(DEV_I2C, DEV_ACC_ADDR,
|
||||
LSM303DLHC_REG_OUT_Y_H_A, &tmp);
|
||||
LSM303DLHC_REG_OUT_Y_H_A, &tmp, 0);
|
||||
data->y_axis |= tmp<<8;
|
||||
res += i2c_read_reg(DEV_I2C, DEV_ACC_ADDR,
|
||||
LSM303DLHC_REG_OUT_Z_L_A, &tmp);
|
||||
LSM303DLHC_REG_OUT_Z_L_A, &tmp, 0);
|
||||
data->z_axis = tmp;
|
||||
res += i2c_read_reg(DEV_I2C, DEV_ACC_ADDR,
|
||||
LSM303DLHC_REG_OUT_Z_H_A, &tmp);
|
||||
LSM303DLHC_REG_OUT_Z_H_A, &tmp, 0);
|
||||
data->z_axis |= tmp<<8;
|
||||
i2c_release(DEV_I2C);
|
||||
DEBUG("read ... ");
|
||||
@ -125,7 +124,7 @@ int lsm303dlhc_read_acc(const lsm303dlhc_t *dev, lsm303dlhc_3d_data_t *data)
|
||||
data->y_axis = data->y_axis>>4;
|
||||
data->z_axis = data->z_axis>>4;
|
||||
|
||||
if (res < 6) {
|
||||
if (res < 0) {
|
||||
DEBUG("[!!failed!!]\n");
|
||||
return -1;
|
||||
}
|
||||
@ -145,10 +144,10 @@ int lsm303dlhc_read_mag(const lsm303dlhc_t *dev, lsm303dlhc_3d_data_t *data)
|
||||
|
||||
i2c_acquire(DEV_I2C);
|
||||
res = i2c_read_regs(DEV_I2C, DEV_MAG_ADDR,
|
||||
LSM303DLHC_REG_OUT_X_H_M, data, 6);
|
||||
LSM303DLHC_REG_OUT_X_H_M, data, 6, 0);
|
||||
i2c_release(DEV_I2C);
|
||||
|
||||
if (res < 6) {
|
||||
if (res < 0) {
|
||||
DEBUG("[!!failed!!]\n");
|
||||
return -1;
|
||||
}
|
||||
@ -172,10 +171,11 @@ int lsm303dlhc_read_temp(const lsm303dlhc_t *dev, int16_t *value)
|
||||
int res;
|
||||
|
||||
i2c_acquire(DEV_I2C);
|
||||
res = i2c_read_regs(DEV_I2C, DEV_MAG_ADDR, LSM303DLHC_REG_TEMP_OUT_H, value, 2);
|
||||
res = i2c_read_regs(DEV_I2C, DEV_MAG_ADDR, LSM303DLHC_REG_TEMP_OUT_H,
|
||||
value, 2, 0);
|
||||
i2c_release(DEV_I2C);
|
||||
|
||||
if (res < 2) {
|
||||
if (res < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -192,14 +192,14 @@ int lsm303dlhc_disable(const lsm303dlhc_t *dev)
|
||||
|
||||
i2c_acquire(DEV_I2C);
|
||||
res = i2c_write_reg(DEV_I2C, DEV_ACC_ADDR,
|
||||
LSM303DLHC_REG_CTRL1_A, LSM303DLHC_CTRL1_A_POWEROFF);
|
||||
LSM303DLHC_REG_CTRL1_A, LSM303DLHC_CTRL1_A_POWEROFF, 0);
|
||||
res += i2c_write_reg(DEV_I2C, DEV_MAG_ADDR,
|
||||
LSM303DLHC_REG_MR_M, LSM303DLHC_MAG_MODE_SLEEP);
|
||||
LSM303DLHC_REG_MR_M, LSM303DLHC_MAG_MODE_SLEEP, 0);
|
||||
res += i2c_write_reg(DEV_I2C, DEV_ACC_ADDR,
|
||||
LSM303DLHC_REG_CRA_M, LSM303DLHC_TEMP_DIS);
|
||||
LSM303DLHC_REG_CRA_M, LSM303DLHC_TEMP_DIS, 0);
|
||||
i2c_release(DEV_I2C);
|
||||
|
||||
return (res < 3) ? -1 : 0;
|
||||
return (res < 0) ? -1 : 0;
|
||||
}
|
||||
|
||||
int lsm303dlhc_enable(const lsm303dlhc_t *dev)
|
||||
@ -210,24 +210,25 @@ int lsm303dlhc_enable(const lsm303dlhc_t *dev)
|
||||
| LSM303DLHC_CTRL1_A_ZEN
|
||||
| LSM303DLHC_CTRL1_A_N1344HZ_L5376HZ);
|
||||
i2c_acquire(DEV_I2C);
|
||||
res = i2c_write_reg(DEV_I2C, DEV_ACC_ADDR, LSM303DLHC_REG_CTRL1_A, tmp);
|
||||
res = i2c_write_reg(DEV_I2C, DEV_ACC_ADDR, LSM303DLHC_REG_CTRL1_A, tmp, 0);
|
||||
|
||||
tmp = (LSM303DLHC_CTRL4_A_BDU| LSM303DLHC_CTRL4_A_SCALE_2G | LSM303DLHC_CTRL4_A_HR);
|
||||
res += i2c_write_reg(DEV_I2C, DEV_ACC_ADDR, LSM303DLHC_REG_CTRL4_A, tmp);
|
||||
res += i2c_write_reg(DEV_I2C, DEV_ACC_ADDR, LSM303DLHC_REG_CTRL3_A, LSM303DLHC_CTRL3_A_I1_DRDY1);
|
||||
res += i2c_write_reg(DEV_I2C, DEV_ACC_ADDR, LSM303DLHC_REG_CTRL4_A, tmp, 0);
|
||||
res += i2c_write_reg(DEV_I2C, DEV_ACC_ADDR, LSM303DLHC_REG_CTRL3_A,
|
||||
LSM303DLHC_CTRL3_A_I1_DRDY1, 0);
|
||||
gpio_init(DEV_ACC_PIN, GPIO_IN);
|
||||
|
||||
tmp = LSM303DLHC_TEMP_EN | LSM303DLHC_TEMP_SAMPLE_75HZ;
|
||||
res += i2c_write_reg(DEV_I2C, DEV_MAG_ADDR, LSM303DLHC_REG_CRA_M, tmp);
|
||||
res += i2c_write_reg(DEV_I2C, DEV_MAG_ADDR, LSM303DLHC_REG_CRA_M, tmp, 0);
|
||||
|
||||
res += i2c_write_reg(DEV_I2C, DEV_MAG_ADDR,
|
||||
LSM303DLHC_REG_CRB_M, LSM303DLHC_GAIN_5);
|
||||
LSM303DLHC_REG_CRB_M, LSM303DLHC_GAIN_5, 0);
|
||||
|
||||
res += i2c_write_reg(DEV_I2C, DEV_MAG_ADDR,
|
||||
LSM303DLHC_REG_MR_M, LSM303DLHC_MAG_MODE_CONTINUOUS);
|
||||
LSM303DLHC_REG_MR_M, LSM303DLHC_MAG_MODE_CONTINUOUS, 0);
|
||||
i2c_release(DEV_I2C);
|
||||
|
||||
gpio_init(DEV_MAG_PIN, GPIO_IN);
|
||||
|
||||
return (res < 6) ? -1 : 0;
|
||||
return (res < 0) ? -1 : 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user