summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2014-10-30 15:02:37 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-11-18 05:19:08 +0000
commit4b154c6f956d0d30e78d7f1d2c5b6867dbfbf8f0 (patch)
treefe1f0e3aea34410b8b5fdfde5cbc907eee27f132 /util
parent89442037be2ebd83be57b68bfabeaf2ad0367171 (diff)
downloadchrome-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 'util')
-rw-r--r--util/ectool.c143
1 files changed, 73 insertions, 70 deletions
diff --git a/util/ectool.c b/util/ectool.c
index 08e50ab58a..0222720d00 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -2360,23 +2360,22 @@ static int cmd_lightbar(int argc, char **argv)
* memory depending on the number of sensors.
*/
#define ECTOOL_MAX_SENSOR 16
-#define MS_DATA_SIZE() { \
- sizeof(((struct ec_params_motion_sense *)0)->data) \
+#define MS_DUMP_SIZE() { \
+ sizeof(((struct ec_params_motion_sense *)0)->dump) \
+ sizeof(((struct ec_params_motion_sense *)0)->cmd), \
- sizeof(((struct ec_response_motion_sense *)0)->data) \
- + ECTOOL_MAX_SENSOR * sizeof(struct sensor_data) }
+ sizeof(((struct ec_response_motion_sense *)0)->dump) \
+ + sizeof(struct ec_response_motion_sensor_data) * \
+ ECTOOL_MAX_SENSOR}
static const struct {
uint8_t insize;
uint8_t outsize;
} ms_command_sizes[] = {
- MS_SIZES(dump),
+ MS_DUMP_SIZE(),
MS_SIZES(info),
MS_SIZES(ec_rate),
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
@@ -2397,67 +2396,68 @@ static int ms_help(const char *cmd)
static int cmd_motionsense(int argc, char **argv)
{
- int i, rv;
+ int i, rv, status_only = (argc == 2);
struct ec_params_motion_sense param;
- struct ec_response_motion_sense resp;
+ uint8_t resp_buffer[ms_command_sizes[MOTIONSENSE_CMD_DUMP].outsize];
+ struct ec_response_motion_sense *resp =
+ (struct ec_response_motion_sense *)resp_buffer;
char *e;
+ /*
+ * Warning: the following strings printed out are read in an
+ * autotest. Do not change string without consulting autotest
+ * for kernel_CrosECSysfsAccel.
+ */
+ const char *motion_status_string[2][2] = {
+ { "Motion sensing inactive", "0"},
+ { "Motion sensing active", "1"},
+ };
/* No motionsense command has more than 5 args. */
if (argc > 5)
return ms_help(argv[0]);
- if (argc == 1) {
- /* No args, dump motion data. */
+ if ((argc == 1) ||
+ (argc == 2 && !strcasecmp(argv[1], "active"))) {
param.cmd = MOTIONSENSE_CMD_DUMP;
- rv = ec_command(EC_CMD_MOTION_SENSE_CMD, 0,
- &param, ms_command_sizes[param.cmd].insize,
- &resp, ms_command_sizes[param.cmd].outsize);
-
- if (rv < 0)
- return rv;
-
- if (resp.dump.module_flags & MOTIONSENSE_MODULE_FLAG_ACTIVE)
- printf("Motion sensing active\n");
- else
- printf("Motion sensing inactive\n");
-
- for (i = 0; i < EC_MOTION_SENSOR_COUNT; i++) {
- printf("Sensor %d: ", i);
- if (resp.dump.sensor_flags[i] &
- MOTIONSENSE_SENSOR_FLAG_PRESENT)
- printf("%d\t%d\t%d\n", resp.dump.data[3*i],
- resp.dump.data[3*i+1],
- resp.dump.data[3*i+2]);
- else
+ param.dump.max_sensor_count = ECTOOL_MAX_SENSOR;
+ rv = ec_command(
+ EC_CMD_MOTION_SENSE_CMD, 1,
+ &param, ms_command_sizes[param.cmd].insize,
+ resp, ms_command_sizes[param.cmd].outsize);
+ if (rv > 0) {
+ printf("%s\n", motion_status_string[
+ !!(resp->dump.module_flags &
+ MOTIONSENSE_MODULE_FLAG_ACTIVE)][
+ status_only]);
+ if (status_only)
+ return 0;
+
+ if (resp->dump.sensor_count > ECTOOL_MAX_SENSOR) {
+ printf("Too many sensors to handle: %d",
+ resp->dump.sensor_count);
+ return -1;
+ }
+ for (i = 0; i < resp->dump.sensor_count; i++) {
/*
* Warning: the following string printed out
* is read by an autotest. Do not change string
* without consulting autotest for
* kernel_CrosECSysfsAccel.
*/
- printf("None\n");
+ printf("Sensor %d: ", i);
+ if (resp->dump.sensor[i].flags &
+ MOTIONSENSE_SENSOR_FLAG_PRESENT)
+ printf("%d\t%d\t%d\n",
+ resp->dump.sensor[i].data[0],
+ resp->dump.sensor[i].data[1],
+ resp->dump.sensor[i].data[2]);
+ else
+ printf("None\n");
+ }
+ return 0;
+ } else {
+ return rv;
}
-
- return 0;
- }
-
- if (argc == 2 && !strcasecmp(argv[1], "active")) {
- param.cmd = MOTIONSENSE_CMD_DUMP;
- rv = ec_command(EC_CMD_MOTION_SENSE_CMD, 0,
- &param, ms_command_sizes[param.cmd].insize,
- &resp, ms_command_sizes[param.cmd].outsize);
-
- /*
- * Warning: the following strings printed out are read in an
- * autotest. Do not change string without consulting autotest
- * for kernel_CrosECSysfsAccel.
- */
- if (resp.dump.module_flags & MOTIONSENSE_MODULE_FLAG_ACTIVE)
- printf("1\n");
- else
- printf("0\n");
-
- return 0;
}
if (argc == 3 && !strcasecmp(argv[1], "info")) {
@@ -2469,15 +2469,15 @@ static int cmd_motionsense(int argc, char **argv)
return -1;
}
- rv = ec_command(EC_CMD_MOTION_SENSE_CMD, 0,
+ rv = ec_command(EC_CMD_MOTION_SENSE_CMD, 1,
&param, ms_command_sizes[param.cmd].insize,
- &resp, ms_command_sizes[param.cmd].outsize);
+ resp, ms_command_sizes[param.cmd].outsize);
if (rv < 0)
return rv;
printf("Type: ");
- switch (resp.info.type) {
+ switch (resp->info.type) {
case MOTIONSENSE_TYPE_ACCEL:
printf("accel\n");
break;
@@ -2489,7 +2489,7 @@ static int cmd_motionsense(int argc, char **argv)
}
printf("Location: ");
- switch (resp.info.location) {
+ switch (resp->info.location) {
case MOTIONSENSE_LOC_BASE:
printf("base\n");
break;
@@ -2501,10 +2501,13 @@ static int cmd_motionsense(int argc, char **argv)
}
printf("Chip: ");
- switch (resp.info.chip) {
+ switch (resp->info.chip) {
case MOTIONSENSE_CHIP_KXCJ9:
printf("kxcj9\n");
break;
+ case MOTIONSENSE_CHIP_LSM6DS0:
+ printf("lsm6ds0\n");
+ break;
default:
printf("unknown\n");
}
@@ -2524,14 +2527,14 @@ static int cmd_motionsense(int argc, char **argv)
}
}
- rv = ec_command(EC_CMD_MOTION_SENSE_CMD, 0,
+ rv = ec_command(EC_CMD_MOTION_SENSE_CMD, 1,
&param, ms_command_sizes[param.cmd].insize,
- &resp, ms_command_sizes[param.cmd].outsize);
+ resp, ms_command_sizes[param.cmd].outsize);
if (rv < 0)
return rv;
- printf("%d\n", resp.ec_rate.ret);
+ printf("%d\n", resp->ec_rate.ret);
return 0;
}
@@ -2562,14 +2565,14 @@ static int cmd_motionsense(int argc, char **argv)
}
}
- rv = ec_command(EC_CMD_MOTION_SENSE_CMD, 0,
+ rv = ec_command(EC_CMD_MOTION_SENSE_CMD, 1,
&param, ms_command_sizes[param.cmd].insize,
- &resp, ms_command_sizes[param.cmd].outsize);
+ resp, ms_command_sizes[param.cmd].outsize);
if (rv < 0)
return rv;
- printf("%d\n", resp.sensor_odr.ret);
+ printf("%d\n", resp->sensor_odr.ret);
return 0;
}
@@ -2600,14 +2603,14 @@ static int cmd_motionsense(int argc, char **argv)
}
}
- rv = ec_command(EC_CMD_MOTION_SENSE_CMD, 0,
+ rv = ec_command(EC_CMD_MOTION_SENSE_CMD, 1,
&param, ms_command_sizes[param.cmd].insize,
- &resp, ms_command_sizes[param.cmd].outsize);
+ resp, ms_command_sizes[param.cmd].outsize);
if (rv < 0)
return rv;
- printf("%d\n", resp.sensor_range.ret);
+ printf("%d\n", resp->sensor_range.ret);
return 0;
}
@@ -2623,14 +2626,14 @@ static int cmd_motionsense(int argc, char **argv)
}
}
- rv = ec_command(EC_CMD_MOTION_SENSE_CMD, 0,
+ rv = ec_command(EC_CMD_MOTION_SENSE_CMD, 1,
&param, ms_command_sizes[param.cmd].insize,
- &resp, ms_command_sizes[param.cmd].outsize);
+ resp, ms_command_sizes[param.cmd].outsize);
if (rv < 0)
return rv;
- printf("%d\n", resp.kb_wake_angle.ret);
+ printf("%d\n", resp->kb_wake_angle.ret);
return 0;
}