diff options
author | Ikjoon Jang <ikjn@chromium.org> | 2020-07-29 19:08:05 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-09-02 14:16:50 +0000 |
commit | b9ae5ccdec033adefa24b60cd458f8a64789a248 (patch) | |
tree | f9752f0f918da6adafc21f873b6585976c4f29a5 /common/motion_sense.c | |
parent | a51ecba6f0bba4c3f660346a9c7fd5fc22a1d3ec (diff) | |
download | chrome-ec-b9ae5ccdec033adefa24b60cd458f8a64789a248.tar.gz |
motion_sense: use clamp functions in sending 32bit sensor values
Apply 32bit clamp functions in sending 32bit sensor values to host.
Clamp functions explicitly clamp values into 16bit ec protocol
regarding its sensor type.
Clamp functions take its sensor type as an argument and clamp 32bit
value into 0~65535 for light sensors and -32768 ~ 32767 for all
other motion sensors.
BUG=b:144002158
TEST=Reading illuminance values in kukui kernel
BRANCH=none
Signed-off-by: Ikjoon Jang <ikjn@chromium.org>
Change-Id: I977114e26f28e7806c11b0a97c9edec7a84ea0dc
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2328951
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
Diffstat (limited to 'common/motion_sense.c')
-rw-r--r-- | common/motion_sense.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/common/motion_sense.c b/common/motion_sense.c index 2592808bb6..85cce294c9 100644 --- a/common/motion_sense.c +++ b/common/motion_sense.c @@ -514,7 +514,7 @@ static inline void set_present(uint8_t *lpc_status) static inline void update_sense_data(uint8_t *lpc_status, int *psample_id) { int s, d, i; - uint16_t *lpc_data = (uint16_t *)host_get_memmap(EC_MEMMAP_ACC_DATA); + int16_t *lpc_data = (int16_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); #endif @@ -552,13 +552,16 @@ static inline void update_sense_data(uint8_t *lpc_status, int *psample_id) 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]; + lpc_data[1 + i + 3 * d] = + ec_motion_sensor_clamp_i16(sensor->xyz[i]); } #if (!defined HAS_TASK_ALS) && (defined CONFIG_ALS) for (i = 0; i < EC_ALS_ENTRIES && i < ALS_COUNT; i++) - lpc_als[i] = motion_als_sensors[i]->xyz[X]; + lpc_als[i] = ec_motion_sensor_clamp_u16( + motion_als_sensors[i]->xyz[X]); #endif /* @@ -633,11 +636,13 @@ static void motion_sense_push_raw_xyz(struct motion_sensor_t *s) if (IS_ENABLED(CONFIG_ACCEL_SPOOF_MODE) && s->flags & MOTIONSENSE_FLAG_IN_SPOOF_MODE) v = s->spoof_xyz; + mutex_lock(&g_sensor_mutex); - vector.data[X] = v[X]; - vector.data[Y] = v[Y]; - vector.data[Z] = v[Z]; + + ec_motion_sensor_fill_values(&vector, v); + mutex_unlock(&g_sensor_mutex); + motion_sense_fifo_stage_data(&vector, s, 3, __hw_clock_source_read()); motion_sense_fifo_commit_data(); @@ -1035,10 +1040,8 @@ static enum ec_status host_cmd_motion_sense(struct host_cmd_handler_args *args) MOTIONSENSE_SENSOR_FLAG_PRESENT; if (i < motion_sensor_count) { sensor = &motion_sensors[i]; - /* casting from int to s16 */ - out->dump.sensor[i].data[X] = sensor->xyz[X]; - out->dump.sensor[i].data[Y] = sensor->xyz[Y]; - out->dump.sensor[i].data[Z] = sensor->xyz[Z]; + ec_motion_sensor_fill_values( + &out->dump.sensor[i], sensor->xyz); } else { memset(out->dump.sensor[i].data, 0, 3 * sizeof(int16_t)); @@ -1058,10 +1061,9 @@ static enum ec_status host_cmd_motion_sense(struct host_cmd_handler_args *args) out->data.flags = 0; mutex_lock(&g_sensor_mutex); - out->data.data[X] = sensor->xyz[X]; - out->data.data[Y] = sensor->xyz[Y]; - out->data.data[Z] = sensor->xyz[Z]; + ec_motion_sensor_fill_values(&out->data, sensor->xyz); mutex_unlock(&g_sensor_mutex); + args->response_size = sizeof(out->data); break; |