1 |
|
|
/*************************************************************************** |
2 |
|
|
* Copyright (c) 2024 Microsoft Corporation |
3 |
|
|
* Copyright (c) 2026-present Eclipse ThreadX contributors |
4 |
|
|
* |
5 |
|
|
* This program and the accompanying materials are made available under the |
6 |
|
|
* terms of the MIT License which is available at |
7 |
|
|
* https://opensource.org/licenses/MIT. |
8 |
|
|
* |
9 |
|
|
* SPDX-License-Identifier: MIT |
10 |
|
|
**************************************************************************/ |
11 |
|
|
|
12 |
|
|
|
13 |
|
|
/**************************************************************************/ |
14 |
|
|
/**************************************************************************/ |
15 |
|
|
/** */ |
16 |
|
|
/** USBX Component */ |
17 |
|
|
/** */ |
18 |
|
|
/** HID Mouse Client Class */ |
19 |
|
|
/** */ |
20 |
|
|
/**************************************************************************/ |
21 |
|
|
/**************************************************************************/ |
22 |
|
|
|
23 |
|
|
|
24 |
|
|
/* Include necessary system files. */ |
25 |
|
|
|
26 |
|
|
#define UX_SOURCE_CODE |
27 |
|
|
|
28 |
|
|
#include "ux_api.h" |
29 |
|
|
#include "ux_host_class_hid.h" |
30 |
|
|
#include "ux_host_class_hid_mouse.h" |
31 |
|
|
#include "ux_host_stack.h" |
32 |
|
|
|
33 |
|
|
|
34 |
|
|
/**************************************************************************/ |
35 |
|
|
/* */ |
36 |
|
|
/* FUNCTION RELEASE */ |
37 |
|
|
/* */ |
38 |
|
|
/* _ux_host_class_hid_mouse_activate PORTABLE C */ |
39 |
|
|
/* 6.1.11 */ |
40 |
|
|
/* AUTHOR */ |
41 |
|
|
/* */ |
42 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
43 |
|
|
/* */ |
44 |
|
|
/* DESCRIPTION */ |
45 |
|
|
/* */ |
46 |
|
|
/* This function performs the enumeration of a HID mouse. */ |
47 |
|
|
/* */ |
48 |
|
|
/* INPUT */ |
49 |
|
|
/* */ |
50 |
|
|
/* command Pointer to command */ |
51 |
|
|
/* */ |
52 |
|
|
/* OUTPUT */ |
53 |
|
|
/* */ |
54 |
|
|
/* Completion Status */ |
55 |
|
|
/* */ |
56 |
|
|
/* CALLS */ |
57 |
|
|
/* */ |
58 |
|
|
/* _ux_host_class_hid_idle_set Set idle rate */ |
59 |
|
|
/* _ux_host_class_hid_report_callback_register */ |
60 |
|
|
/* Register report callback */ |
61 |
|
|
/* _ux_host_class_hid_report_id_get Get report ID */ |
62 |
|
|
/* _ux_host_class_hid_periodic_report_start */ |
63 |
|
|
/* Start periodic report */ |
64 |
|
|
/* _ux_utility_memory_allocate Allocate memory block */ |
65 |
|
|
/* _ux_utility_memory_free Free memory block */ |
66 |
|
|
/* */ |
67 |
|
|
/* CALLED BY */ |
68 |
|
|
/* */ |
69 |
|
|
/* HID Mouse Class */ |
70 |
|
|
/* */ |
71 |
|
|
/**************************************************************************/ |
72 |
|
51 |
UINT _ux_host_class_hid_mouse_activate(UX_HOST_CLASS_HID_CLIENT_COMMAND *command) |
73 |
|
|
{ |
74 |
|
|
|
75 |
|
|
#if !defined(UX_HOST_STANDALONE) |
76 |
|
|
UX_HOST_CLASS_HID_REPORT_CALLBACK call_back; |
77 |
|
|
#endif |
78 |
|
|
UX_HOST_CLASS_HID_REPORT_GET_ID report_id; |
79 |
|
|
UX_HOST_CLASS_HID *hid; |
80 |
|
|
UX_HOST_CLASS_HID_CLIENT *hid_client; |
81 |
|
|
UX_HOST_CLASS_HID_CLIENT_MOUSE *client_mouse; |
82 |
|
|
UX_HOST_CLASS_HID_MOUSE *mouse_instance; |
83 |
|
|
UINT status; |
84 |
|
|
|
85 |
|
|
|
86 |
|
|
/* Get the instance to the HID class. */ |
87 |
|
51 |
hid = command -> ux_host_class_hid_client_command_instance; |
88 |
|
|
|
89 |
|
|
/* Get some memory for both the HID class instance and copy of this client |
90 |
|
|
and for the callback. */ |
91 |
|
|
client_mouse = (UX_HOST_CLASS_HID_CLIENT_MOUSE *) |
92 |
|
51 |
_ux_utility_memory_allocate(UX_NO_ALIGN, UX_REGULAR_MEMORY, |
93 |
|
|
sizeof(UX_HOST_CLASS_HID_CLIENT_MOUSE)); |
94 |
✓✓ |
51 |
if(client_mouse == UX_NULL) |
95 |
|
2 |
return(UX_MEMORY_INSUFFICIENT); |
96 |
|
|
|
97 |
|
|
/* Get client and mouse instance. */ |
98 |
|
49 |
mouse_instance = &client_mouse -> ux_host_class_hid_client_mouse_mouse; |
99 |
|
49 |
hid_client = &client_mouse -> ux_host_class_hid_client_mouse_client; |
100 |
|
49 |
_ux_utility_memory_copy(hid_client, hid -> ux_host_class_hid_client, sizeof(UX_HOST_CLASS_HID_CLIENT)); /* Use case of memcpy is verified. */ |
101 |
|
|
|
102 |
|
|
/* Attach the mouse instance to the client instance. */ |
103 |
|
49 |
hid_client -> ux_host_class_hid_client_local_instance = (VOID *) mouse_instance; |
104 |
|
|
|
105 |
|
|
/* Save the HID instance in the client instance. */ |
106 |
|
49 |
mouse_instance -> ux_host_class_hid_mouse_hid = hid; |
107 |
|
|
|
108 |
|
|
#if defined(UX_HOST_STANDALONE) |
109 |
|
|
|
110 |
|
|
/* The instance is mounting now. */ |
111 |
|
|
mouse_instance -> ux_host_class_hid_mouse_state = UX_HOST_CLASS_INSTANCE_MOUNTING; |
112 |
|
|
|
113 |
|
|
/* Get the report ID for the mouse. The mouse is a INPUT report. |
114 |
|
|
This should be 0 but in case. */ |
115 |
|
|
report_id.ux_host_class_hid_report_get_report = UX_NULL; |
116 |
|
|
report_id.ux_host_class_hid_report_get_type = UX_HOST_CLASS_HID_REPORT_TYPE_INPUT; |
117 |
|
|
status = _ux_host_class_hid_report_id_get(hid, &report_id); |
118 |
|
|
|
119 |
|
|
/* The report ID should exist. */ |
120 |
|
|
if (status == UX_SUCCESS) |
121 |
|
|
{ |
122 |
|
|
|
123 |
|
|
/* Save the mouse report ID. */ |
124 |
|
|
mouse_instance -> ux_host_class_hid_mouse_id = (USHORT)report_id.ux_host_class_hid_report_get_id; |
125 |
|
|
|
126 |
|
|
/* Set state for activate wait steps. */ |
127 |
|
|
mouse_instance -> ux_host_class_hid_mouse_enum_state = UX_STATE_WAIT; |
128 |
|
|
|
129 |
|
|
} |
130 |
|
|
|
131 |
|
|
/* Use our copy of client. */ |
132 |
|
|
hid -> ux_host_class_hid_client = hid_client; |
133 |
|
|
return(status); |
134 |
|
|
#else |
135 |
|
|
|
136 |
|
|
/* The instance is live now. */ |
137 |
|
49 |
mouse_instance -> ux_host_class_hid_mouse_state = UX_HOST_CLASS_INSTANCE_LIVE; |
138 |
|
|
|
139 |
|
|
/* Get the report ID for the mouse. The mouse is a INPUT report. |
140 |
|
|
This should be 0 but in case. */ |
141 |
|
49 |
report_id.ux_host_class_hid_report_get_report = UX_NULL; |
142 |
|
49 |
report_id.ux_host_class_hid_report_get_type = UX_HOST_CLASS_HID_REPORT_TYPE_INPUT; |
143 |
|
49 |
status = _ux_host_class_hid_report_id_get(hid, &report_id); |
144 |
|
|
|
145 |
|
|
/* The report ID should exist. */ |
146 |
✓✓ |
49 |
if (status == UX_SUCCESS) |
147 |
|
|
{ |
148 |
|
|
|
149 |
|
|
/* Save the mouse report ID. */ |
150 |
|
47 |
mouse_instance -> ux_host_class_hid_mouse_id = (USHORT)report_id.ux_host_class_hid_report_get_id; |
151 |
|
|
|
152 |
|
|
/* Set the idle rate of the mouse to 0. This way a report is generated only when there is an activity. */ |
153 |
|
47 |
status = _ux_host_class_hid_idle_set(hid, 0, mouse_instance -> ux_host_class_hid_mouse_id); |
154 |
|
|
|
155 |
|
|
/* Check for error, accept protocol error since it's optional for mouse. */ |
156 |
✓✓ |
47 |
if (status == UX_TRANSFER_STALLED) |
157 |
|
1 |
status = UX_SUCCESS; |
158 |
|
|
} |
159 |
|
|
|
160 |
|
|
/* If we are OK, go on. */ |
161 |
✓✓ |
49 |
if (status == UX_SUCCESS) |
162 |
|
|
{ |
163 |
|
|
|
164 |
|
|
/* Initialize the report callback. */ |
165 |
|
44 |
call_back.ux_host_class_hid_report_callback_id = mouse_instance -> ux_host_class_hid_mouse_id; |
166 |
|
44 |
call_back.ux_host_class_hid_report_callback_function = _ux_host_class_hid_mouse_callback; |
167 |
|
44 |
call_back.ux_host_class_hid_report_callback_buffer = UX_NULL; |
168 |
|
44 |
call_back.ux_host_class_hid_report_callback_flags = UX_HOST_CLASS_HID_REPORT_INDIVIDUAL_USAGE; |
169 |
|
44 |
call_back.ux_host_class_hid_report_callback_length = 0; |
170 |
|
|
|
171 |
|
|
/* Register the report call back when data comes it on this report. */ |
172 |
|
44 |
status = _ux_host_class_hid_report_callback_register(hid, &call_back); |
173 |
|
|
} |
174 |
|
|
|
175 |
|
|
/* If we are OK, go on. */ |
176 |
✓✓ |
49 |
if (status == UX_SUCCESS) |
177 |
|
|
{ |
178 |
|
|
|
179 |
|
|
/* Start the periodic report. */ |
180 |
|
44 |
status = _ux_host_class_hid_periodic_report_start(hid); |
181 |
|
|
|
182 |
✓✓ |
44 |
if (status == UX_SUCCESS) |
183 |
|
|
{ |
184 |
|
|
|
185 |
|
|
/* Use our copy of client. */ |
186 |
|
43 |
hid -> ux_host_class_hid_client = hid_client; |
187 |
|
|
|
188 |
|
|
/* If all is fine and the device is mounted, we may need to inform the application |
189 |
|
|
if a function has been programmed in the system structure. */ |
190 |
✓✓ |
43 |
if (_ux_system_host -> ux_system_host_change_function != UX_NULL) |
191 |
|
|
{ |
192 |
|
|
|
193 |
|
|
/* Call system change function. */ |
194 |
|
33 |
_ux_system_host -> ux_system_host_change_function(UX_HID_CLIENT_INSERTION, hid -> ux_host_class_hid_class, (VOID *) hid_client); |
195 |
|
|
} |
196 |
|
|
|
197 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
198 |
|
|
UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_HID_MOUSE_ACTIVATE, hid, mouse_instance, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0) |
199 |
|
|
|
200 |
|
|
/* Return completion status. */ |
201 |
|
43 |
return(status); |
202 |
|
|
} |
203 |
|
|
} |
204 |
|
|
|
205 |
|
|
/* We are here if there is error. */ |
206 |
|
|
|
207 |
|
|
/* Free mouse client instance. */ |
208 |
|
6 |
_ux_utility_memory_free(mouse_instance); |
209 |
|
|
|
210 |
|
|
/* Return completion status. */ |
211 |
|
6 |
return(status); |
212 |
|
|
#endif |
213 |
|
|
} |
214 |
|
|
|