From db967b35d4c24000ef69283c2995010a08efb598 Mon Sep 17 00:00:00 2001 From: Michal Idziorek Date: Mon, 8 Sep 2014 22:14:26 +0200 Subject: working on mouse driver --- kernel/mouse.c | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 127 insertions(+), 1 deletion(-) (limited to 'kernel/mouse.c') diff --git a/kernel/mouse.c b/kernel/mouse.c index b6fd14d..de1e3bf 100644 --- a/kernel/mouse.c +++ b/kernel/mouse.c @@ -1,9 +1,135 @@ +//http://forum.osdev.org/viewtopic.php?t=10247 +//based on Mouse.inc by SANiK +//License: Use as you wish, except to cause damage + #define FOOLOS_MODULE_NAME "mouse" #include "lib/logger/log.h" +#include "lib/int/stdint.h" + +#include "x86.h" + + +static volatile uint8_t mouse_cycle; +static volatile int8_t mouse_byte[3]; +static volatile int8_t mouse_x; +static volatile int8_t mouse_y; + + +uint8_t mouse_read(); + +int8_t mouse_get_x() +{ + return mouse_x; +} +int8_t mouse_get_y() +{ + return mouse_y; +} void mouse_init() { - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"Initializing mouse driver"); + mouse_cycle=mouse_x=mouse_y=0; + + uint8_t _status; //unsigned char + + //Enable the auxiliary mouse device + mouse_wait(1); + x86_outb(0x64, 0xA8); + + //Enable the interrupts + mouse_wait(1); + x86_outb(0x64, 0x20); + mouse_wait(0); + _status=(x86_inb(0x60) | 2); + mouse_wait(1); + x86_outb(0x64, 0x60); + mouse_wait(1); + x86_outb(0x60, _status); + + //Tell the mouse to use default settings + mouse_write(0xF6); + mouse_read(); //Acknowledge + + //Enable the mouse + mouse_write(0xF4); + mouse_read(); //Acknowledge + + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Mouse Initialized"); + +} + +//Mouse functions +void mouse_handler()//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_cycle++; + break; + case 1: + mouse_byte[1]=x86_inb(0x60); + mouse_cycle++; + break; + case 2: + mouse_byte[2]=x86_inb(0x60); + mouse_x=mouse_byte[1]; + mouse_y=mouse_byte[2]; + mouse_cycle=0; + break; + + } + + //log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"irq12"); + + X86_IRQ_END +} +uint8_t mouse_read() +{ + //Get's response from mouse + mouse_wait(0); + return x86_inb(0x60); +} + +inline void mouse_write(uint8_t a_write) +{ + //Wait to be able to send a command + mouse_wait(1); + //Tell the mouse we are sending a command + x86_outb(0x64, 0xD4); + //Wait for the final part + mouse_wait(1); + //Finally write + x86_outb(0x60, a_write); +} + +inline void mouse_wait(uint8_t a_type) //unsigned char +{ + uint32_t _time_out=100000; //unsigned int + if(a_type==0) + { + while(_time_out--) //Data + { + if((x86_inb(0x64) & 1)==1) + { + return; + } + } + return; + } + else + { + while(_time_out--) //Signal + { + if((x86_inb(0x64) & 2)==0) + { + return; + } + } + return; + } } -- cgit v1.2.3