Skip to content

Commit

Permalink
drivers/mpl3115a2: adapt to new i2c API
Browse files Browse the repository at this point in the history
  • Loading branch information
aabadie authored and dylad committed Jul 25, 2018
1 parent b93245f commit 21e7281
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions drivers/mpl3115a2/mpl3115a2.c
Expand Up @@ -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)

Expand All @@ -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, &reg, 1) != 1) {
if (i2c_read_regs(BUS, ADDR, MPL3115A2_WHO_AM_I, &reg, 1, 0) < 0) {
/* Release the bus for other threads. */
i2c_release(BUS);
LOG_ERROR("mpl3115a2_init: I2C error!\n");
Expand All @@ -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, &reg, 1) != 1) {
if (i2c_write_regs(BUS, ADDR, MPL3115A2_CTRL_REG1, &reg, 1, 0) < 0) {
i2c_release(BUS);
LOG_ERROR("mpl3115a2_init: failed to set sample rate!\n");
return -MPL3115A2_ERROR_CNF;
Expand All @@ -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, &reg, 1) != 1) {
if (i2c_write_regs(BUS, ADDR, MPL3115A2_PT_DATA_CFG, &reg, 1, 0) < 0) {
i2c_release(BUS);
LOG_ERROR("mpl3115a2_init: config failure!\n");
return -MPL3115A2_ERROR_CNF;
Expand All @@ -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, &reg, 1) != 1) {
if (i2c_write_regs(BUS, ADDR, MPL3115A2_CTRL_REG1, &reg, 1, 0) < 0) {
i2c_release(BUS);
LOG_ERROR("mpl3115a2_reset: failed!\n");
return -MPL3115A2_ERROR_I2C;
Expand All @@ -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, &reg, 1) != 1) {
if (i2c_read_regs(BUS, ADDR, MPL3115A2_CTRL_REG1, &reg, 1, 0) < 0) {
i2c_release(BUS);
return -MPL3115A2_ERROR_I2C;
}

reg |= MPL3115A2_CTRL_REG1_SBYB;
if (i2c_write_regs(BUS, ADDR, MPL3115A2_CTRL_REG1, &reg, 1) != 1) {
if (i2c_write_regs(BUS, ADDR, MPL3115A2_CTRL_REG1, &reg, 1, 0) < 0) {
i2c_release(BUS);
return -MPL3115A2_ERROR_I2C;
}
Expand All @@ -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, &reg, 1) != 1) {
if (i2c_read_regs(BUS, ADDR, MPL3115A2_CTRL_REG1, &reg, 1, 0) < 0) {
i2c_release(BUS);
return -MPL3115A2_ERROR_I2C;
}

reg &= ~MPL3115A2_CTRL_REG1_SBYB;
if (i2c_write_regs(BUS, ADDR, MPL3115A2_CTRL_REG1, &reg, 1) != 1) {
if (i2c_write_regs(BUS, ADDR, MPL3115A2_CTRL_REG1, &reg, 1, 0) < 0) {
i2c_release(BUS);
return -MPL3115A2_ERROR_I2C;
}
Expand All @@ -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, &reg, 1) != 1) {
if (i2c_read_regs(BUS, ADDR, MPL3115A2_STATUS, &reg, 1, 0) < 0) {
i2c_release(BUS);
return -MPL3115A2_ERROR_I2C;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 21e7281

Please sign in to comment.