diff options
author | Gwendal Grignou <gwendal@chromium.org> | 2014-10-30 15:02:37 -0700 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2014-11-18 05:19:08 +0000 |
commit | 4b154c6f956d0d30e78d7f1d2c5b6867dbfbf8f0 (patch) | |
tree | fe1f0e3aea34410b8b5fdfde5cbc907eee27f132 /driver/accelgyro_lsm6ds0.c | |
parent | 89442037be2ebd83be57b68bfabeaf2ad0367171 (diff) | |
download | chrome-ec-4b154c6f956d0d30e78d7f1d2c5b6867dbfbf8f0.tar.gz |
motion: Add decoding for MOTION_CMD_DUMP v1 command
MOTIONSENSE_CMD_DUMP is deprecated, replaced with MOTIONSENSE_CMD_GET_DATA
Also use vector_3_t instead of x,y,z
ectool motionsense commands only work with newer firmware, to
handle a dynamic number of sensors.
- The host sends the number of sensor it has allocated space for.
- If 0, the EC just sends the number of sensors available
- Otherwise returns sensor information up to the limit imposed by the host.
Remove MOTIONSENSE_GET_STATUS: not needed. It is only useful for LPC,
to guarantee atomicity of the data.
Remove MOTIONSENSE_GET_DATA: not needed since we increase the version
number of MOTIONSENSE command.
BUG=chrome-os-partner:31071,chromium:430792
BRANCH=ToT
TEST=Compile. On a firmware that support the new command:
/usr/sbin/ectool --name=cros_sh motionsense
Motion sensing active
Sensor 0: 92 15 1030
Sensor 1: -94 -63 718
/usr/sbin/ectool --name=cros_sh motionsense active
0
On a machine with older firmware (samus), check these
functions are not working anymore.
Change-Id: I64b62afff96670fb93457760d43d4e64e26e029f
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/226880
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Diffstat (limited to 'driver/accelgyro_lsm6ds0.c')
-rw-r--r-- | driver/accelgyro_lsm6ds0.c | 61 |
1 files changed, 29 insertions, 32 deletions
diff --git a/driver/accelgyro_lsm6ds0.c b/driver/accelgyro_lsm6ds0.c index d25b91b594..e907995b70 100644 --- a/driver/accelgyro_lsm6ds0.c +++ b/driver/accelgyro_lsm6ds0.c @@ -48,9 +48,9 @@ const struct accel_param_pair dps_ranges[] = { }; static inline const struct accel_param_pair *get_range_table( - enum sensor_type_t type, int *psize) + enum motionsensor_type type, int *psize) { - if (SENSOR_ACCELEROMETER == type) { + if (MOTIONSENSE_TYPE_ACCEL == type) { if (psize) *psize = ARRAY_SIZE(g_ranges); return g_ranges; @@ -84,9 +84,9 @@ const struct accel_param_pair gyro_off_odr[] = { }; static inline const struct accel_param_pair *get_odr_table( - enum sensor_type_t type, int *psize) + enum motionsensor_type type, int *psize) { - if (SENSOR_ACCELEROMETER == type) { + if (MOTIONSENSE_TYPE_ACCEL == type) { if (psize) *psize = ARRAY_SIZE(gyro_off_odr); return gyro_off_odr; @@ -97,15 +97,15 @@ static inline const struct accel_param_pair *get_odr_table( } } -static inline int get_ctrl_reg(enum sensor_type_t type) +static inline int get_ctrl_reg(enum motionsensor_type type) { - return (SENSOR_ACCELEROMETER == type) ? + return (MOTIONSENSE_TYPE_ACCEL == type) ? LSM6DS0_CTRL_REG6_XL : LSM6DS0_CTRL_REG1_G; } -static inline int get_xyz_reg(enum sensor_type_t type) +static inline int get_xyz_reg(enum motionsensor_type type) { - return (SENSOR_ACCELEROMETER == type) ? + return (MOTIONSENSE_TYPE_ACCEL == type) ? LSM6DS0_OUT_X_L_XL : LSM6DS0_OUT_X_L_G; } @@ -254,7 +254,7 @@ static int set_data_rate(const struct motion_sensor_t *s, * [3:0] HPCF_G * Table 48 Gyroscope high-pass filter cutoff frequency */ - if (SENSOR_GYRO == s->type) { + if (MOTIONSENSE_TYPE_GYRO == s->type) { ret = raw_read8(s->i2c_addr, LSM6DS0_CTRL_REG3_G, &val); if (ret != EC_SUCCESS) goto accel_cleanup; @@ -308,7 +308,7 @@ static int is_data_ready(const struct motion_sensor_t *s, int *ready) return ret; } - if (SENSOR_ACCELEROMETER == s->type) + if (MOTIONSENSE_TYPE_ACCEL == s->type) *ready = (LSM6DS0_STS_XLDA_UP == (tmp & LSM6DS0_STS_XLDA_MASK)); else *ready = (LSM6DS0_STS_GDA_UP == (tmp & LSM6DS0_STS_GDA_MASK)); @@ -316,10 +316,7 @@ static int is_data_ready(const struct motion_sensor_t *s, int *ready) return EC_SUCCESS; } -static int read(const struct motion_sensor_t *s, - int *x, - int *y, - int *z) +static int read(const struct motion_sensor_t *s, vector_3_t v) { uint8_t data[6]; uint8_t xyz_reg; @@ -335,9 +332,9 @@ static int read(const struct motion_sensor_t *s, * to get the latest updated sensor data quickly. */ if (!tmp) { - *x = s->xyz[0]; - *y = s->xyz[1]; - *z = s->xyz[2]; + v[0] = s->xyz[0]; + v[1] = s->xyz[1]; + v[2] = s->xyz[2]; return EC_SUCCESS; } @@ -355,27 +352,27 @@ static int read(const struct motion_sensor_t *s, return ret; } - *x = ((int16_t)((data[1] << 8) | data[0])); - *y = ((int16_t)((data[3] << 8) | data[2])); - *z = ((int16_t)((data[5] << 8) | data[4])); + v[0] = ((int16_t)((data[1] << 8) | data[0])); + v[1] = ((int16_t)((data[3] << 8) | data[2])); + v[2] = ((int16_t)((data[5] << 8) | data[4])); ret = get_range(s, &range); if (ret) return EC_ERROR_UNKNOWN; - *x *= range; - *y *= range; - *z *= range; + v[0] *= range; + v[1] *= range; + v[2] *= range; /* normalize the accel scale: 1G = 1024 */ - if (SENSOR_ACCELEROMETER == s->type) { - *x >>= 5; - *y >>= 5; - *z >>= 5; + if (MOTIONSENSE_TYPE_ACCEL == s->type) { + v[0] >>= 5; + v[1] >>= 5; + v[2] >>= 5; } else { - *x >>= 8; - *y >>= 8; - *z >>= 8; + v[0] >>= 8; + v[1] >>= 8; + v[2] >>= 8; } return EC_SUCCESS; @@ -404,7 +401,7 @@ static int init(const struct motion_sensor_t *s) * Requirement: Accel need be init before gyro. * SW_RESET is down for accel only! */ - if (SENSOR_ACCELEROMETER == s->type) { + if (MOTIONSENSE_TYPE_ACCEL == s->type) { mutex_lock(s->mutex); ret = raw_read8(s->i2c_addr, LSM6DS0_CTRL_REG8, &tmp); @@ -434,7 +431,7 @@ static int init(const struct motion_sensor_t *s) return EC_ERROR_UNKNOWN; } - if (SENSOR_GYRO == s->type) { + if (MOTIONSENSE_TYPE_GYRO == s->type) { /* Config GYRO Range */ ret = set_range(s, s->range, 1); if (ret) |