summaryrefslogtreecommitdiff
path: root/src/drivers/hdi/mouse.c
blob: 85d4c82d73a07d90e0a1721e72cbf24e28eb0baa (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
#include "mouse.h"

#include "string.h"
#include "kernel.h"

static mouse_vtable_t const mouse_vtable = {
	{
		mouse_activate,
		mouse_deactivate,
		mouse_deinit,
		mouse_print_info
	},
	mouse_set_resolution,
	mouse_set_position
};

void mouse_init( mouse_t *mouse, mouse_event_handler_t handler, interrupt_t *interrupt, void *context )
{
	memset( mouse, 0, sizeof( mouse_t ) );
	
	driver_init( (driver_t *)mouse, DRIVER_TYPE_MOUSE, interrupt, context );

	mouse->handler = handler;

	((driver_t *)mouse)->vtable = (driver_vtable_t *)&mouse_vtable;
}

void mouse_deinit( void *obj )
{
	// nothing to be done
}

void mouse_activate( void *obj )
{
	kernel_panic( "Activating generic mouse driver should not be called directly." );
}

void mouse_deactivate( void *obj )
{
	kernel_panic( "Deactivating generic mouse driver should not be called directly." );
}

void mouse_print_info( void *obj )
{
	kernel_panic( "Printing info of generic mouse driver should not be called directly." );
}

void mouse_set_resolution( void *obj, const uint32_t res_x, const uint32_t res_y )
{
	mouse_t *mouse = (mouse_t *)obj;
	
	mouse->res_x = res_x;
	mouse->res_y = res_y;
	mouse->cursor_x = mouse->res_x / 2;
	mouse->cursor_y = mouse->res_y / 2;
}

void mouse_set_position( void *obj, const uint32_t x, const uint32_t y )
{
	mouse_t *mouse = (mouse_t *)obj;

	mouse->cursor_x = x;
	mouse->cursor_y = y;
}