summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2014-10-27 09:55:45 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-11-11 23:03:28 +0000
commit1a38df1105020b7fc82e9a2ec100de8d29ca6c04 (patch)
treedd15622bdbce9fdb1afb8da28adc22074d0938d1
parent19243d05ee719f338047c624bb5c8435e06e67f3 (diff)
downloadchrome-ec-1a38df1105020b7fc82e9a2ec100de8d29ca6c04.tar.gz
CHERRY-PICK: 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: Ic19aac1b6f54ef844e242c5d19dfe63bf8e49d9d Original-Change-Id: Ic6c3e9bf9c23f369de9f540c50daab7f2e4582ee Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/225653 Reviewed-on: https://chromium-review.googlesource.com/229156 Reviewed-by: Mohammed Habibulla <moch@chromium.org> Commit-Queue: Mohammed Habibulla <moch@chromium.org> Tested-by: Mohammed Habibulla <moch@chromium.org>
-rw-r--r--include/ec_commands.h49
-rw-r--r--util/ectool.c13
2 files changed, 56 insertions, 6 deletions
diff --git a/include/ec_commands.h b/include/ec_commands.h
index d51c9b7efe..980dfa2b1e 100644
--- a/include/ec_commands.h
+++ b/include/ec_commands.h
@@ -1300,6 +1300,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
};
@@ -1350,10 +1362,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
@@ -1366,7 +1378,6 @@ struct ec_params_motion_sense {
/* Used for MOTIONSENSE_CMD_INFO. */
struct {
- /* Should be element of enum motionsensor_id. */
uint8_t sensor_num;
} info;
@@ -1375,7 +1386,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. */
@@ -1391,18 +1401,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. */
@@ -1415,6 +1447,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 964af5e191..c5fa0dfa71 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -2347,6 +2347,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;
@@ -2357,6 +2368,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