summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHung-Te Lin <hungte@chromium.org>2018-08-08 12:35:37 +0800
committerchrome-bot <chrome-bot@chromium.org>2018-08-16 13:14:46 -0700
commit7ef6291e33c31388652e66ebf0f96ec6d836d528 (patch)
tree675b2d1f463df13a94ea3e7621b714009f4d83c7
parent50e52e2182a09eb862e5a0b4cbb25d052c94364d (diff)
downloadchrome-ec-7ef6291e33c31388652e66ebf0f96ec6d836d528.tar.gz
keyboard: Change scan code magic values to enum.
The key codes are now always scan code set 2 so we can create a list of scan codes and use them easily. BUG=None TEST=make buildall -j; boots properly BRANCH=None Change-Id: I1fdd7ab81bc13c97c4139afc19d71f5898e22f96 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1166743
-rw-r--r--common/keyboard_8042.c23
-rw-r--r--common/keyboard_8042_sharedlib.c24
-rw-r--r--include/keyboard_8042_sharedlib.h49
3 files changed, 74 insertions, 22 deletions
diff --git a/common/keyboard_8042.c b/common/keyboard_8042.c
index 4b2b9a5db9..50320807cb 100644
--- a/common/keyboard_8042.c
+++ b/common/keyboard_8042.c
@@ -776,30 +776,33 @@ static void i8042_handle_from_host(void)
static void keyboard_special(uint16_t k)
{
static uint8_t s;
- static const uint16_t a[] = {0xe075, 0xe075, 0xe072, 0xe072, 0xe06b,
- 0xe074, 0xe06b, 0xe074, 0x0032, 0x001c};
+ static const uint16_t a[] = {
+ SCANCODE_UP, SCANCODE_UP, SCANCODE_DOWN, SCANCODE_DOWN,
+ SCANCODE_LEFT, SCANCODE_RIGHT, SCANCODE_LEFT, SCANCODE_RIGHT,
+ SCANCODE_B, SCANCODE_A};
+
#ifdef HAS_TASK_LIGHTBAR
/* Lightbar demo mode: keyboard can fake the battery state */
switch (k) {
- case 0xe075: /* up */
+ case SCANCODE_UP:
demo_battery_level(1);
break;
- case 0xe072: /* down */
+ case SCANCODE_DOWN:
demo_battery_level(-1);
break;
- case 0xe06b: /* left */
+ case SCANCODE_LEFT:
demo_is_charging(0);
break;
- case 0xe074: /* right */
+ case SCANCODE_RIGHT:
demo_is_charging(1);
break;
- case 0x000b: /* dim */
+ case SCANCODE_F6: /* dim */
demo_brightness(-1);
break;
- case 0x0083: /* bright */
+ case SCANCODE_F7: /* bright */
demo_brightness(1);
break;
- case 0x002c: /* T */
+ case SCANCODE_T:
demo_tap();
break;
}
@@ -807,7 +810,7 @@ static void keyboard_special(uint16_t k)
if (k == a[s])
s++;
- else if (k != 0xe075)
+ else if (k != SCANCODE_UP)
s = 0;
else if (s != 2)
s = 1;
diff --git a/common/keyboard_8042_sharedlib.c b/common/keyboard_8042_sharedlib.c
index 0ea4dca792..513a27913d 100644
--- a/common/keyboard_8042_sharedlib.c
+++ b/common/keyboard_8042_sharedlib.c
@@ -76,20 +76,20 @@ uint8_t scancode_translate_set2_to_1(uint8_t code)
}
/*
- * Button scancodes in code set 2.
+ * Button scan codes.
* Must be in the same order as defined in keyboard_button_type.
*/
SHAREDLIB(const struct button_8042_t buttons_8042[] = {
- {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 */
+ {SCANCODE_POWER, 0},
+ {SCANCODE_VOLUME_DOWN, 1},
+ {SCANCODE_VOLUME_UP, 1},
+ {SCANCODE_1, 1},
+ {SCANCODE_2, 1},
+ {SCANCODE_3, 1},
+ {SCANCODE_4, 1},
+ {SCANCODE_5, 1},
+ {SCANCODE_6, 1},
+ {SCANCODE_7, 1},
+ {SCANCODE_8, 1},
});
BUILD_ASSERT(ARRAY_SIZE(buttons_8042) == KEYBOARD_BUTTON_COUNT);
diff --git a/include/keyboard_8042_sharedlib.h b/include/keyboard_8042_sharedlib.h
index e475288ad5..adf2932231 100644
--- a/include/keyboard_8042_sharedlib.h
+++ b/include/keyboard_8042_sharedlib.h
@@ -31,4 +31,53 @@ 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];
+/* Scan code set 2 table. */
+enum scancode_values {
+ SCANCODE_1 = 0x0016,
+ SCANCODE_2 = 0x001e,
+ SCANCODE_3 = 0x0026,
+ SCANCODE_4 = 0x0025,
+ SCANCODE_5 = 0x002e,
+ SCANCODE_6 = 0x0036,
+ SCANCODE_7 = 0x003d,
+ SCANCODE_8 = 0x003e,
+
+ SCANCODE_A = 0x001c,
+ SCANCODE_B = 0x0032,
+ SCANCODE_T = 0x002c,
+
+ SCANCODE_F1 = 0x0005,
+ SCANCODE_F2 = 0x0006,
+ SCANCODE_F3 = 0x0004,
+ SCANCODE_F4 = 0x000c,
+ SCANCODE_F5 = 0x0003,
+ SCANCODE_F6 = 0x000b,
+ SCANCODE_F7 = 0x0083,
+ SCANCODE_F8 = 0x000a,
+
+ SCANCODE_UP = 0xe075,
+ SCANCODE_DOWN = 0xe072,
+ SCANCODE_LEFT = 0xe06b,
+ SCANCODE_RIGHT = 0xe074,
+
+ SCANCODE_LEFT_CTRL = 0x0014,
+ SCANCODE_RIGHT_CTRL = 0xe014,
+ SCANCODE_LEFT_ALT = 0x0011,
+ SCANCODE_RIGHT_ALT = 0xe011,
+
+ SCANCODE_LEFT_WIN = 0xe01f, /* Also known as GUI or Super key. */
+ SCANCODE_RIGHT_WIN = 0xe027,
+ SCANCODE_MENU = 0xe02f,
+
+ SCANCODE_POWER = 0xe037,
+ SCANCODE_VOLUME_DOWN = 0xe021,
+ SCANCODE_VOLUME_UP = 0xe032,
+
+ SCANCODE_NUMLOCK = 0x0077,
+ SCANCODE_CAPSLOCK = 0x0058,
+ SCANCODE_SCROLL_LOCK = 0x007e,
+
+ SCANCODE_CTRL_BREAK = 0xe07e,
+};
+
#endif /* __CROS_EC_KEYBOARD_8042_SHAREDLIB_H */