You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by je...@apache.org on 2019/06/19 10:41:17 UTC
[mynewt-core] branch master updated: sensors/bmp280: Fix bit filed
access
This is an automated email from the ASF dual-hosted git repository.
jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
The following commit(s) were added to refs/heads/master by this push:
new 212d51d sensors/bmp280: Fix bit filed access
212d51d is described below
commit 212d51dc4a49ad140d162965d709ace7814f0497
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Wed Jun 12 11:58:20 2019 +0200
sensors/bmp280: Fix bit filed access
All writes to bit fields in config and ctrl_meas registers
did not set bit correctly.
Bits were only added and never cleared that could lead
to unpredictable results.
Filter bit field was incorrectly shifted for read and write.
---
hw/drivers/sensors/bmp280/src/bmp280.c | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/hw/drivers/sensors/bmp280/src/bmp280.c b/hw/drivers/sensors/bmp280/src/bmp280.c
index c383f91..3f27a0f 100644
--- a/hw/drivers/sensors/bmp280/src/bmp280.c
+++ b/hw/drivers/sensors/bmp280/src/bmp280.c
@@ -1075,7 +1075,7 @@ bmp280_get_iir(struct sensor_itf *itf, uint8_t *iir)
goto err;
}
- *iir = ((tmp & BMP280_REG_CONFIG_FILTER) >> 5);
+ *iir = (tmp & BMP280_REG_CONFIG_FILTER) >> 2;
return 0;
err:
@@ -1100,7 +1100,8 @@ bmp280_set_iir(struct sensor_itf *itf, uint8_t iir)
goto err;
}
- iir = cfg | ((iir << 5) & BMP280_REG_CONFIG_FILTER);
+ iir = (cfg & ~BMP280_REG_CONFIG_FILTER) |
+ ((iir << 2) & BMP280_REG_CONFIG_FILTER);
rc = bmp280_writelen(itf, BMP280_REG_ADDR_CONFIG, &iir, 1);
if (rc) {
@@ -1155,7 +1156,8 @@ bmp280_set_mode(struct sensor_itf *itf, uint8_t mode)
goto err;
}
- cfg = cfg | (mode & BMP280_REG_CTRL_MEAS_MODE);
+ cfg = (cfg & ~BMP280_REG_CTRL_MEAS_MODE) |
+ (mode & BMP280_REG_CTRL_MEAS_MODE);
rc = bmp280_writelen(itf, BMP280_REG_ADDR_CTRL_MEAS, &cfg, 1);
if (rc) {
@@ -1216,24 +1218,29 @@ bmp280_set_oversample(struct sensor_itf *itf, sensor_type_t type,
int rc;
uint8_t cfg;
- if (type & SENSOR_TYPE_AMBIENT_TEMPERATURE || type & SENSOR_TYPE_PRESSURE) {
+ if (type & (SENSOR_TYPE_AMBIENT_TEMPERATURE | SENSOR_TYPE_PRESSURE)) {
rc = bmp280_readlen(itf, BMP280_REG_ADDR_CTRL_MEAS, &cfg, 1);
if (rc) {
goto err;
}
if (type & SENSOR_TYPE_AMBIENT_TEMPERATURE) {
- cfg = cfg | ((oversample << 5) & BMP280_REG_CTRL_MEAS_TOVER);
+ cfg = (cfg & ~BMP280_REG_CTRL_MEAS_TOVER) |
+ ((oversample << 5) & BMP280_REG_CTRL_MEAS_TOVER);
}
if (type & SENSOR_TYPE_PRESSURE) {
- cfg = cfg | ((oversample << 2) & BMP280_REG_CTRL_MEAS_POVER);
+ cfg = (cfg & ~BMP280_REG_CTRL_MEAS_POVER) |
+ ((oversample << 2) & BMP280_REG_CTRL_MEAS_POVER);
}
rc = bmp280_writelen(itf, BMP280_REG_ADDR_CTRL_MEAS, &cfg, 1);
if (rc) {
goto err;
}
+ } else {
+ rc = EINVAL;
+ goto err;
}
return 0;
@@ -1285,7 +1292,8 @@ bmp280_set_sby_duration(struct sensor_itf *itf, uint8_t dur)
goto err;
}
- cfg = cfg | ((dur << 5) & BMP280_REG_CONFIG_STANDBY);
+ cfg = (cfg & ~BMP280_REG_CONFIG_STANDBY) |
+ ((dur << 5) & BMP280_REG_CONFIG_STANDBY);
rc = bmp280_writelen(itf, BMP280_REG_ADDR_CONFIG, &cfg, 1);
if (rc) {