diff options
author | Alec Berg <alecaberg@chromium.org> | 2014-04-22 17:47:16 -0700 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2014-04-23 20:50:34 +0000 |
commit | 3b36337be1e165db491bc591ae95be3577886465 (patch) | |
tree | 35f2ab82d35c889aa165769c92735ad8e0820de3 /common | |
parent | 67698db7da22449314dc5c0b3f468674afe77092 (diff) | |
download | chrome-ec-3b36337be1e165db491bc591ae95be3577886465.tar.gz |
accel: add accel driver for lsm6ds0
This adds the basics for the accelerometer potion only of the ST
lsm6ds0 accel/gyro. Still need to add the acceleration interrupt
functionality, and all of the gyro portion of the chip.
BUG=none
BRANCH=none
TEST=Tested on a samus prototype hacked up to have the lsm6ds0 connected
to the EC i2c bus. Added motion sense task to the samus tasklist, added
accelerometer information to the samus board file, and tested console
functions interacting with accelerometer. The data seems reasonable,
and can successfully change data rate and range.
Change-Id: I7949d9c20642a40ede82dc291b2c80f01b0a7d8b
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/196426
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'common')
-rw-r--r-- | common/motion_sense.c | 162 |
1 files changed, 162 insertions, 0 deletions
diff --git a/common/motion_sense.c b/common/motion_sense.c index d48b578cd1..90ed1ecd6d 100644 --- a/common/motion_sense.c +++ b/common/motion_sense.c @@ -543,3 +543,165 @@ DECLARE_CONSOLE_COMMAND(lidangle, command_ctrl_print_lid_angle_calcs, "on/off [interval]", "Print lid angle calculations and set calculation frequency.", NULL); #endif /* CONFIG_CMD_LID_ANGLE */ + +#ifdef CONFIG_CMD_ACCELS +static int command_accelrange(int argc, char **argv) +{ + char *e; + int id, data, round = 1; + + if (argc < 2 || argc > 4) + return EC_ERROR_PARAM_COUNT; + + /* First argument is sensor id. */ + id = strtoi(argv[1], &e, 0); + if (*e || id < 0 || id > ACCEL_COUNT) + return EC_ERROR_PARAM1; + + if (argc >= 3) { + /* Second argument is data to write. */ + data = strtoi(argv[2], &e, 0); + if (*e) + return EC_ERROR_PARAM2; + + if (argc == 4) { + /* Third argument is rounding flag. */ + round = strtoi(argv[3], &e, 0); + if (*e) + return EC_ERROR_PARAM3; + } + + /* + * Write new range, if it returns invalid arg, then return + * a parameter error. + */ + if (accel_set_range(id, data, round) == EC_ERROR_INVAL) + return EC_ERROR_PARAM2; + } else { + accel_get_range(id, &data); + ccprintf("Range for sensor %d: %d\n", id, data); + } + + return EC_SUCCESS; +} +DECLARE_CONSOLE_COMMAND(accelrange, command_accelrange, + "id [data [roundup]]", + "Read or write accelerometer range", NULL); + +static int command_accelresolution(int argc, char **argv) +{ + char *e; + int id, data, round = 1; + + if (argc < 2 || argc > 4) + return EC_ERROR_PARAM_COUNT; + + /* First argument is sensor id. */ + id = strtoi(argv[1], &e, 0); + if (*e || id < 0 || id > ACCEL_COUNT) + return EC_ERROR_PARAM1; + + if (argc >= 3) { + /* Second argument is data to write. */ + data = strtoi(argv[2], &e, 0); + if (*e) + return EC_ERROR_PARAM2; + + if (argc == 4) { + /* Third argument is rounding flag. */ + round = strtoi(argv[3], &e, 0); + if (*e) + return EC_ERROR_PARAM3; + } + + /* + * Write new resolution, if it returns invalid arg, then + * return a parameter error. + */ + if (accel_set_resolution(id, data, round) == EC_ERROR_INVAL) + return EC_ERROR_PARAM2; + } else { + accel_get_resolution(id, &data); + ccprintf("Resolution for sensor %d: %d\n", id, data); + } + + return EC_SUCCESS; +} +DECLARE_CONSOLE_COMMAND(accelres, command_accelresolution, + "id [data [roundup]]", + "Read or write accelerometer resolution", NULL); + +static int command_acceldatarate(int argc, char **argv) +{ + char *e; + int id, data, round = 1; + + if (argc < 2 || argc > 4) + return EC_ERROR_PARAM_COUNT; + + /* First argument is sensor id. */ + id = strtoi(argv[1], &e, 0); + if (*e || id < 0 || id > ACCEL_COUNT) + return EC_ERROR_PARAM1; + + if (argc >= 3) { + /* Second argument is data to write. */ + data = strtoi(argv[2], &e, 0); + if (*e) + return EC_ERROR_PARAM2; + + if (argc == 4) { + /* Third argument is rounding flag. */ + round = strtoi(argv[3], &e, 0); + if (*e) + return EC_ERROR_PARAM3; + } + + /* + * Write new data rate, if it returns invalid arg, then + * return a parameter error. + */ + if (accel_set_datarate(id, data, round) == EC_ERROR_INVAL) + return EC_ERROR_PARAM2; + } else { + accel_get_datarate(id, &data); + ccprintf("Data rate for sensor %d: %d\n", id, data); + } + + return EC_SUCCESS; +} +DECLARE_CONSOLE_COMMAND(accelrate, command_acceldatarate, + "id [data [roundup]]", + "Read or write accelerometer range", NULL); + +#ifdef CONFIG_ACCEL_INTERRUPTS +static int command_accelerometer_interrupt(int argc, char **argv) +{ + char *e; + int id, thresh; + + if (argc != 3) + return EC_ERROR_PARAM_COUNT; + + /* First argument is id. */ + id = strtoi(argv[1], &e, 0); + if (*e || id < 0 || id >= ACCEL_COUNT) + return EC_ERROR_PARAM1; + + /* Second argument is interrupt threshold. */ + thresh = strtoi(argv[2], &e, 0); + if (*e) + return EC_ERROR_PARAM2; + + accel_set_interrupt(id, thresh); + + return EC_SUCCESS; +} +DECLARE_CONSOLE_COMMAND(accelint, command_accelerometer_interrupt, + "id threshold", + "Write interrupt threshold", NULL); +#endif /* CONFIG_ACCEL_INTERRUPTS */ + +#endif /* CONFIG_CMD_ACCELS */ + + |