From ccaf2737f82968816c5ec962f936a593686cfb72 Mon Sep 17 00:00:00 2001 From: aqua Date: Wed, 2 Nov 2022 09:34:31 +0200 Subject: Add ps2_ctrl_8042 --- devices/ps2_ctrl_8042.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 devices/ps2_ctrl_8042.c (limited to 'devices/ps2_ctrl_8042.c') diff --git a/devices/ps2_ctrl_8042.c b/devices/ps2_ctrl_8042.c new file mode 100644 index 0000000..4157bd8 --- /dev/null +++ b/devices/ps2_ctrl_8042.c @@ -0,0 +1,43 @@ +#include "ps2_ctrl.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; + +void +ps2_ctrl_init() +{ + // eat all previous keystrikes + while (inb(comm_port) & 0x1) inb(data_port); + + outb(0x64, 0xaa); + printf("8042: self test 0xaa: %x\n", inb(0x60)); + outb(0x64, 0xab); + printf("8042: port1 test 0xab: %x\n", inb(0x60)); + outb(0x64, 0xa9); + printf("8042: port2 test 0xa9: %x\n", inb(0x60)); + + // printf("8042: init keyboard\n"); + + 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); + +} + +unsigned char +ps2_ctrl_read() +{ + return inb(0x60); +} -- cgit v1.2.1