diff options
author | Marvin Borner | 2020-06-17 18:31:46 +0200 |
---|---|---|
committer | Marvin Borner | 2020-06-17 18:31:46 +0200 |
commit | eed77bd2970a00d1394ed027ceca5b646e4671ce (patch) | |
tree | c44643d98aed2b6818f2b33417c0dea9c5853094 /src/kernel/input | |
parent | 49dfa1f4021026bf7c4d77817959c8aa24067016 (diff) |
Started rewrite
Diffstat (limited to 'src/kernel/input')
-rw-r--r-- | src/kernel/input/input.h | 19 | ||||
-rw-r--r-- | src/kernel/input/ps2/keyboard.c | 46 | ||||
-rw-r--r-- | src/kernel/input/ps2/mouse.c | 172 |
3 files changed, 0 insertions, 237 deletions
diff --git a/src/kernel/input/input.h b/src/kernel/input/input.h deleted file mode 100644 index d387172..0000000 --- a/src/kernel/input/input.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef MELVIX_INPUT_H -#define MELVIX_INPUT_H - -#include <stdint.h> - -/** - * Initialize the mouse IRQ handler - */ -void mouse_install(); - -/** - * Initialize the us keyboard layout, - * keyboard rate and IRQ handler - */ -void keyboard_install(); - -char wait_scancode(); - -#endif
\ No newline at end of file diff --git a/src/kernel/input/ps2/keyboard.c b/src/kernel/input/ps2/keyboard.c deleted file mode 100644 index 60ec3df..0000000 --- a/src/kernel/input/ps2/keyboard.c +++ /dev/null @@ -1,46 +0,0 @@ -#include <common.h> -#include <events/event.h> -#include <graphics/vesa.h> -#include <input/input.h> -#include <interrupts/interrupts.h> -#include <io/io.h> -#include <lib/string.h> -#include <memory/alloc.h> - -u8 scancode; - -void keyboard_handler(struct regs *r) -{ - scancode = inb(0x60); - struct keyboard_event *event = malloc(sizeof(struct keyboard_event)); - event->scancode = scancode; - event_trigger(MAP_KEYBOARD, (u8 *)event); -} - -void keyboard_acknowledge() -{ - while (inb(0x60) != 0xfa) - ; -} - -void keyboard_rate() -{ - outb(0x60, 0xF3); - keyboard_acknowledge(); - outb(0x60, 0x0); // Rate{00000} Delay{00} 0 -} - -char wait_scancode() -{ - scancode = 0; - while (scancode == 0) { - }; - return scancode; -} - -void keyboard_install() -{ - keyboard_rate(); - irq_install_handler(1, keyboard_handler); - info("Installed keyboard handler"); -}
\ No newline at end of file diff --git a/src/kernel/input/ps2/mouse.c b/src/kernel/input/ps2/mouse.c deleted file mode 100644 index b86ca99..0000000 --- a/src/kernel/input/ps2/mouse.c +++ /dev/null @@ -1,172 +0,0 @@ -#include <common.h> -#include <events/event.h> -#include <graphics/vesa.h> -#include <interrupts/interrupts.h> -#include <io/io.h> -#include <lib/stdio.h> -#include <memory/alloc.h> - -char mouse_cycle = 0; -char mouse_byte[3]; -int mouse_x = 0; -int mouse_y = 0; -int mouse_but_1 = 0; -int mouse_but_2 = 0; -int mouse_but_3 = 0; - -struct mouse_event *event; - -void mouse_handler(struct regs *r) -{ - switch (mouse_cycle) { - case 0: - mouse_byte[0] = inb(0x60); - if (((mouse_byte[0] >> 3) & 1) == 1) - mouse_cycle++; - else - mouse_cycle = 0; - break; - case 1: - mouse_byte[1] = inb(0x60); - mouse_cycle++; - break; - case 2: - mouse_byte[2] = inb(0x60); - mouse_x += mouse_byte[1]; - mouse_y -= mouse_byte[2]; - mouse_but_1 = mouse_byte[0] & 1; - mouse_but_2 = (mouse_byte[0] >> 1) & 1; - mouse_but_3 = (mouse_byte[0] >> 2) & 1; - mouse_cycle = 0; - - if (mouse_x < 0) - mouse_x = 0; - if (mouse_y < 0) - mouse_y = 0; - if (mouse_x > vbe_width - 1) - mouse_x = vbe_width - 1; - if (mouse_y > vbe_height - 1) - mouse_y = vbe_height - 1; - // vesa_draw_cursor(mouse_x, mouse_y); - - event->mouse_x = mouse_x; - event->mouse_y = mouse_y; - event_trigger(MAP_MOUSE, (u8 *)event); - break; - default: - break; - } -} - -void mouse_wait(u8 a_type) -{ - u32 time_out = 100000; - if (a_type == 0) { - while (time_out--) - if ((inb(0x64) & 1) == 1) - return; - return; - } else { - while (time_out--) - if ((inb(0x64) & 2) == 0) - return; - return; - } -} - -void mouse_write(u8 a_write) -{ - mouse_wait(1); - outb(0x64, 0xD4); - mouse_wait(1); - outb(0x60, a_write); -} - -char mouse_read() -{ - mouse_wait(0); - return inb(0x60); -} - -void mouse_install() -{ - event = malloc(sizeof(struct mouse_event)); - u8 status; - - // Enable auxiliary mouse device - mouse_wait(1); - outb(0x64, 0xA8); - - // Enable interrupts - mouse_wait(1); - outb(0x64, 0x20); - mouse_wait(0); - status = (u8)(inb(0x60) | 3); - mouse_wait(1); - outb(0x64, 0x60); - mouse_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(); - if (status == 3) - log("Scrollwheel support!"); - - // 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(); - if (status == 4) - log("4th and 5th mouse button support!"); - - /* TODO: Fix mouse laggyness - mouse_write(0xE8); - mouse_read(); - mouse_write(0x03); - mouse_read(); - - mouse_write(0xF3); - mouse_read(); - mouse_write(200); - mouse_read(); */ - - // Enable mouse - mouse_write(0xF4); - mouse_read(); - - // Setup the mouse handler - irq_install_handler(12, mouse_handler); - info("Installed mouse handler"); -}
\ No newline at end of file |