1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
21
22
23
24
25
26
27
28
29
33
34
35
39
40
41
45
46
47
52
53
54
59
67
68
73
74
75
76
77
83
105
126
132
140
148
150
151
152
153
154
155
156
157
158
159
160
161
162
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
202
203
204
205
206
207
208
209
210
211
215
219
220
221
222
227
231
232
237
238
239
240
241
242
243
244
245
246
247
251
255
256
260
264
265
269
273
274
275
276
281
282
283
284
285
286
287
295
/* ... */
#include "main.h"
Includes
HID_DEMO_StateMachine hid_demo;
uint8_t prev_select = 0;
uint8_t *DEMO_KEYBOARD_menu[] =
{
(uint8_t *)" 1 - Start Keyboard / Clear ",
(uint8_t *)" 2 - Return ",
...};
uint8_t *DEMO_MOUSE_menu[] =
{
(uint8_t *)" 1 - Start Mouse / Re-Initialize ",
(uint8_t *)" 2 - Return ",
...};
uint8_t *DEMO_HID_menu[] =
{
(uint8_t *)" 1 - Start HID ",
(uint8_t *)" 2 - Re-Enumerate ",
...};
TS_StateTypeDef TS_State = {0};Private variables
static void HID_DEMO_ProbeKey(void);
static void USBH_MouseDemo(USBH_HandleTypeDef *phost);
static void USBH_KeybdDemo(USBH_HandleTypeDef *phost);
Private function prototypes
/* ... */
void HID_MenuInit(void)
{
USBH_UsrLog("Starting HID Demo");
hid_demo.state = HID_DEMO_IDLE;
HID_MenuProcess();
}{ ... }
/* ... */
void HID_MenuProcess(void)
{
switch(hid_demo.state)
{
case HID_DEMO_IDLE:
HID_SelectItem(DEMO_HID_menu, 0);
hid_demo.state = HID_DEMO_WAIT;
hid_demo.select = 0;
break;
case HID_DEMO_IDLE:
case HID_DEMO_WAIT:
if(hid_demo.select != prev_select)
{
prev_select = hid_demo.select;
HID_SelectItem(DEMO_HID_menu, (hid_demo.select >> 4));
switch(hid_demo.select)
{
case 0x0F:
hid_demo.state = HID_DEMO_START;
break;
case 0x0F:
case 0x1F:
hid_demo.state = HID_DEMO_REENUMERATE;
break;
case 0x1F:
default:
break;default
}switch (hid_demo.select) { ... }
}if (hid_demo.select != prev_select) { ... }
break;
case HID_DEMO_WAIT:
case HID_DEMO_START:
if(Appli_state == APPLICATION_READY)
{
if(USBH_HID_GetDeviceType(&hUSBHost) == HID_KEYBOARD)
{
hid_demo.keyboard_state = HID_KEYBOARD_IDLE;
hid_demo.state = HID_DEMO_KEYBOARD;
}if (USBH_HID_GetDeviceType(&hUSBHost) == HID_KEYBOARD) { ... }
else if(USBH_HID_GetDeviceType(&hUSBHost) == HID_MOUSE)
{
hid_demo.mouse_state = HID_MOUSE_IDLE;
hid_demo.state = HID_DEMO_MOUSE;
}else if (USBH_HID_GetDeviceType(&hUSBHost) == HID_MOUSE) { ... }
}if (Appli_state == APPLICATION_READY) { ... }
else
{
LCD_ErrLog("No supported HID device!\n");
hid_demo.state = HID_DEMO_WAIT;
}else { ... }
break;
case HID_DEMO_START:
case HID_DEMO_REENUMERATE:
USBH_ReEnumerate(&hUSBHost);
hid_demo.state = HID_DEMO_WAIT;
break;
case HID_DEMO_REENUMERATE:
case HID_DEMO_MOUSE:
if(Appli_state == APPLICATION_READY)
{
HID_MouseMenuProcess();
USBH_MouseDemo(&hUSBHost);
}if (Appli_state == APPLICATION_READY) { ... }
break;
case HID_DEMO_MOUSE:
case HID_DEMO_KEYBOARD:
if(Appli_state == APPLICATION_READY)
{
HID_KeyboardMenuProcess();
USBH_KeybdDemo(&hUSBHost);
}if (Appli_state == APPLICATION_READY) { ... }
break;
case HID_DEMO_KEYBOARD:
default:
break;default
}switch (hid_demo.state) { ... }
if(Appli_state == APPLICATION_DISCONNECT)
{
Appli_state = APPLICATION_IDLE;
LCD_LOG_ClearTextZone();
LCD_ErrLog("HID device disconnected!\n");
hid_demo.state = HID_DEMO_IDLE;
hid_demo.select = 0;
}if (Appli_state == APPLICATION_DISCONNECT) { ... }
}{ ... }
/* ... */
void HID_SelectItem(uint8_t **menu, uint8_t item)
{
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
switch(item)
{
case 0:
BSP_LCD_SetBackColor(LCD_COLOR_MAGENTA);
BSP_LCD_DisplayStringAtLine(16, menu [0]);
BSP_LCD_DisplayStringAtLine(17, (uint8_t*)" ");
BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
BSP_LCD_DisplayStringAtLine(18, menu [1]);
BSP_LCD_DisplayStringAtLine(19, (uint8_t*)" ");
break;
case 0:
case 1:
BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
BSP_LCD_DisplayStringAtLine(16, menu [0]);
BSP_LCD_DisplayStringAtLine(17, (uint8_t*)" ");
BSP_LCD_SetBackColor(LCD_COLOR_MAGENTA);
BSP_LCD_DisplayStringAtLine(18, menu [1]);
BSP_LCD_DisplayStringAtLine(19, (uint8_t*)" ");
BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
break; case 1:
}switch (item) { ... }
BSP_LCD_SetBackColor(LCD_COLOR_BLACK);
}{ ... }
/* ... */
static void HID_DEMO_ProbeKey(void)
{
uint16_t y1;
BSP_TS_GetState(&TS_State);
if(TS_State.touchDetected)
{
y1 = TouchScreen_Get_Calibrated_Y(TS_State.touchY[0]);
if((y1< 216) && (y1>192))
{
hid_demo.select = 0x0F;
}if ((y1< 216) && (y1>192)) { ... }
else if(y1> 216)
{
hid_demo.select = 0x1F;
}else if (y1> 216) { ... }
}if (TS_State.touchDetected) { ... }
}{ ... }
/* ... */
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
HID_DEMO_ProbeKey();
}{ ... }
/* ... */
static void USBH_MouseDemo(USBH_HandleTypeDef *phost)
{
HID_MOUSE_Info_TypeDef *m_pinfo;
m_pinfo = USBH_HID_GetMouseInfo(phost);
if(m_pinfo != NULL)
{
USR_MOUSE_ProcessData(&mouse_info);
if(m_pinfo->buttons[0])
{
HID_MOUSE_ButtonPressed(0);
}if (m_pinfo->buttons[0]) { ... }
else
{
HID_MOUSE_ButtonReleased(0);
}else { ... }
if(m_pinfo->buttons[1])
{
HID_MOUSE_ButtonPressed(2);
}if (m_pinfo->buttons[1]) { ... }
else
{
HID_MOUSE_ButtonReleased(2);
}else { ... }
if(m_pinfo->buttons[2])
{
HID_MOUSE_ButtonPressed(1);
}if (m_pinfo->buttons[2]) { ... }
else
{
HID_MOUSE_ButtonReleased(1);
}else { ... }
}if (m_pinfo != NULL) { ... }
}{ ... }
/* ... */
static void USBH_KeybdDemo(USBH_HandleTypeDef *phost)
{
HID_KEYBD_Info_TypeDef *k_pinfo;
char c;
k_pinfo = USBH_HID_GetKeybdInfo(phost);
if(k_pinfo != NULL)
{
c = USBH_HID_GetASCIICode(k_pinfo);
if(c != 0)
{
USR_KEYBRD_ProcessData(c);
}if (c != 0) { ... }
}if (k_pinfo != NULL) { ... }
}{ ... }