diff options
| author | Miguel <m.i@gmx.at> | 2018-09-28 00:29:02 +0200 |
|---|---|---|
| committer | Miguel <m.i@gmx.at> | 2018-09-28 00:29:02 +0200 |
| commit | 9a29d452d03a63f39a80c0640b7747d8508568e2 (patch) | |
| tree | 05adc15fac805f019af21107a7e3d84135f483f9 /driver/mouse.c | |
| parent | b3ec24b054fe36c7368048c3f1d0c46ed8fbb55e (diff) | |
moved mouse and kb, fixed mouse a bit
Diffstat (limited to 'driver/mouse.c')
| -rw-r--r-- | driver/mouse.c | 89 |
1 files changed, 45 insertions, 44 deletions
diff --git a/driver/mouse.c b/driver/mouse.c index cebafed..0485096 100644 --- a/driver/mouse.c +++ b/driver/mouse.c @@ -1,3 +1,5 @@ +#include <stdint.h> + #include "mouse.h" #include "ringbuffer.h" @@ -5,24 +7,25 @@ #include "kernel/kernel.h" #include "log.h" #include "driver/vesa.h" - -//http://forum.osdev.org/viewtopic.php?t=10247 -//based on Mouse.inc by SANiK -//License: Use as you wish, except to cause damage - -#include <stdint.h> - #include "asm_x86.h" static volatile uint8_t mouse_cycle; static volatile uint8_t mouse_byte[3]; -volatile int16_t mouse_x; -volatile int16_t mouse_y; -static volatile uint8_t mouse_a; +static volatile int16_t mouse_x; +static volatile int16_t mouse_y; static ringbuffer mouse_in; -uint8_t mouse_read(); +bool mouse_worker() +{ + bool wake=false; + while(ringbuffer_has(&mouse_in)){ + mouse_handler(ringbuffer_get(&mouse_in)); + wake=true; + } + return wake; +} + void mouse_wait(uint8_t a_type) //unsigned char { @@ -51,6 +54,13 @@ void mouse_wait(uint8_t a_type) //unsigned char } } +static uint8_t mouse_read() +{ + //Get's response from mouse + mouse_wait(0); + return x86_inb(0x60); +} + static void mouse_write(uint8_t a_write) { //Wait to be able to send a command @@ -63,31 +73,17 @@ static void mouse_write(uint8_t a_write) x86_outb(0x60, a_write); } -int8_t mouse_get_x() -{ - return mouse_x; -} -int8_t mouse_get_y() -{ - return mouse_y; -} - uint32_t mouse_interrupt(uint32_t esp) { uint8_t b=x86_inb(0x60); ringbuffer_put(&mouse_in,b); - //klog("%d",b); return esp; } void mouse_init() { - interrupt_register(INTERRUPT_MOUSE,&mouse_interrupt); - mouse_in=ringbuffer_init(1);// 4096 bytes ringbuffer; - - mouse_x=mouse_y=0; - mouse_cycle=0; + mouse_in=ringbuffer_init(1);// 4096 bytes ringbuffer; uint8_t _status; //unsigned char @@ -112,18 +108,23 @@ void mouse_init() //Enable the mouse mouse_write(0xF4); mouse_read(); //Acknowledge - + + interrupt_register(INTERRUPT_MOUSE,&mouse_interrupt); } -void mouse_log() +// called as we filled the 3 bytes, everytime. +void mouse_action() { - //klog("%02x / %02x / %02x ",mouse_byte[0], mouse_byte[1],mouse_byte[2]); + //klog("mouse %02x / %02x / %02x ",mouse_byte[0], mouse_byte[1],mouse_byte[2]); //TODO: ignore last packet for 4packets mouse and resync if you get out of sync - if(mouse_byte[0]&0x80||mouse_byte[0]&0x40)return; //skip packet on overflow - if(!(mouse_byte[0]&0x8))kpanic("mouse packets out of sync!?"); // this bit is always 1, otherwise panic! + if(mouse_byte[0]&0x80||mouse_byte[0]&0x40) + { + klog("mouse overflow, skipping packet"); + return; //skip packet on overflow + } - // + //OOOMG!!// if(mouse_byte[1]>127){ mouse_x-=256; mouse_x+=mouse_byte[1]; @@ -132,6 +133,7 @@ void mouse_log() { mouse_x+=mouse_byte[1]; } + if(mouse_byte[2]>127){ mouse_y-=256; mouse_y+=mouse_byte[2]; @@ -153,35 +155,34 @@ void mouse_log() } -//Mouse functions -void mouse_handler()//struct regs *a_r) //struct regs *a_r (not used but just there) +void mouse_handler(uint8_t byte)//struct regs *a_r) //struct regs *a_r (not used but just there) { // X86_IRQ_BEGIN switch(mouse_cycle) { case 0: - mouse_byte[0]=x86_inb(0x60); + mouse_byte[0]=byte; mouse_cycle++; + if(!(mouse_byte[0]&0x8)) + { + klog("mouse out of sync, try resync"); + mouse_cycle--; + // kpanic("mouse packets out of sync!?"); // this bit is always 1, otherwise panic! + } break; case 1: - mouse_byte[1]=x86_inb(0x60); + mouse_byte[1]=byte; mouse_cycle++; break; case 2: - mouse_byte[2]=x86_inb(0x60); + mouse_byte[2]=byte; mouse_cycle=0; - mouse_log(); + mouse_action(); break; } // X86_IRQ_END } -uint8_t mouse_read() -{ - //Get's response from mouse - mouse_wait(0); - return x86_inb(0x60); -} |
