summaryrefslogtreecommitdiff
path: root/driver
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2015-08-06 15:42:44 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-08-24 19:08:04 +0000
commit179d5d3c833433b07530b136a55085a6d22cbeee (patch)
treea1a355b02a65bbfe7f7793e30d833c795bb26e50 /driver
parent0b79533f8874c8824fde3e020d01e328c685037c (diff)
downloadchrome-ec-179d5d3c833433b07530b136a55085a6d22cbeee.tar.gz
bmm150: add measurement repetition
To reduce noise the magnetometer measures in burst and average the data. Use "regular" presets: max frequency is limited to 100Hz. Using a more precise presets limit frequency to no more than 50Hz. BRANCH=smaug TEST=Check magnetomter still works. BUG=chrome-os-partner:39900 Change-Id: Ida6af86f6c207cc91e11378c129032f6d9e6b9ea Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/291990 Reviewed-by: Sheng-liang Song <ssl@chromium.org>
Diffstat (limited to 'driver')
-rw-r--r--driver/accelgyro_bmi160.c7
-rw-r--r--driver/accelgyro_bmi160.h2
-rw-r--r--driver/mag_bmm150.c8
-rw-r--r--driver/mag_bmm150.h14
4 files changed, 27 insertions, 4 deletions
diff --git a/driver/accelgyro_bmi160.c b/driver/accelgyro_bmi160.c
index a6c29bfbb2..3afa3e6bd7 100644
--- a/driver/accelgyro_bmi160.c
+++ b/driver/accelgyro_bmi160.c
@@ -400,9 +400,10 @@ static int set_data_rate(const struct motion_sensor_t *s,
}
break;
case MOTIONSENSE_TYPE_MAG:
- if (reg_val > BMI160_ODR_800HZ) {
- reg_val = BMI160_ODR_800HZ;
- normalized_rate = 800000;
+ /* We use the regular preset we can go about 100Hz */
+ if (reg_val > BMI160_ODR_100HZ) {
+ reg_val = BMI160_ODR_100HZ;
+ normalized_rate = 100000;
} else if (reg_val < BMI160_ODR_0_78HZ) {
reg_val = BMI160_ODR_0_78HZ;
normalized_rate = 780;
diff --git a/driver/accelgyro_bmi160.h b/driver/accelgyro_bmi160.h
index 4740c9a23e..fd2de42a4b 100644
--- a/driver/accelgyro_bmi160.h
+++ b/driver/accelgyro_bmi160.h
@@ -172,6 +172,8 @@ 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
diff --git a/driver/mag_bmm150.c b/driver/mag_bmm150.c
index fb2d5c7108..59ce76785e 100644
--- a/driver/mag_bmm150.c
+++ b/driver/mag_bmm150.c
@@ -115,6 +115,14 @@ int bmm150_init(const struct motion_sensor_t *s)
BMI150_READ_16BIT_COM_REG(regs->dig_z4, BMM150_REGA_DIG_Z4_LSB);
BMI150_READ_16BIT_COM_REG(regs->dig_xyz1, BMM150_REGA_DIG_XYZ1_LSB);
+
+ /* Set the repetition in "Regular Preset" */
+ raw_mag_write8(s->addr, BMM150_REPXY, 1 + 2 * BMM150_REP(REGULAR, XY));
+ raw_mag_write8(s->addr, BMM150_REPZ, 1 + BMM150_REP(REGULAR, Z));
+ ret = raw_mag_read8(s->addr, BMM150_REPXY, &val);
+ CPRINTS("repxy: 0x%02x", val);
+ ret = raw_mag_read8(s->addr, BMM150_REPZ, &val);
+ CPRINTS("repz: 0x%02x", val);
/*
* Set the compass forced mode, to sleep after each measure.
*/
diff --git a/driver/mag_bmm150.h b/driver/mag_bmm150.h
index 7486a77608..1bbf998f6a 100644
--- a/driver/mag_bmm150.h
+++ b/driver/mag_bmm150.h
@@ -34,8 +34,20 @@
#define BMM150_INT_CTRL 0x4d
-/* Hidden registers for RHALL calculation */
+#define BMM150_REPXY 0x51
+#define BMM150_LOW_POWER_nXY 3
+#define BMM150_REGULAR_nXY 9
+#define BMM150_ENHANCED_nXY 15
+#define BMM150_HIGH_ACCURACY_nXY 47
+#define BMM150_REPZ 0x52
+#define BMM150_LOW_POWER_nZ 3
+#define BMM150_REGULAR_nZ 15
+#define BMM150_ENHANCED_nZ 27
+#define BMM150_HIGH_ACCURACY_nZ 83
+
+#define BMM150_REP(_preset, _axis) CONCAT4(BMM150_, _preset, _n, _axis)
+/* Hidden registers for RHALL calculation */
#define BMM150_REGA_DIG_X1 0x5d
#define BMM150_REGA_DIG_Y1 0x5e
#define BMM150_REGA_DIG_Z4_LSB 0x62