1 |
|
|
/*************************************************************************** |
2 |
|
|
* Copyright (c) 2024 Microsoft Corporation |
3 |
|
|
* |
4 |
|
|
* This program and the accompanying materials are made available under the |
5 |
|
|
* terms of the MIT License which is available at |
6 |
|
|
* https://opensource.org/licenses/MIT. |
7 |
|
|
* |
8 |
|
|
* SPDX-License-Identifier: MIT |
9 |
|
|
**************************************************************************/ |
10 |
|
|
|
11 |
|
|
|
12 |
|
|
/**************************************************************************/ |
13 |
|
|
/**************************************************************************/ |
14 |
|
|
/** */ |
15 |
|
|
/** USBX Component */ |
16 |
|
|
/** */ |
17 |
|
|
/** HID Mouse Client Class */ |
18 |
|
|
/** */ |
19 |
|
|
/**************************************************************************/ |
20 |
|
|
/**************************************************************************/ |
21 |
|
|
|
22 |
|
|
|
23 |
|
|
/* Include necessary system files. */ |
24 |
|
|
|
25 |
|
|
#define UX_SOURCE_CODE |
26 |
|
|
|
27 |
|
|
#include "ux_api.h" |
28 |
|
|
#include "ux_host_class_hid.h" |
29 |
|
|
#include "ux_host_class_hid_mouse.h" |
30 |
|
|
#include "ux_host_stack.h" |
31 |
|
|
|
32 |
|
|
|
33 |
|
|
/**************************************************************************/ |
34 |
|
|
/* */ |
35 |
|
|
/* FUNCTION RELEASE */ |
36 |
|
|
/* */ |
37 |
|
|
/* _ux_host_class_hid_mouse_callback PORTABLE C */ |
38 |
|
|
/* 6.1 */ |
39 |
|
|
/* AUTHOR */ |
40 |
|
|
/* */ |
41 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
42 |
|
|
/* */ |
43 |
|
|
/* DESCRIPTION */ |
44 |
|
|
/* */ |
45 |
|
|
/* This function is the callback mechanism for a report registration. */ |
46 |
|
|
/* For the mouse, we filter the mouse coordinate changes and the */ |
47 |
|
|
/* state of the buttons. */ |
48 |
|
|
/* */ |
49 |
|
|
/* INPUT */ |
50 |
|
|
/* */ |
51 |
|
|
/* callback Pointer to callback */ |
52 |
|
|
/* */ |
53 |
|
|
/* OUTPUT */ |
54 |
|
|
/* */ |
55 |
|
|
/* None */ |
56 |
|
|
/* */ |
57 |
|
|
/* CALLS */ |
58 |
|
|
/* */ |
59 |
|
|
/* None */ |
60 |
|
|
/* */ |
61 |
|
|
/* CALLED BY */ |
62 |
|
|
/* */ |
63 |
|
|
/* HID Class */ |
64 |
|
|
/* */ |
65 |
|
|
/* RELEASE HISTORY */ |
66 |
|
|
/* */ |
67 |
|
|
/* DATE NAME DESCRIPTION */ |
68 |
|
|
/* */ |
69 |
|
|
/* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ |
70 |
|
|
/* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ |
71 |
|
|
/* resulting in version 6.1 */ |
72 |
|
|
/* */ |
73 |
|
|
/**************************************************************************/ |
74 |
|
336 |
VOID _ux_host_class_hid_mouse_callback(UX_HOST_CLASS_HID_REPORT_CALLBACK *callback) |
75 |
|
|
{ |
76 |
|
|
|
77 |
|
|
UX_HOST_CLASS_HID_CLIENT *hid_client; |
78 |
|
|
UX_HOST_CLASS_HID_MOUSE *mouse_instance; |
79 |
|
|
|
80 |
|
|
/* Get the HID client instance that issued the callback. */ |
81 |
|
336 |
hid_client = callback -> ux_host_class_hid_report_callback_client; |
82 |
|
|
|
83 |
|
|
/* Get the mouse local instance */ |
84 |
|
336 |
mouse_instance = (UX_HOST_CLASS_HID_MOUSE *) hid_client -> ux_host_class_hid_client_local_instance; |
85 |
|
|
|
86 |
|
|
/* Analyze the usage we have received. */ |
87 |
✓✓✓✓ ✓✓✓ |
336 |
switch (callback -> ux_host_class_hid_report_callback_usage) |
88 |
|
|
{ |
89 |
|
|
|
90 |
|
|
|
91 |
|
|
/* X/Y Axis movement. */ |
92 |
|
48 |
case UX_HOST_CLASS_HID_MOUSE_AXIS_X : |
93 |
|
|
|
94 |
|
|
/* Add the deplacement to the position. */ |
95 |
|
48 |
mouse_instance -> ux_host_class_hid_mouse_x_position += (SCHAR) callback -> ux_host_class_hid_report_callback_value; |
96 |
|
|
|
97 |
|
48 |
break; |
98 |
|
|
|
99 |
|
48 |
case UX_HOST_CLASS_HID_MOUSE_AXIS_Y : |
100 |
|
|
|
101 |
|
|
/* Add the deplacement to the position. */ |
102 |
|
48 |
mouse_instance -> ux_host_class_hid_mouse_y_position += (SCHAR) callback -> ux_host_class_hid_report_callback_value; |
103 |
|
48 |
break; |
104 |
|
|
|
105 |
|
|
/* Buttons. */ |
106 |
|
48 |
case UX_HOST_CLASS_HID_MOUSE_BUTTON_1 : |
107 |
|
|
|
108 |
|
|
/* Check the state of button 1. */ |
109 |
✓✓ |
48 |
if (callback -> ux_host_class_hid_report_callback_value == UX_TRUE) |
110 |
|
24 |
mouse_instance -> ux_host_class_hid_mouse_buttons |= UX_HOST_CLASS_HID_MOUSE_BUTTON_1_PRESSED; |
111 |
|
|
else |
112 |
|
24 |
mouse_instance -> ux_host_class_hid_mouse_buttons &= (ULONG)~UX_HOST_CLASS_HID_MOUSE_BUTTON_1_PRESSED; |
113 |
|
48 |
break; |
114 |
|
|
|
115 |
|
48 |
case UX_HOST_CLASS_HID_MOUSE_BUTTON_2 : |
116 |
|
|
|
117 |
|
|
/* Check the state of button 2. */ |
118 |
✓✓ |
48 |
if (callback -> ux_host_class_hid_report_callback_value == UX_TRUE) |
119 |
|
24 |
mouse_instance -> ux_host_class_hid_mouse_buttons |= UX_HOST_CLASS_HID_MOUSE_BUTTON_2_PRESSED; |
120 |
|
|
else |
121 |
|
24 |
mouse_instance -> ux_host_class_hid_mouse_buttons &= (ULONG)~UX_HOST_CLASS_HID_MOUSE_BUTTON_2_PRESSED; |
122 |
|
48 |
break; |
123 |
|
|
|
124 |
|
48 |
case UX_HOST_CLASS_HID_MOUSE_BUTTON_3 : |
125 |
|
|
|
126 |
|
|
/* Check the state of button 3. */ |
127 |
✓✓ |
48 |
if (callback -> ux_host_class_hid_report_callback_value == UX_TRUE) |
128 |
|
24 |
mouse_instance -> ux_host_class_hid_mouse_buttons |= UX_HOST_CLASS_HID_MOUSE_BUTTON_3_PRESSED; |
129 |
|
|
else |
130 |
|
24 |
mouse_instance -> ux_host_class_hid_mouse_buttons &= (ULONG)~UX_HOST_CLASS_HID_MOUSE_BUTTON_3_PRESSED; |
131 |
|
48 |
break; |
132 |
|
|
|
133 |
|
|
|
134 |
|
|
/* Wheel movement. */ |
135 |
|
48 |
case UX_HOST_CLASS_HID_MOUSE_WHEEL : |
136 |
|
|
|
137 |
|
48 |
mouse_instance -> ux_host_class_hid_mouse_wheel += (SCHAR) callback -> ux_host_class_hid_report_callback_value; |
138 |
|
|
|
139 |
|
48 |
break; |
140 |
|
|
|
141 |
|
48 |
default : |
142 |
|
|
|
143 |
|
|
/* We have received a Usage we don't know about. Ignore it. */ |
144 |
|
48 |
break; |
145 |
|
|
} |
146 |
|
|
|
147 |
|
|
/* Return to caller. */ |
148 |
|
336 |
return; |
149 |
|
|
} |
150 |
|
|
|