From 02a703e8dca690780d6e00198274a2139e89f01a Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Wed, 3 Mar 2021 11:43:43 +0200 Subject: Add some comments to keyboard driver --- drivers/keyboard.cc | 27 ++++++++++++++++++++------- drivers/keyboard.h | 10 ++++++++-- drivers/ports.h | 3 --- 3 files changed, 28 insertions(+), 12 deletions(-) (limited to 'drivers') diff --git a/drivers/keyboard.cc b/drivers/keyboard.cc index 268ce2b..09fd4e9 100644 --- a/drivers/keyboard.cc +++ b/drivers/keyboard.cc @@ -1,15 +1,28 @@ #include "keyboard.h" #include +/* + * https://wiki.osdev.org/%228042%22_PS/2_Controller + * https://wiki.osdev.org/PS/2_Keyboard + */ + +constexpr uint8_t comm_enable_first_ps2 = 0xae; +constexpr uint8_t comm_read_ctrl_config = 0x20; +constexpr uint8_t comm_write_ctrl_config = 0x60; + +constexpr uint8_t dat_enable_scanning = 0xf4; + Keyboard::Keyboard() : InterruptHandler(0x01) { // eat all previous keystrikes - while (commandport.read() & 0x1) dataport.read(); - commandport.write(0xae); // ??? - commandport.write(0x20); // get state ??? - auto status = (dataport.read() | 1) & ~0x10; - commandport.write(0x60); // set state ??? - dataport.write(status); // ??? - dataport.write(0xf4); // ??? + while (commstatport.read() & 0x1) { + [[maybe_unused]] auto _c = dataport.read(); + } + commstatport.write(comm_enable_first_ps2); + commstatport.write(comm_read_ctrl_config); + const uint8_t conf = (dataport.read() | 1) & ~0x10; + commstatport.write(comm_write_ctrl_config); + dataport.write(conf); + dataport.write(dat_enable_scanning); } void Keyboard::trigger() { diff --git a/drivers/keyboard.h b/drivers/keyboard.h index a14c2c0..cac0cb0 100644 --- a/drivers/keyboard.h +++ b/drivers/keyboard.h @@ -3,6 +3,7 @@ #include "idt.h" #include "ports.h" +/* PS/2 Keyboard */ class Keyboard : public InterruptHandler { public: Keyboard(); @@ -10,6 +11,11 @@ public: void trigger() override; private: - keyboard_comm_t commandport; - keyboard_data_t dataport; + /* 8042 PS/2 Controller Ports */ + typedef Port<0x60, uint8_t> data_port_t; // rw data port + typedef Port<0x64, uint8_t> comm_port_t; // r status register + // w command register + + data_port_t dataport; + comm_port_t commstatport; }; diff --git a/drivers/ports.h b/drivers/ports.h index 2d26e65..393fd4d 100644 --- a/drivers/ports.h +++ b/drivers/ports.h @@ -58,6 +58,3 @@ typedef Port<0x2e8, uint8_t> com4_port_t; typedef Port<0x20, uint8_t> pic1_t; typedef Port<0xa0, uint8_t> pic2_t; -/* PS/2 keyboard */ -typedef Port<0x60, uint8_t> keyboard_data_t; -typedef Port<0x64, uint8_t> keyboard_comm_t; -- cgit v1.2.1