summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2015-09-08 11:43:25 -0700
committerchrome-bot <chrome-bot@chromium.org>2015-09-19 15:18:09 -0700
commitb98e33c95000976d689a9e5537402eafadad6507 (patch)
tree684cd3ee19cc2164d23449b7bfb516e6709b0849 /common
parent1ce66908fb6f1a34cdf9a9775d9c832e83dc0d0c (diff)
downloadchrome-ec-b98e33c95000976d689a9e5537402eafadad6507.tar.gz
common: motion: Fix oversampling calculation.
Was setting frequency radix at 1 mHz. That would limit frequency to 32Hz, which is not enough for accelerometor. Set radix as a fixed point or float variable, to calculate the rate properly. BRANCH=smaug BUG=None TEST=Check that when Ryu set accelerometer to 100Hz internally (for double tap), that AP gets data when requested frequency is 15Hz. Change-Id: I84e0ea784f8bd04566aa91bc4300cf4ff30b350c Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/298688 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'common')
-rw-r--r--common/motion_sense.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/common/motion_sense.c b/common/motion_sense.c
index 5a1afb353d..b825e6bb8b 100644
--- a/common/motion_sense.c
+++ b/common/motion_sense.c
@@ -94,7 +94,9 @@ void motion_sense_fifo_add_unit(struct ec_response_motion_sensor_data *data,
/* For valid sensors, check if AP really needs this data */
if (valid_data) {
int ap_odr = BASE_ODR(sensor->config[SENSOR_CONFIG_AP].odr);
- int rate = INT_TO_FP(sensor->drv->get_data_rate(sensor));
+
+ /* Use integer, conversion to FP will overflow */
+ fp_t rate = fp_div(sensor->drv->get_data_rate(sensor), 1000);
/*
* If the AP does not want sensor info, skip.
@@ -120,11 +122,11 @@ void motion_sense_fifo_add_unit(struct ec_response_motion_sensor_data *data,
/* Skip if EC is oversampling */
if (sensor->oversampling < 0) {
- sensor->oversampling += fp_div(INT_TO_FP(1000), rate);
+ sensor->oversampling += fp_div(INT_TO_FP(1), rate);
return;
}
- sensor->oversampling += fp_div(INT_TO_FP(1000), rate) -
- fp_div(INT_TO_FP(1000), INT_TO_FP(ap_odr));
+ sensor->oversampling += fp_div(INT_TO_FP(1), rate) -
+ fp_div(INT_TO_FP(1), INT_TO_FP(ap_odr));
}
if (data->flags & MOTIONSENSE_SENSOR_FLAG_WAKEUP)
wake_up_needed = 1;