diff --git a/drivers/mpl3115a2/mpl3115a2.c b/drivers/mpl3115a2/mpl3115a2.c index 80e39bf273..ac76a7f185 100644 --- a/drivers/mpl3115a2/mpl3115a2.c +++ b/drivers/mpl3115a2/mpl3115a2.c @@ -35,8 +35,6 @@ #define ENABLE_DEBUG (0) #include "debug.h" -#define I2C_SPEED I2C_SPEED_FAST - #define BUS (dev->params.i2c) #define ADDR (dev->params.addr) @@ -51,14 +49,8 @@ int mpl3115a2_init(mpl3115a2_t *dev, const mpl3115a2_params_t *params) memcpy(dev, params, sizeof(mpl3115a2_params_t)); i2c_acquire(BUS); - /* initialize the I2C bus */ - if (i2c_init_master(BUS, I2C_SPEED) < 0) { - i2c_release(BUS); - LOG_ERROR("mpl3115a2_init: failed to init I2C!\n"); - return -MPL3115A2_ERROR_I2C; - } /* test device */ - if (i2c_read_regs(BUS, ADDR, MPL3115A2_WHO_AM_I, ®, 1) != 1) { + if (i2c_read_regs(BUS, ADDR, MPL3115A2_WHO_AM_I, ®, 1, 0) < 0) { /* Release the bus for other threads. */ i2c_release(BUS); LOG_ERROR("mpl3115a2_init: I2C error!\n"); @@ -70,7 +62,7 @@ int mpl3115a2_init(mpl3115a2_t *dev, const mpl3115a2_params_t *params) } /* set sample rate */ reg = MPL3115A2_CTRL_REG1_OS(dev->params.ratio); - if (i2c_write_regs(BUS, ADDR, MPL3115A2_CTRL_REG1, ®, 1) != 1) { + if (i2c_write_regs(BUS, ADDR, MPL3115A2_CTRL_REG1, ®, 1, 0) < 0) { i2c_release(BUS); LOG_ERROR("mpl3115a2_init: failed to set sample rate!\n"); return -MPL3115A2_ERROR_CNF; @@ -79,7 +71,7 @@ int mpl3115a2_init(mpl3115a2_t *dev, const mpl3115a2_params_t *params) reg = MPL3115A2_PT_DATA_CFG_TDEFE | MPL3115A2_PT_DATA_CFG_PDEFE | MPL3115A2_PT_DATA_CFG_DREM; - if (i2c_write_regs(BUS, ADDR, MPL3115A2_PT_DATA_CFG, ®, 1) != 1) { + if (i2c_write_regs(BUS, ADDR, MPL3115A2_PT_DATA_CFG, ®, 1, 0) < 0) { i2c_release(BUS); LOG_ERROR("mpl3115a2_init: config failure!\n"); return -MPL3115A2_ERROR_CNF; @@ -96,7 +88,7 @@ int mpl3115a2_reset(const mpl3115a2_t *dev) i2c_acquire(BUS); reg = MPL3115A2_CTRL_REG1_RST; - if (i2c_write_regs(BUS, ADDR, MPL3115A2_CTRL_REG1, ®, 1) != 1) { + if (i2c_write_regs(BUS, ADDR, MPL3115A2_CTRL_REG1, ®, 1, 0) < 0) { i2c_release(BUS); LOG_ERROR("mpl3115a2_reset: failed!\n"); return -MPL3115A2_ERROR_I2C; @@ -111,13 +103,13 @@ int mpl3115a2_set_active(const mpl3115a2_t *dev) uint8_t reg; i2c_acquire(BUS); - if (i2c_read_regs(BUS, ADDR, MPL3115A2_CTRL_REG1, ®, 1) != 1) { + if (i2c_read_regs(BUS, ADDR, MPL3115A2_CTRL_REG1, ®, 1, 0) < 0) { i2c_release(BUS); return -MPL3115A2_ERROR_I2C; } reg |= MPL3115A2_CTRL_REG1_SBYB; - if (i2c_write_regs(BUS, ADDR, MPL3115A2_CTRL_REG1, ®, 1) != 1) { + if (i2c_write_regs(BUS, ADDR, MPL3115A2_CTRL_REG1, ®, 1, 0) < 0) { i2c_release(BUS); return -MPL3115A2_ERROR_I2C; } @@ -131,13 +123,13 @@ int mpl3115a2_set_standby(const mpl3115a2_t *dev) uint8_t reg; i2c_acquire(BUS); - if (i2c_read_regs(BUS, ADDR, MPL3115A2_CTRL_REG1, ®, 1) != 1) { + if (i2c_read_regs(BUS, ADDR, MPL3115A2_CTRL_REG1, ®, 1, 0) < 0) { i2c_release(BUS); return -MPL3115A2_ERROR_I2C; } reg &= ~MPL3115A2_CTRL_REG1_SBYB; - if (i2c_write_regs(BUS, ADDR, MPL3115A2_CTRL_REG1, ®, 1) != 1) { + if (i2c_write_regs(BUS, ADDR, MPL3115A2_CTRL_REG1, ®, 1, 0) < 0) { i2c_release(BUS); return -MPL3115A2_ERROR_I2C; } @@ -151,7 +143,7 @@ int mpl3115a2_is_ready(const mpl3115a2_t *dev) uint8_t reg; i2c_acquire(BUS); - if (i2c_read_regs(BUS, ADDR, MPL3115A2_STATUS, ®, 1) != 1) { + if (i2c_read_regs(BUS, ADDR, MPL3115A2_STATUS, ®, 1, 0) < 0) { i2c_release(BUS); return -MPL3115A2_ERROR_I2C; } @@ -165,7 +157,7 @@ int mpl3115a2_read_pressure(const mpl3115a2_t *dev, uint32_t *pres, uint8_t *sta uint8_t buf[4]; i2c_acquire(BUS); - if (i2c_read_regs(BUS, ADDR, MPL3115A2_STATUS, buf, 4) != 4) { + if (i2c_read_regs(BUS, ADDR, MPL3115A2_STATUS, buf, 4, 0) < 0) { i2c_release(BUS); return -MPL3115A2_ERROR_I2C; } @@ -184,7 +176,7 @@ int mpl3115a2_read_temp(const mpl3115a2_t *dev, int16_t *temp) uint8_t buf[2]; i2c_acquire(BUS); - if (i2c_read_regs(BUS, ADDR, MPL3115A2_OUT_T_MSB, buf, 2) != 2) { + if (i2c_read_regs(BUS, ADDR, MPL3115A2_OUT_T_MSB, buf, 2, 0) < 0) { i2c_release(BUS); return -MPL3115A2_ERROR_I2C; }