diff options
author | Yuval Peress <peress@chromium.org> | 2019-05-20 21:10:30 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-05-23 18:08:51 +0000 |
commit | 5509210e5de81c58662cb1e32ad0b916edccdb9c (patch) | |
tree | d11ad5ede88ae949e201189e43e77e14a3c4a16a | |
parent | 3ba695cbfa548c77dce8d0f3284575c07205455a (diff) | |
download | chrome-ec-5509210e5de81c58662cb1e32ad0b916edccdb9c.tar.gz |
motionsense: Convert in_spoof_mode to a more generic flags
BUG=b:129159505
BRANCH=arcada
TEST=I ran `make buildall` since this change isn't used yet it doesn't
affect run-time behavior.
Change-Id: I01857d679b800f9b53762c659ebd9a018cbf16db
Signed-off-by: Yuval Peress <peress@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1612251
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1626320
Reviewed-by: Jett Rink <jettrink@chromium.org>
Commit-Queue: Jett Rink <jettrink@chromium.org>
Tested-by: Jett Rink <jettrink@chromium.org>
-rw-r--r-- | common/motion_sense.c | 25 | ||||
-rw-r--r-- | driver/accelgyro_bmi160.c | 2 | ||||
-rw-r--r-- | include/motion_sense.h | 11 |
3 files changed, 23 insertions, 15 deletions
diff --git a/common/motion_sense.c b/common/motion_sense.c index 3ab78cf7b4..c2df8f080e 100644 --- a/common/motion_sense.c +++ b/common/motion_sense.c @@ -434,9 +434,6 @@ static inline int motion_sense_init(struct motion_sensor_t *sensor) { int ret, cnt = 3; - /* By default, report the actual sensor values. */ - sensor->in_spoof_mode = 0; - /* Initialize accelerometers. */ do { ret = sensor->drv->init(sensor); @@ -695,7 +692,7 @@ static int motion_sense_read(struct motion_sensor_t *sensor) * If the sensor is in spoof mode, the readings are already present in * spoof_xyz. */ - if (sensor->in_spoof_mode) + if (sensor->flags & MOTIONSENSE_FLAG_IN_SPOOF_MODE) return EC_SUCCESS; #endif /* defined(CONFIG_ACCEL_SPOOF_MODE) */ @@ -758,7 +755,8 @@ static int motion_sense_process(struct motion_sensor_t *sensor, vector.flags = 0; vector.sensor_num = sensor - motion_sensors; #ifdef CONFIG_ACCEL_SPOOF_MODE - if (sensor->in_spoof_mode) + if (sensor->flags & + MOTIONSENSE_FLAG_IN_SPOOF_MODE) v = sensor->spoof_xyz; #endif /* defined(CONFIG_ACCEL_SPOOF_MODE) */ vector.data[X] = v[X]; @@ -1480,7 +1478,7 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args) switch (in->spoof.spoof_enable) { case MOTIONSENSE_SPOOF_MODE_DISABLE: /* Disable spoof mode. */ - sensor->in_spoof_mode = 0; + sensor->flags &= ~MOTIONSENSE_FLAG_IN_SPOOF_MODE; break; case MOTIONSENSE_SPOOF_MODE_CUSTOM: @@ -1490,7 +1488,7 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args) sensor->spoof_xyz[X] = (int)in->spoof.components[X]; sensor->spoof_xyz[Y] = (int)in->spoof.components[Y]; sensor->spoof_xyz[Z] = (int)in->spoof.components[Z]; - sensor->in_spoof_mode = 1; + sensor->flags |= MOTIONSENSE_FLAG_IN_SPOOF_MODE; break; case MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT: @@ -1501,12 +1499,13 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args) sensor->spoof_xyz[X] = sensor->raw_xyz[X]; sensor->spoof_xyz[Y] = sensor->raw_xyz[Y]; sensor->spoof_xyz[Z] = sensor->raw_xyz[Z]; - sensor->in_spoof_mode = 1; + sensor->flags |= MOTIONSENSE_FLAG_IN_SPOOF_MODE; break; case MOTIONSENSE_SPOOF_MODE_QUERY: /* Querying the spoof status of the sensor. */ - out->spoof.ret = sensor->in_spoof_mode; + out->spoof.ret = !!(sensor->flags & + MOTIONSENSE_FLAG_IN_SPOOF_MODE); args->response_size = sizeof(out->spoof); break; @@ -1843,7 +1842,8 @@ DECLARE_CONSOLE_COMMAND(fiforead, motion_sense_read_fifo, static void print_spoof_mode_status(int id) { CPRINTS("Sensor %d spoof mode is %s. <%d, %d, %d>", id, - motion_sensors[id].in_spoof_mode ? "enabled" : "disabled", + (motion_sensors[id].flags & MOTIONSENSE_FLAG_IN_SPOOF_MODE) + ? "enabled" : "disabled", motion_sensors[id].spoof_xyz[X], motion_sensors[id].spoof_xyz[Y], motion_sensors[id].spoof_xyz[Z]); @@ -1895,7 +1895,10 @@ static int command_accelspoof(int argc, char **argv) return EC_ERROR_PARAM_COUNT; } } - s->in_spoof_mode = enable; + if (enable) + s->flags |= MOTIONSENSE_FLAG_IN_SPOOF_MODE; + else + s->flags &= ~MOTIONSENSE_FLAG_IN_SPOOF_MODE; print_spoof_mode_status(id); } diff --git a/driver/accelgyro_bmi160.c b/driver/accelgyro_bmi160.c index d441ee3c9e..cc8dddece1 100644 --- a/driver/accelgyro_bmi160.c +++ b/driver/accelgyro_bmi160.c @@ -835,7 +835,7 @@ static int bmi160_decode_header(struct motion_sensor_t *accel, vector.flags = 0; normalize(s, v, *bp); #ifdef CONFIG_ACCEL_SPOOF_MODE - if (s->in_spoof_mode) + if (s->flags & MOTIONSENSE_FLAG_IN_SPOOF_MODE) v = s->spoof_xyz; #endif /* defined(CONFIG_ACCEL_SPOOF_MODE) */ vector.data[X] = v[X]; diff --git a/include/motion_sense.h b/include/motion_sense.h index c76c5b1326..e4ca21ac30 100644 --- a/include/motion_sense.h +++ b/include/motion_sense.h @@ -107,6 +107,12 @@ struct motion_data_t { unsigned int ec_rate; }; +/* + * When set, spoof mode will allow the EC to report arbitrary values for any of + * the components. + */ +#define MOTIONSENSE_FLAG_IN_SPOOF_MODE BIT(1) + struct motion_sensor_t { /* RO fields */ uint32_t active_mask; @@ -125,10 +131,9 @@ struct motion_sensor_t { uint8_t addr; /* - * When non-zero, spoof mode will allow the EC to report arbitrary - * values for any of the components. + * Various flags, see MOTIONSENSE_FLAG_* */ - uint8_t in_spoof_mode; + uint32_t flags; const mat33_fp_t *rot_standard_ref; |