From ee3e51aa1624693217b1a4ae7bfb2730424c08f2 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Tue, 18 Jul 2017 21:23:22 +0200 Subject: added a virtual mouse driver interface, made the PS/2 mouse a specialization of it --- src/drivers/hdi/mouse.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/drivers/hdi/mouse.c (limited to 'src/drivers/hdi/mouse.c') diff --git a/src/drivers/hdi/mouse.c b/src/drivers/hdi/mouse.c new file mode 100644 index 0000000..85d4c82 --- /dev/null +++ b/src/drivers/hdi/mouse.c @@ -0,0 +1,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; +} + -- cgit v1.2.3-54-g00ecf