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 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_stack.h" |
31 |
|
|
|
32 |
|
|
|
33 |
|
|
/**************************************************************************/ |
34 |
|
|
/* */ |
35 |
|
|
/* FUNCTION RELEASE */ |
36 |
|
|
/* */ |
37 |
|
|
/* _ux_host_class_hid_client_search PORTABLE C */ |
38 |
|
|
/* 6.1 */ |
39 |
|
|
/* AUTHOR */ |
40 |
|
|
/* */ |
41 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
42 |
|
|
/* */ |
43 |
|
|
/* DESCRIPTION */ |
44 |
|
|
/* */ |
45 |
|
|
/* This function searches for a HID client that wants to own this HID */ |
46 |
|
|
/* device. */ |
47 |
|
|
/* */ |
48 |
|
|
/* INPUT */ |
49 |
|
|
/* */ |
50 |
|
|
/* hid Pointer to HID class */ |
51 |
|
|
/* */ |
52 |
|
|
/* OUTPUT */ |
53 |
|
|
/* */ |
54 |
|
|
/* Completion Status */ |
55 |
|
|
/* */ |
56 |
|
|
/* CALLS */ |
57 |
|
|
/* */ |
58 |
|
|
/* (ux_host_class_hid_client_handler) HID client handler */ |
59 |
|
|
/* */ |
60 |
|
|
/* CALLED BY */ |
61 |
|
|
/* */ |
62 |
|
|
/* HID Class */ |
63 |
|
|
/* */ |
64 |
|
|
/**************************************************************************/ |
65 |
|
274 |
UINT _ux_host_class_hid_client_search(UX_HOST_CLASS_HID *hid) |
66 |
|
|
{ |
67 |
|
|
|
68 |
|
|
UX_HOST_CLASS_HID_CLIENT *hid_client; |
69 |
|
|
ULONG hid_client_index; |
70 |
|
|
UINT status; |
71 |
|
|
UX_HOST_CLASS_HID_CLIENT_COMMAND hid_client_command; |
72 |
|
|
|
73 |
|
|
|
74 |
|
|
/* In order to search a HID client, we need both the main page and the main usage. */ |
75 |
|
274 |
hid_client_command.ux_host_class_hid_client_command_page = hid -> ux_host_class_hid_parser.ux_host_class_hid_parser_main_page; |
76 |
|
274 |
hid_client_command.ux_host_class_hid_client_command_usage = hid -> ux_host_class_hid_parser.ux_host_class_hid_parser_main_usage & 0xffff; |
77 |
|
274 |
hid_client_command.ux_host_class_hid_client_command_instance = hid; |
78 |
|
274 |
hid_client_command.ux_host_class_hid_client_command_container = (VOID *) hid -> ux_host_class_hid_class; |
79 |
|
274 |
hid_client_command.ux_host_class_hid_client_command_request = UX_HOST_CLASS_COMMAND_QUERY; |
80 |
|
|
|
81 |
|
|
/* Dereference the client pointer into a HID client pointer. */ |
82 |
|
274 |
hid_client = (UX_HOST_CLASS_HID_CLIENT *) hid -> ux_host_class_hid_class -> ux_host_class_client; |
83 |
|
|
|
84 |
|
|
/* If the hid_client pointer is NULL, the array of clients was not initialized. */ |
85 |
✓✓ |
274 |
if (hid_client == UX_NULL) |
86 |
|
|
{ |
87 |
|
|
|
88 |
|
|
/* Error trap. */ |
89 |
|
32 |
_ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_HID_UNKNOWN); |
90 |
|
|
|
91 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
92 |
|
|
UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_HID_UNKNOWN, hid, 0, 0, UX_TRACE_ERRORS, 0, 0) |
93 |
|
|
|
94 |
|
32 |
return(UX_HOST_CLASS_HID_UNKNOWN); |
95 |
|
|
} |
96 |
|
|
|
97 |
|
|
/* We need to parse the hid client driver table to find a registered client. */ |
98 |
✓✓ |
449 |
for (hid_client_index = 0; hid_client_index < UX_HOST_CLASS_HID_MAX_CLIENTS; hid_client_index++) |
99 |
|
|
{ |
100 |
|
|
|
101 |
|
|
/* Check if this HID client is registered. */ |
102 |
✓✓ |
436 |
if (hid_client -> ux_host_class_hid_client_status == UX_USED) |
103 |
|
|
{ |
104 |
|
|
|
105 |
|
|
/* Call the HID client with a query command. */ |
106 |
|
345 |
status = hid_client -> ux_host_class_hid_client_handler(&hid_client_command); |
107 |
|
|
|
108 |
|
|
/* Have we found a HID client? */ |
109 |
✓✓ |
345 |
if (status == UX_SUCCESS) |
110 |
|
|
{ |
111 |
|
|
|
112 |
|
|
/* Update the command to activate the client. */ |
113 |
|
229 |
hid_client_command.ux_host_class_hid_client_command_request = UX_HOST_CLASS_COMMAND_ACTIVATE; |
114 |
|
|
|
115 |
|
|
/* Memorize the client for this HID device. */ |
116 |
|
229 |
hid -> ux_host_class_hid_client = hid_client; |
117 |
|
|
|
118 |
|
|
/* Call the HID client with an activate command. */ |
119 |
|
229 |
status = hid_client -> ux_host_class_hid_client_handler(&hid_client_command); |
120 |
|
|
|
121 |
|
|
/* Unmount the client if activation fail. */ |
122 |
✓✓ |
229 |
if (status != UX_SUCCESS) |
123 |
|
26 |
hid -> ux_host_class_hid_client = UX_NULL; |
124 |
|
|
|
125 |
|
|
/* Return completion status. */ |
126 |
|
229 |
return(status); |
127 |
|
|
} |
128 |
|
|
} |
129 |
|
|
|
130 |
|
|
/* Try the next HID client. */ |
131 |
|
207 |
hid_client++; |
132 |
|
|
} |
133 |
|
|
|
134 |
|
|
/* Error trap. */ |
135 |
|
13 |
_ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_HID_UNKNOWN); |
136 |
|
|
|
137 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
138 |
|
|
UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_HID_UNKNOWN, hid, 0, 0, UX_TRACE_ERRORS, 0, 0) |
139 |
|
|
|
140 |
|
|
/* Return an error. */ |
141 |
|
13 |
return(UX_HOST_CLASS_HID_UNKNOWN); |
142 |
|
|
} |
143 |
|
|
|