diff options
author | Gwendal Grignou <gwendal@chromium.org> | 2014-10-27 09:55:45 -0700 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2014-10-29 22:23:49 +0000 |
commit | d5b32aa6e1e9ac206f4cbdd6cf4452a08dc2ec36 (patch) | |
tree | 1e3a7bb0952fa5afe003cafa43c036685cd1a983 | |
parent | f3b29e3fec5fcdb5449cee5c8b2068229fb0f3c0 (diff) | |
download | chrome-ec-d5b32aa6e1e9ac206f4cbdd6cf4452a08dc2ec36.tar.gz |
core: Add subcommands to MOTION_SENSE_CMD
These subcommands allow accessing sensor (accel+gyro)
over i2c.
BRANCH=ToT
BUG=chrome-os-partner:31071
TEST=Compile.
Change-Id: Ic6c3e9bf9c23f369de9f540c50daab7f2e4582ee
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/225653
-rw-r--r-- | include/ec_commands.h | 49 | ||||
-rw-r--r-- | util/ectool.c | 13 |
2 files changed, 56 insertions, 6 deletions
diff --git a/include/ec_commands.h b/include/ec_commands.h index 3cea697cf9..52a0996b91 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -1301,6 +1301,18 @@ enum motionsense_command { */ MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5, + /* + * Sensor subsytem status. + * Same format as EC_MEMMAP_ACC_STATUS + * - for system without LPC - + */ + MOTIONSENSE_CMD_GET_STATUS = 6, + + /* + * Retrieve data and flags from all accel/gyro sensors. + */ + MOTIONSENSE_CMD_GET_DATA = 7, + /* Number of motionsense sub-commands. */ MOTIONSENSE_NUM_CMDS }; @@ -1351,10 +1363,10 @@ enum motionsensor_chip { struct ec_params_motion_sense { uint8_t cmd; union { - /* Used for MOTIONSENSE_CMD_DUMP. */ + /* Used for MOTIONSENSE_CMD_DUMP, GET_STATUS, GET_DATA. */ struct { /* no args */ - } dump; + } data, dump, status; /* * Used for MOTIONSENSE_CMD_EC_RATE and @@ -1367,7 +1379,6 @@ struct ec_params_motion_sense { /* Used for MOTIONSENSE_CMD_INFO. */ struct { - /* Should be element of enum motionsensor_id. */ uint8_t sensor_num; } info; @@ -1376,7 +1387,6 @@ struct ec_params_motion_sense { * MOTIONSENSE_CMD_SENSOR_RANGE. */ struct { - /* Should be element of enum motionsensor_id. */ uint8_t sensor_num; /* Rounding flag, true for round-up, false for down. */ @@ -1392,18 +1402,40 @@ struct ec_params_motion_sense { struct ec_response_motion_sense { union { - /* Used for MOTIONSENSE_CMD_DUMP. */ + /* Used for MOTIONSENSE_CMD_DUMP */ struct { /* Flags representing the motion sensor module. */ uint8_t module_flags; - /* Flags for each sensor in enum motionsensor_id. */ + /* Flags for each sensor. */ uint8_t sensor_flags[EC_MOTION_SENSOR_COUNT]; /* Array of all sensor data. Each sensor is 3-axis. */ int16_t data[3*EC_MOTION_SENSOR_COUNT]; } dump; + /* Used for MOTIONSENSE_CMD_GET_DATA */ + struct { + /* Flags representing the motion sensor module. */ + uint8_t module_flags; + + /* Number of sensors managed directly by the EC */ + uint8_t sensor_number; + + /* + * sensor data is truncated if response_max is too small + * for holding all the data. + */ + struct sensor_data { + /* Flags for each sensor. */ + uint8_t flags; + uint8_t padding; + + /* Each sensor is up to 3-axis. */ + int16_t data[3]; + } sensor[0]; + } data; + /* Used for MOTIONSENSE_CMD_INFO. */ struct { /* Should be element of enum motionsensor_type. */ @@ -1416,6 +1448,11 @@ struct ec_response_motion_sense { uint8_t chip; } info; + /* Used for MOTIONSENSE_CMD_GET_STATUS */ + struct { + uint8_t value; + } status; + /* * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR, * MOTIONSENSE_CMD_SENSOR_RANGE, and diff --git a/util/ectool.c b/util/ectool.c index 526807566f..2823ede20d 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -2323,6 +2323,17 @@ static int cmd_lightbar(int argc, char **argv) sizeof(((struct ec_params_motion_sense *)0)->SUBCMD) \ + sizeof(((struct ec_params_motion_sense *)0)->cmd), \ sizeof(((struct ec_response_motion_sense *)0)->SUBCMD) } +/* + * For ectool only, assume no more than 16 sensors. + * More advanced implementation would allocate the right amount of + * memory depending on the number of sensors. + */ +#define ECTOOL_MAX_SENSOR 16 +#define MS_DATA_SIZE() { \ + sizeof(((struct ec_params_motion_sense *)0)->data) \ + + sizeof(((struct ec_params_motion_sense *)0)->cmd), \ + sizeof(((struct ec_response_motion_sense *)0)->data) \ + + ECTOOL_MAX_SENSOR * sizeof(struct sensor_data) } static const struct { uint8_t insize; uint8_t outsize; @@ -2333,6 +2344,8 @@ static const struct { MS_SIZES(sensor_odr), MS_SIZES(sensor_range), MS_SIZES(kb_wake_angle), + MS_SIZES(status), + MS_DATA_SIZE(), }; BUILD_ASSERT(ARRAY_SIZE(ms_command_sizes) == MOTIONSENSE_NUM_CMDS); #undef MS_SIZES |