Newer
Older
honey-os / src / userland / hid / usagePages / keyboard.c
@biosfood biosfood on 23 Aug 2023 894 bytes keyboard: implement key repeat behaviour
#include <hid.h>

// 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);
        }
    }
}