summaryrefslogtreecommitdiff
path: root/driver
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2018-09-28 00:29:02 +0200
committerMiguel <m.i@gmx.at>2018-09-28 00:29:02 +0200
commit9a29d452d03a63f39a80c0640b7747d8508568e2 (patch)
tree05adc15fac805f019af21107a7e3d84135f483f9 /driver
parentb3ec24b054fe36c7368048c3f1d0c46ed8fbb55e (diff)
moved mouse and kb, fixed mouse a bit
Diffstat (limited to 'driver')
-rw-r--r--driver/keyboard.c13
-rw-r--r--driver/keyboard.h4
-rw-r--r--driver/mouse.c89
-rw-r--r--driver/mouse.h15
-rw-r--r--driver/timer.c2
-rw-r--r--driver/vesa.c6
-rw-r--r--driver/vesa.h2
7 files changed, 79 insertions, 52 deletions
diff --git a/driver/keyboard.c b/driver/keyboard.c
index efbcc53..757bbb8 100644
--- a/driver/keyboard.c
+++ b/driver/keyboard.c
@@ -10,7 +10,7 @@
#include "net/inet.h"
-ringbuffer kb_in;
+static ringbuffer kb_in;
static bool ctrl_l=false;
static bool shift_l=false;
@@ -41,6 +41,17 @@ uint32_t keyboard_interrupt(uint32_t esp)
return esp;
}
+bool keyboard_worker()
+{
+ bool wake=false;
+ while(ringbuffer_has(&kb_in)){
+ keyboard_handle(ringbuffer_get(&kb_in));
+ wake=true;
+ }
+ return wake;
+}
+
+
void keyboard_init(uint32_t s)
{
kb_in=ringbuffer_init(1);// 4096 bytes ringbuffer;
diff --git a/driver/keyboard.h b/driver/keyboard.h
index 0e746ba..98f1f4e 100644
--- a/driver/keyboard.h
+++ b/driver/keyboard.h
@@ -5,5 +5,9 @@
// http://www.computer-engineering.org/ps2keyboard/scancodes1.html
// */
+
+#include <stdbool.h>
+
void keyboard_init(uint32_t s);
void keyboard_handle(uint8_t in);
+bool keyboard_worker();
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);
-}
diff --git a/driver/mouse.h b/driver/mouse.h
index 95bf088..77a93b8 100644
--- a/driver/mouse.h
+++ b/driver/mouse.h
@@ -1,2 +1,15 @@
-void mouse_handler();
+/**
+ * @file
+ *
+//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 <stdbool.h>
+
+void mouse_handler(uint8_t byte);
void mouse_init();
+bool mouse_worker();
diff --git a/driver/timer.c b/driver/timer.c
index 4b8f050..1c1fc05 100644
--- a/driver/timer.c
+++ b/driver/timer.c
@@ -149,7 +149,7 @@ static uint64_t get_rtc_time()
return epoch_seconds;
}
-uint32_t timer_interrupt(uint32_t esp)
+static uint32_t timer_interrupt(uint32_t esp)
{
asm_pit_tick();
return esp;
diff --git a/driver/vesa.c b/driver/vesa.c
index ba87e6d..848b0bf 100644
--- a/driver/vesa.c
+++ b/driver/vesa.c
@@ -1,6 +1,5 @@
#include "kernel/kernel.h"
#include "log.h"
-//http://wiki.osdev.org/GUI
#include <stdarg.h>
#include "kernel/mem.h"
@@ -8,9 +7,6 @@
#include "lib/printf/printf.h"
-
-//#define FOOLSOS_SHOW_VESAMODES
-
static foolfont *deffont;
//static vbemodeinfo *VbeModeInfoBlock;
@@ -78,7 +74,7 @@ void vesa_console_put_char(uint8_t c,uint8_t color_bg, uint8_t color_fg, uint32_
//PutFont(c, console_x*10,console_y*12, cols[color_fg],cols[color_bg]);
//PutFont(c, x*10,y*12, cols[color_bg],cols[color_fg]);
- PutFont(c, x*9,y*11, cols[color_bg],cols[color_fg]);
+ PutFont(c, x*8,y*11, cols[color_bg],cols[color_fg]);
// buf[console_x][console_y]=c;
diff --git a/driver/vesa.h b/driver/vesa.h
index f98e612..63fbd55 100644
--- a/driver/vesa.h
+++ b/driver/vesa.h
@@ -1,3 +1,5 @@
+//http://wiki.osdev.org/GUI
+
#include <stdint.h>
#include "lib/printf/printf.h"
#include "multiboot.h"