1 #include <stdio.h>
2 #include <stdarg.h>
3 #include "tx_api.h"
4 #include "ux_api.h"
5 #include "ux_system.h"
6 #include "ux_utility.h"
7 #include "ux_host_class_hid.h"
8 #include "ux_host_class_hid_keyboard.h"
9 #include "ux_host_class_hid_mouse.h"
10 #include "ux_host_class_hid_remote_control.h"
11 #include "ux_device_class_hid.h"
12 #include "ux_device_stack.h"
13 
14 #include "ux_test.h"
15 #include "usbx_test_common.h"
16 
17 #define     ARRAY_COUNT(array)  (sizeof(array)/sizeof(array[0]))
18 #define     LSB(x)              (x & 0xff)
19 #define     MSB(x)              ((x & 0xff00) >> 8)
20 
21 /* Define constants.  */
22 #define                             UX_DEMO_STACK_SIZE  	1024
23 #define                             UX_DEMO_MEMORY_SIZE     (96*1024)
24 
25 /* Define local/extern function prototypes.  */
26 static void                         demo_thread_entry(ULONG);
27 static UINT                         demo_thread_hid_callback(UX_SLAVE_CLASS_HID *, UX_SLAVE_CLASS_HID_EVENT *);
28 static UINT                         demo_thread_hid_set_callback(UX_SLAVE_CLASS_HID *, UX_SLAVE_CLASS_HID_EVENT *);
29 static UINT                         demo_thread_hid_get_callback(UX_SLAVE_CLASS_HID *, UX_SLAVE_CLASS_HID_EVENT *);
30 static void                         tx_demo_thread_host_simulation_entry(ULONG);
31 static void                         tx_demo_thread_slave_simulation_entry(ULONG);
32 static void                         tx_demo_thread_device_simulation_entry(ULONG);
33 
34 static void                         demo_device_hid_instance_activate(VOID *);
35 static void                         demo_device_hid_instance_deactivate(VOID *);
36 
37 
38 /* Define global data structures.  */
39 static UCHAR                               usbx_memory[UX_DEMO_MEMORY_SIZE + (UX_DEMO_STACK_SIZE * 2)];
40 static TX_THREAD                           tx_demo_thread_host_simulation;
41 static TX_THREAD                           tx_demo_thread_slave_simulation;
42 static TX_THREAD                           tx_demo_thread_device_simulation;
43 static UX_HOST_CLASS_HID                   *hid;
44 static UX_HOST_CLASS_HID_REPORT_CALLBACK   hid_report_callback;
45 static UX_HOST_CLASS_HID_CLIENT            *hid_client;
46 static UX_HOST_CLASS_HID_KEYBOARD          *hid_keyboard;
47 static UX_HOST_CLASS_HID_MOUSE             *hid_mouse;
48 static UX_HOST_CLASS_HID_REMOTE_CONTROL    *hid_remote_control;
49 static UX_HOST_CLASS_HID_REPORT_GET_ID     hid_report_id;
50 static UX_HOST_CLASS_HID_CLIENT_REPORT     client_report;
51 static UX_SLAVE_CLASS_HID_PARAMETER        hid_parameter;
52 static UX_SLAVE_CLASS_HID                  *device_hid;
53 static UX_SLAVE_CLASS_HID_EVENT            device_hid_event;
54 
55 
56 /* Prototype for test control return.  */
57 void  test_control_return(UINT status);
58 
59 
demo_class_hid_get(void)60 static UINT demo_class_hid_get(void)
61 {
62 
63 UINT                 status;
64 UX_HOST_CLASS       *class;
65 
66 
67     /* Wait for enum thread to complete. */
68     ux_test_wait_for_enum_thread_completion();
69 
70     /* Find the main HID container */
71     status = ux_host_stack_class_get(_ux_system_host_class_hid_name, &class);
72     if (status != UX_SUCCESS)
73         return(status);
74 
75     /* We get the first instance of the hid device */
76     status = ux_host_stack_class_instance_get(class, 0, (void **)&hid);
77     if (status != UX_SUCCESS)
78         return(status);
79 
80     if(hid -> ux_host_class_hid_state != UX_HOST_CLASS_INSTANCE_LIVE)
81         return(UX_ERROR);
82 
83     /* Get client.  */
84     hid_client = hid -> ux_host_class_hid_client;
85     return(UX_SUCCESS);
86 }
87 
demo_class_hid_keyboard_get(void)88 static UINT demo_class_hid_keyboard_get(void)
89 {
90 UINT                 status;
91 
92     status = demo_class_hid_get();
93     if (status != UX_SUCCESS)
94         return(status);
95 
96     /* Check client entry.  */
97     if (hid_client -> ux_host_class_hid_client_handler != ux_host_class_hid_keyboard_entry)
98         return(UX_ERROR);
99 
100     /* Get instance.  */
101     hid_keyboard = (UX_HOST_CLASS_HID_KEYBOARD *)hid_client -> ux_host_class_hid_client_local_instance;
102     if (hid_keyboard == UX_NULL)
103         return(UX_ERROR);
104 
105     /* Check instance state.  */
106     if (hid_keyboard -> ux_host_class_hid_keyboard_state != UX_HOST_CLASS_INSTANCE_LIVE)
107         return(UX_ERROR);
108 
109     /* Instance is good.  */
110     return(UX_SUCCESS);
111 }
112 
demo_class_hid_mouse_get(void)113 static UINT demo_class_hid_mouse_get(void)
114 {
115 UINT                 status;
116 
117     status = demo_class_hid_get();
118     if (status != UX_SUCCESS)
119         return(status);
120 
121     /* Check client entry.  */
122     if (hid_client -> ux_host_class_hid_client_handler != ux_host_class_hid_mouse_entry)
123         return(UX_ERROR);
124 
125     /* Get instance.  */
126     hid_mouse = (UX_HOST_CLASS_HID_MOUSE *)hid_client -> ux_host_class_hid_client_local_instance;
127     if (hid_mouse == UX_NULL)
128         return(UX_ERROR);
129 
130     /* Check instance state.  */
131     if (hid_mouse -> ux_host_class_hid_mouse_state != UX_HOST_CLASS_INSTANCE_LIVE)
132         return(UX_ERROR);
133 
134     /* Instance is good.  */
135     return(UX_SUCCESS);
136 }
137 
demo_class_hid_remote_control_get(void)138 static UINT demo_class_hid_remote_control_get(void)
139 {
140 UINT                 status;
141 
142     status = demo_class_hid_get();
143     if (status != UX_SUCCESS)
144         return(status);
145 
146     /* Check client entry.  */
147     if (hid_client -> ux_host_class_hid_client_handler != ux_host_class_hid_remote_control_entry)
148         return(UX_ERROR);
149 
150     /* Get instance.  */
151     hid_remote_control = (UX_HOST_CLASS_HID_REMOTE_CONTROL *)hid_client -> ux_host_class_hid_client_local_instance;
152     if (hid_remote_control == UX_NULL)
153         return(UX_ERROR);
154 
155     /* Check instance state.  */
156     if (hid_remote_control -> ux_host_class_hid_remote_control_state != UX_HOST_CLASS_INSTANCE_LIVE)
157         return(UX_ERROR);
158 
159     /* Instance is good.  */
160     return(UX_SUCCESS);
161 }
162