Ultibo API
C/C++ API for Ultibo Core
Loading...
Searching...
No Matches
mouse.h
Go to the documentation of this file.
1/*
2 * This file is part of the Ultibo project, https://ultibo.org/
3 *
4 * The MIT License (MIT)
5 *
6 * Copyright (c) 2026 Garry Wood <garry@softoz.com.au>
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
25 */
26#ifndef _ULTIBO_MOUSE_H
27#define _ULTIBO_MOUSE_H
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33#include "ultibo/globaltypes.h"
34#include "ultibo/globalconst.h"
35#include "ultibo/devices.h"
36
38#define MOUSE_NAME_PREFIX "Mouse"
39
41#define MOUSE_TYPE_NONE 0
42#define MOUSE_TYPE_USB 1
43#define MOUSE_TYPE_PS2 2
44#define MOUSE_TYPE_SERIAL 3
45
46#define MOUSE_TYPE_MAX 3
47
49#define MOUSE_STATE_DETACHED 0
50#define MOUSE_STATE_DETACHING 1
51#define MOUSE_STATE_ATTACHING 2
52#define MOUSE_STATE_ATTACHED 3
53
54#define MOUSE_STATE_MAX 3
55
57#define MOUSE_FLAG_NONE 0x00000000
58#define MOUSE_FLAG_NON_BLOCK 0x00000001
59#define MOUSE_FLAG_DIRECT_READ 0x00000002
60#define MOUSE_FLAG_SWAP_BUTTONS 0x00000004
61#define MOUSE_FLAG_PEEK_BUFFER 0x00000008
62#define MOUSE_FLAG_SWAP_XY 0x00000010
63#define MOUSE_FLAG_INVERT_X 0x00000020
64#define MOUSE_FLAG_INVERT_Y 0x00000040
65#define MOUSE_FLAG_SWAP_MAX_XY 0x00000080
66
68#define MOUSE_FLAG_MASK MOUSE_FLAG_NON_BLOCK | MOUSE_FLAG_DIRECT_READ | MOUSE_FLAG_SWAP_BUTTONS | MOUSE_FLAG_SWAP_XY | MOUSE_FLAG_INVERT_X | MOUSE_FLAG_INVERT_Y | MOUSE_FLAG_SWAP_MAX_XY
69
71#define MOUSE_CONTROL_GET_FLAG 1
72#define MOUSE_CONTROL_SET_FLAG 2
73#define MOUSE_CONTROL_CLEAR_FLAG 3
74#define MOUSE_CONTROL_FLUSH_BUFFER 4
75#define MOUSE_CONTROL_GET_SAMPLE_RATE 5
76#define MOUSE_CONTROL_SET_SAMPLE_RATE 6
77#define MOUSE_CONTROL_GET_MAX_X 7
78#define MOUSE_CONTROL_GET_MAX_Y 8
79#define MOUSE_CONTROL_GET_MAX_WHEEL 9
80#define MOUSE_CONTROL_GET_MAX_BUTTONS 10
81#define MOUSE_CONTROL_GET_ROTATION 11
82#define MOUSE_CONTROL_SET_ROTATION 12
83
85#define MOUSE_BUFFER_SIZE 512
86
88#define MOUSE_SAMPLE_RATE 100
89
91#define MOUSE_LEFT_BUTTON 0x0001
92#define MOUSE_RIGHT_BUTTON 0x0002
93#define MOUSE_MIDDLE_BUTTON 0x0004
94#define MOUSE_SIDE_BUTTON 0x0008
95#define MOUSE_EXTRA_BUTTON 0x0010
96#define MOUSE_TOUCH_BUTTON 0x0020
97#define MOUSE_ABSOLUTE_X 0x0040
98#define MOUSE_ABSOLUTE_Y 0x0080
99#define MOUSE_ABSOLUTE_WHEEL 0x0100
100
102#define MOUSE_ROTATION_0 FRAMEBUFFER_ROTATION_0
103#define MOUSE_ROTATION_90 FRAMEBUFFER_ROTATION_90
104#define MOUSE_ROTATION_180 FRAMEBUFFER_ROTATION_180
105#define MOUSE_ROTATION_270 FRAMEBUFFER_ROTATION_270
106
109
111#define USB_HID_SUBCLASS_NONE 0
112#define USB_HID_SUBCLASS_BOOT 1
113
115#define USB_HID_BOOT_PROTOCOL_NONE 0
116#define USB_HID_BOOT_PROTOCOL_KEYBOARD 1
117#define USB_HID_BOOT_PROTOCOL_MOUSE 2
118
120#define USB_HID_DESCRIPTOR_TYPE_HID 0x21
121#define USB_HID_DESCRIPTOR_TYPE_REPORT 0x22
122#define USB_HID_DESCRIPTOR_TYPE_PHYSICAL_DESCRIPTOR 0x23
123
125#define USB_HID_REQUEST_GET_REPORT 0x01
126#define USB_HID_REQUEST_GET_IDLE 0x02
127#define USB_HID_REQUEST_GET_PROTOCOL 0x03
128#define USB_HID_REQUEST_SET_REPORT 0x09
129#define USB_HID_REQUEST_SET_IDLE 0x0A
130#define USB_HID_REQUEST_SET_PROTOCOL 0x0B
131
133#define USB_HID_PROTOCOL_BOOT 0
134#define USB_HID_PROTOCOL_REPORT 1
135
137#define USB_HID_REPORT_INPUT 1
138#define USB_HID_REPORT_OUTPUT 2
139#define USB_HID_REPORT_FEATURE 3
140
142#define USB_HID_REPORTID_NONE 0
143
145#define USB_HID_BOOT_LEFT_BUTTON (1 << 0)
146#define USB_HID_BOOT_RIGHT_BUTTON (1 << 1)
147#define USB_HID_BOOT_MIDDLE_BUTTON (1 << 2)
148#define USB_HID_BOOT_SIDE_BUTTON (1 << 3)
149#define USB_HID_BOOT_EXTRA_BUTTON (1 << 4)
150
152#define USB_HID_BOOT_REPORT_SIZE 8
153#define USB_HID_BOOT_DATA_SIZE 8
154
157typedef struct _MOUSE_DATA MOUSE_DATA;
159{
160 uint16_t buttons;
161 int16_t offsetx;
162 int16_t offsety;
163 int16_t offsetwheel;
164 uint16_t maximumx;
165 uint16_t maximumy;
166 uint16_t maximumwheel;
167 uint16_t reserved;
168};
169
179
183{
184 uint32_t flags;
185 uint32_t rotation;
186 uint32_t maxx;
187 uint32_t maxy;
188 uint32_t maxwheel;
189 uint32_t maxbuttons;
190};
191
194
196typedef uint32_t STDCALL (*mouse_enumerate_cb)(MOUSE_DEVICE *mouse, void *data);
198typedef uint32_t STDCALL (*mouse_notification_cb)(DEVICE *device, void *data, uint32_t notification);
199
201typedef uint32_t STDCALL (*mouse_device_read_proc)(MOUSE_DEVICE *mouse, void *buffer, uint32_t size, uint32_t *count);
203typedef uint32_t STDCALL (*mouse_device_control_proc)(MOUSE_DEVICE *mouse, int request, size_t argument1, size_t *argument2);
204
206
231
234
235#ifndef _ULTIBO_KEYBOARD_H
239{
240 uint8_t blength;
241 uint8_t bdescriptortype;
242 uint16_t bcdhid;
243 uint8_t bcountrycode;
244 uint8_t bnumdescriptors;
245 uint8_t bhiddescriptortype;
246 uint16_t whiddescriptorlength;
247 // Note: Up to two optional bHIDDescriptorType/wHIDDescriptorLength pairs after the Report descriptor details
249#endif // _ULTIBO_KEYBOARD_H
250
252
257uint32_t STDCALL mouse_peek(void);
258
266uint32_t STDCALL mouse_read(void *buffer, uint32_t size, uint32_t *count);
267
276uint32_t STDCALL mouse_read_ex(void *buffer, uint32_t size, uint32_t flags, uint32_t *count);
277
285uint32_t STDCALL mouse_write(void *buffer, uint32_t size, uint32_t count);
286
291uint32_t STDCALL mouse_flush(void);
292
301uint32_t STDCALL mouse_device_read(MOUSE_DEVICE *mouse, void *buffer, uint32_t size, uint32_t *count);
302
310
319uint32_t STDCALL mouse_device_control(MOUSE_DEVICE *mouse, int request, size_t argument1, size_t *argument2);
320
328
335uint32_t STDCALL mouse_device_set_state(MOUSE_DEVICE *mouse, uint32_t state);
336
342
349
356
363
370
377
384
391
398uint32_t STDCALL mouse_device_enumerate(mouse_enumerate_cb callback, void *data);
399
408uint32_t STDCALL mouse_device_notification(MOUSE_DEVICE *mouse, mouse_notification_cb callback, void *data, uint32_t notification, uint32_t flags);
409
411
416
421
422uint32_t STDCALL mouse_device_type_to_string(uint32_t mousetype, char *string, uint32_t len);
423uint32_t STDCALL mouse_device_state_to_string(uint32_t mousestate, char *string, uint32_t len);
424
428uint32_t STDCALL mouse_device_rotation_to_string(uint32_t rotation, char *string, uint32_t len);
429
434
439uint32_t STDCALL mouse_device_resolve_rotation(uint32_t rotation);
440
449uint32_t STDCALL mouse_insert_data(MOUSE_DEVICE *mouse, MOUSE_DATA *data, BOOL signal);
450
451#ifdef __cplusplus
452}
453#endif
454
455#endif // _ULTIBO_MOUSE_H
struct _DEVICE DEVICE
Definition devices.h:373
#define STDCALL
Definition globaltypes.h:45
#define PACKED
Definition globaltypes.h:48
_Bool BOOL
Built in Boolean type (1 byte) (Redeclared here for flexibility).
Definition globaltypes.h:55
HANDLE SEMAPHORE_HANDLE
Definition globaltypes.h:107
HANDLE MUTEX_HANDLE
Definition globaltypes.h:105
struct _USB_HID_DESCRIPTOR USB_HID_DESCRIPTOR
Definition keyboard.h:248
uint32_t STDCALL mouse_device_register(MOUSE_DEVICE *mouse)
Register a new Mouse device in the Mouse table.
uint32_t STDCALL mouse_device_type_to_string(uint32_t mousetype, char *string, uint32_t len)
MOUSE_DEVICE *STDCALL mouse_device_create_ex(uint32_t size)
Create a new Mouse device entry.
uint32_t STDCALL mouse_device_get_properties(MOUSE_DEVICE *mouse, MOUSE_PROPERTIES *properties)
Get the properties for the specified mouse device.
MOUSE_DEVICE *STDCALL mouse_device_find_by_description(const char *description)
Find a mouse device by description in the mouse table.
uint32_t STDCALL mouse_device_rotation_to_string(uint32_t rotation, char *string, uint32_t len)
Return a string describing the supplied mouse rotation value.
uint32_t STDCALL mouse_flush(void)
Flush the contents of the global mouse buffer.
uint32_t STDCALL mouse_device_destroy(MOUSE_DEVICE *mouse)
Destroy an existing Mouse device entry.
uint32_t STDCALL mouse_insert_data(MOUSE_DEVICE *mouse, MOUSE_DATA *data, BOOL signal)
Insert a TMouseData entry into the mouse buffer (Direct or Global).
uint32_t STDCALL mouse_read(void *buffer, uint32_t size, uint32_t *count)
Read mouse data packets from the global mouse buffer.
struct _MOUSE_PROPERTIES MOUSE_PROPERTIES
Definition mouse.h:181
uint32_t STDCALL mouse_device_update(MOUSE_DEVICE *mouse)
Request the specified mouse device to update the current configuration.
uint32_t STDCALL(* mouse_notification_cb)(DEVICE *device, void *data, uint32_t notification)
Definition mouse.h:198
uint32_t STDCALL mouse_device_state_to_notification(uint32_t state)
Convert a Mouse state value into the notification code for device notifications.
uint32_t STDCALL mouse_peek(void)
Peek at the global mouse buffer to see if any data packets are ready.
uint32_t STDCALL mouse_device_state_to_string(uint32_t mousestate, char *string, uint32_t len)
MOUSE_DEVICE *STDCALL mouse_device_find_by_name(const char *name)
Find a mouse device by name in the mouse table.
uint32_t STDCALL mouse_device_set_state(MOUSE_DEVICE *mouse, uint32_t state)
Set the state of the specified mouse and send a notification.
uint32_t STDCALL(* mouse_device_update_proc)(MOUSE_DEVICE *mouse)
Definition mouse.h:202
uint32_t STDCALL mouse_device_deregister(MOUSE_DEVICE *mouse)
Deregister a Mouse device from the Mouse table.
uint32_t STDCALL mouse_get_count(void)
Get the current mouse count.
uint32_t STDCALL(* mouse_enumerate_cb)(MOUSE_DEVICE *mouse, void *data)
Definition mouse.h:196
MOUSE_DEVICE *STDCALL mouse_device_find(uint32_t mouseid)
Find a mouse device by ID in the mouse table.
#define MOUSE_BUFFER_SIZE
Definition mouse.h:85
MOUSE_DEVICE *STDCALL mouse_device_check(MOUSE_DEVICE *mouse)
Check if the supplied Mouse is in the mouse table.
uint32_t STDCALL mouse_read_ex(void *buffer, uint32_t size, uint32_t flags, uint32_t *count)
Read mouse data packets from the global mouse buffer.
uint32_t STDCALL mouse_device_notification(MOUSE_DEVICE *mouse, mouse_notification_cb callback, void *data, uint32_t notification, uint32_t flags)
Register a notification for mouse device changes.
uint32_t STDCALL(* mouse_device_read_proc)(MOUSE_DEVICE *mouse, void *buffer, uint32_t size, uint32_t *count)
Definition mouse.h:201
uint32_t STDCALL mouse_device_enumerate(mouse_enumerate_cb callback, void *data)
Enumerate all mouse devices in the mouse table.
uint32_t STDCALL mouse_device_control(MOUSE_DEVICE *mouse, int request, size_t argument1, size_t *argument2)
Perform a control request on the specified mouse device.
uint32_t STDCALL(* mouse_device_control_proc)(MOUSE_DEVICE *mouse, int request, size_t argument1, size_t *argument2)
Definition mouse.h:203
uint32_t STDCALL(* mouse_device_get_properties_proc)(MOUSE_DEVICE *mouse, MOUSE_PROPERTIES *properties)
Definition mouse.h:205
MOUSE_DEVICE *STDCALL mouse_device_create(void)
Create a new Mouse device entry.
struct _MOUSE_DATA MOUSE_DATA
Definition mouse.h:157
struct _MOUSE_BUFFER MOUSE_BUFFER
Definition mouse.h:171
struct _MOUSE_DEVICE MOUSE_DEVICE
Definition mouse.h:193
uint32_t STDCALL mouse_write(void *buffer, uint32_t size, uint32_t count)
Write mouse data packets to the global mouse buffer.
uint32_t STDCALL mouse_device_read(MOUSE_DEVICE *mouse, void *buffer, uint32_t size, uint32_t *count)
Read mouse data packets from the buffer of the specified mouse.
uint32_t STDCALL mouse_device_resolve_rotation(uint32_t rotation)
Resolve a value of 0, 90, 180 or 270 to a mouse rotation constant (eg MOUSE_ROTATION_180).
Definition mouse.h:173
MOUSE_DATA buffer[MOUSE_BUFFER_SIZE]
Definition mouse.h:177
uint32_t start
Index of first buffer ready.
Definition mouse.h:175
uint32_t count
Number of entries ready in buffer.
Definition mouse.h:176
SEMAPHORE_HANDLE wait
Buffer ready semaphore.
Definition mouse.h:174
Definition mouse.h:159
uint16_t maximumwheel
The maximum Wheel value of the mouse (Only applicable if Buttons includes MOUSE_ABSOLUTE_WHEEL,...
Definition mouse.h:166
int16_t offsetx
The X offset of the mouse pointer (May be negative, read as absolute if Buttons includes MOUSE_ABSOLU...
Definition mouse.h:161
uint16_t maximumx
The maximum X value of the mouse (Only applicable if Buttons includes MOUSE_ABSOLUTE_X,...
Definition mouse.h:164
uint16_t maximumy
The maximum Y value of the mouse (Only applicable if Buttons includes MOUSE_ABSOLUTE_Y,...
Definition mouse.h:165
uint16_t buttons
The bitmap of current button values (eg MOUSE_LEFT_BUTTON or MOUSE_RIGHT_BUTTON).
Definition mouse.h:160
uint16_t reserved
Reserved field (Round structure to 16 bytes).
Definition mouse.h:167
int16_t offsety
The Y offset of the mouse pointer (May be negative, read as absolute if Buttons includes MOUSE_ABSOLU...
Definition mouse.h:162
int16_t offsetwheel
The X offset of the mouse pointer (May be negative, read as absolute if Buttons includes MOUSE_ABSOLU...
Definition mouse.h:163
Definition mouse.h:208
MUTEX_HANDLE lock
Mouse lock.
Definition mouse.h:220
uint32_t receiveerrors
Definition mouse.h:225
uint32_t mouseid
Unique Id of this Mouse in the Mouse table.
Definition mouse.h:212
MOUSE_PROPERTIES properties
Device properties.
Definition mouse.h:222
uint32_t mousestate
Mouse state (eg MOUSE_STATE_ATTACHED).
Definition mouse.h:213
mouse_device_control_proc devicecontrol
A Device specific DeviceControl method implementing a standard Mouse device interface (Or nil if the ...
Definition mouse.h:217
DEVICE device
The Device entry for this Mouse.
Definition mouse.h:210
MOUSE_DEVICE * next
Next entry in Mouse table.
Definition mouse.h:229
uint32_t receivecount
Definition mouse.h:224
MOUSE_DEVICE * prev
Previous entry in Mouse table.
Definition mouse.h:228
MOUSE_BUFFER buffer
Mouse input buffer.
Definition mouse.h:221
mouse_device_get_properties_proc devicegetproperties
A Device specific DeviceGetProperties method implementing a standard Mouse device interface (Or nil i...
Definition mouse.h:218
mouse_device_update_proc deviceupdate
A Device specific DeviceUpdate method implementing a standard Mouse device interface (Or nil if the d...
Definition mouse.h:216
uint32_t mouserate
Mouse sample rate (Samples per second).
Definition mouse.h:214
uint32_t bufferoverruns
Definition mouse.h:226
mouse_device_read_proc deviceread
A Device specific DeviceRead method implementing a standard Mouse device interface (Or nil if the def...
Definition mouse.h:215
Definition mouse.h:183
uint32_t maxwheel
Maximum (absolute) wheel value for the mouse device.
Definition mouse.h:188
uint32_t maxx
Maximum (absolute) X value for the mouse device.
Definition mouse.h:186
uint32_t flags
Device flags (eg MOUSE_FLAG_SWAP_BUTTONS).
Definition mouse.h:184
uint32_t maxbuttons
Maximum buttons mask (eg MOUSE_LEFT_BUTTON or MOUSE_RIGHT_BUTTON etc).
Definition mouse.h:189
uint32_t maxy
Maximum (absolute) Y value for the mouse device.
Definition mouse.h:187
uint32_t rotation
Screen Rotation (eg MOUSE_ROTATION_180).
Definition mouse.h:185
Definition keyboard.h:250
uint16_t whiddescriptorlength
Definition keyboard.h:257
uint8_t bnumdescriptors
Definition keyboard.h:255
uint16_t bcdhid
Definition keyboard.h:253
uint8_t bdescriptortype
Definition keyboard.h:252
uint8_t bhiddescriptortype
Definition keyboard.h:256
uint8_t blength
Definition keyboard.h:251
uint8_t bcountrycode
Definition keyboard.h:254