From 1b7d2b908585876b1fde8df5201b4af74a5f014a Mon Sep 17 00:00:00 2001 From: Drew Galbraith Date: Sat, 25 Nov 2023 19:48:01 -0800 Subject: [PATCH] [Teton/Voyageurs] Subscribe to scancodes in teton and print them to screen. Right now there appears to be an error with the font so that the proper character is received but we write an incorect character to the screen (off by one?). --- lib/mammoth/ipc/port_server.cpp | 8 ++ lib/mammoth/ipc/port_server.h | 2 + sys/teton/CMakeLists.txt | 1 + sys/teton/teton.cpp | 24 +++++- sys/voyageurs/keyboard/keyboard_driver.cpp | 88 +++++++++++++++++++++- 5 files changed, 121 insertions(+), 2 deletions(-) diff --git a/lib/mammoth/ipc/port_server.cpp b/lib/mammoth/ipc/port_server.cpp index 6208c85..4643143 100644 --- a/lib/mammoth/ipc/port_server.cpp +++ b/lib/mammoth/ipc/port_server.cpp @@ -47,4 +47,12 @@ glcr::ErrorCode PortServer::PollForIntCap(uint64_t *msg, uint64_t *cap) { return glcr::OK; } +glcr::ErrorOr PortServer::RecvChar() { + uint64_t bytes = 1; + uint64_t caps = 0; + char byte; + RET_ERR(ZPortRecv(port_cap_, &bytes, &byte, &caps, nullptr)); + return byte; +} + } // namespace mmth diff --git a/lib/mammoth/ipc/port_server.h b/lib/mammoth/ipc/port_server.h index 997c134..9e46599 100644 --- a/lib/mammoth/ipc/port_server.h +++ b/lib/mammoth/ipc/port_server.h @@ -18,6 +18,8 @@ class PortServer { glcr::ErrorCode RecvCap(uint64_t* num_bytes, char* msg, uint64_t* cap); glcr::ErrorCode PollForIntCap(uint64_t* msg, uint64_t* cap); + glcr::ErrorOr RecvChar(); + z_cap_t cap() { return port_cap_; } private: diff --git a/sys/teton/CMakeLists.txt b/sys/teton/CMakeLists.txt index bbc80eb..c8e05e6 100644 --- a/sys/teton/CMakeLists.txt +++ b/sys/teton/CMakeLists.txt @@ -13,6 +13,7 @@ target_link_libraries(teton glacier mammoth victoriafalls_yunq + voyageurs_yunq yellowstone_yunq ) diff --git a/sys/teton/teton.cpp b/sys/teton/teton.cpp index e0b4900..5c00071 100644 --- a/sys/teton/teton.cpp +++ b/sys/teton/teton.cpp @@ -1,6 +1,8 @@ +#include #include #include #include +#include #include #include "framebuffer/console.h" @@ -28,13 +30,33 @@ uint64_t main(uint64_t init_port) { Psf psf("/default8x16.psfu"); psf.DumpHeader(); + // 3. Write a line to the screen. Console console(fbuf, psf); console.WriteString("Hello World!\n"); for (uint8_t i = 0x20; i < 0x7E; i++) { console.WriteChar(i); } - // 3. Write a line to the screen. + GetEndpointRequest req; + req.set_endpoint_name("voyageurs"); + Endpoint endpoint; + RET_ERR(client.GetEndpoint(req, endpoint)); + + VoyageursClient voyaguers(endpoint.endpoint()); + ASSIGN_OR_RETURN(mmth::PortServer server, mmth::PortServer::Create()); + KeyboardListener listener; + ASSIGN_OR_RETURN(mmth::PortClient pclient, server.CreateClient()); + listener.set_port_capability(pclient.cap()); + None n; + RET_ERR(voyaguers.RegisterKeyboardListener(listener, n)); + + while (true) { + ASSIGN_OR_RETURN(char c, server.RecvChar()); + if (c != '\0') { + console.WriteChar(c); + dbgln("{}", c); + } + } return 0; } diff --git a/sys/voyageurs/keyboard/keyboard_driver.cpp b/sys/voyageurs/keyboard/keyboard_driver.cpp index 924d96a..8215e9e 100644 --- a/sys/voyageurs/keyboard/keyboard_driver.cpp +++ b/sys/voyageurs/keyboard/keyboard_driver.cpp @@ -2,6 +2,92 @@ #include +namespace { + +char ScancodeToChar(uint8_t code) { + switch (code) { + case 0x02: + return '1'; + case 0x03: + return '2'; + case 0x04: + return '3'; + case 0x05: + return '4'; + case 0x06: + return '5'; + case 0x07: + return '6'; + case 0x08: + return '7'; + case 0x09: + return '8'; + case 0x0A: + return '9'; + case 0x0B: + return '0'; + case 0x10: + return 'Q'; + case 0x11: + return 'W'; + case 0x12: + return 'E'; + case 0x13: + return 'R'; + case 0x14: + return 'T'; + case 0x15: + return 'Y'; + case 0x16: + return 'U'; + case 0x17: + return 'I'; + case 0x18: + return 'O'; + case 0x19: + return 'P'; + case 0x1E: + return 'A'; + case 0x1F: + return 'S'; + case 0x20: + return 'D'; + case 0x21: + return 'F'; + case 0x22: + return 'G'; + case 0x23: + return 'H'; + case 0x24: + return 'J'; + case 0x25: + return 'K'; + case 0x26: + return 'L'; + case 0x2C: + return 'Z'; + case 0x2D: + return 'X'; + case 0x2E: + return 'Y'; + case 0x2F: + return 'C'; + case 0x30: + return 'V'; + case 0x31: + return 'B'; + case 0x32: + return 'N'; + case 0x33: + return 'M'; + } + + dbgln("Unhandled scancode {x}", code); + return '\0'; +} + +} // namespace + void InterruptEnter(void* void_keyboard) { KeyboardDriver* keyboard = static_cast(void_keyboard); @@ -28,7 +114,7 @@ void KeyboardDriver::InterruptLoop() { dbgln("Scan {x}", scancode); for (mmth::PortClient& client : listeners_) { - client.WriteByte(scancode); + client.WriteByte(ScancodeToChar(scancode)); } } }