From 462eaa9531b9e62916b02ab52759cd070de755d3 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Wed, 14 Apr 2021 14:34:38 +0200 Subject: Implemented some I/O interfaces --- kernel/drivers/ps2/mouse.c | 119 +++++---------------------------------------- 1 file changed, 11 insertions(+), 108 deletions(-) (limited to 'kernel/drivers/ps2/mouse.c') diff --git a/kernel/drivers/ps2/mouse.c b/kernel/drivers/ps2/mouse.c index 9b3fa2e..1d3c1ae 100644 --- a/kernel/drivers/ps2/mouse.c +++ b/kernel/drivers/ps2/mouse.c @@ -3,8 +3,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -14,7 +14,6 @@ #include PROTECTED static struct stack *queue = NULL; -PROTECTED static u32 dev_id = 0; static struct event_mouse *event = NULL; static char mouse_cycle = 0; @@ -52,46 +51,13 @@ static void mouse_handler(struct regs *r) } } -#define MOUSE_WAIT_OUT 0 -#define MOUSE_WAIT_IN 1 -CLEAR static void mouse_serial_wait(u8 in) -{ - u32 time_out = 100000; - if (in) { - while (time_out--) - if (ps2_read_status().in_full) - return; - return; - } else { - while (time_out--) - if (ps2_read_status().out_full) - return; - return; - } -} - -CLEAR static void mouse_serial_write(u8 data) -{ - mouse_serial_wait(MOUSE_WAIT_IN); - ps2_write_command(0xd4); - mouse_serial_wait(MOUSE_WAIT_IN); - ps2_write_data(data); -} - -CLEAR static u8 mouse_serial_read(void) -{ - mouse_serial_wait(MOUSE_WAIT_OUT); - return ps2_read_data(); -} - static res mouse_ready(void) { return !stack_empty(queue); } -static res mouse_read(void *buf, u32 offset, u32 count, struct vfs_dev *dev) +static res mouse_read(void *buf, u32 offset, u32 count) { - (void)dev; if (stack_empty(queue)) return -EINVAL; @@ -101,96 +67,33 @@ static res mouse_read(void *buf, u32 offset, u32 count, struct vfs_dev *dev) return MIN(count, sizeof(*e)); } -CLEAR void ps2_mouse_install(void) +CLEAR void ps2_mouse_install(u8 device) { u8 status; // Enable auxiliary mouse device - mouse_serial_wait(MOUSE_WAIT_IN); - ps2_write_command(0xa8); + ps2_write_device(device, 0xa8); // Enable interrupts - mouse_serial_wait(MOUSE_WAIT_IN); ps2_write_command(0x20); - mouse_serial_wait(MOUSE_WAIT_OUT); status = ps2_read_data() | 3; - mouse_serial_wait(MOUSE_WAIT_IN); ps2_write_command(0x60); - mouse_serial_wait(MOUSE_WAIT_IN); ps2_write_data(status); // Use default settings - mouse_serial_write(0xf6); - mouse_serial_read(); - - // Enable mousewheel - mouse_serial_write(0xf2); - mouse_serial_read(); - mouse_serial_read(); - mouse_serial_write(0xf3); - mouse_serial_read(); - mouse_serial_write(200); - mouse_serial_read(); - mouse_serial_write(0xf3); - mouse_serial_read(); - mouse_serial_write(100); - mouse_serial_read(); - mouse_serial_write(0xf3); - mouse_serial_read(); - mouse_serial_write(80); - mouse_serial_read(); - mouse_serial_write(0xf2); - mouse_serial_read(); - status = (u8)mouse_serial_read(); - if (status == 3) { - } - /* printf("Scrollwheel support!\n"); */ - - // Activate 4th and 5th mouse buttons - mouse_serial_write(0xf2); - mouse_serial_read(); - mouse_serial_read(); - mouse_serial_write(0xf3); - mouse_serial_read(); - mouse_serial_write(200); - mouse_serial_read(); - mouse_serial_write(0xf3); - mouse_serial_read(); - mouse_serial_write(200); - mouse_serial_read(); - mouse_serial_write(0xf3); - mouse_serial_read(); - mouse_serial_write(80); - mouse_serial_read(); - mouse_serial_write(0xf2); - mouse_serial_read(); - status = (u8)mouse_serial_read(); - if (status == 4) { - } - /* printf("4th and 5th mouse button support!\n"); */ - - /* TODO: Fix mouse laggyness - mouse_serial_write(0xE8); - mouse_serial_read(); - mouse_serial_write(0x03); - mouse_serial_read(); - mouse_serial_write(0xF3); - mouse_serial_read(); - mouse_serial_write(200); - mouse_serial_read(); */ + ps2_write_device(device, 0xf6); + ps2_read_data(); // Enable mouse - mouse_serial_write(0xf4); - mouse_serial_read(); + ps2_write_device(device, 0xf4); + ps2_read_data(); // Setup the mouse handler irq_install_handler(12, mouse_handler); queue = stack_new(); - struct vfs_dev *dev = zalloc(sizeof(*dev)); - dev->name = strdup("mouse"); - dev->type = DEV_CHAR; + struct io_dev *dev = zalloc(sizeof(*dev)); dev->read = mouse_read; - /* device_add(dev); */ - dev_id = dev->id; + dev->ready = mouse_ready; + io_add(IO_MOUSE, dev); } -- cgit v1.2.3