diff --git a/src/include/keycodes.h b/src/include/keycodes.h index 4069534..235a21b 100644 --- a/src/include/keycodes.h +++ b/src/include/keycodes.h @@ -6,7 +6,7 @@ // modeled after // https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf, // page 53, section 10, Table 12: Keyboard / Keypad page - +// made to densely fill an array #define KEYS(f) \ f(KEY_NONE, 0, "", "", MODIFIERS_SHIFT) \ f(KEY_ERROR, 1, "", "", MODIFIERS_SHIFT) \ @@ -59,7 +59,7 @@ Key key; char *normal; char *modified; - uint32_t modifierKeys[2]; + uint32_t *modifierKeys; } KeyInfo; #endif diff --git a/src/include/keycodes.h b/src/include/keycodes.h index 4069534..235a21b 100644 --- a/src/include/keycodes.h +++ b/src/include/keycodes.h @@ -6,7 +6,7 @@ // modeled after // https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf, // page 53, section 10, Table 12: Keyboard / Keypad page - +// made to densely fill an array #define KEYS(f) \ f(KEY_NONE, 0, "", "", MODIFIERS_SHIFT) \ f(KEY_ERROR, 1, "", "", MODIFIERS_SHIFT) \ @@ -59,7 +59,7 @@ Key key; char *normal; char *modified; - uint32_t modifierKeys[2]; + uint32_t *modifierKeys; } KeyInfo; #endif diff --git a/src/userland/hid/usagePages/keyboard.c b/src/userland/hid/usagePages/keyboard.c index 8a2b1ca..431d118 100644 --- a/src/userland/hid/usagePages/keyboard.c +++ b/src/userland/hid/usagePages/keyboard.c @@ -3,24 +3,13 @@ // https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf // section 10, page 53, table 12 -char keycodes[] = { - 0, 0, 0, 0, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', - 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', - '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '\n', /* escape*/0, '\b', '\t', ' ', - '-', '=', '[', ']', '\\', '#', ';', '\'', /* grave accent */ 0, ',', '.', '/', /* caps lock */ 0 -}; - REQUEST(keyDown, "keyboard", "keyDown"); REQUEST(keyUp, "keyboard", "keyUp"); void handleKeyboard(uint32_t usage, int32_t data) { - if (usage >= sizeof(keycodes) / sizeof(char)) { - printf("keyboard: unknown keycode %i\n", usage); - } else if (keycodes[usage]) { - if (data) { - keyDown(keycodes[usage], 0); - } else { - keyUp(keycodes[usage], 0); - } + if (data) { + keyDown(usage, 0); + } else { + keyUp(usage, 0); } } diff --git a/src/include/keycodes.h b/src/include/keycodes.h index 4069534..235a21b 100644 --- a/src/include/keycodes.h +++ b/src/include/keycodes.h @@ -6,7 +6,7 @@ // modeled after // https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf, // page 53, section 10, Table 12: Keyboard / Keypad page - +// made to densely fill an array #define KEYS(f) \ f(KEY_NONE, 0, "", "", MODIFIERS_SHIFT) \ f(KEY_ERROR, 1, "", "", MODIFIERS_SHIFT) \ @@ -59,7 +59,7 @@ Key key; char *normal; char *modified; - uint32_t modifierKeys[2]; + uint32_t *modifierKeys; } KeyInfo; #endif diff --git a/src/userland/hid/usagePages/keyboard.c b/src/userland/hid/usagePages/keyboard.c index 8a2b1ca..431d118 100644 --- a/src/userland/hid/usagePages/keyboard.c +++ b/src/userland/hid/usagePages/keyboard.c @@ -3,24 +3,13 @@ // https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf // section 10, page 53, table 12 -char keycodes[] = { - 0, 0, 0, 0, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', - 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', - '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '\n', /* escape*/0, '\b', '\t', ' ', - '-', '=', '[', ']', '\\', '#', ';', '\'', /* grave accent */ 0, ',', '.', '/', /* caps lock */ 0 -}; - REQUEST(keyDown, "keyboard", "keyDown"); REQUEST(keyUp, "keyboard", "keyUp"); void handleKeyboard(uint32_t usage, int32_t data) { - if (usage >= sizeof(keycodes) / sizeof(char)) { - printf("keyboard: unknown keycode %i\n", usage); - } else if (keycodes[usage]) { - if (data) { - keyDown(keycodes[usage], 0); - } else { - keyUp(keycodes[usage], 0); - } + if (data) { + keyDown(usage, 0); + } else { + keyUp(usage, 0); } } diff --git a/src/userland/keyboard/main.c b/src/userland/keyboard/main.c index 982a47b..34f84d4 100644 --- a/src/userland/keyboard/main.c +++ b/src/userland/keyboard/main.c @@ -1,6 +1,13 @@ #define ALLOC_MAIN - #include +#include + +#define KEY_STRUCT(_name, _id, _normal, _modified, _modifiers) \ + { .key = _name, .normal = _normal, .modified = _modified, .modifierKeys = _modifiers }, + +uint32_t MODIFIERS_SHIFT[] = { 225, 229, 0 }; + +KeyInfo keyInfos[] = { KEYS(KEY_STRUCT) }; // maximum number of simultaniously pressed keys #define MAX_PRESSED 10 @@ -22,7 +29,13 @@ } void sendPress(uint32_t keycode) { - doKeyCallback(keycode, 0); + if (keycode >= sizeof(keyInfos) / sizeof(KeyInfo)) { + return; + } + KeyInfo *info = &keyInfos[keycode]; + for (uint32_t i = 0; info->normal[i]; i++) { + doKeyCallback(info->normal[i], 0); + } } void keyRepeat(uint32_t keycode, uint32_t threadId) {