1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
/***************************************************************************
* Copyright (c) 2024 Microsoft Corporation
* Copyright (c) 2026-present Eclipse ThreadX contributors
*
* This program and the accompanying materials are made available under the
* terms of the MIT License which is available at
* https://opensource.org/licenses/MIT.
*
* SPDX-License-Identifier: MIT
**************************************************************************/
/**************************************************************************/
/**************************************************************************/
/** */
/** USBX Component */
/** */
/** HID Class */
/** */
/**************************************************************************/
/**************************************************************************/
/* Include necessary system files. */
#define UX_SOURCE_CODE
#include "ux_api.h"
#include "ux_host_class_hid.h"
#include "ux_host_stack.h"
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _ux_host_class_hid_main_item_parse PORTABLE C */
/* 6.1 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function parses a main item from the report descriptor. */
/* */
/* INPUT */
/* */
/* hid Pointer to HID class */
/* item Pointer to item */
/* descriptor Pointer to descriptor */
/* */
/* OUTPUT */
/* */
/* Completion Status */
/* */
/* CALLS */
/* */
/* _ux_host_class_hid_item_data_get Get data item */
/* _ux_host_class_hid_report_add Add report */
/* _ux_utility_memory_set Memory block set */
/* */
/* CALLED BY */
/* */
/* HID Class */
/* */
/**************************************************************************/
UINT _ux_host_class_hid_main_item_parse(UX_HOST_CLASS_HID *hid, UX_HOST_CLASS_HID_ITEM *item, UCHAR *descriptor)
{
UX_HOST_CLASS_HID_PARSER *hid_parser;
UINT status = UX_ERROR;
ULONG collection_type;
/* Get the temporary parser structure pointer. */
hid_parser = &hid -> ux_host_class_hid_parser;
/* Analyze the tag. */
switch (item -> ux_host_class_hid_item_report_tag)
{
case UX_HOST_CLASS_HID_MAIN_TAG_COLLECTION:
/* We have a new collection to open. If the collection type is application,
we have to differentiate the first collection. */
collection_type = _ux_host_class_hid_item_data_get(descriptor, item);
/* Check the collection type. */
if (collection_type == UX_HOST_CLASS_HID_COLLECTION_APPLICATION)
{
/* We have a collection of type application, check if this is the first one */
if ((hid_parser -> ux_host_class_hid_parser_main_page == 0) && (hid_parser -> ux_host_class_hid_parser_main_usage == 0))
{
/* It is the first application. Since the main usage and page have not yet
been defined, we use the global page and the current local usage. */
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;
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];
}
/* Memorize the application. */
hid_parser -> ux_host_class_hid_parser_application = collection_type;
/* Add one collection to this report */
hid_parser -> ux_host_class_hid_parser_number_collection++;
/* Set the status to success. */
status = UX_SUCCESS;
}
else
{
if (hid_parser -> ux_host_class_hid_parser_number_collection >= UX_HOST_CLASS_HID_MAX_COLLECTION)
{
/* Error trap. */
_ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_HID_COLLECTION_OVERFLOW);
/* If trace is enabled, insert this event into the trace buffer. */
UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_HID_COLLECTION_OVERFLOW, hid, 0, 0, UX_TRACE_ERRORS, 0, 0)
return(UX_HOST_CLASS_HID_COLLECTION_OVERFLOW);
}
else
{
hid_parser -> ux_host_class_hid_parser_collection[hid_parser -> ux_host_class_hid_parser_number_collection] = collection_type;
/* Add one collection to this report. */
hid_parser -> ux_host_class_hid_parser_number_collection++;
/* Set the status to success. */
status = UX_SUCCESS;
}
}
break;
case UX_HOST_CLASS_HID_MAIN_TAG_END_COLLECTION:
/* We need to pop back the last collection. */
if (hid_parser -> ux_host_class_hid_parser_number_collection == 0)
{
/* Error trap. */
_ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_HID_COLLECTION_OVERFLOW);
/* If trace is enabled, insert this event into the trace buffer. */
UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_HID_COLLECTION_OVERFLOW, hid, 0, 0, UX_TRACE_ERRORS, 0, 0)
return(UX_HOST_CLASS_HID_COLLECTION_OVERFLOW);
}
else
hid_parser -> ux_host_class_hid_parser_number_collection--;
status = UX_SUCCESS;
break;
case UX_HOST_CLASS_HID_MAIN_TAG_INPUT:
case UX_HOST_CLASS_HID_MAIN_TAG_OUTPUT:
case UX_HOST_CLASS_HID_MAIN_TAG_FEATURE:
/* We need to add a report. */
status = _ux_host_class_hid_report_add(hid, descriptor, item);
break;
}
/* We have a new main item, so the local instances have to be cleaned. */
_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. */
/* Return completion status. */
return(status);
}
|