summaryrefslogtreecommitdiff
path: root/src/drivers/hdi/ps2/mouse.h
blob: 1a00b5eeb299311f8e05b3729963602c22218e6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef MOUSE_H
#define MOUSE_H

#include "string.h"

#include "interrupts.h"
#include "port.h"

#include "driver.h"

#define MAX_NOF_MOUSE_PACKETS 5

typedef enum {
	MOUSE_EVENT_TYPE_BUTTON_UP,
	MOUSE_EVENT_TYPE_BUTTON_DOWN,
	MOUSE_EVENT_TYPE_MOVE
} mouse_event_type_t;

typedef enum {
	MOUSE_BUTTON_LEFT = 1,
	MOUSE_BUTTON_RIGHT = 2,
	MOUSE_BUTTON_MIDDLE = 3
} mouse_button_t;

typedef struct {
	mouse_event_type_t type;
	mouse_button_t button;
	int32_t old_cursor_x;
	int32_t old_cursor_y;
	int32_t cursor_x;
	int32_t cursor_y;
} mouse_event_t;

typedef void (*mouse_event_handler_t)( mouse_event_t *event, void *context );

typedef struct {
	driver_t base;
	interrupt_t *interrupts;
	port8_t command_port;
	port8_t data_port;
	int nof_packets;	// 3 or more mouse packets
	uint8_t buf[MAX_NOF_MOUSE_PACKETS];
	uint8_t buttons;
	uint8_t offset;
	uint32_t res_x;
	uint32_t res_y;
	int32_t cursor_x;
	int32_t cursor_y;
	mouse_event_handler_t handler;
	interrupt_handler_t interrupt_handler;
} mouse_t;

typedef struct {
	driver_vtable_t base;
} mouse_vtable_t;

void mouse_init( mouse_t *mouse, mouse_event_handler_t handler, interrupt_t *interrupt, void *context );
void mouse_activate( void *obj );
void mouse_deactivate( void *obj );
void mouse_deinit( void *obj );
void mouse_print_info( void *obj );

void mouse_set_resolution( mouse_t *mouse, const uint32_t x, const uint32_t y );
void mouse_set_position( mouse_t *mouse, const uint32_t x, const uint32_t y );

uint32_t mouse_handle_interrupt( interrupt_handler_t *handler, uint32_t esp );

#endif // MOUSE_H