diff options
author | Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> | 2021-02-08 16:59:06 +0000 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-02-25 20:17:53 +0000 |
commit | 71d6b16eff18aab1f7c592a75e5489a4f14b8790 (patch) | |
tree | e309a6915f7b3375f5db7a8ea4780d914e0f9a7f /driver/accelgyro_icm_common.h | |
parent | ae50227d0d5b9c135e474bbfd3bb8cce6efef71f (diff) | |
download | chrome-ec-71d6b16eff18aab1f7c592a75e5489a4f14b8790.tar.gz |
driver: icm426xx: discard first data instead of sleeping
Sleeping when turning a sensor on/off is problematic when the
other sensor is running.
Replace sleeping by discarding first events until sensor is
stabilized.
BUG=chromium:1175757
BRANCH=hatch,nami,kukui,dedede,grunt,zork,octopus,volteer
TEST=turn sensor on/off when the other is running using cros-ec
iio devices
Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>
Change-Id: I61801970b12f9fbdcc2cd96cb4df1edae5ed521f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2682715
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
Commit-Queue: Gwendal Grignou <gwendal@chromium.org>
Tested-by: Gwendal Grignou <gwendal@chromium.org>
Diffstat (limited to 'driver/accelgyro_icm_common.h')
-rw-r--r-- | driver/accelgyro_icm_common.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/driver/accelgyro_icm_common.h b/driver/accelgyro_icm_common.h index 4d991ce341..33a94274fd 100644 --- a/driver/accelgyro_icm_common.h +++ b/driver/accelgyro_icm_common.h @@ -9,6 +9,8 @@ #define __CROS_EC_ACCELGYRO_ICM_COMMON_H #include "accelgyro.h" +#include "hwtimer.h" +#include "timer.h" #ifdef CONFIG_ACCEL_FIFO /* reserve maximum 4 samples of 16 bytes */ @@ -21,6 +23,7 @@ struct icm_drv_data_t { struct accelgyro_saved_data_t saved_data[2]; struct motion_sensor_t *accel; struct motion_sensor_t *gyro; + uint32_t stabilize_ts[2]; uint8_t bank; uint8_t fifo_en; uint8_t fifo_buffer[ICM_FIFO_BUFFER] __aligned(sizeof(long)); @@ -98,4 +101,35 @@ int icm_get_scale(const struct motion_sensor_t *s, uint16_t *scale, ssize_t icm_fifo_decode_packet(const void *packet, const uint8_t **accel, const uint8_t **gyro); +static inline void icm_set_stabilize_ts(const struct motion_sensor_t *s, + uint32_t delay) +{ + struct icm_drv_data_t *st = ICM_GET_DATA(s); + uint32_t stabilize_ts; + + stabilize_ts = __hw_clock_source_read() + delay; + /* prevent 0 value used for disabling time checking */ + st->stabilize_ts[s->type] = stabilize_ts | 1; +} + +static inline void icm_reset_stabilize_ts(const struct motion_sensor_t *s) +{ + struct icm_drv_data_t *st = ICM_GET_DATA(s); + + st->stabilize_ts[s->type] = 0; +} + +static inline +int32_t icm_get_sensor_stabilized(const struct motion_sensor_t *s, + uint32_t ts) +{ + struct icm_drv_data_t *st = ICM_GET_DATA(s); + uint32_t stabilize_ts = st->stabilize_ts[s->type]; + + if (stabilize_ts == 0) + return 0; + + return time_until(ts, stabilize_ts); +} + #endif /* __CROS_EC_ACCELGYRO_ICM_COMMON_H */ |