1 /* This test concentrates on the ux_host_class_hid_keyboard_key_get API.  */
2 
3 #include <stdio.h>
4 #include "tx_api.h"
5 #include "ux_api.h"
6 #include "ux_system.h"
7 #include "ux_utility.h"
8 #include "ux_host_class_hid.h"
9 #include "ux_host_class_hid_keyboard.h"
10 #include "ux_device_class_hid.h"
11 #include "ux_device_stack.h"
12 
13 extern UCHAR ux_host_class_hid_keyboard_regular_array[];
14 
15 static UCHAR ux_host_class_hid_keyboard_shift_array_jp_0_9[] =
16 {
17    0,0,0,0,
18    'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
19    '!','"','#','$','%','&','\'','(',')', 0, /* JP key decode in this part.  */
20    0x0d,0x1b,0x08,0x07,0x20,'_','+','{','}',
21    '|','~',':','"','~','<','>','?',0xf0,
22    0xbb,0xbc,0xbd,0xbe,0xbf,0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,
23    0x00,0xf1,0x00,0xd2,0xc7,0xc9,0xd3,0xcf,0xd1,0xcd,0xcd,0xd0,0xc8,0xf2,
24    '/','*','-','+',
25    0x0d,'1','2','3','4','5','6','7','8','9','0','.','\\',0x00,0x00,'=',
26    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
27 };
28 
29 extern UCHAR ux_host_class_hid_keyboard_numlock_on_array[];
30 extern UCHAR ux_host_class_hid_keyboard_numlock_off_array[];
31 
32 static UX_HOST_CLASS_HID_KEYBOARD_LAYOUT test_layout_jp_0_9 =
33 {
34     .ux_host_class_hid_keyboard_layout_regular_array = ux_host_class_hid_keyboard_regular_array,
35     .ux_host_class_hid_keyboard_layout_shift_array = ux_host_class_hid_keyboard_shift_array_jp_0_9,
36     .ux_host_class_hid_keyboard_layout_numlock_on_array = ux_host_class_hid_keyboard_numlock_on_array,
37     .ux_host_class_hid_keyboard_layout_numlock_off_array = ux_host_class_hid_keyboard_numlock_off_array,
38     .ux_host_class_hid_keyboard_layout_keys_upper_range = UX_HID_KEYBOARD_KEYS_UPPER_RANGE,
39     .ux_host_class_hid_keyboard_layout_letters_lower_range = UX_HID_KEYBOARD_KEY_LETTER_A,
40     .ux_host_class_hid_keyboard_layout_letters_upper_range = UX_HID_KEYBOARD_KEY_LETTER_Z,
41     .ux_host_class_hid_keyboard_layout_keypad_lower_range = UX_HID_KEYBOARD_KEYS_KEYPAD_LOWER_RANGE,
42     .ux_host_class_hid_keyboard_layout_keypad_upper_range = UX_HID_KEYBOARD_KEYS_KEYPAD_UPPER_RANGE,
43 };
44 
45 /* Define constants.  */
46 #define                             UX_DEMO_STACK_SIZE  1024
47 #define                             UX_DEMO_MEMORY_SIZE     (64*1024)
48 
49 /* Define local/extern function prototypes.  */
50 static void                         demo_thread_entry(ULONG);
51 static UINT                         demo_thread_hid_callback(UX_SLAVE_CLASS_HID *, UX_SLAVE_CLASS_HID_EVENT *);
52 static TX_THREAD                    tx_demo_thread_host_simulation;
53 static TX_THREAD                    tx_demo_thread_slave_simulation;
54 static void                         tx_demo_thread_host_simulation_entry(ULONG);
55 static void                         tx_demo_thread_slave_simulation_entry(ULONG);
56 
57 
58 /* Define global data structures.  */
59 static UCHAR                               usbx_memory[UX_DEMO_MEMORY_SIZE + (UX_DEMO_STACK_SIZE * 2)];
60 static ULONG                               error_counter;
61 static TX_THREAD                           demo_thread;
62 static UX_HOST_CLASS                       *class_driver;
63 static ULONG                               class_driver_index;
64 static UX_HOST_CLASS_HID                   *hid;
65 static UX_HOST_CLASS_HID_CLIENT            *hid_client;
66 static UX_HOST_CLASS_HID_KEYBOARD          *keyboard;
67 static UINT                                status;
68 
69 static UX_SLAVE_CLASS_HID_PARAMETER        hid_parameter;
70 
71 #define DEVICE_FRAMEWORK_LENGTH_FULL_SPEED 52
72 static UCHAR device_framework_full_speed[] = {
73 
74     /* Device descriptor */
75         0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08,
76         0x81, 0x0A, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
77         0x00, 0x01,
78 
79     /* Configuration descriptor */
80         0x09, 0x02, 0x22, 0x00, 0x01, 0x01, 0x00, 0xc0,
81         0x32,
82 
83     /* Interface descriptor */
84         0x09, 0x04, 0x02, 0x00, 0x01, 0x03, 0x00, 0x00,
85         0x00,
86 
87     /* HID descriptor */
88         0x09, 0x21, 0x10, 0x01, 0x21, 0x01, 0x22, 0x3f,
89         0x00,
90 
91     /* Endpoint descriptor (Interrupt) */
92         0x07, 0x05, 0x82, 0x03, 0x08, 0x00, 0x08
93 
94     };
95 
96 
97 #define DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED 62
98 static UCHAR device_framework_high_speed[] = {
99 
100     /* Device descriptor */
101         0x12, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x40,
102         0x0a, 0x07, 0x25, 0x40, 0x01, 0x00, 0x01, 0x02,
103         0x03, 0x01,
104 
105     /* Device qualifier descriptor */
106         0x0a, 0x06, 0x00, 0x02, 0x00, 0x00, 0x00, 0x40,
107         0x01, 0x00,
108 
109     /* Configuration descriptor */
110         0x09, 0x02, 0x22, 0x00, 0x01, 0x01, 0x00, 0xc0,
111         0x32,
112 
113     /* Interface descriptor */
114         0x09, 0x04, 0x02, 0x00, 0x01, 0x03, 0x00, 0x00,
115         0x00,
116 
117     /* HID descriptor */
118         0x09, 0x21, 0x10, 0x01, 0x21, 0x01, 0x22, 0x3f,
119         0x00,
120 
121     /* Endpoint descriptor (Interrupt) */
122         0x07, 0x05, 0x82, 0x03, 0x08, 0x00, 0x08
123 
124     };
125 
126 
127     /* String Device Framework :
128      Byte 0 and 1 : Word containing the language ID : 0x0904 for US
129      Byte 2       : Byte containing the index of the descriptor
130      Byte 3       : Byte containing the length of the descriptor string
131     */
132 
133 #define STRING_FRAMEWORK_LENGTH 40
134 static UCHAR string_framework[] = {
135 
136     /* Manufacturer string descriptor : Index 1 */
137         0x09, 0x04, 0x01, 0x0c,
138         0x45, 0x78, 0x70, 0x72,0x65, 0x73, 0x20, 0x4c,
139         0x6f, 0x67, 0x69, 0x63,
140 
141     /* Product string descriptor : Index 2 */
142         0x09, 0x04, 0x02, 0x0c,
143         0x55, 0x53, 0x42, 0x20, 0x4b, 0x65, 0x79, 0x62,
144         0x6f, 0x61, 0x72, 0x64,
145 
146     /* Serial Number string descriptor : Index 3 */
147         0x09, 0x04, 0x03, 0x04,
148         0x30, 0x30, 0x30, 0x31
149     };
150 
151 
152     /* Multiple languages are supported on the device, to add
153        a language besides english, the unicode language code must
154        be appended to the language_id_framework array and the length
155        adjusted accordingly. */
156 #define LANGUAGE_ID_FRAMEWORK_LENGTH 2
157 static UCHAR language_id_framework[] = {
158 
159     /* English. */
160         0x09, 0x04
161     };
162 
163 #define HID_KEYBOARD_REPORT_LENGTH 63
164 static UCHAR hid_keyboard_report[HID_KEYBOARD_REPORT_LENGTH] = {
165 
166     0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
167     0x09, 0x06,                    // USAGE (Keyboard)
168     0xa1, 0x01,                    // COLLECTION (Application)
169     0x05, 0x07,                    //   USAGE_PAGE (Keyboard)
170     0x19, 0xe0,                    //   USAGE_MINIMUM (Keyboard LeftControl)
171     0x29, 0xe7,                    //   USAGE_MAXIMUM (Keyboard Right GUI)
172     0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
173     0x25, 0x01,                    //   LOGICAL_MAXIMUM (1)
174     0x75, 0x01,                    //   REPORT_SIZE (1)
175     0x95, 0x08,                    //   REPORT_COUNT (8)
176     0x81, 0x02,                    //   INPUT (Data,Var,Abs)
177     0x95, 0x01,                    //   REPORT_COUNT (1)
178     0x75, 0x08,                    //   REPORT_SIZE (8)
179     0x81, 0x03,                    //   INPUT (Cnst,Var,Abs)
180     0x95, 0x05,                    //   REPORT_COUNT (5)
181     0x75, 0x01,                    //   REPORT_SIZE (1)
182     0x05, 0x08,                    //   USAGE_PAGE (LEDs)
183     0x19, 0x01,                    //   USAGE_MINIMUM (Num Lock)
184     0x29, 0x05,                    //   USAGE_MAXIMUM (Kana)
185     0x91, 0x02,                    //   OUTPUT (Data,Var,Abs)
186     0x95, 0x01,                    //   REPORT_COUNT (1)
187     0x75, 0x03,                    //   REPORT_SIZE (3)
188     0x91, 0x03,                    //   OUTPUT (Cnst,Var,Abs)
189     0x95, 0x06,                    //   REPORT_COUNT (6)
190     0x75, 0x08,                    //   REPORT_SIZE (8)
191     0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
192     0x25, 0x65,                    //   LOGICAL_MAXIMUM (101)
193     0x05, 0x07,                    //   USAGE_PAGE (Keyboard)
194     0x19, 0x00,                    //   USAGE_MINIMUM (Reserved (no event indicated))
195     0x29, 0x65,                    //   USAGE_MAXIMUM (Keyboard Application)
196     0x81, 0x00,                    //   INPUT (Data,Ary,Abs)
197     0xc0                           // END_COLLECTION
198 };
199 
200 
201 
202 /* Define the ISR dispatch.  */
203 
204 extern VOID    (*test_isr_dispatch)(void);
205 
206 
207 /* Prototype for test control return.  */
208 
209 void  test_control_return(UINT status);
210 
211 
212 /* Define the ISR dispatch routine.  */
213 
test_isr(void)214 static void    test_isr(void)
215 {
216 
217     /* For further expansion of interrupt-level testing.  */
218 }
219 
220 
error_callback(UINT system_level,UINT system_context,UINT error_code)221 static VOID error_callback(UINT system_level, UINT system_context, UINT error_code)
222 {
223 
224     /* @BUG_FIX_PENDING: ux_dcd_sim_slave_function.c doesn't support transfer aborts, which happen during device unregistration of a class. */
225     if (error_code != UX_FUNCTION_NOT_SUPPORTED)
226     {
227 
228         /* Failed test.  */
229         printf("Error on line %d, system_level: %d, system_context: %d, error code: %d\n", __LINE__, system_level, system_context, error_code);
230         test_control_return(1);
231     }
232 }
233 
ux_system_host_change_function(ULONG a,UX_HOST_CLASS * b,VOID * c)234 static UINT ux_system_host_change_function(ULONG a, UX_HOST_CLASS *b, VOID *c)
235 {
236     switch(a)
237     {
238 
239     case UX_HID_CLIENT_INSERTION:
240         hid_client = (UX_HOST_CLASS_HID_CLIENT *)c;
241         keyboard = (UX_HOST_CLASS_HID_KEYBOARD *)hid_client -> ux_host_class_hid_client_local_instance;
242         break;
243 
244     case UX_HID_CLIENT_REMOVAL:
245         if ((VOID *)hid_client == c)
246         {
247             keyboard = UX_NULL;
248             hid_client = UX_NULL;
249         }
250         break;
251 
252     default:
253         break;
254     }
255     return 0;
256 }
257 
258 /* Define what the initial system looks like.  */
259 
260 #ifdef CTEST
test_application_define(void * first_unused_memory)261 void test_application_define(void *first_unused_memory)
262 #else
263 void    usbx_test_USBX_141_keyboard_layout_application_define(void *first_unused_memory)
264 #endif
265 {
266 
267 UINT status;
268 CHAR *                          stack_pointer;
269 CHAR *                          memory_pointer;
270 
271     /* Inform user.  */
272     printf("Running USBX-141 HID Keyboard Decode Layout Test.................... ");
273 
274     /* Initialize the free memory pointer */
275     stack_pointer = (CHAR *) usbx_memory;
276     memory_pointer = stack_pointer + (UX_DEMO_STACK_SIZE * 2);
277 
278     /* Initialize USBX. Memory */
279     status = ux_system_initialize(memory_pointer, UX_DEMO_MEMORY_SIZE, UX_NULL,0);
280 
281     /* Check for error.  */
282     if (status != UX_SUCCESS)
283     {
284 
285         printf("Error on line %d\n", __LINE__);
286         test_control_return(1);
287     }
288 
289     /* Register the error callback. */
290     _ux_utility_error_callback_register(error_callback);
291 
292     /* The code below is required for installing the host portion of USBX */
293     status =  ux_host_stack_initialize(ux_system_host_change_function);
294     if (status != UX_SUCCESS)
295     {
296 
297         printf("Error on line %d\n", __LINE__);
298         test_control_return(1);
299     }
300 
301     status =  ux_host_stack_class_register(_ux_system_host_class_hid_name, ux_host_class_hid_entry);
302     if (status != UX_SUCCESS)
303     {
304 
305         printf("Error on line %d\n", __LINE__);
306         test_control_return(1);
307     }
308 
309     /* Register the HID client(s).  */
310     status =  ux_host_class_hid_client_register(_ux_system_host_class_hid_client_keyboard_name, ux_host_class_hid_keyboard_entry);
311     if (status != UX_SUCCESS)
312     {
313 
314         printf("Error on line %d\n", __LINE__);
315         test_control_return(1);
316     }
317 
318     /* The code below is required for installing the device portion of USBX. No call back for
319        device status change in this example. */
320     status =  ux_device_stack_initialize(device_framework_high_speed, DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED,
321                                        device_framework_full_speed, DEVICE_FRAMEWORK_LENGTH_FULL_SPEED,
322                                        string_framework, STRING_FRAMEWORK_LENGTH,
323                                        language_id_framework, LANGUAGE_ID_FRAMEWORK_LENGTH,UX_NULL);
324     if(status!=UX_SUCCESS)
325     {
326 
327         printf("Error on line %d\n", __LINE__);
328         test_control_return(1);
329     }
330 
331     /* Initialize the hid class parameters for a keyboard.  */
332     hid_parameter.ux_device_class_hid_parameter_report_address = hid_keyboard_report;
333     hid_parameter.ux_device_class_hid_parameter_report_length  = HID_KEYBOARD_REPORT_LENGTH;
334     hid_parameter.ux_device_class_hid_parameter_callback       = demo_thread_hid_callback;
335 
336     /* Initilize the device hid class. The class is connected with interface 2 */
337     status =  ux_device_stack_class_register(_ux_system_slave_class_hid_name, ux_device_class_hid_entry,
338                                                 1,2, (VOID *)&hid_parameter);
339     if(status!=UX_SUCCESS)
340     {
341 
342         printf("Error on line %d\n", __LINE__);
343         test_control_return(1);
344     }
345 
346 
347     /* Initialize the simulated device controller.  */
348     status =  _ux_dcd_sim_slave_initialize();
349 
350     /* Check for error.  */
351     if (status != UX_SUCCESS)
352     {
353 
354         printf("Error on line %d\n", __LINE__);
355         test_control_return(1);
356     }
357 
358     /* Register all the USB host controllers available in this system */
359     status =  ux_host_stack_hcd_register(_ux_system_host_hcd_simulator_name, ux_hcd_sim_host_initialize,0,0);
360 
361     /* Check for error.  */
362     if (status != UX_SUCCESS)
363     {
364 
365         printf("Error on line %d\n", __LINE__);
366         test_control_return(1);
367     }
368 
369     /* Create the main host simulation thread.  */
370     status =  tx_thread_create(&tx_demo_thread_host_simulation, "tx demo host simulation", tx_demo_thread_host_simulation_entry, 0,
371             stack_pointer, UX_DEMO_STACK_SIZE,
372             20, 20, 1, TX_AUTO_START);
373 
374     /* Check for error.  */
375     if (status != TX_SUCCESS)
376     {
377 
378         printf("Error on line %d\n", __LINE__);
379         test_control_return(1);
380     }
381 
382     /* Create the main demo thread.  */
383     status =  tx_thread_create(&tx_demo_thread_slave_simulation, "tx demo slave simulation", tx_demo_thread_slave_simulation_entry, 0,
384             stack_pointer + UX_DEMO_STACK_SIZE, UX_DEMO_STACK_SIZE,
385             20, 20, 1, TX_DONT_START);
386 
387     /* Check for error.  */
388     if (status != TX_SUCCESS)
389     {
390 
391         printf("Error on line %d\n", __LINE__);
392         test_control_return(1);
393     }
394 
395 }
396 
demo_class_hid_get(void)397 static UINT  demo_class_hid_get(void)
398 {
399 
400 UINT status;
401 UX_HOST_CLASS       *class;
402 
403     /* Find the main HID container */
404     status =  ux_host_stack_class_get(_ux_system_host_class_hid_name, &class);
405     if (status != UX_SUCCESS)
406         return(status);
407 
408     /* We get the first instance of the hid device */
409     do
410     {
411 
412         status =  ux_host_stack_class_instance_get(class, 0, (void **) &hid);
413         tx_thread_sleep(10);
414     } while (status != UX_SUCCESS);
415 
416     /* We still need to wait for the hid status to be live */
417     while (hid -> ux_host_class_hid_state != UX_HOST_CLASS_INSTANCE_LIVE)
418         tx_thread_sleep(10);
419 
420     return(UX_SUCCESS);
421 }
422 
_wait_key(UX_HOST_CLASS_HID_KEYBOARD * keyboard,ULONG * keyboard_key,ULONG * keyboard_state)423 static UINT  _wait_key(UX_HOST_CLASS_HID_KEYBOARD *keyboard, ULONG *keyboard_key, ULONG *keyboard_state)
424 {
425 
426 UINT        i;
427 
428 
429     for(i = 0; i < 50; i ++)
430     {
431         if (ux_host_class_hid_keyboard_key_get(keyboard, keyboard_key, keyboard_state) == UX_SUCCESS)
432         {
433             return UX_SUCCESS;
434         }
435         _ux_utility_delay_ms(1);
436     }
437     return UX_ERROR;
438 }
439 
tx_demo_thread_host_simulation_entry(ULONG arg)440 static void  tx_demo_thread_host_simulation_entry(ULONG arg)
441 {
442 
443 #define N_TEST 3
444 #define N_KEY  4
445 
446 UINT                            status;
447 ULONG                           keyboard_key;
448 ULONG                           keyboard_state;
449 UINT                            i, j;
450 UCHAR                             decode_disable[N_TEST] = {UX_FALSE, UX_FALSE, UX_TRUE};
451 UX_HOST_CLASS_HID_KEYBOARD_LAYOUT *layouts[N_TEST] = {&test_layout_jp_0_9, UX_NULL, &test_layout_jp_0_9};
452 UCHAR                             expected_keys[N_TEST][N_KEY] = {
453     /*        4 (a)
454      * SHIFT  4 (A)
455      *       31 (2)
456      * SHIFT 31 (@) (")
457      */
458     {'a', 'A', '2', '"'},
459     {'a', 'A', '2', '@'},
460     { 4 ,  4 ,  31,  31}
461 };
462 
463 
464     /* Find the HID class */
465     status =  demo_class_hid_get();
466     if (status != UX_SUCCESS)
467     {
468 
469         /* HID Keyboard basic test error.  */
470         printf("Error on line %d\n", __LINE__);
471         test_control_return(1);
472     }
473 
474     /* Check if the instance of the keyboard is live */
475     while (hid_client == UX_NULL && keyboard == UX_NULL)
476         tx_thread_sleep(10);
477 
478     for (i = 0; i < N_TEST; i ++)
479     {
480         /* Set up decode & layout.  */
481         status  = ux_host_class_hid_keyboard_ioctl(keyboard,
482                                                    UX_HID_KEYBOARD_IOCTL_SET_LAYOUT, (VOID *)layouts[i]);
483         status |= ux_host_class_hid_keyboard_ioctl(keyboard,
484                                                    decode_disable[i] ? UX_HID_KEYBOARD_IOCTL_DISABLE_KEYS_DECODE :
485                                                                        UX_HID_KEYBOARD_IOCTL_ENABLE_KEYS_DECODE,
486                                                    UX_NULL);
487 
488         /* Enable device to send keys.  */
489         ux_utility_thread_resume(&tx_demo_thread_slave_simulation);
490 
491         /* Wait keys.  */
492         for (j = 0; j < N_KEY; j ++)
493         {
494             status = _wait_key(keyboard, &keyboard_key, &keyboard_state);
495             if (status != UX_SUCCESS)
496             {
497                 printf("ERROR #%d.%d.%d: code 0x%x\n", __LINE__, i, j, status);
498                 test_control_return(1);
499             }
500             if ((UCHAR)keyboard_key != expected_keys[i][j])
501             {
502                 printf("ERROR #%d.%d.%d: key 0x%x (%c) <> 0x%x (%c)\n", __LINE__, i, j,
503                         (UCHAR)keyboard_key, (UCHAR)keyboard_key,
504                         expected_keys[i][j], expected_keys[i][j]);
505                 test_control_return(1);
506             }
507             printf("state: 0x%4lx, key: 0x%2lx (%c)\n", keyboard_state, keyboard_key, (char)keyboard_key);
508         }
509     }
510 
511     /* Now disconnect the device.  */
512     _ux_device_stack_disconnect();
513 
514     /* And deinitialize the class.  */
515     status =  ux_device_stack_class_unregister(_ux_system_slave_class_hid_name, ux_device_class_hid_entry);
516 
517     /* Deinitialize the device side of usbx.  */
518     _ux_device_stack_uninitialize();
519 
520     /* And finally the usbx system resources.  */
521     _ux_system_uninitialize();
522 
523     /* Successful test.  */
524     printf("SUCCESS!\n");
525     test_control_return(0);
526 }
527 
demo_thread_hid_callback(UX_SLAVE_CLASS_HID * class,UX_SLAVE_CLASS_HID_EVENT * event)528 static UINT    demo_thread_hid_callback(UX_SLAVE_CLASS_HID *class, UX_SLAVE_CLASS_HID_EVENT *event)
529 {
530     return(UX_SUCCESS);
531 }
532 
tx_demo_thread_slave_simulation_entry(ULONG arg)533 static void  tx_demo_thread_slave_simulation_entry(ULONG arg)
534 {
535 
536 UX_SLAVE_DEVICE                 *device;
537 UX_SLAVE_INTERFACE              *interface;
538 UX_SLAVE_CLASS_HID              *hid;
539 UX_SLAVE_CLASS_HID_EVENT        hid_event;
540 UCHAR                           modifiers[4];
541 UCHAR                           keys[4];
542 UINT                            i;
543 
544     /* Get the pointer to the device.  */
545     device =  &_ux_system_slave -> ux_system_slave_device;
546 
547     /* Set the keys.  */
548     /*        4 (a)
549      * SHIFT  4 (A)
550      *       31 (2)
551      * SHIFT 31 (@) (")
552      */
553     modifiers[0] = 0;
554     keys[0] = 4;  /* a */
555     modifiers[1] = 1u << 1;
556     keys[1] = 4;  /* A */
557     modifiers[2] = 0;
558     keys[2] = 31; /* 2 */
559     modifiers[3] = 1u << 1;
560     keys[3] = 31; /* @/" */
561 
562     /* reset the HID event structure.  */
563     ux_utility_memory_set(&hid_event, 0, sizeof(UX_SLAVE_CLASS_HID_EVENT));
564 
565     while(1)
566     {
567         /* Is the device configured ? */
568         if (device -> ux_slave_device_state != UX_DEVICE_CONFIGURED)
569         {
570 
571             /* Then wait.  */
572             ux_utility_delay_ms(5);
573             continue;
574         }
575 
576         /* Get the interface.  We use the first interface, this is a simple device.  */
577         interface =  device -> ux_slave_device_first_interface;
578 
579         /* Form that interface, derive the HID owner.  */
580         hid = interface -> ux_slave_interface_class_instance;
581 
582         /* Send keys.  */
583         for (i = 0; i < sizeof(keys); i ++)
584         {
585 
586             /* Then insert a key into the keyboard event.  Length is fixed to 8.  */
587             hid_event.ux_device_class_hid_event_length = 8;
588 
589             /* First byte is a modifier byte.  */
590             hid_event.ux_device_class_hid_event_buffer[0] = modifiers[i];
591 
592             /* Second byte is reserved. */
593             hid_event.ux_device_class_hid_event_buffer[1] = 0;
594 
595             /* The 6 next bytes are keys. We only have one key here.  */
596             hid_event.ux_device_class_hid_event_buffer[2] = keys[i];
597 
598             /* Set the keyboard event.  */
599             ux_device_class_hid_event_set(hid, &hid_event);
600 
601             /* Next event has the key depressed.  */
602             hid_event.ux_device_class_hid_event_buffer[2] = 0;
603 
604             /* Length is fixed to 8.  */
605             hid_event.ux_device_class_hid_event_length = 8;
606 
607             /* Set the keyboard event.  */
608             ux_device_class_hid_event_set(hid, &hid_event);
609         }
610 
611         ux_utility_thread_suspend(&tx_demo_thread_slave_simulation);
612     }
613 }
614 
615