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