1 /**************************************************************************/
2 /* */
3 /* Copyright (c) Microsoft Corporation. All rights reserved. */
4 /* */
5 /* This software is licensed under the Microsoft Software License */
6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */
7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
8 /* and in the root directory of this software. */
9 /* */
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_report_id_get PORTABLE C */
38 /* 6.1.10 */
39 /* AUTHOR */
40 /* */
41 /* Chaoqiong Xiao, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function retrieves the report after */
46 /* report_id -> ux_host_class_hid_report_get_id and stores it in the */
47 /* same pointer. If report_id -> ux_host_class_hid_report_get_id is */
48 /* null, retrieves the first report of the type specified by */
49 /* report_id -> ux_host_class_hid_report_get_type. */
50 /* */
51 /* INPUT */
52 /* */
53 /* hid Pointer to HID class */
54 /* report_id Report id structure */
55 /* */
56 /* OUTPUT */
57 /* */
58 /* Completion Status */
59 /* */
60 /* CALLS */
61 /* */
62 /* _ux_host_semaphore_get Get protection semaphore */
63 /* _ux_host_semaphore_put Release protection semaphore */
64 /* _ux_host_stack_class_instance_verify Verify class instance is valid*/
65 /* */
66 /* CALLED BY */
67 /* */
68 /* Application */
69 /* HID Class */
70 /* */
71 /* RELEASE HISTORY */
72 /* */
73 /* DATE NAME DESCRIPTION */
74 /* */
75 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
76 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
77 /* resulting in version 6.1 */
78 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
79 /* added standalone support, */
80 /* resulting in version 6.1.10 */
81 /* */
82 /**************************************************************************/
_ux_host_class_hid_report_id_get(UX_HOST_CLASS_HID * hid,UX_HOST_CLASS_HID_REPORT_GET_ID * report_id)83 UINT _ux_host_class_hid_report_id_get(UX_HOST_CLASS_HID *hid, UX_HOST_CLASS_HID_REPORT_GET_ID *report_id)
84 {
85 #if defined(UX_HOST_STANDALONE)
86 UX_INTERRUPT_SAVE_AREA
87 #endif
88 UINT status;
89 UX_HOST_CLASS_HID_REPORT *next_hid_report;
90
91
92 /* Ensure the instance is valid. */
93 if (_ux_host_stack_class_instance_verify(_ux_system_host_class_hid_name, (VOID *) hid) != UX_SUCCESS)
94 {
95
96 /* Error trap. */
97 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_INSTANCE_UNKNOWN);
98
99 /* If trace is enabled, insert this event into the trace buffer. */
100 UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, hid, 0, 0, UX_TRACE_ERRORS, 0, 0)
101
102 return(UX_HOST_CLASS_INSTANCE_UNKNOWN);
103 }
104
105 /* Protect thread reentry to this instance. */
106 _ux_host_class_hid_lock_fail_return(hid);
107
108 /* Check if this is the first report to get. */
109 if (report_id -> ux_host_class_hid_report_get_report == UX_NULL)
110 {
111
112 /* Check for the type of report ID to get (Input, Output, Feature). */
113 switch (report_id -> ux_host_class_hid_report_get_type)
114 {
115
116 case UX_HOST_CLASS_HID_REPORT_TYPE_INPUT :
117
118 /* Search for the input report ID. */
119 next_hid_report = hid -> ux_host_class_hid_parser.ux_host_class_hid_parser_input_report;
120 break;
121
122 case UX_HOST_CLASS_HID_REPORT_TYPE_OUTPUT :
123
124 /* Search for the output report ID. */
125 next_hid_report = hid -> ux_host_class_hid_parser.ux_host_class_hid_parser_output_report;
126 break;
127
128 case UX_HOST_CLASS_HID_REPORT_TYPE_FEATURE :
129
130 /* Search for the feature report ID. */
131 next_hid_report = hid -> ux_host_class_hid_parser.ux_host_class_hid_parser_feature_report;
132 break;
133
134 default :
135
136 /* Error trap. */
137 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_HID_REPORT_ERROR);
138
139 /* If trace is enabled, insert this event into the trace buffer. */
140 UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_HID_REPORT_ERROR, hid, 0, 0, UX_TRACE_ERRORS, 0, 0)
141
142 /* The report ID could not be found amongst the reports. */
143 next_hid_report = UX_NULL;
144 break;
145 }
146 }
147 else
148 {
149
150 /* We had a report ID scan previously, point to the next report. */
151 next_hid_report = report_id -> ux_host_class_hid_report_get_report -> ux_host_class_hid_report_next_report;
152 }
153
154 /* Did we find the next report? */
155 if (next_hid_report != UX_NULL)
156 {
157
158 /* We want the first report, memorize the ID. */
159 report_id -> ux_host_class_hid_report_get_id = next_hid_report -> ux_host_class_hid_report_id;
160
161 /* And remember where we left. */
162 report_id -> ux_host_class_hid_report_get_report = next_hid_report;
163
164 /* Successfully found next report. */
165 status = UX_SUCCESS;
166 }
167 else
168 {
169
170 /* If trace is enabled, insert this event into the trace buffer. */
171 UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_HID_REPORT_ERROR, hid, 0, 0, UX_TRACE_ERRORS, 0, 0)
172
173 /* No more reports. */
174 status = UX_HOST_CLASS_HID_REPORT_ERROR;
175 }
176
177 /* Unprotect thread reentry to this instance. */
178 _ux_host_class_hid_unlock(hid);
179
180 /* The status variable has been set correctly. */
181 return(status);
182 }
183
184