diff options
author | Gerrit <chrome-bot@google.com> | 2012-05-29 18:19:17 -0700 |
---|---|---|
committer | Gerrit Code Review <gerrit@gerrit.golo.chromium.org> | 2012-05-29 18:19:17 -0700 |
commit | 8bb9091f2ec880f0f8b38559c0a8101ba46557a0 (patch) | |
tree | fe57a3f4c21df544c19c3ad8832500bcb32cc70f | |
parent | fa8788e8c0384d6980a4618d5434defae0b77355 (diff) | |
parent | abce21c6cfcce85145cec4bf0c7b4001bdb63f48 (diff) | |
download | chrome-ec-8bb9091f2ec880f0f8b38559c0a8101ba46557a0.tar.gz |
Merge "Add host command to simulate key press"
-rw-r--r-- | common/keyboard.c | 15 | ||||
-rw-r--r-- | include/ec_commands.h | 8 | ||||
-rw-r--r-- | util/ectool.c | 43 |
3 files changed, 66 insertions, 0 deletions
diff --git a/common/keyboard.c b/common/keyboard.c index 8b05485d2b..d0ac87e00b 100644 --- a/common/keyboard.c +++ b/common/keyboard.c @@ -11,6 +11,7 @@ #include "keyboard.h" #include "i8042.h" #include "hooks.h" +#include "host_command.h" #include "lightbar.h" #include "lpc.h" #include "ec_commands.h" @@ -863,6 +864,20 @@ DECLARE_CONSOLE_COMMAND(kblog, command_keyboard_log, NULL); +static int mkbp_command_simulate_key(uint8_t *data, int *resp_size) +{ + struct ec_params_mkbp_simulate_key *p = + (struct ec_params_mkbp_simulate_key *)data; + + simulated_key[p->col] = (simulated_key[p->col] & ~(1 << p->row)) | + (p->pressed << p->row); + + keyboard_state_changed(p->row, p->col, p->pressed); + return EC_RES_SUCCESS; +} +DECLARE_HOST_COMMAND(EC_CMD_MKBP_SIMULATE_KEY, mkbp_command_simulate_key); + + /* Preserves the states of keyboard controller to keep the initialized states * between reboot_ec commands. Saving info include: * diff --git a/include/ec_commands.h b/include/ec_commands.h index f76cadb7f3..4599cf4475 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -535,6 +535,14 @@ struct ec_response_mkbp_info { uint32_t cols; } __attribute__ ((packed)); +/* Simulate key press */ +#define EC_CMD_MKBP_SIMULATE_KEY 0x62 +struct ec_params_mkbp_simulate_key { + uint8_t col; + uint8_t row; + uint8_t pressed; +} __attribute__ ((packed)); + /*****************************************************************************/ /* Temperature sensor commands */ diff --git a/util/ectool.c b/util/ectool.c index 4c9ff31bb5..abdb9a0938 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -57,6 +57,8 @@ const char help_str[] = " Erases EC flash\n" " hello\n" " Checks for basic communication with EC\n" + " kbpress\n" + " Simulate key press\n" " lightbar [CMDS]\n" " Various lightbar control commands\n" " vboot get\n" @@ -1036,6 +1038,46 @@ int cmd_usb_charge_set_mode(int argc, char *argv[]) } +int cmd_kbpress(int argc, char *argv[]) +{ + struct ec_params_mkbp_simulate_key p; + char *e; + int rv; + + if (argc != 4) { + fprintf(stderr, + "Usage: %s <row> <col> <0|1>\n", argv[0]); + return -1; + } + p.row = strtol(argv[1], &e, 0); + if (e && *e) { + fprintf(stderr, "Bad row.\n"); + return -1; + } + p.col = strtol(argv[2], &e, 0); + if (e && *e) { + fprintf(stderr, "Bad column.\n"); + return -1; + } + p.pressed = strtol(argv[3], &e, 0); + if (e && *e) { + fprintf(stderr, "Bad pressed flag.\n"); + return -1; + } + + printf("%s row %d col %d.\n", p.pressed ? "Pressing" : "Releasing", + p.row, + p.col); + + rv = ec_command(EC_CMD_MKBP_SIMULATE_KEY, + &p, sizeof(p), NULL, 0); + if (rv) + return rv; + printf("Done.\n"); + return 0; +} + + int cmd_pstore_info(int argc, char *argv[]) { struct ec_response_pstore_info r; @@ -1452,6 +1494,7 @@ const struct command commands[] = { {"flashwrite", cmd_flash_write}, {"flashinfo", cmd_flash_info}, {"hello", cmd_hello}, + {"kbpress", cmd_kbpress}, {"lightbar", cmd_lightbar}, {"vboot", cmd_vboot}, {"pstoreinfo", cmd_pstore_info}, |