From 9a43ead118ec1506848bad9d2bcddfb0fd458552 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Sun, 7 Aug 2022 22:07:27 +0200 Subject: kernel: ps2 mouse support --- src/user/app/mousedump/mousedump.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/user/app/mousedump/mousedump.c (limited to 'src/user') diff --git a/src/user/app/mousedump/mousedump.c b/src/user/app/mousedump/mousedump.c new file mode 100644 index 0000000..04331a3 --- /dev/null +++ b/src/user/app/mousedump/mousedump.c @@ -0,0 +1,32 @@ +#include +#include +#include +#include + +static uint8_t r_buf[64]; +static ring_t r = {(void*)r_buf, sizeof r_buf, 0, 0}; + +struct packet { + uint8_t stuff; + int8_t dx, dy; +} __attribute__((packed)); + +int main(void) { + char buf[64]; + handle_t fd = _syscall_open("/kdev/ps2/mouse", 15, 0); + if (fd < 0) { + fprintf(stderr, "couldn't open mouse\n"); + exit(1); + } + for (;;) { + int len = _syscall_read(fd, buf, sizeof buf, 0); + if (len == 0) break; + ring_put(&r, buf, len); + while (ring_size(&r) >= 3) { + struct packet p; + ring_get(&r, &p, sizeof p); + printf("%4d %4d\n", p.dx, p.dy); + } + } + return 0; +} -- cgit v1.2.3