1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

drivers/bh1750fvi: adapt to new i2c API

This commit is contained in:
Michel Rottleuthner 2018-07-04 11:06:22 +02:00 committed by dylad
parent a82f4e1778
commit 27f8924bed

View File

@ -38,10 +38,9 @@ int bh1750fvi_init(bh1750fvi_t *dev, bh1750fvi_params_t *params)
/* initialize the I2C bus */
i2c_acquire(dev->i2c);
i2c_init_master(dev->i2c, params->clk);
/* send a power down command to make sure we can speak to the device */
res = i2c_write_byte(dev->i2c, dev->addr, OP_POWER_DOWN);
res = i2c_write_byte(dev->i2c, dev->addr, OP_POWER_DOWN, 0);
i2c_release(dev->i2c);
if (res < 0) {
return BH1750FVI_ERR_I2C;
@ -57,8 +56,8 @@ uint16_t bh1750fvi_sample(const bh1750fvi_t *dev)
/* power on the device and send single H-mode measurement command */
DEBUG("[bh1750fvi] sample: triggering a conversion\n");
i2c_acquire(dev->i2c);
i2c_write_byte(dev->i2c, dev->addr, OP_POWER_ON);
i2c_write_byte(dev->i2c, dev->addr, OP_SINGLE_HRES1);
i2c_write_byte(dev->i2c, dev->addr, OP_POWER_ON, 0);
i2c_write_byte(dev->i2c, dev->addr, OP_SINGLE_HRES1, 0);
i2c_release(dev->i2c);
/* wait for measurement to complete */
@ -67,7 +66,7 @@ uint16_t bh1750fvi_sample(const bh1750fvi_t *dev)
/* read the results */
DEBUG("[bh1750fvi] sample: reading the results\n");
i2c_acquire(dev->i2c);
i2c_read_bytes(dev->i2c, dev->addr, raw, 2);
i2c_read_bytes(dev->i2c, dev->addr, raw, 2, 0);
i2c_release(dev->i2c);
/* and finally we calculate the actual LUX value */