mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 15:08:21 +00:00
generic mouse interface
This commit is contained in:
@@ -91,6 +91,8 @@ void kmain(){
|
|||||||
|
|
||||||
keyboard_init();
|
keyboard_init();
|
||||||
|
|
||||||
|
mouse_init();
|
||||||
|
|
||||||
ps2_init();
|
ps2_init();
|
||||||
|
|
||||||
sched_runinit();
|
sched_runinit();
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#define MAJOR_FB 5
|
#define MAJOR_FB 5
|
||||||
#define MAJOR_KB 6
|
#define MAJOR_KB 6
|
||||||
#define MAJOR_E9OUT 7
|
#define MAJOR_E9OUT 7
|
||||||
|
#define MAJOR_MOUSE 8
|
||||||
|
|
||||||
typedef struct{
|
typedef struct{
|
||||||
int (*read)(int* error, int minor, void* buff, size_t count, size_t offset);
|
int (*read)(int* error, int minor, void* buff, size_t count, size_t offset);
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
#ifndef _MOUSE_H_INCLUDE
|
||||||
|
#define _MOUSE_H_INCLUDE
|
||||||
|
|
||||||
|
#define MOUSE_FLAG_RB 1
|
||||||
|
#define MOUSE_FLAG_MB 2
|
||||||
|
#define MOUSE_FLAG_LB 4
|
||||||
|
#define MOUSE_FLAG_B4 8
|
||||||
|
#define MOUSE_FLAG_B5 16
|
||||||
|
|
||||||
|
#include <ringbuffer.h>
|
||||||
|
#include <kernel/event.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int flags;
|
||||||
|
int x,y,z;
|
||||||
|
} mousepacket_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
ringbuffer_t buffer;
|
||||||
|
event_t event;
|
||||||
|
int flags;
|
||||||
|
} mouse_t;
|
||||||
|
|
||||||
|
void mouse_init();
|
||||||
|
int mouse_getnew();
|
||||||
|
void mouse_packet(int, mousepacket_t);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
#include <kernel/mouse.h>
|
||||||
|
#include <kernel/devman.h>
|
||||||
|
#include <arch/panic.h>
|
||||||
|
#include <poll.h>
|
||||||
|
#include <arch/interrupt.h>
|
||||||
|
|
||||||
|
#define MOUSE_COUNT 32
|
||||||
|
|
||||||
|
static int mouseinuse;
|
||||||
|
|
||||||
|
mouse_t mouse[MOUSE_COUNT];
|
||||||
|
ringbuffer_t devbuffer;
|
||||||
|
|
||||||
|
void mouse_packet(int id, mousepacket_t packet){
|
||||||
|
ringbuffer_write(&devbuffer, &packet, sizeof(mousepacket_t));
|
||||||
|
ringbuffer_write(&mouse[id].buffer, &packet, sizeof(mousepacket_t));
|
||||||
|
event_signal(&mouse[id].event, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
int mouse_getnew(){
|
||||||
|
|
||||||
|
int id;
|
||||||
|
|
||||||
|
for(id = 0; id < 32; ++id)
|
||||||
|
if(((mouseinuse >> id) & 1) == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if(id == 32)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
mouseinuse |= 1 << id;
|
||||||
|
|
||||||
|
return id;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static int read(int *error, int minor, void* buff, size_t count, size_t offset){
|
||||||
|
count /= sizeof(mousepacket_t);
|
||||||
|
if(count == 0){
|
||||||
|
*error = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
arch_interrupt_disable();
|
||||||
|
|
||||||
|
count = ringbuffer_read(&devbuffer, buff, count*sizeof(mousepacket_t));
|
||||||
|
|
||||||
|
arch_interrupt_enable();
|
||||||
|
|
||||||
|
*error = 0;
|
||||||
|
return count;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static int poll(int minor, pollfd* fd){
|
||||||
|
|
||||||
|
if((fd->events & POLLIN) && devbuffer.read != devbuffer.write)
|
||||||
|
fd->revents |= POLLIN;
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static devcalls calls = {
|
||||||
|
.read = read,
|
||||||
|
.poll = poll
|
||||||
|
};
|
||||||
|
|
||||||
|
void mouse_init(){
|
||||||
|
|
||||||
|
for(uintmax_t i = 0; i < MOUSE_COUNT; ++i){
|
||||||
|
if(ringbuffer_init(&mouse[i].buffer, sizeof(mousepacket_t)*100))
|
||||||
|
_panic("Out of memory!", NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ringbuffer_init(&devbuffer, sizeof(mousepacket_t)*100))
|
||||||
|
_panic("Out of memory", NULL);
|
||||||
|
|
||||||
|
if(devman_newdevice("mouse", TYPE_CHARDEV, MAJOR_MOUSE, 0, &calls))
|
||||||
|
_panic("Failed to create mouse device", NULL);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -278,7 +278,7 @@ static int poll(int minor, pollfd* fd){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
devcalls calls = {
|
static devcalls calls = {
|
||||||
read, write, isatty, isseekable, ioctl, poll
|
read, write, isatty, isseekable, ioctl, poll
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user