From b98e33c95000976d689a9e5537402eafadad6507 Mon Sep 17 00:00:00 2001 From: Gwendal Grignou Date: Tue, 8 Sep 2015 11:43:25 -0700 Subject: [PATCH] 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 Reviewed-on: https://chromium-review.googlesource.com/298688 Reviewed-by: Vincent Palatin --- common/motion_sense.c | 10 ++++++---- 1 file 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;