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_main_item_parse PORTABLE C */ |
38 |
|
|
/* 6.1 */ |
39 |
|
|
/* AUTHOR */ |
40 |
|
|
/* */ |
41 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
42 |
|
|
/* */ |
43 |
|
|
/* DESCRIPTION */ |
44 |
|
|
/* */ |
45 |
|
|
/* This function parses a main item from the report descriptor. */ |
46 |
|
|
/* */ |
47 |
|
|
/* INPUT */ |
48 |
|
|
/* */ |
49 |
|
|
/* hid Pointer to HID class */ |
50 |
|
|
/* item Pointer to item */ |
51 |
|
|
/* descriptor Pointer to descriptor */ |
52 |
|
|
/* */ |
53 |
|
|
/* OUTPUT */ |
54 |
|
|
/* */ |
55 |
|
|
/* Completion Status */ |
56 |
|
|
/* */ |
57 |
|
|
/* CALLS */ |
58 |
|
|
/* */ |
59 |
|
|
/* _ux_host_class_hid_item_data_get Get data item */ |
60 |
|
|
/* _ux_host_class_hid_report_add Add report */ |
61 |
|
|
/* _ux_utility_memory_set Memory block set */ |
62 |
|
|
/* */ |
63 |
|
|
/* CALLED BY */ |
64 |
|
|
/* */ |
65 |
|
|
/* HID Class */ |
66 |
|
|
/* */ |
67 |
|
|
/**************************************************************************/ |
68 |
|
3269 |
UINT _ux_host_class_hid_main_item_parse(UX_HOST_CLASS_HID *hid, UX_HOST_CLASS_HID_ITEM *item, UCHAR *descriptor) |
69 |
|
|
{ |
70 |
|
|
|
71 |
|
|
UX_HOST_CLASS_HID_PARSER *hid_parser; |
72 |
|
3269 |
UINT status = UX_ERROR; |
73 |
|
|
ULONG collection_type; |
74 |
|
|
|
75 |
|
|
|
76 |
|
|
/* Get the temporary parser structure pointer. */ |
77 |
|
3269 |
hid_parser = &hid -> ux_host_class_hid_parser; |
78 |
|
|
|
79 |
|
|
/* Analyze the tag. */ |
80 |
✓✓✓✓
|
3269 |
switch (item -> ux_host_class_hid_item_report_tag) |
81 |
|
|
{ |
82 |
|
|
|
83 |
|
723 |
case UX_HOST_CLASS_HID_MAIN_TAG_COLLECTION: |
84 |
|
|
|
85 |
|
|
/* We have a new collection to open. If the collection type is application, |
86 |
|
|
we have to differentiate the first collection. */ |
87 |
|
723 |
collection_type = _ux_host_class_hid_item_data_get(descriptor, item); |
88 |
|
|
|
89 |
|
|
/* Check the collection type. */ |
90 |
✓✓ |
723 |
if (collection_type == UX_HOST_CLASS_HID_COLLECTION_APPLICATION) |
91 |
|
|
{ |
92 |
|
|
|
93 |
|
|
/* We have a collection of type application, check if this is the first one */ |
94 |
✓✓✓✓
|
562 |
if ((hid_parser -> ux_host_class_hid_parser_main_page == 0) && (hid_parser -> ux_host_class_hid_parser_main_usage == 0)) |
95 |
|
|
{ |
96 |
|
|
|
97 |
|
|
/* It is the first application. Since the main usage and page have not yet |
98 |
|
|
been defined, we use the global page and the current local usage. */ |
99 |
|
445 |
hid_parser -> ux_host_class_hid_parser_main_page = hid_parser -> ux_host_class_hid_parser_global.ux_host_class_hid_global_item_usage_page; |
100 |
|
445 |
hid_parser -> ux_host_class_hid_parser_main_usage = hid_parser -> ux_host_class_hid_parser_local.ux_host_class_hid_local_item_usages[0]; |
101 |
|
|
} |
102 |
|
|
|
103 |
|
|
/* Memorize the application. */ |
104 |
|
562 |
hid_parser -> ux_host_class_hid_parser_application = collection_type; |
105 |
|
|
|
106 |
|
|
/* Add one collection to this report */ |
107 |
|
562 |
hid_parser -> ux_host_class_hid_parser_number_collection++; |
108 |
|
|
|
109 |
|
|
/* Set the status to success. */ |
110 |
|
562 |
status = UX_SUCCESS; |
111 |
|
|
} |
112 |
|
|
else |
113 |
|
|
{ |
114 |
|
|
|
115 |
✓✓ |
161 |
if (hid_parser -> ux_host_class_hid_parser_number_collection >= UX_HOST_CLASS_HID_MAX_COLLECTION) |
116 |
|
|
{ |
117 |
|
|
|
118 |
|
|
/* Error trap. */ |
119 |
|
3 |
_ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_HID_COLLECTION_OVERFLOW); |
120 |
|
|
|
121 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
122 |
|
|
UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_HID_COLLECTION_OVERFLOW, hid, 0, 0, UX_TRACE_ERRORS, 0, 0) |
123 |
|
|
|
124 |
|
3 |
return(UX_HOST_CLASS_HID_COLLECTION_OVERFLOW); |
125 |
|
|
} |
126 |
|
|
else |
127 |
|
|
{ |
128 |
|
|
|
129 |
|
158 |
hid_parser -> ux_host_class_hid_parser_collection[hid_parser -> ux_host_class_hid_parser_number_collection] = collection_type; |
130 |
|
|
|
131 |
|
|
/* Add one collection to this report. */ |
132 |
|
158 |
hid_parser -> ux_host_class_hid_parser_number_collection++; |
133 |
|
|
|
134 |
|
|
/* Set the status to success. */ |
135 |
|
158 |
status = UX_SUCCESS; |
136 |
|
|
} |
137 |
|
|
} |
138 |
|
720 |
break; |
139 |
|
|
|
140 |
|
525 |
case UX_HOST_CLASS_HID_MAIN_TAG_END_COLLECTION: |
141 |
|
|
|
142 |
|
|
/* We need to pop back the last collection. */ |
143 |
✓✓ |
525 |
if (hid_parser -> ux_host_class_hid_parser_number_collection == 0) |
144 |
|
|
{ |
145 |
|
|
|
146 |
|
|
/* Error trap. */ |
147 |
|
3 |
_ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_HID_COLLECTION_OVERFLOW); |
148 |
|
|
|
149 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
150 |
|
|
UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_HID_COLLECTION_OVERFLOW, hid, 0, 0, UX_TRACE_ERRORS, 0, 0) |
151 |
|
|
|
152 |
|
3 |
return(UX_HOST_CLASS_HID_COLLECTION_OVERFLOW); |
153 |
|
|
} |
154 |
|
|
|
155 |
|
|
else |
156 |
|
|
|
157 |
|
522 |
hid_parser -> ux_host_class_hid_parser_number_collection--; |
158 |
|
|
|
159 |
|
522 |
status = UX_SUCCESS; |
160 |
|
522 |
break; |
161 |
|
|
|
162 |
|
2018 |
case UX_HOST_CLASS_HID_MAIN_TAG_INPUT: |
163 |
|
|
case UX_HOST_CLASS_HID_MAIN_TAG_OUTPUT: |
164 |
|
|
case UX_HOST_CLASS_HID_MAIN_TAG_FEATURE: |
165 |
|
|
|
166 |
|
|
/* We need to add a report. */ |
167 |
|
2018 |
status = _ux_host_class_hid_report_add(hid, descriptor, item); |
168 |
|
2018 |
break; |
169 |
|
|
} |
170 |
|
|
|
171 |
|
|
/* We have a new main item, so the local instances have to be cleaned. */ |
172 |
|
3263 |
_ux_utility_memory_set(&hid_parser -> ux_host_class_hid_parser_local, 0, sizeof(UX_HOST_CLASS_HID_LOCAL_ITEM)); /* Use case of memset is verified. */ |
173 |
|
|
|
174 |
|
|
/* Return completion status. */ |
175 |
|
3263 |
return(status); |
176 |
|
|
} |
177 |
|
|
|