summaryrefslogtreecommitdiff
path: root/driver/baro_bmp280.c
diff options
context:
space:
mode:
authorJonathan Brandmeyer <jbrandmeyer@chromium.org>2018-08-07 16:04:23 -0600
committerchrome-bot <chrome-bot@chromium.org>2018-08-09 22:04:40 -0700
commit740427a24398b3fd66904e913b742f751371d09c (patch)
tree1efe5fd4db314fbbb44bdd3a5bc726c4ee818ad0 /driver/baro_bmp280.c
parentaba9f5e09f7fb1f18a297fb5552404706a642351 (diff)
downloadchrome-ec-740427a24398b3fd66904e913b742f751371d09c.tar.gz
drivers: Refactor to use high-level i2c APIs
Using the high-level APIs for block transfers eliminates some code duplication and error-prone manual locking sequences. - common/cbi: Block transfers - driver/accel_bma2x2: Block transfers - driver/accel_kionix: Block transfers - driver/accelgyro_bmi160: Block transfers - driver/accelgyro_lsm6ds0: Block transfers - driver/baro_bmp280: Block and byte transfers - driver/charger/rt946x: Block transfers - driver/gyro_l3gd20h: Block transfers - driver/stm_mems_common: Block transfers - driver/tcpm: Block transfers TEST=buildall; motionsense and PD testing on Grunt convertible which exercises the bma160, kionix and tcpcm drivers. BRANCH=none BUG=chromium:871851 Change-Id: I1732253a244c3343459265ce1e1e54488cee65b8 Signed-off-by: Jonathan Brandmeyer <jbrandmeyer@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1167958 Reviewed-by: Jett Rink <jettrink@chromium.org>
Diffstat (limited to 'driver/baro_bmp280.c')
-rw-r--r--driver/baro_bmp280.c48
1 files changed, 8 insertions, 40 deletions
diff --git a/driver/baro_bmp280.c b/driver/baro_bmp280.c
index 3ca0084704..e6220c7e35 100644
--- a/driver/baro_bmp280.c
+++ b/driver/baro_bmp280.c
@@ -68,37 +68,6 @@
static const uint16_t standby_durn[] = {1, 63, 125, 250, 500, 1000, 2000, 4000};
-static inline int raw_read8(const int port, const int addr, const int reg,
- int *data_ptr)
-{
- return i2c_read8(port, addr, reg, data_ptr);
-}
-
-/*
- * Read n bytes from barometer.
- */
-static inline int raw_read_n(const int port, const int addr, const uint8_t reg,
- uint8_t *data_ptr, const int len)
-{
- int rv;
-
- i2c_lock(port, 1);
- rv = i2c_xfer(port, addr, &reg, 1,
- data_ptr, len, I2C_XFER_SINGLE);
- i2c_lock(port, 0);
- return rv;
-}
-
-/*
- * Write 8bit register from accelerometer.
- */
-static inline int raw_write8(const int port, const int addr, const int reg,
- int data)
-{
- return i2c_write8(port, addr, reg, data);
-}
-
-
/*
* This function is used to get calibration parameters used for
* calculation in the registers
@@ -122,7 +91,6 @@ static inline int raw_write8(const int port, const int addr, const int reg,
* @retval 0 -> Success
*
*/
-
static int bmp280_get_calib_param(const struct motion_sensor_t *s)
{
int ret;
@@ -130,7 +98,7 @@ static int bmp280_get_calib_param(const struct motion_sensor_t *s)
uint8_t a_data_u8[BMP280_CALIB_DATA_SIZE] = {0};
struct bmp280_drv_data_t *data = BMP280_GET_DATA(s);
- ret = raw_read_n(s->port, s->addr,
+ ret = i2c_read_block(s->port, s->addr,
BMP280_TEMPERATURE_CALIB_DIG_T1_LSB_REG,
a_data_u8, BMP280_CALIB_DATA_SIZE);
@@ -161,7 +129,7 @@ static int bmp280_read_uncomp_pressure(const struct motion_sensor_t *s,
int ret;
uint8_t a_data_u8[BMP280_PRESSURE_DATA_SIZE] = {0};
- ret = raw_read_n(s->port, s->addr,
+ ret = i2c_read_block(s->port, s->addr,
BMP280_PRESSURE_MSB_REG,
a_data_u8, BMP280_PRESSURE_DATA_SIZE);
@@ -250,13 +218,13 @@ static int bmp280_set_standby_durn(const struct motion_sensor_t *s,
{
int ret, val;
- ret = raw_read8(s->port, s->addr,
+ ret = i2c_read8(s->port, s->addr,
BMP280_CONFIG_REG, &val);
if (ret == EC_SUCCESS) {
val = (val & 0xE0) | ((durn << 5) & 0xE0);
/* write the standby duration*/
- ret = raw_write8(s->port, s->addr,
+ ret = i2c_write8(s->port, s->addr,
BMP280_CONFIG_REG, val);
}
@@ -271,7 +239,7 @@ static int bmp280_set_power_mode(const struct motion_sensor_t *s,
val = (BMP280_OVERSAMP_TEMP << 5) +
(BMP280_OVERSAMP_PRES << 2) + power_mode;
- return raw_write8(s->port, s->addr, BMP280_CTRL_MEAS_REG, val);
+ return i2c_write8(s->port, s->addr, BMP280_CTRL_MEAS_REG, val);
}
static int bmp280_set_range(const struct motion_sensor_t *s,
@@ -309,7 +277,7 @@ static int bmp280_init(const struct motion_sensor_t *s)
return EC_ERROR_INVAL;
/* Read chip id */
- ret = raw_read8(s->port, s->addr,
+ ret = i2c_read8(s->port, s->addr,
BMP280_CHIP_ID_REG, &val);
if (ret)
return ret;
@@ -415,7 +383,7 @@ struct i2c_stress_test_dev bmp280_i2c_stress_test_dev = {
.read_val = BMP280_CHIP_ID,
.write_reg = BMP280_CONFIG_REG,
},
- .i2c_read = &raw_read8,
- .i2c_write = &raw_write8,
+ .i2c_read = &i2c_read8,
+ .i2c_write = &i2c_write8,
};
#endif /* CONFIG_CMD_I2C_STRESS_TEST_ACCEL */