diff options
author | aqua <aqua@iserlohn-fortress.net> | 2022-10-31 15:39:51 +0200 |
---|---|---|
committer | aqua <aqua@iserlohn-fortress.net> | 2022-10-31 21:59:49 +0200 |
commit | cbd3cdf7cb34529e269bb27c654765a0c9c21799 (patch) | |
tree | 4ee555d5cb575af003e10e597666b4a7b17b17a7 /devices/ps2_keyboard.c | |
parent | makefile: auto-generate OBJS from SRCS (diff) | |
download | kernel-cbd3cdf7cb34529e269bb27c654765a0c9c21799.tar.xz |
add ps2_keyboard driver
Diffstat (limited to 'devices/ps2_keyboard.c')
-rw-r--r-- | devices/ps2_keyboard.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/devices/ps2_keyboard.c b/devices/ps2_keyboard.c new file mode 100644 index 0000000..6171d18 --- /dev/null +++ b/devices/ps2_keyboard.c @@ -0,0 +1,40 @@ +#include "ps2_keyboard.h" +#include <stdint.h> +#include <stdio.h> +#include <sys/io.h> + +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); +} |