aboutsummaryrefslogtreecommitdiff
path: root/kernel/drivers
diff options
context:
space:
mode:
authorMarvin Borner2021-01-21 17:04:15 +0100
committerMarvin Borner2021-01-21 17:04:15 +0100
commitb3fafef621bb4404208e65ff1f78e15da3b216f7 (patch)
tree6f1c610b816f574c77615cb03d5507a4281411dd /kernel/drivers
parentef407d1e965674c5278daeb25a72acf446ec3223 (diff)
Implementing new features...
Diffstat (limited to 'kernel/drivers')
-rw-r--r--kernel/drivers/keyboard.c4
-rw-r--r--kernel/drivers/mouse.c146
2 files changed, 90 insertions, 60 deletions
diff --git a/kernel/drivers/keyboard.c b/kernel/drivers/keyboard.c
index 744ca99..054849c 100644
--- a/kernel/drivers/keyboard.c
+++ b/kernel/drivers/keyboard.c
@@ -71,12 +71,12 @@ u32 keyboard_read(void *buf, u32 offset, u32 count, struct device *dev)
return count;
}
-u32 keyboard_ready()
+u32 keyboard_ready(void)
{
return !stack_empty(queue);
}
-void keyboard_reset()
+void keyboard_reset(void)
{
stack_clear(queue);
}
diff --git a/kernel/drivers/mouse.c b/kernel/drivers/mouse.c
index f70fb6a..99fb80b 100644
--- a/kernel/drivers/mouse.c
+++ b/kernel/drivers/mouse.c
@@ -2,13 +2,18 @@
#include <boot.h>
#include <cpu.h>
+#include <fs.h>
#include <interrupts.h>
#include <mem.h>
#include <print.h>
+#include <stack.h>
+#include <str.h>
#include <sys.h>
static char mouse_cycle = 0;
static char mouse_byte[3] = { 0 };
+static struct stack *queue = NULL;
+static u32 dev_id = 0;
static struct event_mouse *event = NULL;
@@ -38,7 +43,7 @@ void mouse_handler()
event->but1 = mouse_byte[0] & 1;
event->but2 = (mouse_byte[0] >> 1) & 1;
event->but3 = (mouse_byte[0] >> 2) & 1;
- //event_trigger(EVENT_MOUSE, event);
+ stack_push_bot(queue, event);
mouse_cycle = 0;
break;
@@ -47,7 +52,7 @@ void mouse_handler()
}
}
-void mouse_wait(u8 a_type)
+void mouse_serial_wait(u8 a_type)
{
u32 time_out = 100000;
if (a_type == 0) {
@@ -63,96 +68,121 @@ void mouse_wait(u8 a_type)
}
}
-void mouse_write(u8 a_write)
+void mouse_serial_write(u8 a_write)
{
- mouse_wait(1);
+ mouse_serial_wait(1);
outb(0x64, 0xD4);
- mouse_wait(1);
+ mouse_serial_wait(1);
outb(0x60, a_write);
}
-u8 mouse_read(void)
+u8 mouse_serial_read(void)
{
- mouse_wait(0);
+ mouse_serial_wait(0);
return inb(0x60);
}
+u32 mouse_ready(void)
+{
+ return !stack_empty(queue);
+}
+
+u32 mouse_read(void *buf, u32 offset, u32 count, struct device *dev)
+{
+ (void)dev;
+ if (stack_empty(queue))
+ return 0;
+
+ struct event *e = stack_pop(queue);
+ memcpy(buf, (u8 *)e + offset, count);
+ return count;
+}
+
void mouse_install(void)
{
u8 status;
// Enable auxiliary mouse device
- mouse_wait(1);
+ mouse_serial_wait(1);
outb(0x64, 0xA8);
// Enable interrupts
- mouse_wait(1);
+ mouse_serial_wait(1);
outb(0x64, 0x20);
- mouse_wait(0);
+ mouse_serial_wait(0);
status = (u8)(inb(0x60) | 3);
- mouse_wait(1);
+ mouse_serial_wait(1);
outb(0x64, 0x60);
- mouse_wait(1);
+ mouse_serial_wait(1);
outb(0x60, status);
// Enable mousewheel
- mouse_write(0xF2);
- mouse_read();
- mouse_read();
- mouse_write(0xF3);
- mouse_read();
- mouse_write(200);
- mouse_read();
- mouse_write(0xF3);
- mouse_read();
- mouse_write(100);
- mouse_read();
- mouse_write(0xF3);
- mouse_read();
- mouse_write(80);
- mouse_read();
- mouse_write(0xF2);
- mouse_read();
- status = (u8)mouse_read();
+ 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_write(0xF2);
- mouse_read();
- mouse_read();
- mouse_write(0xF3);
- mouse_read();
- mouse_write(200);
- mouse_read();
- mouse_write(0xF3);
- mouse_read();
- mouse_write(200);
- mouse_read();
- mouse_write(0xF3);
- mouse_read();
- mouse_write(80);
- mouse_read();
- mouse_write(0xF2);
- mouse_read();
- status = (u8)mouse_read();
+ 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_write(0xE8);
- mouse_read();
- mouse_write(0x03);
- mouse_read();
- mouse_write(0xF3);
- mouse_read();
- mouse_write(200);
- mouse_read(); */
+ 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(); */
// Enable mouse
- mouse_write(0xF4);
- mouse_read();
+ mouse_serial_write(0xF4);
+ mouse_serial_read();
// Setup the mouse handler
irq_install_handler(12, mouse_handler);
+
+ queue = stack_new();
+ struct device *dev = malloc(sizeof(*dev));
+ dev->name = strdup("mouse");
+ dev->type = DEV_CHAR;
+ dev->read = mouse_read;
+ dev->ready = mouse_ready;
+ device_add(dev);
+ dev_id = dev->id;
}