diff options
author | Gwendal Grignou <gwendal@chromium.org> | 2017-08-28 13:57:05 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-08-30 03:58:29 -0700 |
commit | b52f9b8ea614804e5e198f00cc24a5084e14470e (patch) | |
tree | b31455b2a61a166ad13efc9394eb6b5ca9d958c0 | |
parent | 09136dea764dbe482392c29b3c8d1763149df3e6 (diff) | |
download | chrome-ec-b52f9b8ea614804e5e198f00cc24a5084e14470e.tar.gz |
sensors: Support device with only one accelerometer
LPC area for sensors support 3 sensors:
up to 2 accelerometers and 1 gyro.
If only 1 accelerometer is present, only the first accelerometer slot is
populated.
If there is no gyro, the gyro slot is not populated.
Add tests and remove assumption in the code to be sure the rules above
are enforced.
BRANCH=none
BUG=b:64232053
TEST=compile, check eve is still working.
On soraka:
ectool motionsense odr 2 10000
ectool motionsense
output matches:
grep . /sys/bus/iio/devices/*/in_*_raw
Change-Id: Ifd791a6fa89d94bf91ad1a65b8987f69bada801e
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/639319
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
-rw-r--r-- | common/motion_sense.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/common/motion_sense.c b/common/motion_sense.c index e3cf38b88a..77ddd29e3c 100644 --- a/common/motion_sense.c +++ b/common/motion_sense.c @@ -591,7 +591,7 @@ static inline void set_present(uint8_t *lpc_status) /* Update/Write LPC data */ static inline void update_sense_data(uint8_t *lpc_status, int *psample_id) { - int i; + int s, d, i; uint16_t *lpc_data = (uint16_t *)host_get_memmap(EC_MEMMAP_ACC_DATA); #if (!defined HAS_TASK_ALS) && (defined CONFIG_ALS) uint16_t *lpc_als = (uint16_t *)host_get_memmap(EC_MEMMAP_ALS); @@ -619,12 +619,19 @@ static inline void update_sense_data(uint8_t *lpc_status, int *psample_id) #else lpc_data[0] = LID_ANGLE_UNRELIABLE; #endif - /* Assumptions on the list of sensors */ - for (i = 0; i < MIN(motion_sensor_count, 3); i++) { - sensor = &motion_sensors[i]; - lpc_data[1+3*i] = sensor->xyz[X]; - lpc_data[2+3*i] = sensor->xyz[Y]; - lpc_data[3+3*i] = sensor->xyz[Z]; + /* + * The first 2 entries must be accelerometers, then gyroscope. + * If there is only one accel and one gyro, the entry for the second + * accel is skipped. + */ + for (s = 0, d = 0; d < 3 && s < motion_sensor_count; s++, d++) { + sensor = &motion_sensors[s]; + if (sensor->type > MOTIONSENSE_TYPE_GYRO) + break; + else if (sensor->type == MOTIONSENSE_TYPE_GYRO) + d = 2; + for (i = X; i <= Z; i++) + lpc_data[1 + i + 3 * d] = sensor->xyz[i]; } #if (!defined HAS_TASK_ALS) && (defined CONFIG_ALS) |