[Voyageurs] Add a basic ps/2 keyboard driver.
This commit is contained in:
parent
7151a509ee
commit
8365d47cbe
18 changed files with 532 additions and 0 deletions
34
sys/voyageurs/keyboard/keyboard_driver.cpp
Normal file
34
sys/voyageurs/keyboard/keyboard_driver.cpp
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#include "keyboard/keyboard_driver.h"
|
||||
|
||||
#include <mammoth/util/debug.h>
|
||||
|
||||
void InterruptEnter(void* void_keyboard) {
|
||||
KeyboardDriver* keyboard = static_cast<KeyboardDriver*>(void_keyboard);
|
||||
|
||||
keyboard->InterruptLoop();
|
||||
}
|
||||
|
||||
KeyboardDriver::KeyboardDriver() { check(ZIrqRegister(kZIrqKbd, &irq_cap_)); }
|
||||
|
||||
void KeyboardDriver::RegisterListener(uint64_t port_cap) {
|
||||
listeners_.PushFront(mmth::PortClient::AdoptPort(port_cap));
|
||||
}
|
||||
|
||||
Thread KeyboardDriver::StartInterruptLoop() {
|
||||
return Thread(InterruptEnter, this);
|
||||
}
|
||||
|
||||
void KeyboardDriver::InterruptLoop() {
|
||||
dbgln("Interrupt");
|
||||
while (true) {
|
||||
uint8_t scancode;
|
||||
uint64_t num_bytes = 1;
|
||||
uint64_t num_caps = 0;
|
||||
check(ZPortRecv(irq_cap_, &num_bytes, &scancode, &num_caps, nullptr));
|
||||
dbgln("Scan {x}", scancode);
|
||||
|
||||
for (mmth::PortClient& client : listeners_) {
|
||||
client.WriteByte(scancode);
|
||||
}
|
||||
}
|
||||
}
|
||||
22
sys/voyageurs/keyboard/keyboard_driver.h
Normal file
22
sys/voyageurs/keyboard/keyboard_driver.h
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#pragma once
|
||||
|
||||
#include <glacier/container/linked_list.h>
|
||||
#include <mammoth/ipc/port_client.h>
|
||||
#include <mammoth/ipc/port_server.h>
|
||||
#include <mammoth/proc/thread.h>
|
||||
|
||||
class KeyboardDriver {
|
||||
public:
|
||||
KeyboardDriver();
|
||||
KeyboardDriver(const KeyboardDriver&) = delete;
|
||||
KeyboardDriver(KeyboardDriver&&) = delete;
|
||||
|
||||
void RegisterListener(uint64_t port_cap);
|
||||
|
||||
Thread StartInterruptLoop();
|
||||
void InterruptLoop();
|
||||
|
||||
private:
|
||||
z_cap_t irq_cap_;
|
||||
glcr::LinkedList<mmth::PortClient> listeners_;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue