diff options
-rw-r--r-- | board/eve/board.c | 1 | ||||
-rw-r--r-- | common/keyboard_8042.c | 88 | ||||
-rw-r--r-- | common/keyboard_8042_sharedlib.c | 102 | ||||
-rw-r--r-- | include/keyboard_8042_sharedlib.h | 9 |
4 files changed, 92 insertions, 108 deletions
diff --git a/board/eve/board.c b/board/eve/board.c index 1ab87d7d9d..30089a3321 100644 --- a/board/eve/board.c +++ b/board/eve/board.c @@ -489,7 +489,6 @@ static void board_init(void) if (board_get_version() == 4) { /* Set F13 to new defined key on EVT */ CPRINTS("Overriding F13 scan code"); - scancode_set1[3][9] = 0xe058; scancode_set2[3][9] = 0xe007; } #endif diff --git a/common/keyboard_8042.c b/common/keyboard_8042.c index 04e00d2bb2..4b2b9a5db9 100644 --- a/common/keyboard_8042.c +++ b/common/keyboard_8042.c @@ -252,6 +252,11 @@ static enum scancode_set_list acting_code_set(enum scancode_set_list set) return set; } +static int is_supported_code_set(enum scancode_set_list set) +{ + return (set == SCANCODE_SET_1 || set == SCANCODE_SET_2); +} + /** * Return the make or break code bytes for the active scancode set. * @@ -269,33 +274,22 @@ static void scancode_bytes(uint16_t make_code, int8_t pressed, /* Output the make code (from table) */ if (make_code >= 0x0100) { - *len += 2; - scan_code[0] = make_code >> 8; - scan_code[1] = make_code & 0xff; - } else { - *len += 1; - scan_code[0] = make_code & 0xff; + scan_code[(*len)++] = make_code >> 8; + make_code &= 0xff; } switch (code_set) { case SCANCODE_SET_1: - /* OR 0x80 for the last byte. */ - if (!pressed) { - ASSERT(*len >= 1); - scan_code[*len - 1] |= 0x80; - } + make_code = scancode_translate_set2_to_1(make_code); + scan_code[(*len)++] = pressed ? make_code : (make_code | 0x80); break; case SCANCODE_SET_2: - /* - * Insert the break byte, move back the last byte and insert a - * 0xf0 byte before that. - */ - if (!pressed) { - ASSERT(*len >= 1); - scan_code[*len] = scan_code[*len - 1]; - scan_code[*len - 1] = 0xf0; - *len += 1; + if (pressed) { + scan_code[(*len)++] = make_code; + } else { + scan_code[(*len)++] = 0xf0; + scan_code[(*len)++] = make_code; } break; default: @@ -316,21 +310,12 @@ static enum ec_error_list matrix_callback(int8_t row, int8_t col, if (row >= KEYBOARD_ROWS || col >= KEYBOARD_COLS) return EC_ERROR_INVAL; + make_code = scancode_set2[row][col]; if (pressed) - keyboard_special(scancode_set1[row][col]); + keyboard_special(make_code); code_set = acting_code_set(code_set); - - switch (code_set) { - case SCANCODE_SET_1: - make_code = scancode_set1[row][col]; - break; - - case SCANCODE_SET_2: - make_code = scancode_set2[row][col]; - break; - - default: + if (!is_supported_code_set(code_set)) { CPRINTS("KB scancode set %d unsupported", code_set); return EC_ERROR_UNIMPLEMENTED; } @@ -791,30 +776,30 @@ static void i8042_handle_from_host(void) static void keyboard_special(uint16_t k) { static uint8_t s; - static const uint16_t a[] = {0xe048, 0xe048, 0xe050, 0xe050, 0xe04b, - 0xe04d, 0xe04b, 0xe04d, 0x0030, 0x001e}; + static const uint16_t a[] = {0xe075, 0xe075, 0xe072, 0xe072, 0xe06b, + 0xe074, 0xe06b, 0xe074, 0x0032, 0x001c}; #ifdef HAS_TASK_LIGHTBAR /* Lightbar demo mode: keyboard can fake the battery state */ switch (k) { - case 0xe048: /* up */ + case 0xe075: /* up */ demo_battery_level(1); break; - case 0xe050: /* down */ + case 0xe072: /* down */ demo_battery_level(-1); break; - case 0xe04b: /* left */ + case 0xe06b: /* left */ demo_is_charging(0); break; - case 0xe04d: /* right */ + case 0xe074: /* right */ demo_is_charging(1); break; - case 0x0040: /* dim */ + case 0x000b: /* dim */ demo_brightness(-1); break; - case 0x0041: /* bright */ + case 0x0083: /* bright */ demo_brightness(1); break; - case 0x0014: /* T */ + case 0x002c: /* T */ demo_tap(); break; } @@ -822,7 +807,7 @@ static void keyboard_special(uint16_t k) if (k == a[s]) s++; - else if (k != 0xe048) + else if (k != 0xe075) s = 0; else if (s != 2) s = 1; @@ -919,7 +904,6 @@ test_mockable void keyboard_update_button(enum keyboard_button_type button, int is_pressed) { 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; @@ -932,20 +916,12 @@ test_mockable void keyboard_update_button(enum keyboard_button_type button, return; code_set = acting_code_set(scancode_set); - 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 */ - } + if (!is_supported_code_set(code_set)) + return; - scancode_bytes(make_code, is_pressed, code_set, scan_code, &len); + button_8042 = buttons_8042[button]; + scancode_bytes(button_8042.scancode, is_pressed, code_set, scan_code, + &len); ASSERT(len > 0); if (button_8042.repeat) { 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); diff --git a/include/keyboard_8042_sharedlib.h b/include/keyboard_8042_sharedlib.h index 5c9b559279..e475288ad5 100644 --- a/include/keyboard_8042_sharedlib.h +++ b/include/keyboard_8042_sharedlib.h @@ -13,20 +13,21 @@ #include "keyboard_protocol.h" struct button_8042_t { - uint16_t scancode_set1; - uint16_t scancode_set2; + uint16_t scancode; int repeat; }; /* The standard Chrome OS keyboard matrix table. */ #ifdef CONFIG_KEYBOARD_SCANCODE_MUTABLE -extern uint16_t scancode_set1[KEYBOARD_ROWS][KEYBOARD_COLS]; extern uint16_t scancode_set2[KEYBOARD_ROWS][KEYBOARD_COLS]; #else -extern const uint16_t scancode_set1[KEYBOARD_ROWS][KEYBOARD_COLS]; extern const uint16_t scancode_set2[KEYBOARD_ROWS][KEYBOARD_COLS]; #endif +/* Translation from scan code set 2 to set 1. */ +extern const uint8_t scancode_translate_table[]; +extern uint8_t scancode_translate_set2_to_1(uint8_t code); + /* Button scancodes (Power, Volume Down, Volume Up, etc.) */ extern const struct button_8042_t buttons_8042[KEYBOARD_BUTTON_COUNT]; |