GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usbx_host_classes/src/ux_host_class_hid_global_item_parse.c Lines: 67 67 100.0 %
Date: 2026-03-06 18:57:10 Branches: 21 21 100.0 %

Line Branch Exec Source
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_global_item_parse                PORTABLE C      */
38
/*                                                           6.1          */
39
/*  AUTHOR                                                                */
40
/*                                                                        */
41
/*    Chaoqiong Xiao, Microsoft Corporation                               */
42
/*                                                                        */
43
/*  DESCRIPTION                                                           */
44
/*                                                                        */
45
/*    This function parses a global 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_utility_memory_copy               Copy memory block             */
61
/*                                                                        */
62
/*  CALLED BY                                                             */
63
/*                                                                        */
64
/*    HID Class                                                           */
65
/*                                                                        */
66
/**************************************************************************/
67
7382
UINT  _ux_host_class_hid_global_item_parse(UX_HOST_CLASS_HID *hid, UX_HOST_CLASS_HID_ITEM *item, UCHAR *descriptor)
68
{
69
70
UX_HOST_CLASS_HID_PARSER     *hid_parser;
71
72
73
    /* Get the temporary parser structure pointer.  */
74
7382
    hid_parser =  &hid -> ux_host_class_hid_parser;
75
76
    /* Get the tag of the item structure and process it.  */
77



7382
    switch(item -> ux_host_class_hid_item_report_tag)
78
    {
79
80
1443
    case UX_HOST_CLASS_HID_GLOBAL_TAG_USAGE_PAGE:
81
82
        /* Usage Page Tag.  */
83
1443
        hid_parser -> ux_host_class_hid_parser_global.ux_host_class_hid_global_item_usage_page =
84
1443
                                                _ux_host_class_hid_item_data_get(descriptor, item);
85
1443
        break;
86
87
88
786
    case UX_HOST_CLASS_HID_GLOBAL_TAG_LOGICAL_MINIMUM:
89
90
        /* Logical Minimum Tag.  */
91
786
        hid_parser -> ux_host_class_hid_parser_global.ux_host_class_hid_global_item_logical_min =
92
786
                                                (SLONG) _ux_host_class_hid_item_data_get(descriptor, item);
93
786
        break;
94
95
96
801
    case UX_HOST_CLASS_HID_GLOBAL_TAG_LOGICAL_MAXIMUM:
97
98
        /* Logical Maximum Tag.  */
99
801
        hid_parser -> ux_host_class_hid_parser_global.ux_host_class_hid_global_item_logical_max =
100
801
                                                (SLONG) _ux_host_class_hid_item_data_get(descriptor, item);
101
801
        break;
102
103
104
18
    case UX_HOST_CLASS_HID_GLOBAL_TAG_PHYSICAL_MINIMUM:
105
106
        /* Physical Minimum Tag.  */
107
18
        hid_parser -> ux_host_class_hid_parser_global.ux_host_class_hid_global_item_physical_min =
108
18
                                                (SLONG) _ux_host_class_hid_item_data_get(descriptor, item);
109
18
        break;
110
111
112
18
    case UX_HOST_CLASS_HID_GLOBAL_TAG_PHYSICAL_MAXIMUM:
113
114
        /* Physical Maximum Tag.  */
115
18
        hid_parser -> ux_host_class_hid_parser_global.ux_host_class_hid_global_item_physical_max =
116
18
                                                (SLONG) _ux_host_class_hid_item_data_get(descriptor, item);
117
18
        break;
118
119
120
14
    case UX_HOST_CLASS_HID_GLOBAL_TAG_UNIT_EXPONENT:
121
122
        /* Unit Exponent Tag.  */
123
14
        hid_parser -> ux_host_class_hid_parser_global.ux_host_class_hid_global_item_unit_expo =
124
14
                                                _ux_host_class_hid_item_data_get(descriptor, item);
125
14
        break;
126
127
128
19
    case UX_HOST_CLASS_HID_GLOBAL_TAG_UNIT:
129
130
        /* Unit tag.  */
131
19
        hid_parser -> ux_host_class_hid_parser_global.ux_host_class_hid_global_item_unit =
132
19
                                                _ux_host_class_hid_item_data_get(descriptor, item);
133
19
        break;
134
135
136
2004
    case UX_HOST_CLASS_HID_GLOBAL_TAG_REPORT_SIZE:
137
138
        /* Report Size tag.  */
139
2004
        hid_parser -> ux_host_class_hid_parser_global.ux_host_class_hid_global_item_report_size =
140
2004
                                                _ux_host_class_hid_item_data_get(descriptor, item);
141
142
2004
        if (hid_parser -> ux_host_class_hid_parser_global.ux_host_class_hid_global_item_report_size > UX_HOST_CLASS_HID_REPORT_SIZE)
143
        {
144
145
            /* Error trap. */
146
3
            _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_HID_REPORT_OVERFLOW);
147
148
            /* If trace is enabled, insert this event into the trace buffer.  */
149
            UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_HID_REPORT_OVERFLOW, hid, 0, 0, UX_TRACE_ERRORS, 0, 0)
150
151
3
            return(UX_HOST_CLASS_HID_REPORT_OVERFLOW);
152
        }
