summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2019-03-21 15:44:42 -0700
committerCommit Bot <commit-bot@chromium.org>2019-05-24 00:43:43 +0000
commit648b4fc1e9aa62dff5f9b6cda55fc465ef5e8b1d (patch)
tree537bb673e086e04ee76985365318479a22ba4398
parenta948e0e1d3c97c3e59ef45dc5767c69a1bd2254a (diff)
downloadchrome-ec-648b4fc1e9aa62dff5f9b6cda55fc465ef5e8b1d.tar.gz
bmi160: Fix ODR to REG when rate is less than 100Hz
The calculation was wrong and always returned the next value. We were lucky that we always ask to round up, so the frequencies were rounded up from the get go. BUG=b:120942904 BRANCH=none TEST=Test with several ODR for correctness: cout << "10:" << BMI160_ODR_TO_REG(10000) << ":" << BMI160_REG_TO_ODR(BMI160_ODR_TO_REG(10000)) << "\n" << "29:" << BMI160_ODR_TO_REG(29000) << ":" << BMI160_REG_TO_ODR(BMI160_ODR_TO_REG(29000)) << "\n" << "59:" << BMI160_ODR_TO_REG(59000) << ":" << BMI160_REG_TO_ODR(BMI160_ODR_TO_REG(59000)) << "\n" << "99:" << BMI160_ODR_TO_REG(99000) << ":" << BMI160_REG_TO_ODR(BMI160_ODR_TO_REG(99000)) << "\n" << "109:" << BMI160_ODR_TO_REG(109000) << ":" << BMI160_REG_TO_ODR(BMI160_ODR_TO_REG(109000)) << "\n" << "209:" << BMI160_ODR_TO_REG(209000) << ":" << BMI160_REG_TO_ODR(BMI160_ODR_TO_REG(209000)) << "\n" ; Returns: 10:4:6250 29:6:25000 59:7:50000 99:7:50000 109:8:100000 209:9:200000 (cherry picked from commit 0e99e97634135c9d4e6b60dcd6837bb76d91acf7) Reviewed-on: https://chromium-review.googlesource.com/1535160 Reviewed-by: Yilun Lin <yllin@chromium.org> Change-Id: I898d1077af78ab1d0e65ac0e8f7714a2a3b042b3 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1621508
-rw-r--r--driver/accelgyro_bmi160.h11
1 files changed, 3 insertions, 8 deletions
diff --git a/driver/accelgyro_bmi160.h b/driver/accelgyro_bmi160.h
index 9d756ae9c2..84acf29fb5 100644
--- a/driver/accelgyro_bmi160.h
+++ b/driver/accelgyro_bmi160.h
@@ -180,18 +180,13 @@ enum fifo_header {
/* odr = 100 / (1 << (8 - reg)) ,within limit */
#define BMI160_ODR_0_78HZ 0x01
-#define BMI160_ODR_25HZ 0x06
-#define BMI160_ODR_50HZ 0x07
#define BMI160_ODR_100HZ 0x08
-#define BMI160_ODR_800HZ 0x0b
-#define BMI160_ODR_1600HZ 0x0c
-#define BMI160_ODR_3200HZ 0x0d
#define BMI160_REG_TO_ODR(_regval) \
- ((_regval) < 8 ? 100000 / (1 << (8 - (_regval))) : \
- 100000 * (1 << ((_regval) - 8)))
+ ((_regval) < BMI160_ODR_100HZ ? 100000 / (1 << (8 - (_regval))) : \
+ 100000 * (1 << ((_regval) - 8)))
#define BMI160_ODR_TO_REG(_odr) \
- ((_odr) < 100000 ? (__builtin_clz(100000 / (_odr)) - 23) : \
+ ((_odr) < 100000 ? (__builtin_clz(100000 / (_odr)) - 24) : \
(39 - __builtin_clz((_odr) / 100000)))
#define BMI160_CONF_REG(_sensor) (0x40 + 2 * (_sensor))