[Voyageurs] Send USB keypress data to the keyboard driver.
This commit is contained in:
parent
3c1e435e04
commit
02d4f8c80e
10 changed files with 79 additions and 20 deletions
|
|
@ -2,13 +2,24 @@
|
|||
|
||||
#include <mammoth/util/debug.h>
|
||||
|
||||
namespace {
|
||||
|
||||
KeyboardDriver* gKeyboardDriver = nullptr;
|
||||
|
||||
}
|
||||
|
||||
void InterruptEnter(void* void_keyboard) {
|
||||
KeyboardDriver* keyboard = static_cast<KeyboardDriver*>(void_keyboard);
|
||||
|
||||
keyboard->InterruptLoop();
|
||||
}
|
||||
|
||||
KeyboardDriver::KeyboardDriver() { check(ZIrqRegister(kZIrqKbd, &irq_cap_)); }
|
||||
KeyboardDriver::KeyboardDriver() {
|
||||
check(ZPortCreate(&port_cap_));
|
||||
gKeyboardDriver = this;
|
||||
}
|
||||
|
||||
z_cap_t KeyboardDriver::GetPortCap() { return gKeyboardDriver->port_cap_; }
|
||||
|
||||
void KeyboardDriver::RegisterListener(uint64_t port_cap) {
|
||||
listeners_.PushFront(mmth::PortClient::AdoptPort(port_cap));
|
||||
|
|
@ -21,13 +32,37 @@ Thread KeyboardDriver::StartInterruptLoop() {
|
|||
void KeyboardDriver::InterruptLoop() {
|
||||
dbgln("Interrupt");
|
||||
while (true) {
|
||||
uint8_t scancode;
|
||||
uint64_t num_bytes = 1;
|
||||
uint64_t scancode;
|
||||
uint64_t num_bytes = 8;
|
||||
uint64_t num_caps = 0;
|
||||
check(ZPortRecv(irq_cap_, &num_bytes, &scancode, &num_caps, nullptr));
|
||||
check(ZPortRecv(port_cap_, &num_bytes, &scancode, &num_caps, nullptr));
|
||||
|
||||
for (mmth::PortClient& client : listeners_) {
|
||||
client.WriteByte(scancode);
|
||||
}
|
||||
ProcessInput(scancode);
|
||||
}
|
||||
}
|
||||
|
||||
void KeyboardDriver::ProcessInput(uint64_t input) {
|
||||
uint64_t new_bitmap = 0;
|
||||
for (uint8_t i = 2; i < 8; i++) {
|
||||
uint8_t code = (input >> (8 * i)) & 0xFF;
|
||||
if (code == 0) {
|
||||
break;
|
||||
}
|
||||
if (code >= 64) {
|
||||
dbgln("Skipping keycode: {x}", code);
|
||||
}
|
||||
uint64_t bit = 1 << code;
|
||||
new_bitmap |= bit;
|
||||
if ((bitmap_ & bit) != bit) {
|
||||
SendKeypress(code);
|
||||
}
|
||||
}
|
||||
bitmap_ = new_bitmap;
|
||||
}
|
||||
|
||||
void KeyboardDriver::SendKeypress(uint8_t scancode) {
|
||||
dbgln("{x}", scancode);
|
||||
for (mmth::PortClient& client : listeners_) {
|
||||
client.WriteByte(scancode);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue