summaryrefslogtreecommitdiff
path: root/common/keyboard_8042_sharedlib.c
diff options
context:
space:
mode:
authorHung-Te Lin <hungte@chromium.org>2018-08-08 08:55:38 +0800
committerchrome-bot <chrome-bot@chromium.org>2018-08-15 20:36:15 -0700
commit43899e1d9e3f523701d8d8b5c93890322894e6e4 (patch)
treee1064e69d6b8bbf91e050c34251a77ba3ce959e2 /common/keyboard_8042_sharedlib.c
parent0c94bad3ebecb4f33544ffb3b136746d044c4ea9 (diff)
downloadchrome-ec-43899e1d9e3f523701d8d8b5c93890322894e6e4.tar.gz
keyboard: Keep only scan code set 2 table and do translation for set 1.
The 8042 scan code set 1 can be directly translated from set 2, with a 256 byte table. With this change, we can always process key stroke in scan code (set 2), and only translate in the single function `scancode_bytes`. This is very helpful when we need to do key processing, for example the buttons_8042 can now be simplified with only one scan code. And is extremely helpful if we want to do dynamic translation (i.e., to prevent something like CL:1164725). For `make BOARD=samus', the free space is also increased from 18472 to 18656 (+184) bytes. BUG=None TEST=make buildall; manually installed on Eve and tested by running 'keyboard' factory test to make sure all key scancodes are not changed. BRANCH=None Change-Id: Ieb303d84edcd4375bbeb1ea5f032d0462bbfd250 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1166742 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'common/keyboard_8042_sharedlib.c')
-rw-r--r--common/keyboard_8042_sharedlib.c102
1 files changed, 55 insertions, 47 deletions
diff --git a/common/keyboard_8042_sharedlib.c b/common/keyboard_8042_sharedlib.c
index 7aba63502d..0ea4dca792 100644
--- a/common/keyboard_8042_sharedlib.c
+++ b/common/keyboard_8042_sharedlib.c
@@ -12,39 +12,11 @@
#include "libsharedobjs.h"
#include "util.h"
-/* The standard Chrome OS keyboard matrix table. */
-#ifdef CONFIG_KEYBOARD_SCANCODE_MUTABLE
-uint16_t scancode_set1[KEYBOARD_ROWS][KEYBOARD_COLS] = {
-#else
-SHAREDLIB(const uint16_t scancode_set1[KEYBOARD_ROWS][KEYBOARD_COLS] = {
+/* The standard Chrome OS keyboard matrix table in scan code set 2. */
+#ifndef CONFIG_KEYBOARD_SCANCODE_MUTABLE
+SHAREDLIB(const
#endif
- {0x0000, 0xe05b, 0x003b, 0x0030, 0x0044, 0x0073, 0x0031, 0x0000, 0x000d,
- 0x0000, 0xe038, 0x0000, 0x0000},
- {0x0000, 0x0001, 0x003e, 0x0022, 0x0041, 0x0000, 0x0023, 0x0000, 0x0028,
- 0x0043, 0x0000, 0x000e, 0x0079},
- {0x001d, 0x000f, 0x003d, 0x0014, 0x0040, 0x001b, 0x0015, 0x0056, 0x001a,
- 0x0042, 0x007d, 0x0000, 0x0000},
- {0xe05b, 0x0029, 0x003c, 0x0006, 0x003f, 0x0000, 0x0007, 0x0000, 0x000c,
- 0x005d, 0x0000, 0x002b, 0x007b},
- {0xe01d, 0x001e, 0x0020, 0x0021, 0x001f, 0x0025, 0x0024, 0x0000, 0x0027,
- 0x0026, 0x002b, 0x001c, 0x0000},
- {0xe058, 0x002c, 0x002e, 0x002f, 0x002d, 0x0033, 0x0032, 0x002a, 0x0035,
- 0x0034, 0x0000, 0x0039, 0x0000},
- {0x0000, 0x0002, 0x0004, 0x0005, 0x0003, 0x0009, 0x0008, 0x0000, 0x000b,
- 0x000a, 0x0038, 0xe050, 0xe04d},
- {0x0000, 0x0010, 0x0012, 0x0013, 0x0011, 0x0017, 0x0016, 0x0036, 0x0019,
- 0x0018, 0x0000, 0xe048, 0xe04b},
-#ifdef CONFIG_KEYBOARD_SCANCODE_MUTABLE
-};
-#else
-});
-#endif
-
-#ifdef CONFIG_KEYBOARD_SCANCODE_MUTABLE
uint16_t scancode_set2[KEYBOARD_ROWS][KEYBOARD_COLS] = {
-#else
-SHAREDLIB(uint16_t const scancode_set2[KEYBOARD_ROWS][KEYBOARD_COLS] = {
-#endif
{0x0000, 0xe01f, 0x0005, 0x0032, 0x0009, 0x0051, 0x0031, 0x0000, 0x0055,
0x0000, 0xe011, 0x0000, 0x0000},
{0x0000, 0x0076, 0x000c, 0x0034, 0x0083, 0x0000, 0x0033, 0x0000, 0x0052,
@@ -61,27 +33,63 @@ SHAREDLIB(uint16_t const scancode_set2[KEYBOARD_ROWS][KEYBOARD_COLS] = {
0x0046, 0x0011, 0xe072, 0xe074},
{0x0000, 0x0015, 0x0024, 0x002d, 0x001d, 0x0043, 0x003c, 0x0059, 0x004d,
0x0044, 0x0000, 0xe075, 0xe06b},
-#ifdef CONFIG_KEYBOARD_SCANCODE_MUTABLE
-};
-#else
-});
+}
+#ifndef CONFIG_KEYBOARD_SCANCODE_MUTABLE
+)
#endif
+;
+
+/*
+ * The translation table from scan code set 2 to set 1.
+ * Ref: http://kbd-project.org/docs/scancodes/scancodes-10.html#ss10.3
+ * To reduce space, we only keep the translation for 0~127,
+ * so a real translation need to do 0x83=>0x41 explicitly (
+ * see scancode_translate_set2_to_1 below).
+ */
+SHAREDLIB(const uint8_t scancode_translate_table[128] = {
+ 0xff, 0x43, 0x41, 0x3f, 0x3d, 0x3b, 0x3c, 0x58,
+ 0x64, 0x44, 0x42, 0x40, 0x3e, 0x0f, 0x29, 0x59,
+ 0x65, 0x38, 0x2a, 0x70, 0x1d, 0x10, 0x02, 0x5a,
+ 0x66, 0x71, 0x2c, 0x1f, 0x1e, 0x11, 0x03, 0x5b,
+ 0x67, 0x2e, 0x2d, 0x20, 0x12, 0x05, 0x04, 0x5c,
+ 0x68, 0x39, 0x2f, 0x21, 0x14, 0x13, 0x06, 0x5d,
+ 0x69, 0x31, 0x30, 0x23, 0x22, 0x15, 0x07, 0x5e,
+ 0x6a, 0x72, 0x32, 0x24, 0x16, 0x08, 0x09, 0x5f,
+ 0x6b, 0x33, 0x25, 0x17, 0x18, 0x0b, 0x0a, 0x60,
+ 0x6c, 0x34, 0x35, 0x26, 0x27, 0x19, 0x0c, 0x61,
+ 0x6d, 0x73, 0x28, 0x74, 0x1a, 0x0d, 0x62, 0x6e,
+ 0x3a, 0x36, 0x1c, 0x1b, 0x75, 0x2b, 0x63, 0x76,
+ 0x55, 0x56, 0x77, 0x78, 0x79, 0x7a, 0x0e, 0x7b,
+ 0x7c, 0x4f, 0x7d, 0x4b, 0x47, 0x7e, 0x7f, 0x6f,
+ 0x52, 0x53, 0x50, 0x4c, 0x4d, 0x48, 0x01, 0x45,
+ 0x57, 0x4e, 0x51, 0x4a, 0x37, 0x49, 0x46, 0x54,
+});
+
+uint8_t scancode_translate_set2_to_1(uint8_t code)
+{
+ if (code & 0x80) {
+ if (code == 0x83)
+ return 0x41;
+ return code;
+ }
+ return scancode_translate_table[code];
+}
/*
- * Button scancodes.
+ * Button scancodes in code set 2.
* Must be in the same order as defined in keyboard_button_type.
*/
SHAREDLIB(const struct button_8042_t buttons_8042[] = {
- {0xe05e, 0xe037, 0}, /* Power */
- {0xe02e, 0xe021, 1}, /* Volume Down */
- {0xe030, 0xe032, 1}, /* Volume Up */
- {0x0002, 0x0016, 1}, /* 1 */
- {0x0003, 0x001e, 1}, /* 2 */
- {0x0004, 0x0026, 1}, /* 3 */
- {0x0005, 0x0025, 1}, /* 4 */
- {0x0006, 0x002e, 1}, /* 5 */
- {0x0007, 0x0036, 1}, /* 6 */
- {0x0008, 0x003d, 1}, /* 7 */
- {0x0009, 0x003e, 1}, /* 8 */
+ {0xe037, 0}, /* Power */
+ {0xe021, 1}, /* Volume Down */
+ {0xe032, 1}, /* Volume Up */
+ {0x0016, 1}, /* 1 */
+ {0x001e, 1}, /* 2 */
+ {0x0026, 1}, /* 3 */
+ {0x0025, 1}, /* 4 */
+ {0x002e, 1}, /* 5 */
+ {0x0036, 1}, /* 6 */
+ {0x003d, 1}, /* 7 */
+ {0x003e, 1}, /* 8 */
});
BUILD_ASSERT(ARRAY_SIZE(buttons_8042) == KEYBOARD_BUTTON_COUNT);