diff options
Diffstat (limited to 'Source/Kernel/Devices')
-rw-r--r-- | Source/Kernel/Devices/Keyboard/Keyboard.proto.h | 11 | ||||
-rw-r--r-- | Source/Kernel/Devices/Keyboard/PS2Keyboard.class.cpp | 52 | ||||
-rw-r--r-- | Source/Kernel/Devices/Keyboard/PS2Keyboard.class.h | 18 |
3 files changed, 81 insertions, 0 deletions
diff --git a/Source/Kernel/Devices/Keyboard/Keyboard.proto.h b/Source/Kernel/Devices/Keyboard/Keyboard.proto.h new file mode 100644 index 0000000..d6898f8 --- /dev/null +++ b/Source/Kernel/Devices/Keyboard/Keyboard.proto.h @@ -0,0 +1,11 @@ +#ifndef DEF_KEYBOARD_PROTO_H +#define DEF_KEYBOARD_PROTO_H + +#include <Devices/Device.proto.h> + +class Keyboard : public Device { + public: + virtual void updateLeds(u32int kbdstatus) = 0; +}; + +#endif diff --git a/Source/Kernel/Devices/Keyboard/PS2Keyboard.class.cpp b/Source/Kernel/Devices/Keyboard/PS2Keyboard.class.cpp new file mode 100644 index 0000000..f5216c7 --- /dev/null +++ b/Source/Kernel/Devices/Keyboard/PS2Keyboard.class.cpp @@ -0,0 +1,52 @@ +#include "PS2Keyboard.class.h" +#include <DeviceManager/Dev.ns.h> +#include <DeviceManager/Kbd.ns.h> + +using namespace Sys; + +PS2Keyboard::PS2Keyboard() { + Dev::requestIRQ(this, 1); + m_escaped = false; +} + +String PS2Keyboard::getClass() { + return "keyboard.ps2"; +} + +String PS2Keyboard::getName() { + return "Standard PS2 keyboard"; +} + +void PS2Keyboard::handleIRQ(registers_t regs, int irq) { + if (irq == 1) { + u8int scancode = inb(0x60); + if (scancode == 0xE0) { + m_escaped = true; + } else { + if (scancode & 0x80) { + if (m_escaped) { + Kbd::keyRelease(scancode); + } else { + Kbd::keyRelease(scancode & 0x7F); + } + } else { + if (m_escaped) { + Kbd::keyPress(scancode | 0x80); + } else { + Kbd::keyPress(scancode); + } + } + } + } +} + +void PS2Keyboard::updateLeds(u32int kbdstatus) { + u8int temp = 0; + if (kbdstatus & STATUS_SCRL) + temp |= 1; + if (kbdstatus & STATUS_NUM) + temp |= 2; + if (kbdstatus & STATUS_CAPS) + temp |= 4; + outb(0x60, temp); +} diff --git a/Source/Kernel/Devices/Keyboard/PS2Keyboard.class.h b/Source/Kernel/Devices/Keyboard/PS2Keyboard.class.h new file mode 100644 index 0000000..b4cd7a8 --- /dev/null +++ b/Source/Kernel/Devices/Keyboard/PS2Keyboard.class.h @@ -0,0 +1,18 @@ +#ifndef DEF_PS2KEYBOARD_CLASS_H +#define DEF_PS2KEYBOARD_CLASS_H + +#include <Devices/Keyboard/Keyboard.proto.h> + +class PS2Keyboard : public Keyboard { + private: + bool m_escaped; + + public: + PS2Keyboard(); + String getClass(); + String getName(); + void handleIRQ(registers_t regs, int irq); + void updateLeds(u32int kbdstatus); +}; + +#endif |