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

drivers/lps331ap: adapt to new I2C api

This commit is contained in:
Alexandre Abadie 2018-05-27 22:45:38 +02:00 committed by dylad
parent 917fd3c117
commit d1a19db350
2 changed files with 12 additions and 23 deletions

View File

@ -96,7 +96,7 @@ int lps331ap_read_pres(const lps331ap_t *dev);
* @param[in] dev device descriptor of sensor to enable
*
* @return 0 on success
* @return -1 on error
* @return <0 on error
*/
int lps331ap_enable(const lps331ap_t *dev);
@ -106,7 +106,7 @@ int lps331ap_enable(const lps331ap_t *dev);
* @param[in] dev device descriptor of sensor to disable
*
* @return 0 on success
* @return -1 on error
* @return <0 on error
*/
int lps331ap_disable(const lps331ap_t *dev);

View File

@ -29,11 +29,6 @@
#include "lps331ap.h"
#include "lps331ap-internal.h"
/**
* @brief default I2C bus speed for this sensor
*/
#define BUS_SPEED I2C_SPEED_FAST
/**
* @brief pressure divider for norming pressure output
*/
@ -57,17 +52,11 @@ int lps331ap_init(lps331ap_t *dev, const lps331ap_params_t * params)
/* Acquire exclusive access to the bus. */
i2c_acquire(DEV_I2C);
/* initialize underlying I2C bus */
if (i2c_init_master(DEV_I2C, BUS_SPEED) < 0) {
/* Release the bus for other threads. */
i2c_release(DEV_I2C);
return -1;
}
/* configure device, for simple operation only CTRL_REG1 needs to be touched */
tmp = LPS331AP_CTRL_REG1_DBDU | LPS331AP_CTRL_REG1_PD |
(DEV_RATE << LPS331AP_CTRL_REG1_ODR_POS);
if (i2c_write_reg(DEV_I2C, DEV_ADDR, LPS331AP_REG_CTRL_REG1, tmp) != 1) {
if (i2c_write_reg(DEV_I2C, DEV_ADDR, LPS331AP_REG_CTRL_REG1, tmp, 0) < 0) {
i2c_release(DEV_I2C);
return -1;
}
@ -83,9 +72,9 @@ int lps331ap_read_temp(const lps331ap_t *dev)
float res = TEMP_BASE; /* reference value -> see datasheet */
i2c_acquire(DEV_I2C);
i2c_read_reg(DEV_I2C, DEV_ADDR, LPS331AP_REG_TEMP_OUT_L, &tmp);
i2c_read_reg(DEV_I2C, DEV_ADDR, LPS331AP_REG_TEMP_OUT_L, &tmp, 0);
val |= tmp;
i2c_read_reg(DEV_I2C, DEV_ADDR, LPS331AP_REG_TEMP_OUT_H, &tmp);
i2c_read_reg(DEV_I2C, DEV_ADDR, LPS331AP_REG_TEMP_OUT_H, &tmp, 0);
i2c_release(DEV_I2C);
val |= ((uint16_t)tmp << 8);
@ -103,11 +92,11 @@ int lps331ap_read_pres(const lps331ap_t *dev)
float res;
i2c_acquire(DEV_I2C);
i2c_read_reg(DEV_I2C, DEV_ADDR, LPS331AP_REG_PRESS_OUT_XL, &tmp);
i2c_read_reg(DEV_I2C, DEV_ADDR, LPS331AP_REG_PRESS_OUT_XL, &tmp, 0);
val |= tmp;
i2c_read_reg(DEV_I2C, DEV_ADDR, LPS331AP_REG_PRESS_OUT_L, &tmp);
i2c_read_reg(DEV_I2C, DEV_ADDR, LPS331AP_REG_PRESS_OUT_L, &tmp, 0);
val |= ((uint32_t)tmp << 8);
i2c_read_reg(DEV_I2C, DEV_ADDR, LPS331AP_REG_PRESS_OUT_H, &tmp);
i2c_read_reg(DEV_I2C, DEV_ADDR, LPS331AP_REG_PRESS_OUT_H, &tmp, 0);
i2c_release(DEV_I2C);
val |= ((uint32_t)tmp << 16);
/* see if value is negative */
@ -128,12 +117,12 @@ int lps331ap_enable(const lps331ap_t *dev)
int status;
i2c_acquire(DEV_I2C);
if (i2c_read_reg(DEV_I2C, DEV_ADDR, LPS331AP_REG_CTRL_REG1, &tmp) != 1) {
if (i2c_read_reg(DEV_I2C, DEV_ADDR, LPS331AP_REG_CTRL_REG1, &tmp, 0) < 0) {
i2c_release(DEV_I2C);
return -1;
}
tmp |= (LPS331AP_CTRL_REG1_PD);
status = i2c_write_reg(DEV_I2C, DEV_ADDR, LPS331AP_REG_CTRL_REG1, tmp);
status = i2c_write_reg(DEV_I2C, DEV_ADDR, LPS331AP_REG_CTRL_REG1, tmp, 0);
i2c_release(DEV_I2C);
return status;
@ -145,12 +134,12 @@ int lps331ap_disable(const lps331ap_t *dev)
int status;
i2c_acquire(DEV_I2C);
if (i2c_read_reg(DEV_I2C, DEV_ADDR, LPS331AP_REG_CTRL_REG1, &tmp) != 1) {
if (i2c_read_reg(DEV_I2C, DEV_ADDR, LPS331AP_REG_CTRL_REG1, &tmp, 0) < 0) {
i2c_release(DEV_I2C);
return -1;
}
tmp &= ~(LPS331AP_CTRL_REG1_PD);
status = i2c_write_reg(DEV_I2C, DEV_ADDR, LPS331AP_REG_CTRL_REG1, tmp);
status = i2c_write_reg(DEV_I2C, DEV_ADDR, LPS331AP_REG_CTRL_REG1, tmp, 0);
i2c_release(DEV_I2C);
return status;