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