diff options
author | Alec Berg <alecaberg@chromium.org> | 2014-04-03 16:01:42 -0700 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2014-04-05 03:27:13 +0000 |
commit | b12206307e3a6a2b4c2c577c95d9fb298ec366a3 (patch) | |
tree | 56c367f9670784796502db897f1b8a9c89925190 /common | |
parent | e3579f43d8e9bf90f9df1ffb1f927f52fdef212b (diff) | |
download | chrome-ec-b12206307e3a6a2b4c2c577c95d9fb298ec366a3.tar.gz |
accel: refined motion sense host command interface
Added enum for motion sensor ID's into ec_commands.h so that the host
can easily send host commands targeting the desired accelerometer.
Changed sensor present flag to just senosr flags, currently with only a
single mask defined for sensor present. This allows for easier future
expansion of various flags.
Also, added a motion sense module flags to the dump sub-command for flags
that represent all sensors, such as is the motion sense task active.
BUG=chrome-os-partner:27321
BRANCH=rambi
TEST=Manual test on a glimmer by testing ectool motionsense command
Change-Id: Iac052269a60db9ff4506f0490c3a0c6daad5b626
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/193122
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/193309
Diffstat (limited to 'common')
-rw-r--r-- | common/motion_sense.c | 47 |
1 files changed, 37 insertions, 10 deletions
diff --git a/common/motion_sense.c b/common/motion_sense.c index e94604fae5..1fb158b7c9 100644 --- a/common/motion_sense.c +++ b/common/motion_sense.c @@ -322,6 +322,27 @@ void accel_int_base(enum gpio_signal signal) /*****************************************************************************/ /* Host commands */ +/** + * Temporary function to map host sensor IDs to EC sensor IDs. + * + * TODO(crosbug.com/p/27320): Eventually we need a board specific table + * specifying which motion sensors are attached and which driver to use to + * access that sensor. Once we have this, this function should be able to go + * away. + */ +static int host_sensor_id_to_ec_sensor_id(int host_id) +{ + switch (host_id) { + case EC_MOTION_SENSOR_ACCEL_BASE: + return ACCEL_BASE; + case EC_MOTION_SENSOR_ACCEL_LID: + return ACCEL_LID; + } + + /* If no match then the EC currently doesn't support ID received. */ + return -1; +} + static int host_cmd_motion_sense(struct host_cmd_handler_args *args) { const struct ec_params_motion_sense *in = args->params; @@ -335,9 +356,13 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args) * use some motion_sense data structure from the board file to * help fill in this response. */ - out->dump.sensor_presence[0] = 1; - out->dump.sensor_presence[1] = 1; - out->dump.sensor_presence[2] = 0; + out->dump.module_flags = + (*(host_get_memmap(EC_MEMMAP_ACC_STATUS)) & + EC_MEMMAP_ACC_STATUS_PRESENCE_BIT) ? + MOTIONSENSE_MODULE_FLAG_ACTIVE : 0; + out->dump.sensor_flags[0] = MOTIONSENSE_SENSOR_FLAG_PRESENT; + out->dump.sensor_flags[1] = MOTIONSENSE_SENSOR_FLAG_PRESENT; + out->dump.sensor_flags[2] = 0; out->dump.data[0] = acc_base_host[X]; out->dump.data[1] = acc_base_host[Y]; out->dump.data[2] = acc_base_host[Z]; @@ -354,7 +379,11 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args) * use some motion_sense data structure from the board file to * help fill in this response. */ - switch (in->sensor_odr.sensor_num) { + id = host_sensor_id_to_ec_sensor_id(in->sensor_odr.sensor_num); + if (id < 0) + return EC_RES_INVALID_PARAM; + + switch (id) { case ACCEL_BASE: out->info.type = MOTIONSENSE_TYPE_ACCEL; out->info.location = MOTIONSENSE_LOC_BASE; @@ -396,11 +425,10 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args) case MOTIONSENSE_CMD_SENSOR_ODR: /* Verify sensor number is valid. */ - if (in->sensor_odr.sensor_num >= ACCEL_COUNT) + id = host_sensor_id_to_ec_sensor_id(in->sensor_odr.sensor_num); + if (id < 0) return EC_RES_INVALID_PARAM; - id = in->sensor_odr.sensor_num; - /* Set new datarate if the data arg has a value. */ if (in->sensor_odr.data != EC_MOTION_SENSE_NO_VALUE) { if (accel_set_datarate(id, in->sensor_odr.data, @@ -419,11 +447,10 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args) case MOTIONSENSE_CMD_SENSOR_RANGE: /* Verify sensor number is valid. */ - if (in->sensor_odr.sensor_num >= ACCEL_COUNT) + id = host_sensor_id_to_ec_sensor_id(in->sensor_odr.sensor_num); + if (id < 0) return EC_RES_INVALID_PARAM; - id = in->sensor_odr.sensor_num; - /* Set new datarate if the data arg has a value. */ if (in->sensor_range.data != EC_MOTION_SENSE_NO_VALUE) { if (accel_set_range(id, in->sensor_range.data, |