1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-19 19:43:52 +01:00

drivers/l3g4200d: fixed initialization

This commit is contained in:
Hauke Petersen 2015-11-18 16:34:50 +01:00
parent 4cb4d294d0
commit cb6f3e9566

View File

@ -39,16 +39,6 @@ int l3g4200d_init(l3g4200d_t *dev, i2c_t i2c, uint8_t address,
{ {
char tmp; char tmp;
/* Acquire exclusive access to the bus. */
i2c_acquire(dev->i2c);
/* initialize the I2C bus */
if (i2c_init_master(i2c, I2C_SPEED) < 0) {
/* Release the bus for other threads. */
i2c_release(dev->i2c);
return -1;
}
i2c_release(dev->i2c);
/* write device descriptor */ /* write device descriptor */
dev->i2c = i2c; dev->i2c = i2c;
dev->addr = address; dev->addr = address;
@ -71,9 +61,16 @@ int l3g4200d_init(l3g4200d_t *dev, i2c_t i2c, uint8_t address,
break; break;
} }
/* acquire exclusive access to the bus. */
i2c_acquire(dev->i2c);
/* initialize the I2C bus */
if (i2c_init_master(i2c, I2C_SPEED) < 0) {
/* Release the bus for other threads. */
i2c_release(dev->i2c);
return -1;
}
/* configure CTRL_REG1 */ /* configure CTRL_REG1 */
tmp = ((mode & 0xf) << L3G4200D_CTRL1_MODE_POS) | L3G4200D_CTRL1_ALLON; tmp = ((mode & 0xf) << L3G4200D_CTRL1_MODE_POS) | L3G4200D_CTRL1_ALLON;
i2c_acquire(dev->i2c);
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) != 1) {
i2c_release(dev->i2c); i2c_release(dev->i2c);
return -1; return -1;