153
154
2001
        break;
155
156
157
243
    case UX_HOST_CLASS_HID_GLOBAL_TAG_REPORT_ID:
158
159
        /* Report ID tag.  */
160
243
        hid_parser -> ux_host_class_hid_parser_global.ux_host_class_hid_global_item_report_id =
161
243
                                                _ux_host_class_hid_item_data_get(descriptor, item);
162
243
        break;
163
164
165
2003
    case UX_HOST_CLASS_HID_GLOBAL_TAG_REPORT_COUNT:
166
167
        /* Report Count tag.  */
168
2003
        hid_parser -> ux_host_class_hid_parser_global.ux_host_class_hid_global_item_report_count =
169
2003
                                                _ux_host_class_hid_item_data_get(descriptor, item);
170
171
2003
        if (hid_parser -> ux_host_class_hid_parser_global.ux_host_class_hid_global_item_report_count > UX_HOST_CLASS_HID_USAGES)
172
        {
173
174
            /* Error trap. */
175
3
            _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_HID_USAGE_OVERFLOW);
176
177
            /* If trace is enabled, insert this event into the trace buffer.  */
178
            UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_HID_USAGE_OVERFLOW, hid, 0, 0, UX_TRACE_ERRORS, 0, 0)
179
180
3
            return(UX_HOST_CLASS_HID_USAGE_OVERFLOW);
181
        }
182
183
2000
        break;
184
185
21
    case UX_HOST_CLASS_HID_GLOBAL_TAG_PUSH:
186
187
        /* Push tag.  */
188
21
        if (hid_parser -> ux_host_class_hid_parser_number_global >= UX_HOST_CLASS_HID_MAX_GLOBAL)
189
        {
190
191
            /* Error trap. */
192
3
            _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_HID_PUSH_OVERFLOW);
193
194
            /* If trace is enabled, insert this event into the trace buffer.  */
195
            UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_HID_PUSH_OVERFLOW, hid, 0, 0, UX_TRACE_ERRORS, 0, 0)
196
197
3
            return(UX_HOST_CLASS_HID_PUSH_OVERFLOW);
198
        }
199
200
        else
201
18
            _ux_utility_memory_copy(&hid_parser -> ux_host_class_hid_parser_global_pool[hid_parser -> ux_host_class_hid_parser_number_global++],
202
18
                                        &hid_parser -> ux_host_class_hid_parser_global, sizeof(UX_HOST_CLASS_HID_GLOBAL_ITEM)); /* Use case of memcpy is verified. */
203
18
        break;
204
205
206
9
    case UX_HOST_CLASS_HID_GLOBAL_TAG_POP:
207
208
        /* Pop tag.  */
209
9
        if(hid_parser -> ux_host_class_hid_parser_number_global == 0)
210
        {
211
212
            /* Error trap. */
213
3
            _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_HID_POP_UNDERFLOW);
214
215
            /* If trace is enabled, insert this event into the trace buffer.  */
216
            UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_HID_POP_UNDERFLOW, hid, 0, 0, UX_TRACE_ERRORS, 0, 0)
217
218
3
            return(UX_HOST_CLASS_HID_POP_UNDERFLOW);
219
        }
220
        else
221
6
            _ux_utility_memory_copy(&hid_parser -> ux_host_class_hid_parser_global,
222
6
                                   &hid_parser -> ux_host_class_hid_parser_global_pool[--hid_parser -> ux_host_class_hid_parser_number_global],
223
                                        sizeof(UX_HOST_CLASS_HID_GLOBAL_ITEM)); /* Use case of memcpy is verified. */
224
225
6
        break;
226
227
228
3
    default:
229
230
        /* Error trap. */
231
3
        _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_HID_TAG_UNSUPPORTED);
232
233
        /* If trace is enabled, insert this event into the trace buffer.  */
234
        UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_HID_TAG_UNSUPPORTED, hid, 0, 0, UX_TRACE_ERRORS, 0, 0)
235
236
        /* This tag was not recognized or is not supported.  */
237
3
        return(UX_HOST_CLASS_HID_TAG_UNSUPPORTED);
238
    }
239
240
    /* We get here when the tag has been processed successfully.  */
241
7367
    return(UX_SUCCESS);
242
}
243