1 /**************************************************/
2 /** Test case: hid_parser -> ux_host_class_hid_parser_main_usage == 0) fails in **/
3 /** if ((hid_parser -> ux_host_class_hid_parser_main_page == 0) && (hid_parser -> ux_host_class_hid_parser_main_usage == 0)) **/
4 /** How: Two application collections, the first one having a zero usage page, and a non-zero usage. **/
5 /** Note: Since USBX doesn't support any devices with a usage page of 0, it generates an error and will call our error callback. **/
6 /**************************************************/
7
8 #include "usbx_test_common_hid.h"
9 #include "ux_host_class_hid_keyboard.h"
10
11
12 #define DUMMY_USBX_MEMORY_SIZE (64*1024)
13 static UCHAR dummy_usbx_memory[DUMMY_USBX_MEMORY_SIZE];
14
15 static UCHAR hid_report_descriptor[] = {
16
17 /* Make sure the usage page is 0 */
18 0x05, 0x00, // USAGE_PAGE ()
19 /* Make sure the usage is not 0 */
20 0x09, 0x06, // USAGE (Keyboard)
21 0xa1, 0x01, // COLLECTION (Application)
22 0x05, 0x07, // USAGE_PAGE (Keyboard)
23 0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)
24 0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)
25 0x15, 0x00, // LOGICAL_MINIMUM (0)
26 0x25, 0x01, // LOGICAL_MAXIMUM (1)
27 0x75, 0x01, // REPORT_SIZE (1)
28 0x95, 0x08, // REPORT_COUNT (8)
29 0x81, 0x02, // INPUT (Data,Var,Abs)
30 0x95, 0x01, // REPORT_COUNT (1)
31 0x75, 0x08, // REPORT_SIZE (8)
32 0x81, 0x03, // INPUT (Cnst,Var,Abs)
33 0x95, 0x05, // REPORT_COUNT (5)
34 0x75, 0x01, // REPORT_SIZE (1)
35 0x05, 0x08, // USAGE_PAGE (LEDs)
36 0x19, 0x01, // USAGE_MINIMUM (Num Lock)
37 0x29, 0x05, // USAGE_MAXIMUM (Kana)
38 0x91, 0x02, // OUTPUT (Data,Var,Abs)
39 0x95, 0x01, // REPORT_COUNT (1)
40 0x75, 0x03, // REPORT_SIZE (3)
41 0x91, 0x03, // OUTPUT (Cnst,Var,Abs)
42 0x95, 0x06, // REPORT_COUNT (6)
43 0x75, 0x08, // REPORT_SIZE (8)
44 0x15, 0x00, // LOGICAL_MINIMUM (0)
45 0x25, 0x65, // LOGICAL_MAXIMUM (101)
46 0x05, 0x07, // USAGE_PAGE (Keyboard)
47 0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))
48 0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)
49 0x81, 0x00, // INPUT (Data,Ary,Abs)
50 0xc0, // END_COLLECTION
51 /* Second Application Collection. */
52 0xa1, 0x01, // COLLECTION (Application)
53 0x05, 0x07, // USAGE_PAGE (Keyboard)
54 0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)
55 0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)
56 0x15, 0x00, // LOGICAL_MINIMUM (0)
57 0x25, 0x01, // LOGICAL_MAXIMUM (1)
58 0x75, 0x01, // REPORT_SIZE (1)
59 0x95, 0x08, // REPORT_COUNT (8)
60 0x81, 0x02, // INPUT (Data,Var,Abs)
61 0x95, 0x01, // REPORT_COUNT (1)
62 0x75, 0x08, // REPORT_SIZE (8)
63 0x81, 0x03, // INPUT (Cnst,Var,Abs)
64 0x95, 0x05, // REPORT_COUNT (5)
65 0x75, 0x01, // REPORT_SIZE (1)
66 0x05, 0x08, // USAGE_PAGE (LEDs)
67 0x19, 0x01, // USAGE_MINIMUM (Num Lock)
68 0x29, 0x05, // USAGE_MAXIMUM (Kana)
69 0x91, 0x02, // OUTPUT (Data,Var,Abs)
70 0x95, 0x01, // REPORT_COUNT (1)
71 0x75, 0x03, // REPORT_SIZE (3)
72 0x91, 0x03, // OUTPUT (Cnst,Var,Abs)
73 0x95, 0x06, // REPORT_COUNT (6)
74 0x75, 0x08, // REPORT_SIZE (8)
75 0x15, 0x00, // LOGICAL_MINIMUM (0)
76 0x25, 0x65, // LOGICAL_MAXIMUM (101)
77 0x05, 0x07, // USAGE_PAGE (Keyboard)
78 0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))
79 0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)
80 0x81, 0x00, // INPUT (Data,Ary,Abs)
81 0xc0 // END_COLLECTION
82 };
83 #define HID_REPORT_LENGTH sizeof(hid_report_descriptor)/sizeof(hid_report_descriptor[0])
84
85
86 #define DEVICE_FRAMEWORK_LENGTH_FULL_SPEED 52
87 static UCHAR device_framework_full_speed[DEVICE_FRAMEWORK_LENGTH_FULL_SPEED] = {
88
89 /* Device descriptor */
90 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08,
91 0x81, 0x0A, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
92 0x00, 0x01,
93
94 /* Configuration descriptor */
95 0x09, 0x02, 0x22, 0x00, 0x01, 0x01, 0x00, 0xc0,
96 0x32,
97
98 /* Interface descriptor */
99 0x09, 0x04, 0x02, 0x00, 0x01, 0x03, 0x00, 0x00,
100 0x00,
101
102 /* HID descriptor */
103 0x09, 0x21, 0x10, 0x01, 0x21, 0x01, 0x22, LSB(HID_REPORT_LENGTH),
104 MSB(HID_REPORT_LENGTH),
105
106 /* Endpoint descriptor (Interrupt) */
107 0x07, 0x05, 0x82, 0x03, 0x08, 0x00, 0x08
108
109 };
110
111
112 #define DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED 62
113 static UCHAR device_framework_high_speed[DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED] = {
114
115 /* Device descriptor */
116 0x12, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x40,
117 0x0a, 0x07, 0x25, 0x40, 0x01, 0x00, 0x01, 0x02,
118 0x03, 0x01,
119
120 /* Device qualifier descriptor */
121 0x0a, 0x06, 0x00, 0x02, 0x00, 0x00, 0x00, 0x40,
122 0x01, 0x00,
123
124 /* Configuration descriptor */
125 0x09, 0x02, 0x22, 0x00, 0x01, 0x01, 0x00, 0xc0,
126 0x32,
127
128 /* Interface descriptor */
129 0x09, 0x04, 0x02, 0x00, 0x01, 0x03, 0x00, 0x00,
130 0x00,
131
132 /* HID descriptor */
133 0x09, 0x21, 0x10, 0x01, 0x21, 0x01, 0x22, LSB(HID_REPORT_LENGTH),
134 MSB(HID_REPORT_LENGTH),
135
136 /* Endpoint descriptor (Interrupt) */
137 0x07, 0x05, 0x82, 0x03, 0x08, 0x00, 0x08
138
139 };
140
141
142 /* String Device Framework :
143 Byte 0 and 1 : Word containing the language ID : 0x0904 for US
144 Byte 2 : Byte containing the index of the descriptor
145 Byte 3 : Byte containing the length of the descriptor string
146 */
147
148 #define STRING_FRAMEWORK_LENGTH 40
149 static UCHAR string_framework[] = {
150
151 /* Manufacturer string descriptor : Index 1 */
152 0x09, 0x04, 0x01, 0x0c,
153 0x45, 0x78, 0x70, 0x72,0x65, 0x73, 0x20, 0x4c,
154 0x6f, 0x67, 0x69, 0x63,
155
156 /* Product string descriptor : Index 2 */
157 0x09, 0x04, 0x02, 0x0c,
158 0x55, 0x53, 0x42, 0x20, 0x4b, 0x65, 0x79, 0x62,
159 0x6f, 0x61, 0x72, 0x64,
160
161 /* Serial Number string descriptor : Index 3 */
162 0x09, 0x04, 0x03, 0x04,
163 0x30, 0x30, 0x30, 0x31
164 };
165
166
167 /* Multiple languages are supported on the device, to add
168 a language besides english, the unicode language code must
169 be appended to the language_id_framework array and the length
170 adjusted accordingly. */
171 #define LANGUAGE_ID_FRAMEWORK_LENGTH 2
172 static UCHAR language_id_framework[] = {
173
174 /* English. */
175 0x09, 0x04
176 };
177
178
179 UINT _ux_hcd_sim_host_entry(UX_HCD *hcd, UINT function, VOID *parameter);
180
181
ux_system_host_change_function(ULONG a,UX_HOST_CLASS * b,VOID * c)182 static UINT ux_system_host_change_function(ULONG a, UX_HOST_CLASS *b, VOID *c)
183 {
184 return 0;
185 }
186
error_callback(UINT system_level,UINT system_context,UINT error_code)187 static VOID error_callback(UINT system_level, UINT system_context, UINT error_code)
188 {
189
190 if (error_code != UX_HOST_CLASS_HID_UNKNOWN)
191 {
192
193 /* Error callback should have been invoked. */
194 printf("Error on line %d\n", __LINE__);
195 test_control_return(1);
196 }
197 }
198
199 /* Define what the initial system looks like. */
200
201 #ifdef CTEST
test_application_define(void * first_unused_memory)202 void test_application_define(void *first_unused_memory)
203 #else
204 void usbx_ux_host_class_hid_main_item_parse_test2_application_define(void *first_unused_memory)
205 #endif
206 {
207
208 UINT status;
209 CHAR * stack_pointer;
210 CHAR * memory_pointer;
211
212
213 /* Inform user. */
214 printf("Running ux_host_class_hid_main_item_parse Test 2.................... ");
215
216 /* Initialize the free memory pointer */
217 stack_pointer = (CHAR *) usbx_memory;
218 memory_pointer = stack_pointer + (UX_DEMO_STACK_SIZE * 2);
219
220 /* Initialize USBX. Memory */
221 status = ux_system_initialize(memory_pointer, UX_DEMO_MEMORY_SIZE, UX_NULL,0);
222
223 /* Check for error. */
224 if (status != UX_SUCCESS)
225 {
226
227 printf("Error on line %d, error code: %d\n", __LINE__, status);
228 test_control_return(1);
229 }
230
231 /* Register the error callback. */
232 _ux_utility_error_callback_register(error_callback);
233
234 /* The code below is required for installing the host portion of USBX */
235 status = ux_host_stack_initialize(ux_system_host_change_function);
236 if (status != UX_SUCCESS)
237 {
238
239 printf("Error on line %d, error code: %d\n", __LINE__, status);
240 test_control_return(1);
241 }
242
243 status = ux_host_stack_class_register(_ux_system_host_class_hid_name, ux_host_class_hid_entry);
244 if (status != UX_SUCCESS)
245 {
246
247 printf("Error on line %d, error code: %d\n", __LINE__, status);
248 test_control_return(1);
249 }
250
251 /* Register the HID client(s). */
252 status = ux_host_class_hid_client_register(_ux_system_host_class_hid_client_keyboard_name, ux_host_class_hid_keyboard_entry);
253 if (status != UX_SUCCESS)
254 {
255
256 printf("Error on line %d, error code: %d\n", __LINE__, status);
257 test_control_return(1);
258 }
259
260 /* The code below is required for installing the device portion of USBX. No call back for
261 device status change in this example. */
262 status = ux_device_stack_initialize(device_framework_high_speed, DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED,
263 device_framework_full_speed, DEVICE_FRAMEWORK_LENGTH_FULL_SPEED,
264 string_framework, STRING_FRAMEWORK_LENGTH,
265 language_id_framework, LANGUAGE_ID_FRAMEWORK_LENGTH,UX_NULL);
266 if(status!=UX_SUCCESS)
267 {
268
269 printf("Error on line %d, error code: %d\n", __LINE__, status);
270 test_control_return(1);
271 }
272
273 /* Initialize the hid class parameters. */
274 hid_parameter.ux_device_class_hid_parameter_report_address = hid_report_descriptor;
275 hid_parameter.ux_device_class_hid_parameter_report_length = HID_REPORT_LENGTH;
276 hid_parameter.ux_device_class_hid_parameter_callback = demo_thread_hid_callback;
277
278 /* Initilize the device hid class. The class is connected with interface 2 */
279 status = ux_device_stack_class_register(_ux_system_slave_class_hid_name, ux_device_class_hid_entry,
280 1,2, (VOID *)&hid_parameter);
281 if(status!=UX_SUCCESS)
282 {
283
284 printf("Error on line %d, error code: %d\n", __LINE__, status);
285 test_control_return(1);
286 }
287
288 /* Initialize the simulated device controller. */
289 status = _ux_dcd_sim_slave_initialize();
290
291 /* Check for error. */
292 if (status != UX_SUCCESS)
293 {
294
295 printf("Error on line %d, error code: %d\n", __LINE__, status);
296 test_control_return(1);
297 }
298
299 /* Register all the USB host controllers available in this system */
300 status = ux_host_stack_hcd_register(_ux_system_host_hcd_simulator_name, ux_hcd_sim_host_initialize,0,0);
301
302 /* Check for error. */
303 if (status != UX_SUCCESS)
304 {
305
306 printf("Error on line %d, error code: %d\n", __LINE__, status);
307 test_control_return(1);
308 }
309
310 /* Create the main host simulation thread. */
311 status = tx_thread_create(&tx_demo_thread_host_simulation, "tx demo host simulation", tx_demo_thread_host_simulation_entry, 0,
312 stack_pointer, UX_DEMO_STACK_SIZE,
313 20, 20, 1, TX_AUTO_START);
314
315 /* Check for error. */
316 if (status != TX_SUCCESS)
317 {
318
319 printf("Error on line %d, error code: %d\n", __LINE__, status);
320 test_control_return(1);
321 }
322 }
323
tx_demo_thread_host_simulation_entry(ULONG arg)324 static void tx_demo_thread_host_simulation_entry(ULONG arg)
325 {
326
327 UINT status;
328
329 /* Find the HID class */
330 status = demo_class_hid_get();
331 if (status != UX_SUCCESS)
332 {
333
334 printf("Error on line %d, error code: %d\n", __LINE__, status);
335 test_control_return(1);
336 }
337
338 /* Now disconnect the device. */
339 _ux_device_stack_disconnect();
340
341 /* And deinitialize the class. */
342 status = ux_device_stack_class_unregister(_ux_system_slave_class_hid_name, ux_device_class_hid_entry);
343
344 /* Deinitialize the device side of usbx. */
345 _ux_device_stack_uninitialize();
346
347 /* And finally the usbx system resources. */
348 _ux_system_uninitialize();
349
350 /* Successful test. */
351 printf("SUCCESS!\n");
352 test_control_return(0);
353 }
354
demo_thread_hid_callback(UX_SLAVE_CLASS_HID * class,UX_SLAVE_CLASS_HID_EVENT * event)355 static UINT demo_thread_hid_callback(UX_SLAVE_CLASS_HID *class, UX_SLAVE_CLASS_HID_EVENT *event)
356 {
357 return(UX_SUCCESS);
358 }
359