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