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
30
36
37
38
44
45
46
52
53
57
58
59
64
65
66
67
68
74
103
124
132
140
142
143
144
145
150
151
152
153
154
155
156
157
158
159
160
161
165
169
170
174
178
179
183
187
188
189
190
195
196
197
198
199
200
201
202
210
/* ... */
#include "main.h"
Includes
extern DEMO_StateMachine demo;
extern HID_MOUSE_Info_TypeDef mouse_info;
extern uint8_t prev_select;
uint8_t *DEMO_KEYBOARD_menu[] =
{
(uint8_t *)" 1 - Start Keyboard / Clear ",
(uint8_t *)" 2 - Return ",
(uint8_t *)" ",
(uint8_t *)" ",
...};
uint8_t *DEMO_MOUSE_menu[] =
{
(uint8_t *)" 1 - Start Mouse / Re-Initialize ",
(uint8_t *)" 2 - Return ",
(uint8_t *)" ",
(uint8_t *)" ",
...};
uint8_t *DEMO_HID_menu[] =
{
(uint8_t *)" 1 - Start HID ",
(uint8_t *)" 2 - Re-Enumerate ",
(uint8_t *)" ",
(uint8_t *)" ",
...};
Private variables
static void USBH_MouseDemo(USBH_HandleTypeDef *phost);
static void USBH_KeybdDemo(USBH_HandleTypeDef *phost);
Private function prototypes
/* ... */
void HID_MenuProcess(void)
{
switch(demo.hid_state)
{
case APPLI_HID_IDLE:
Demo_SelectItem(DEMO_HID_menu, 0);
demo.hid_state = APPLI_HID_WAIT;
demo.select = 0;
break;
case APPLI_HID_IDLE:
case APPLI_HID_WAIT:
if(demo.select != prev_select)
{
prev_select = demo.select;
Demo_SelectItem(DEMO_HID_menu, demo.select & 0x7F);
if(demo.select & 0x80)
{
demo.select &= 0x7F;
switch(demo.select)
{
case 0:
demo.hid_state = APPLI_HID_START;
break;
case 0:
case 1:
demo.state = DEMO_IDLE;
demo.select = 0;
LCD_UsrLogY("> HID application closed.\n");
break;
case 1:
default:
break;default
}switch (demo.select) { ... }
}if (demo.select & 0x80) { ... }
}if (demo.select != prev_select) { ... }
break;
case APPLI_HID_WAIT:
case APPLI_HID_START:
if(Appli_FS_state == APPLICATION_FS_READY)
{
if(USBH_HID_GetDeviceType(&hUSBHost_FS) == HID_KEYBOARD)
{
demo.keyboard_state = HID_KEYBOARD_IDLE;
demo.hid_state = APPLI_HID_KEYBOARD;
}if (USBH_HID_GetDeviceType(&hUSBHost_FS) == HID_KEYBOARD) { ... }
else if(USBH_HID_GetDeviceType(&hUSBHost_FS) == HID_MOUSE)
{
demo.mouse_state = HID_MOUSE_IDLE;
demo.hid_state = APPLI_HID_MOUSE;
}else if (USBH_HID_GetDeviceType(&hUSBHost_FS) == HID_MOUSE) { ... }
}if (Appli_FS_state == APPLICATION_FS_READY) { ... }
else
{
LCD_ErrLog("No supported HID device!\n");
demo.hid_state = APPLI_HID_WAIT;
}else { ... }
break;
case APPLI_HID_START:
case APPLI_HID_MOUSE:
if(Appli_FS_state == APPLICATION_FS_READY)
{
HID_MouseMenuProcess();
USBH_MouseDemo(&hUSBHost_FS);
}if (Appli_FS_state == APPLICATION_FS_READY) { ... }
break;
case APPLI_HID_MOUSE:
case APPLI_HID_KEYBOARD:
if(Appli_FS_state == APPLICATION_FS_READY)
{
HID_KeyboardMenuProcess();
USBH_KeybdDemo(&hUSBHost_FS);
}if (Appli_FS_state == APPLICATION_FS_READY) { ... }
break;
case APPLI_HID_KEYBOARD:
default:
break;default
}switch (demo.hid_state) { ... }
}{ ... }
/* ... */
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) { ... }
}{ ... }