feat: partially implement PS/2 input subsystem with keyboard and mouse support
This implementation is incomplete, and doesn't work, but it will soon, to be determined, hopefully, uh, yknow. Signed-off-by kaguya <vpshinomiya@protonmail.com>
This commit is contained in:
+65
@@ -27,6 +27,8 @@
|
||||
#include "arch/x86_64/pci.h"
|
||||
#include "sound/hda.h"
|
||||
#include "sound/pcm.h"
|
||||
#include "arch/x86_64/ps2.h"
|
||||
#include "input/input.h"
|
||||
|
||||
|
||||
uintptr_t g_hhdm_offset;
|
||||
@@ -201,6 +203,7 @@ void kmain(void) {
|
||||
x86_64_ISR_Initialize();
|
||||
x86_64_IRQ_Initialize();
|
||||
x86_64_PIT_Initialize(1000);
|
||||
ps2_init();
|
||||
asm volatile("sti");
|
||||
calibrate_tsc();
|
||||
|
||||
@@ -446,6 +449,68 @@ void kmain(void) {
|
||||
//start_userspace();
|
||||
printf("tst");
|
||||
|
||||
printf("\n=== Input Subsystem Test ===\n");
|
||||
printf("Opening /dev/input/event0...\n");
|
||||
|
||||
fd_t input_fd = VFS_Open("/dev/input/event0");
|
||||
if (input_fd < 0) {
|
||||
printf("Failed to open /dev/input/event0!\n");
|
||||
} else {
|
||||
printf("Successfully opened /dev/input/event0 (fd=%d)\n", input_fd);
|
||||
printf("Press keys or move mouse... (press ESC to exit test)\n\n");
|
||||
|
||||
input_event_t ev;
|
||||
bool running = true;
|
||||
|
||||
while (running) {
|
||||
// Non-blocking read from the input device
|
||||
int bytes = VFS_Read(input_fd, (uint8_t*)&ev, sizeof(input_event_t));
|
||||
if (bytes == sizeof(input_event_t)) {
|
||||
switch (ev.type) {
|
||||
case INPUT_EV_KEY:
|
||||
printf("KEY: scancode=0x%02X ascii='%c' (%d) pressed=%s\n",
|
||||
ev.key.scancode,
|
||||
ev.key.ascii ? ev.key.ascii : '?',
|
||||
ev.key.ascii,
|
||||
ev.key.pressed ? "YES" : "NO");
|
||||
|
||||
// Exit test on ESC key release
|
||||
if (ev.key.scancode == 0x01 && !ev.key.pressed) {
|
||||
printf("ESC pressed - exiting input test.\n");
|
||||
running = false;
|
||||
}
|
||||
break;
|
||||
|
||||
case INPUT_EV_MOUSE_REL:
|
||||
if (ev.rel.dx || ev.rel.dy) {
|
||||
printf("MOUSE MOVE: dx=%d dy=%d\n", ev.rel.dx, ev.rel.dy);
|
||||
}
|
||||
break;
|
||||
|
||||
case INPUT_EV_MOUSE_BTN:
|
||||
printf("MOUSE BTN: button=%d pressed=%s\n",
|
||||
ev.btn.button,
|
||||
ev.btn.pressed ? "YES" : "NO");
|
||||
break;
|
||||
|
||||
case INPUT_EV_MOUSE_WHEEL:
|
||||
printf("MOUSE WHEEL: delta=%d\n", ev.wheel.delta);
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("Unknown event type %d\n", ev.type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Small yield so we don't spin the CPU too hard
|
||||
// (you can replace with a proper sleep later)
|
||||
asm volatile("pause");
|
||||
}
|
||||
|
||||
VFS_Close(input_fd);
|
||||
printf("Input test finished.\n");
|
||||
}
|
||||
|
||||
// We're done, just hang...
|
||||
hcf();
|
||||
|
||||
Reference in New Issue
Block a user