#include "ps2_keyboard.h" #include #include #include const uint8_t comm_port = 0x64; // r status register // w command register const uint8_t comm_enable_first_ps2 = 0xae; const uint8_t comm_read_ctrl_config = 0x20; const uint8_t comm_write_ctrl_config = 0x60; const uint8_t data_port = 0x60; // rw const uint8_t data_enable_scanning = 0xf4; const char scancodes[] = {'E', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\b', 'T', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', 'C', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`', 'L', '\\', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', 'R'}; void ps2_keyboard_init() { // eat all previous keystrikes while (inb(comm_port) & 0x1) inb(data_port); outb(comm_port, comm_enable_first_ps2); outb(comm_port, comm_read_ctrl_config); const uint8_t conf = (inb(data_port) | 1) & ~0x10; outb(comm_port, comm_write_ctrl_config); outb(data_port, conf); outb(data_port, data_enable_scanning); } void ps2_keyboard_irq_handler() { const uint8_t key = inb(data_port); if (key >= 0x80) return; if (key < 0x37) printf("%c", scancodes[key - 1]); else printf("key pressed: %x\n", key); }