From a2d1558922ad3788dd17137edd0f3a9e6ab6b6e4 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Tue, 29 May 2018 17:10:50 +0200 Subject: [PATCH] drivers/bmp180: adapt to new I2C api --- drivers/bmp180/bmp180.c | 22 +++++++++------------- drivers/include/bmp180.h | 2 -- tests/driver_bmp180/main.c | 6 +----- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/drivers/bmp180/bmp180.c b/drivers/bmp180/bmp180.c index 1927c6e797..5959d84a89 100644 --- a/drivers/bmp180/bmp180.c +++ b/drivers/bmp180/bmp180.c @@ -52,18 +52,12 @@ int bmp180_init(bmp180_t *dev, const bmp180_params_t *params) OVERSAMPLING = BMP180_ULTRAHIGHRES; } - /* Initialize I2C interface */ - if (i2c_init_master(DEV_I2C, I2C_SPEED_NORMAL)) { - DEBUG("[Error] I2C device not enabled\n"); - return -BMP180_ERR_NOI2C; - } - /* Acquire exclusive access */ i2c_acquire(DEV_I2C); /* Check sensor ID */ uint8_t checkid; - i2c_read_reg(DEV_I2C, DEV_ADDR, BMP180_REGISTER_ID, &checkid); + i2c_read_reg(DEV_I2C, DEV_ADDR, BMP180_REGISTER_ID, &checkid, 0); if (checkid != 0x55) { DEBUG("[Error] Wrong device ID\n"); i2c_release(DEV_I2C); @@ -75,7 +69,8 @@ int bmp180_init(bmp180_t *dev, const bmp180_params_t *params) uint8_t buffer[22] = {0}; /* Read calibration values, using contiguous register addresses */ - if (i2c_read_regs(DEV_I2C, DEV_ADDR, BMP180_CALIBRATION_AC1, buffer, 22) < 0) { + if (i2c_read_regs(DEV_I2C, DEV_ADDR, BMP180_CALIBRATION_AC1, + buffer, 22, 0) < 0) { DEBUG("[Error] Cannot read calibration registers.\n"); i2c_release(DEV_I2C); return -BMP180_ERR_NOCAL; @@ -191,9 +186,9 @@ static int _read_ut(const bmp180_t *dev, int32_t *output) /* Read UT (Uncompsensated Temperature value) */ uint8_t ut[2] = {0}; uint8_t control[2] = { BMP180_REGISTER_CONTROL, BMP180_TEMPERATURE_COMMAND }; - i2c_write_bytes(DEV_I2C, DEV_ADDR, control, 2); + i2c_write_bytes(DEV_I2C, DEV_ADDR, control, 2, 0); xtimer_usleep(BMP180_ULTRALOWPOWER_DELAY); - if (i2c_read_regs(DEV_I2C, DEV_ADDR, BMP180_REGISTER_DATA, ut, 2) < 0) { + if (i2c_read_regs(DEV_I2C, DEV_ADDR, BMP180_REGISTER_DATA, ut, 2, 0) < 0) { DEBUG("[Error] Cannot read uncompensated temperature.\n"); i2c_release(DEV_I2C); return -1; @@ -209,8 +204,9 @@ static int _read_up(const bmp180_t *dev, int32_t *output) { /* Read UP (Uncompsensated Pressure value) */ uint8_t up[3] = {0}; - uint8_t control[2] = { BMP180_REGISTER_CONTROL, BMP180_PRESSURE_COMMAND | (OVERSAMPLING & 0x3) << 6 }; - i2c_write_bytes(DEV_I2C, DEV_ADDR, control, 2); + uint8_t control[2] = { BMP180_REGISTER_CONTROL, + BMP180_PRESSURE_COMMAND | (OVERSAMPLING & 0x3) << 6 }; + i2c_write_bytes(DEV_I2C, DEV_ADDR, control, 2, 0); switch (OVERSAMPLING) { case BMP180_ULTRALOWPOWER: xtimer_usleep(BMP180_ULTRALOWPOWER_DELAY); @@ -228,7 +224,7 @@ static int _read_up(const bmp180_t *dev, int32_t *output) xtimer_usleep(BMP180_ULTRALOWPOWER_DELAY); break; } - if (i2c_read_regs(DEV_I2C, DEV_ADDR, BMP180_REGISTER_DATA, up, 3) < 0) { + if (i2c_read_regs(DEV_I2C, DEV_ADDR, BMP180_REGISTER_DATA, up, 3, 0) < 0) { DEBUG("[Error] Cannot read uncompensated pressure.\n"); i2c_release(DEV_I2C); return -1; diff --git a/drivers/include/bmp180.h b/drivers/include/bmp180.h index 7c9bc929a2..e7b7940952 100644 --- a/drivers/include/bmp180.h +++ b/drivers/include/bmp180.h @@ -77,7 +77,6 @@ typedef struct { */ enum { BMP180_OK = 0, /**< everything was fine */ - BMP180_ERR_NOI2C, /**< error initializing the I2C bus */ BMP180_ERR_NODEV, /**< did not detect BMP180 */ BMP180_ERR_NOCAL, /**< error when reading calibration values */ }; @@ -89,7 +88,6 @@ enum { * @param[in] params Initialization parameters * * @return BMP180_OK on success - * @return -BMP180_ERR_NOI2C if given I2C is not enabled in board config * @return -BMP180_ERR_NODEV if not a BMP180 at given address * @return -BMP180_ERR_NOCAL if an error occured when reading calibration values */ diff --git a/tests/driver_bmp180/main.c b/tests/driver_bmp180/main.c index 2c6628760f..779ccde847 100644 --- a/tests/driver_bmp180/main.c +++ b/tests/driver_bmp180/main.c @@ -35,11 +35,7 @@ int main(void) printf("+------------Initializing------------+\n"); result = bmp180_init(&dev, &bmp180_params[0]); - if (result == -BMP180_ERR_NOI2C) { - puts("[Error] The given i2c is not enabled"); - return 1; - } - else if (result == -BMP180_ERR_NODEV) { + if (result == -BMP180_ERR_NODEV) { puts("[Error] The sensor did not answer correctly on the given address"); return 1; }