summaryrefslogtreecommitdiff
path: root/common/motion_sense.c
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2016-09-13 16:47:31 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-09-14 03:58:46 -0700
commit51c5fd5c150dd1bad2660dbb38d432e7234910f0 (patch)
treeff83ef57a558410401db770d12604d54d629e986 /common/motion_sense.c
parent9e7c12b74e96ca123865b0ac4ca96b32aad548a7 (diff)
downloadchrome-ec-51c5fd5c150dd1bad2660dbb38d432e7234910f0.tar.gz
motion: Add minimum to oversample.
In case the AP is asking for a ODR frequency the sensor can not achieve (for instance over 76Hz for BMP280), be sure we do not set oversampling to 0. Otherwise, no sensor data will be sent to the AP. BUG=b:27849483 BRANCH=reef TEST=Check Androsensor reports presure information even when frequency is set at 100Hz. Change-Id: Idb849782daa96531cc33d21ea6780fd7f1f299d5 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/385081 Commit-Ready: Gwendal Grignou <gwendal@google.com> Tested-by: Gwendal Grignou <gwendal@google.com> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'common/motion_sense.c')
-rw-r--r--common/motion_sense.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/common/motion_sense.c b/common/motion_sense.c
index 662f07a692..65cb7de93d 100644
--- a/common/motion_sense.c
+++ b/common/motion_sense.c
@@ -183,7 +183,7 @@ static inline int motion_sensor_time_to_read(const timestamp_t *ts,
if (rate_mhz == 0)
return 0;
/*
- * converting from kHz to us.
+ * converting from mHz to us.
* If within 95% of the time, check sensor.
*/
return time_after(ts->le.lo,
@@ -241,8 +241,12 @@ int motion_sense_set_data_rate(struct motion_sensor_t *sensor)
BASE_ODR(sensor->config[SENSOR_CONFIG_AP].odr));
mutex_lock(&g_sensor_mutex);
if (ap_odr_mhz)
- sensor->oversampling_ratio =
- sensor->drv->get_data_rate(sensor) / ap_odr_mhz;
+ /*
+ * In case the AP want to run the sensors faster than it can,
+ * be sure we don't see the ratio to 0.
+ */
+ sensor->oversampling_ratio = MIN(1,
+ sensor->drv->get_data_rate(sensor) / ap_odr_mhz);
else
sensor->oversampling_ratio = 0;
@@ -266,6 +270,10 @@ static int motion_sense_set_ec_rate_from_ap(
return 0;
#ifdef CONFIG_ACCEL_FORCE_MODE_MASK
if (CONFIG_ACCEL_FORCE_MODE_MASK & (1 << (sensor - motion_sensors)))
+ /*
+ * AP EC sampling rate does not matter: we will collect at the
+ * requested sensor frequency.
+ */
goto end_set_ec_rate_from_ap;
#endif
if (odr_mhz == 0)