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