summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChromeOS Developer <dparker@chromium.org>2014-02-25 17:59:29 -0800
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-02-26 21:33:36 +0000
commit1de3b97e78cf4568f2492bfaf13fe65f91457152 (patch)
tree5ae0a56a5294641d04f1d878b40b8e58903c7ff5
parenta6824770ccae3de4a0f27907db7eddd57b080d52 (diff)
downloadchrome-ec-1de3b97e78cf4568f2492bfaf13fe65f91457152.tar.gz
8042: Add typematic support for non-matrixed buttons
BUG=chrome-os-partner:24956 BRANCH=ToT TEST=Using evtest, verify off-keyboard volume buttons now send repeat codes while held down. Verify power button does not send repeat codes. Verify keyboard keys still send repeat codes as before. Change-Id: I873548181cdfa40d8e8929a6538c0ecd5ed8e92c Signed-off-by: Dave Parker <dparker@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/187938 Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r--common/keyboard_8042.c66
1 files changed, 51 insertions, 15 deletions
diff --git a/common/keyboard_8042.c b/common/keyboard_8042.c
index 04488ab070..fbe5b1bd8d 100644
--- a/common/keyboard_8042.c
+++ b/common/keyboard_8042.c
@@ -189,14 +189,23 @@ static const uint16_t scancode_set2[KEYBOARD_ROWS][KEYBOARD_COLS] = {
0x0044, 0x0000, 0xe075, 0xe06b},
};
-/* Button scancodes. Must be in the same order as defined in button_type */
-static const uint16_t button_scancodes[2][KEYBOARD_BUTTON_COUNT] = {
- /* Set 1 */
- {0xe05e, 0xe02e, 0xe030},
- /* Set 2 */
- {0xe037, 0xe021, 0xe032},
+struct button_8042_t {
+ uint16_t scancode_set1;
+ uint16_t scancode_set2;
+ int repeat;
};
+/*
+ * Button scancodes.
+ * Must be in the same order as defined in keyboard_button_type.
+ */
+static const struct button_8042_t buttons_8042[] = {
+ {0xe05e, 0xe037, 0}, /* Power */
+ {0xe02e, 0xe021, 1}, /* Volume Down */
+ {0xe030, 0xe032, 1}, /* Volume Up */
+};
+BUILD_ASSERT(ARRAY_SIZE(buttons_8042) == KEYBOARD_BUTTON_COUNT);
+
/*****************************************************************************/
/* Keyboard event log */
@@ -421,6 +430,18 @@ static void keyboard_wakeup(void)
host_set_single_event(EC_HOST_EVENT_KEY_PRESSED);
}
+static void set_typematic_key(const uint8_t *scan_code, int32_t len)
+{
+ typematic_deadline.val = get_time().val + typematic_first_delay;
+ memcpy(typematic_scan_code, scan_code, len);
+ typematic_len = len;
+}
+
+static void clear_typematic_key(void)
+{
+ typematic_len = 0;
+}
+
void keyboard_state_changed(int row, int col, int is_pressed)
{
uint8_t scan_code[MAX_SCAN_CODE_LEN];
@@ -439,14 +460,10 @@ void keyboard_state_changed(int row, int col, int is_pressed)
if (is_pressed) {
keyboard_wakeup();
-
- typematic_deadline.val = get_time().val + typematic_first_delay;
-
- memcpy(typematic_scan_code, scan_code, len);
- typematic_len = len;
+ set_typematic_key(scan_code, len);
task_wake(TASK_ID_KEYPROTO);
} else {
- typematic_len = 0;
+ clear_typematic_key();
}
}
@@ -931,11 +948,10 @@ void keyboard_protocol_task(void)
test_mockable void keyboard_update_button(enum keyboard_button_type button,
int is_pressed)
{
- /* TODO(crosbug.com/p/24956): Add typematic repeat support. */
-
uint8_t scan_code[MAX_SCAN_CODE_LEN];
uint16_t make_code;
uint32_t len;
+ struct button_8042_t button_8042;
enum scancode_set_list code_set;
/*
@@ -946,9 +962,29 @@ test_mockable void keyboard_update_button(enum keyboard_button_type button,
return;
code_set = acting_code_set(scancode_set);
- make_code = button_scancodes[code_set - SCANCODE_SET_1][button];
+ button_8042 = buttons_8042[button];
+
+ switch (code_set) {
+ case SCANCODE_SET_1:
+ make_code = button_8042.scancode_set1;
+ break;
+ case SCANCODE_SET_2:
+ make_code = button_8042.scancode_set2;
+ break;
+ default:
+ return; /* Other sets are not supported */
+ }
+
scancode_bytes(make_code, is_pressed, code_set, scan_code, &len);
ASSERT(len > 0);
+
+ if (button_8042.repeat) {
+ if (is_pressed)
+ set_typematic_key(scan_code, len);
+ else
+ clear_typematic_key();
+ }
+
if (keystroke_enabled) {
i8042_send_to_host(len, scan_code);
task_wake(TASK_ID_KEYPROTO);