Merge pull request #15049 from aabadie/pr/drivers/lsm303dlhc_enh_init

drivers/lsm303dlhc: slightly enhance the initialization code
This commit is contained in:
Alexandre Abadie 2020-09-21 11:44:08 +02:00 committed by GitHub
commit c270aadc00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -42,15 +42,13 @@ int lsm303dlhc_init(lsm303dlhc_t *dev, const lsm303dlhc_params_t *params)
int res;
uint8_t tmp;
DEBUG("lsm303dlhc init...");
/* Acquire exclusive access to the bus. */
i2c_acquire(DEV_I2C);
DEBUG("lsm303dlhc reboot...");
/* reboot sensor */
res = i2c_write_reg(DEV_I2C, DEV_ACC_ADDR,
LSM303DLHC_REG_CTRL5_A, LSM303DLHC_REG_CTRL5_A_BOOT, 0);
/* Release the bus for other threads. */
i2c_release(DEV_I2C);
DEBUG("[OK]\n");
/* configure accelerometer */
/* enable all three axis and set sample rate */
@ -58,7 +56,6 @@ int lsm303dlhc_init(lsm303dlhc_t *dev, const lsm303dlhc_params_t *params)
| LSM303DLHC_CTRL1_A_YEN
| LSM303DLHC_CTRL1_A_ZEN
| DEV_ACC_RATE);
i2c_acquire(DEV_I2C);
res += i2c_write_reg(DEV_I2C, DEV_ACC_ADDR,
LSM303DLHC_REG_CTRL1_A, tmp, 0);
/* update on read, MSB @ low address, scale and high-resolution */
@ -85,6 +82,12 @@ int lsm303dlhc_init(lsm303dlhc_t *dev, const lsm303dlhc_params_t *params)
i2c_release(DEV_I2C);
/* configure mag data ready pin */
gpio_init(DEV_MAG_PIN, GPIO_IN);
if (ENABLE_DEBUG && res == 0) {
DEBUG("[OK]\n");
}
else {
DEBUG("[Failed]\n");
}
return (res < 0) ? -1 : 0;
}