summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2020-05-17 16:43:02 -0700
committerCommit Bot <commit-bot@chromium.org>2020-11-12 03:23:26 +0000
commitd28c10498cdbf007b97b5c0a9a951373574d4eea (patch)
tree3d66ca06837aae98ff747fff85b439976e563045 /common
parent9676f9291f60efdfb31373aeb77385ebb6e9f6e5 (diff)
downloadchrome-ec-d28c10498cdbf007b97b5c0a9a951373574d4eea.tar.gz
motion_sense: Make change in range permanent
When AP changes range, unlike offset or ODR, it was not surviving init() call. If the sensor is powered off in S3, at resume the range would be back to the default. To make it consistent with other attributes, remember range change until EC powers down. - remove get_range - add current_range to store the range currently used. This is modifiable by the AP - when the AP shutdown, revert current_range to default_range - Remove const attribute for sensor structure when init and set_range is called. BUG=chromium:1083791 BRANCH=none TEST=One eve branch, check range is preserved even after 'shutdown -h 0' Change-Id: Ia7126ac0cc9c3fef60b4464d95d6dd15e64b0fc4 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2215751 Reviewed-by: Yuval Peress <peress@chromium.org>
Diffstat (limited to 'common')
-rw-r--r--common/body_detection.c4
-rw-r--r--common/motion_lid.c6
-rw-r--r--common/motion_sense.c29
-rw-r--r--common/online_calibration.c4
4 files changed, 22 insertions, 21 deletions
diff --git a/common/body_detection.c b/common/body_detection.c
index 375b4456d0..c15e1bc6bb 100644
--- a/common/body_detection.c
+++ b/common/body_detection.c
@@ -169,7 +169,6 @@ static void determine_threshold_scale(int range, int resolution, int rms_noise)
void body_detect_reset(void)
{
int odr = body_sensor->drv->get_data_rate(body_sensor);
- int range = body_sensor->drv->get_range(body_sensor);
int resolution = body_sensor->drv->get_resolution(body_sensor);
int rms_noise = body_sensor->drv->get_rms_noise(body_sensor);
@@ -181,7 +180,8 @@ void body_detect_reset(void)
if (odr == 0)
return;
determine_window_size(odr);
- determine_threshold_scale(range, resolution, rms_noise);
+ determine_threshold_scale(body_sensor->current_range,
+ resolution, rms_noise);
/* initialize motion data and state */
memset(data, 0, sizeof(data));
history_idx = 0;
diff --git a/common/motion_lid.c b/common/motion_lid.c
index f8933a1b2b..0ab0dd9238 100644
--- a/common/motion_lid.c
+++ b/common/motion_lid.c
@@ -307,10 +307,8 @@ static int calculate_lid_angle(const intv3_t base, const intv3_t lid,
* possible.
*/
for (i = X; i <= Z; i++) {
- scaled_base[i] = base[i] *
- accel_base->drv->get_range(accel_base);
- scaled_lid[i] = lid[i] *
- accel_lid->drv->get_range(accel_lid);
+ scaled_base[i] = base[i] * accel_base->current_range;
+ scaled_lid[i] = lid[i] * accel_lid->current_range;
if (ABS(scaled_base[i]) > MOTION_SCALING_AXIS_MAX ||
ABS(scaled_lid[i]) > MOTION_SCALING_AXIS_MAX) {
reliable = 0;
diff --git a/common/motion_sense.c b/common/motion_sense.c
index e31ec5eddc..4b3f66cd07 100644
--- a/common/motion_sense.c
+++ b/common/motion_sense.c
@@ -339,19 +339,19 @@ static inline int motion_sense_init(struct motion_sensor_t *sensor)
*
* Called by init routine of each sensors when successful.
*/
-int sensor_init_done(const struct motion_sensor_t *s)
+int sensor_init_done(struct motion_sensor_t *s)
{
int ret;
- ret = s->drv->set_range(s, BASE_RANGE(s->default_range),
- !!(s->default_range & ROUND_UP_FLAG));
+ ret = s->drv->set_range(s, BASE_RANGE(s->current_range),
+ !!(s->current_range & ROUND_UP_FLAG));
if (ret == EC_RES_SUCCESS) {
if (IS_ENABLED(CONFIG_CONSOLE_VERBOSE))
CPRINTS("%s: MS Done Init type:0x%X range:%d",
- s->name, s->type, s->drv->get_range(s));
+ s->name, s->type, s->current_range);
else
CPRINTS("%c%d InitDone r:%d", s->name[0], s->type,
- s->drv->get_range(s));
+ s->current_range);
}
return ret;
}
@@ -369,9 +369,15 @@ static void motion_sense_switch_sensor_rate(void)
for (i = 0; i < motion_sensor_count; ++i) {
sensor = &motion_sensors[i];
if (SENSOR_ACTIVE(sensor)) {
- /* Initialize or just back the odr previously set. */
+ /*
+ * Initialize or just back the odr/range previously
+ * set.
+ */
if (sensor->state == SENSOR_INITIALIZED) {
motion_sense_set_data_rate(sensor);
+ sensor->drv->set_range(sensor,
+ sensor->current_range,
+ 1);
} else {
ret = motion_sense_init(sensor);
if (ret != EC_SUCCESS)
@@ -408,6 +414,7 @@ static void motion_sense_shutdown(void)
/* Forget about changes made by the AP */
sensor->config[SENSOR_CONFIG_AP].odr = 0;
sensor->config[SENSOR_CONFIG_AP].ec_rate = 0;
+ sensor->current_range = sensor->default_range;
}
motion_sense_switch_sensor_rate();
@@ -1145,10 +1152,7 @@ static enum ec_status host_cmd_motion_sense(struct host_cmd_handler_args *args)
}
}
- if (!sensor->drv->get_range)
- return EC_RES_INVALID_COMMAND;
-
- out->sensor_range.ret = sensor->drv->get_range(sensor);
+ out->sensor_range.ret = sensor->current_range;
args->response_size = sizeof(out->sensor_range);
break;
@@ -1485,8 +1489,7 @@ static int command_accelrange(int argc, char **argv)
round) == EC_ERROR_INVAL)
return EC_ERROR_PARAM2;
} else {
- ccprintf("Range for sensor %d: %d\n", id,
- sensor->drv->get_range(sensor));
+ ccprintf("Sensor %d range: %d\n", id, sensor->current_range);
}
return EC_SUCCESS;
@@ -1684,7 +1687,7 @@ static int command_display_accel_info(int argc, char **argv)
ccprintf("port: %d\n", motion_sensors[i].port);
ccprintf("addr: %d\n", I2C_STRIP_FLAGS(motion_sensors[i]
.i2c_spi_addr_flags));
- ccprintf("range: %d\n", motion_sensors[i].default_range);
+ ccprintf("range: %d\n", motion_sensors[i].current_range);
ccprintf("min_freq: %d\n", motion_sensors[i].min_frequency);
ccprintf("max_freq: %d\n", motion_sensors[i].max_frequency);
ccprintf("config:\n");
diff --git a/common/online_calibration.c b/common/online_calibration.c
index 5cef26fd00..f026f1adf7 100644
--- a/common/online_calibration.c
+++ b/common/online_calibration.c
@@ -61,7 +61,7 @@ static void data_int16_to_fp(const struct motion_sensor_t *s,
const int16_t *data, fpv3_t out)
{
int i;
- fp_t range = INT_TO_FP(s->drv->get_range(s));
+ fp_t range = INT_TO_FP(s->current_range);
for (i = 0; i < 3; ++i) {
fp_t v = INT_TO_FP((int32_t)data[i]);
@@ -77,7 +77,7 @@ static void data_fp_to_int16(const struct motion_sensor_t *s, const fpv3_t data,
int16_t *out)
{
int i;
- fp_t range = INT_TO_FP(s->drv->get_range(s));
+ fp_t range = INT_TO_FP(s->current_range);
for (i = 0; i < 3; ++i) {
int32_t iv;