-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo_host_hid_mouse_rtos.c
More file actions
208 lines (160 loc) · 6.78 KB
/
demo_host_hid_mouse_rtos.c
File metadata and controls
208 lines (160 loc) · 6.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/***************************************************************************
* Copyright (c) 2025-present Eclipse ThreadX Contributors
*
* This program and the accompanying materials are made available under the
* terms of the MIT License which is available at
* https://opensource.org/licenses/MIT.
*
*
* SPDX-License-Identifier: MIT
**************************************************************************/
/**************************************************************************/
/**************************************************************************/
/** */
/** Overview */
/** */
/** */
/** Note */
/** */
/** This demonstration is not optimized, to optimize application user */
/** should configure related class flag in ux_user.h and adjust */
/** UX_DEVICE_MEMORY_STACK_SIZE */
/** */
/** */
/** AUTHOR */
/** */
/** Mohamed AYED */
/** */
/**************************************************************************/
/**************************************************************************/
#include "ux_api.h"
#include "ux_host_class_hid.h"
#include "ux_host_class_hid_mouse.h"
#ifndef UX_DEVICE_SIDE_ONLY
#error UX_DEVICE_SIDE_ONLY must be defined
#endif
/**************************************************/
/** Define constants */
/**************************************************/
#define UX_HOST_MEMORY_STACK_SIZE 1024
#define UX_DEMO_THREAD_STACK_SIZE 1024
/**************************************************/
/** usbx application initialization with RTOS */
/**************************************************/
VOID tx_application_define(VOID *first_unused_memory);
/**************************************************/
/** usbx device hid demo thread */
/**************************************************/
VOID ux_demo_device_hid_thread_entry(ULONG thread_input);
/**************************************************/
/** usbx device hid demo mouse */
/**************************************************/
static UINT ux_demo_host_change_callback(ULONG event, UX_HOST_CLASS *host_class, VOID *instance);
UX_HOST_CLASS_HID *hid_instance;
UX_HOST_CLASS_HID_MOUSE *mouse;
/**************************************************/
/** thread object */
/**************************************************/
static UX_THREAD ux_hid_thread;
static ULONG ux_hid_thread_stack[UX_DEMO_THREAD_STACK_SIZE / sizeof(ULONG)];
/**************************************************/
/** usbx callback error */
/**************************************************/
static VOID ux_demo_error_callback(UINT system_level, UINT system_context, UINT error_code);
static CHAR ux_system_memory_pool[UX_HOST_MEMORY_STACK_SIZE];
#ifndef EXTERNAL_MAIN
extern int board_setup(void);
#endif /* EXTERNAL_MAIN */
extern int usb_device_dcd_initialize(void *param);
#ifndef EXTERNAL_MAIN
int main(void)
{
/* Initialize the board. */
board_setup();
/* Enter the ThreadX kernel. */
tx_kernel_enter();
}
#endif /* EXTERNAL_MAIN */
VOID tx_application_define(VOID *first_unused_memory)
{
CHAR *memory_pointer;
UINT status;
UX_PARAMETER_NOT_USED(first_unused_memory);
/* Use static memory block. */
memory_pointer = ux_system_memory_pool;
/* Initialize USBX Memory */
status = ux_system_initialize(memory_pointer, UX_HOST_MEMORY_STACK_SIZE, UX_NULL, 0);
if(status != UX_SUCCESS)
return;
/* Install the device portion of USBX. */
status = ux_host_stack_initialize(ux_demo_host_change_callback);
if(status != UX_SUCCESS)
return;
/* Register the hid class. */
status = ux_host_stack_class_register(_ux_system_host_class_hid_name, ux_host_class_hid_entry);
if(status != UX_SUCCESS)
return;
/* Register the HID mouse client. */
status = ux_host_class_hid_client_register(_ux_system_host_class_hid_client_mouse_name,
ux_host_class_hid_mouse_entry);
if(status != UX_SUCCESS)
return;
/* Register error callback. */
ux_utility_error_callback_register(ux_demo_error_callback);
}
static UINT ux_demo_host_change_callback(ULONG event, UX_HOST_CLASS *current_class, VOID *current_instance)
{
/* Get current Hid Client */
UX_HOST_CLASS_HID_CLIENT *client = (UX_HOST_CLASS_HID_CLIENT *)current_instance;
switch (event)
{
case UX_DEVICE_INSERTION:
/* Get current Hid Class */
if (current_class -> ux_host_class_entry_function == ux_host_class_hid_entry)
{
if (hid_instance == UX_NULL)
{
/* Get current Hid Instance */
hid_instance = (UX_HOST_CLASS_HID *)current_instance;
}
}
break;
case UX_DEVICE_REMOVAL:
/* Free HID Instance */
if ((VOID*)hid_instance == current_instance)
{
hid_instance = UX_NULL;
}
break;
case UX_HID_CLIENT_INSERTION:
/* Check the HID_client if this is a HID mouse device */
if (client -> ux_host_class_hid_client_handler == ux_host_class_hid_mouse_entry)
{
/* Get current Hid Client */
if (mouse == UX_NULL)
{
mouse = client -> ux_host_class_hid_client_local_instance;
}
}
/* USER CODE END UX_HID_CLIENT_INSERTION */
break;
case UX_HID_CLIENT_REMOVAL:
if ((VOID*)mouse == client -> ux_host_class_hid_client_local_instance)
{
/* Clear hid mouse instance */
mouse = UX_NULL;
}
break;
default:
break;
}
return UX_SUCCESS;
}
static VOID ux_demo_error_callback(UINT system_level, UINT system_context, UINT error_code)
{
/*
* Refer to ux_api.h. For example,
* UX_SYSTEM_LEVEL_INTERRUPT, UX_SYSTEM_CONTEXT_DCD, UX_DEVICE_HANDLE_UNKNOWN
*/
printf("USBX error: system level(%d), context(%d), error code(0x%x)\r\n", system_level, system_context, error_code);
}