diff options
author | Boris Mittelberg <bmbm@google.com> | 2021-04-13 22:49:42 +0000 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-05-10 22:34:46 +0000 |
commit | fa985803d6bd7c76b8eddc49d1bab4434cc545f3 (patch) | |
tree | ff2645c8fdd0c8c36a68d89b3e4536f2bc538643 /common | |
parent | 3a2f77758104a581ade2ecb406b8d099eada6a90 (diff) | |
download | chrome-ec-fa985803d6bd7c76b8eddc49d1bab4434cc545f3.tar.gz |
mkbp: Move key simulation to input devices
Today some platforms include MKBP_KEYBOARD because they use side buttons,
switches or other events that share the same driver with MKBP keyboard.
Those platforms don't enable KEYSCAN task. The CL is moving key emulation
functionality to MKBP input devices, to make a clear separation
between the real keyboard usage and emulation/buttons/switches/etc.
All boards that were selecting `CONFIG_KEYBOARD_PROTOCOL_MKBP` without
KEYSCAN task are now updated to select `CONFIG_MKBP_INPUT_DEVICES`
BUG=b:170966461
BRANCH=main,firmware-dedede-13606.B,firmware-volteer-13672.B-main
TEST=None
Signed-off-by: Boris Mittelberg <bmbm@google.com>
Change-Id: I515140ebf6e175f4b29991329f92266ffca232a8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2824044
Diffstat (limited to 'common')
-rw-r--r-- | common/keyboard_mkbp.c | 66 | ||||
-rw-r--r-- | common/mkbp_input_devices.c | 67 |
2 files changed, 68 insertions, 65 deletions
diff --git a/common/keyboard_mkbp.c b/common/keyboard_mkbp.c index eabb4c5829..d8e9f8d909 100644 --- a/common/keyboard_mkbp.c +++ b/common/keyboard_mkbp.c @@ -31,9 +31,7 @@ #define BATTERY_KEY_ROW_MASK BIT(BATTERY_KEY_ROW) #ifndef HAS_TASK_KEYSCAN -/* Keys simulated-pressed */ -static uint8_t __bss_slow simulated_key[KEYBOARD_COLS_MAX]; -uint8_t keyboard_cols = KEYBOARD_COLS_MAX; +#error "Task KEYSCAN has to be enabled for MKBP keyboard" #endif /* !defined(HAS_TASK_KEYSCAN) */ /* Config for mkbp protocol; does not include fields from scan config */ @@ -98,67 +96,6 @@ void keyboard_send_battery_key(void) void clear_typematic_key(void) { } -#ifndef HAS_TASK_KEYSCAN -/* For boards without a keyscan task, try and simulate keyboard presses. */ -static void simulate_key(int row, int col, int pressed) -{ - if ((simulated_key[col] & BIT(row)) == ((pressed ? 1 : 0) << row)) - return; /* No change */ - - simulated_key[col] &= ~BIT(row); - if (pressed) - simulated_key[col] |= BIT(row); - - mkbp_keyboard_add(simulated_key); -} - -static int command_mkbp_keyboard_press(int argc, char **argv) -{ - if (argc == 1) { - int i, j; - - ccputs("Simulated keys:\n"); - for (i = 0; i < keyboard_cols; ++i) { - if (simulated_key[i] == 0) - continue; - for (j = 0; j < KEYBOARD_ROWS; ++j) - if (simulated_key[i] & BIT(j)) - ccprintf("\t%d %d\n", i, j); - } - - } else if (argc == 3 || argc == 4) { - int r, c, p; - char *e; - - c = strtoi(argv[1], &e, 0); - if (*e || c < 0 || c >= keyboard_cols) - return EC_ERROR_PARAM1; - - r = strtoi(argv[2], &e, 0); - if (*e || r < 0 || r >= KEYBOARD_ROWS) - return EC_ERROR_PARAM2; - - if (argc == 3) { - /* Simulate a press and release */ - simulate_key(r, c, 1); - simulate_key(r, c, 0); - } else { - p = strtoi(argv[3], &e, 0); - if (*e || p < 0 || p > 1) - return EC_ERROR_PARAM3; - - simulate_key(r, c, p); - } - } - - return EC_SUCCESS; -} -DECLARE_CONSOLE_COMMAND(kbpress, command_mkbp_keyboard_press, - "[col row [0 | 1]]", - "Simulate keypress"); -#endif /* !defined(HAS_TASK_KEYSCAN) */ - -#ifdef HAS_TASK_KEYSCAN static void set_keyscan_config(const struct ec_mkbp_config *src, struct ec_mkbp_protocol_config *dst, uint32_t valid_mask, uint8_t new_flags) @@ -285,4 +222,3 @@ host_command_mkbp_get_config(struct host_cmd_handler_args *args) DECLARE_HOST_COMMAND(EC_CMD_MKBP_GET_CONFIG, host_command_mkbp_get_config, EC_VER_MASK(0)); -#endif /* HAS_TASK_KEYSCAN */ diff --git a/common/mkbp_input_devices.c b/common/mkbp_input_devices.c index 56d2234775..e058c9d320 100644 --- a/common/mkbp_input_devices.c +++ b/common/mkbp_input_devices.c @@ -11,6 +11,7 @@ #include "hooks.h" #include "host_command.h" #include "keyboard_mkbp.h" +#include "keyboard_scan.h" #include "lid_switch.h" #include "mkbp_event.h" #include "mkbp_fifo.h" @@ -176,3 +177,69 @@ static int sysrq_get_next_event(uint8_t *out) } DECLARE_EVENT_SOURCE(EC_MKBP_EVENT_SYSRQ, sysrq_get_next_event); #endif + +/************************ Keyboard press simulation ************************/ +#ifndef HAS_TASK_KEYSCAN +/* Keys simulated-pressed */ +static uint8_t __bss_slow simulated_key[KEYBOARD_COLS_MAX]; +uint8_t keyboard_cols = KEYBOARD_COLS_MAX; + +/* For boards without a keyscan task, try and simulate keyboard presses. */ +static void simulate_key(int row, int col, int pressed) +{ + if ((simulated_key[col] & BIT(row)) == ((pressed ? 1 : 0) << row)) + return; /* No change */ + + simulated_key[col] &= ~BIT(row); + if (pressed) + simulated_key[col] |= BIT(row); + + mkbp_fifo_add((uint8_t)EC_MKBP_EVENT_KEY_MATRIX, simulated_key); +} + +static int command_mkbp_keyboard_press(int argc, char **argv) +{ + if (argc == 1) { + int i, j; + + ccputs("Simulated keys:\n"); + for (i = 0; i < keyboard_cols; ++i) { + if (simulated_key[i] == 0) + continue; + for (j = 0; j < KEYBOARD_ROWS; ++j) + if (simulated_key[i] & BIT(j)) + ccprintf("\t%d %d\n", i, j); + } + + } else if (argc == 3 || argc == 4) { + int r, c, p; + char *e; + + c = strtoi(argv[1], &e, 0); + if (*e || c < 0 || c >= keyboard_cols) + return EC_ERROR_PARAM1; + + r = strtoi(argv[2], &e, 0); + if (*e || r < 0 || r >= KEYBOARD_ROWS) + return EC_ERROR_PARAM2; + + if (argc == 3) { + /* Simulate a press and release */ + simulate_key(r, c, 1); + simulate_key(r, c, 0); + } else { + p = strtoi(argv[3], &e, 0); + if (*e || p < 0 || p > 1) + return EC_ERROR_PARAM3; + + simulate_key(r, c, p); + } + } + + return EC_SUCCESS; +} +DECLARE_CONSOLE_COMMAND(kbpress, command_mkbp_keyboard_press, + "[col row [0 | 1]]", + "Simulate keypress"); + +#endif /* !defined(HAS_TASK_KEYSCAN) */ |