Simplify scancode set 1 transformation

This commit is contained in:
Jeremy Soller
2019-11-18 20:34:19 -07:00
parent d928ef8a9a
commit c1fe4eeb43
2 changed files with 29 additions and 113 deletions

View File

@ -23,6 +23,12 @@ uint16_t keymap_translate(uint16_t key);
#define K_FN (0x8000)
// Hotkeys
#define K_MUTE (K_E0 | 0x23)
#define K_VOLUME_DOWN (K_E0 | 0x21)
#define K_VOLUME_UP (K_E0 | 0x32)
// Function keys
#define K_F1 (0x05)

View File

@ -100,7 +100,7 @@ uint16_t __code KEYMAP[KM_OUT][KM_IN][KM_LAY] = {
{K_7, 0}, // 4
{K_6, 0}, // 5
{K_F4, 0}, // 6
{K_F3, 0}, // 7
{K_F3, K_MUTE}, // 7
},
{ // 10
{K_S, 0}, // 0
@ -109,8 +109,8 @@ uint16_t __code KEYMAP[KM_OUT][KM_IN][KM_LAY] = {
{K_O, 0}, // 3
{K_9, 0}, // 4
{K_8, 0}, // 5
{K_F6, 0}, // 6
{K_F5, 0}, // 7
{K_F6, K_VOLUME_UP}, // 6
{K_F5, K_VOLUME_DOWN}, // 7
},
{ // 11
{0, 0}, // 0
@ -172,116 +172,26 @@ uint16_t keymap(int output, int input, int layer) {
}
}
// This is terrible, from http://www.vetra.com/scancodes.html
// TODO: redo by applying transform at lower level as recommended by:
// https://www.win.tue.nl/~aeb/linux/kbd/scancodes-10.html#ss10.3
static uint8_t __code lookup[256] = {
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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xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
};
uint16_t keymap_translate(uint16_t key) {
switch (key) {
// Function keys
case K_F1: return 0x3B;
case K_F2: return 0x3C;
case K_F3: return 0x3D;
case K_F4: return 0x3E;
case K_F5: return 0x3F;
case K_F6: return 0x40;
case K_F7: return 0x41;
case K_F8: return 0x42;
case K_F9: return 0x43;
case K_F10: return 0x44;
case K_F11: return 0x57;
case K_F12: return 0x58;
// Number keys
case K_0: return 0x0B;
case K_1: return 0x02;
case K_2: return 0x03;
case K_3: return 0x04;
case K_4: return 0x05;
case K_5: return 0x06;
case K_6: return 0x07;
case K_7: return 0x08;
case K_8: return 0x09;
case K_9: return 0x0A;
// Letter keys
case K_A: return 0x1E;
case K_B: return 0x30;
case K_C: return 0x2E;
case K_D: return 0x20;
case K_E: return 0x12;
case K_F: return 0x21;
case K_G: return 0x22;
case K_H: return 0x23;
case K_I: return 0x17;
case K_J: return 0x24;
case K_K: return 0x25;
case K_L: return 0x26;
case K_M: return 0x32;
case K_N: return 0x31;
case K_O: return 0x18;
case K_P: return 0x19;
case K_Q: return 0x10;
case K_R: return 0x13;
case K_S: return 0x1F;
case K_T: return 0x14;
case K_U: return 0x16;
case K_V: return 0x2F;
case K_W: return 0x11;
case K_X: return 0x2D;
case K_Y: return 0x15;
case K_Z: return 0x2C;
// Special keys
case K_ESC: return 0x01;
case K_TICK: return 0x29;
case K_MINUS: return 0x0C;
case K_EQUALS: return 0x0D;
case K_BKSP: return 0x0E;
case K_TAB: return 0x0F;
case K_BRACE_OPEN: return 0x1A;
case K_BRACE_CLOSE: return 0x1B;
case K_BACKSLASH: return 0x2B;
case K_CAPS: return 0x3A;
case K_SEMICOLON: return 0x27;
case K_QUOTE: return 0x28;
case K_ENTER: return 0x1C;
case K_LEFT_SHIFT: return 0x2A;
case K_COMMA: return 0x33;
case K_PERIOD: return 0x34;
case K_SLASH: return 0x35;
case K_RIGHT_SHIFT: return 0x36;
case K_LEFT_CTRL: return 0x1D;
case K_LEFT_SUPER: return (K_E0 | 0x5B);
case K_LEFT_ALT: return 0x38;
case K_SPACE: return 0x39;
case K_RIGHT_ALT: return (K_E0 | 0x38);
case K_RIGHT_SUPER: return (K_E0 | 0x5C);
case K_APP: return (K_E0 | 0x5D);
case K_RIGHT_CTRL: return (K_E0 | 0x1D);
case K_INSERT: return (K_E0 | 0x52);
case K_DEL: return (K_E0 | 0x53);
case K_HOME: return (K_E0 | 0x47);
case K_END: return (K_E0 | 0x4F);
case K_PGUP: return (K_E0 | 0x49);
case K_PGDN: return (K_E0 | 0x51);
case K_UP: return (K_E0 | 0x48);
case K_LEFT: return (K_E0 | 0x4B);
case K_DOWN: return (K_E0 | 0x50);
case K_RIGHT: return (K_E0 | 0x4D);
default:
WARN("keymap_translate: unknown %02X\n", key);
return 0;
}
return (key & 0xFF00) | lookup[(key & 0xFF)];
}