diff options
author | Hung-Te Lin <hungte@chromium.org> | 2018-08-09 11:45:15 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-08-17 11:17:57 -0700 |
commit | cd8cc76e3034c1935245b9b20e7fc4efbb0b0471 (patch) | |
tree | 8df7b9e8921d728d0849f9931ed90bf4300ad1d8 | |
parent | 195a3e8589312d0bc96f37c08e266539d7895d74 (diff) | |
download | chrome-ec-cd8cc76e3034c1935245b9b20e7fc4efbb0b0471.tar.gz |
keyboard: Add CONFIG_KEYBOARD_SCANCODE_CALLBACK for board-specific hooks.
Many devices may want board-specific keyboard hooks, for example
allowing easter egg (to replace the key_special today), or to provide
dynamic translation. Both can be done by having a callback whenever the
key state is changed (after scancode is found).
The new CONFIG_KEYBOARD_SCANCODE_CALLBACK allows boards to define their
own hook keyboard_scancode_callback so the keystrokes can be either
changed or monitored.
BUG=b:72200093
TEST=make buildall -j
BRANCH=eve
Change-Id: I02e3bf5c217b2f30b942d96ecb2c493ce200638f
Signed-off-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1168281
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r-- | common/keyboard_8042.c | 9 | ||||
-rw-r--r-- | include/config.h | 5 | ||||
-rw-r--r-- | include/keyboard_8042.h | 17 |
3 files changed, 31 insertions, 0 deletions
diff --git a/common/keyboard_8042.c b/common/keyboard_8042.c index 50320807cb..b178c50066 100644 --- a/common/keyboard_8042.c +++ b/common/keyboard_8042.c @@ -314,6 +314,15 @@ static enum ec_error_list matrix_callback(int8_t row, int8_t col, if (pressed) keyboard_special(make_code); +#ifdef CONFIG_KEYBOARD_SCANCODE_CALLBACK + { + enum ec_error_list r = keyboard_scancode_callback( + &make_code, pressed); + if (r != EC_SUCCESS) + return r; + } +#endif + code_set = acting_code_set(code_set); if (!is_supported_code_set(code_set)) { CPRINTS("KB scancode set %d unsupported", code_set); diff --git a/include/config.h b/include/config.h index ba1ffd954a..a5c17ad9b5 100644 --- a/include/config.h +++ b/include/config.h @@ -2043,6 +2043,11 @@ #undef CONFIG_KEYBOARD_SCANCODE_MUTABLE /* + * Allow board-specific 8042 keyboard callback when a key state is changed. + */ +#undef CONFIG_KEYBOARD_SCANCODE_CALLBACK + +/* * Call board-supplied keyboard_suppress_noise() function when the debounced * keyboard state changes. Some boards use this to send a signal to the audio * codec to suppress typing noise picked up by the microphone. diff --git a/include/keyboard_8042.h b/include/keyboard_8042.h index 00fdc9901b..7bde59ac35 100644 --- a/include/keyboard_8042.h +++ b/include/keyboard_8042.h @@ -28,4 +28,21 @@ void button_state_changed(enum keyboard_button_type button, int is_pressed); */ void keyboard_host_write(int data, int is_cmd); +/* + * Board specific callback function when a key state is changed. + * + * A board may watch key events and create some easter eggs, or apply dynamic + * translation to the make code (i.e., remap keys). + * + * Returning EC_SUCCESS implies *make_code is still a valid make code to be + * processed. Any other return value will abort processing of this make code. + * If callback alters *make_code or aborts key processing when pressed=1, it is + * responsible for also altering/aborting the matching pressed=0 call. + * + * @param make_code Pointer to scan code (set 2) of key in action. + * @param pressed Is the key being pressed (1) or released (0). + */ +enum ec_error_list keyboard_scancode_callback(uint16_t *make_code, + int8_t pressed); + #endif /* __CROS_EC_KEYBOARD_8042_H */ |