1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
22
23
24
25
28
32
33
34
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
57
58
59
60
61
62
63
64
65
66
67
68
69
70
73
74
75
76
77
78
83
84
85
92
99
101
102
103
104
109
110
111
112
113
114
115
116
117
118
119
120
124
128
129
133
137
138
142
146
147
148
149
154
155
156
157
158
159
160
168
/* ... */
#include "main.h"
Includes
HID_DEMO_StateMachine hid_demo;
Private variables
static void USBH_MouseDemo(USBH_HandleTypeDef *phost);
static void USBH_KeybdDemo(USBH_HandleTypeDef *phost);
Private function prototypes
/* ... */
void HID_MenuProcess(void)
{
switch(hid_demo.state)
{
case HID_DEMO_START:
if(Appli_state == APPLICATION_HID)
{
if(USBH_HID_GetDeviceType(&hUSBHost) == HID_KEYBOARD)
{
hid_demo.keyboard_state = HID_KEYBOARD_IDLE;
hid_demo.state = HID_DEMO_KEYBOARD;
BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
BSP_LCD_DisplayStringAtLine(27, (uint8_t *)"Press User button to start");
while((BSP_PB_GetState(BUTTON_WAKEUP) != SET) && (Appli_state != APPLICATION_DISCONNECT))
{
}while ((BSP_PB_GetState(BUTTON_WAKEUP) != SET) && (Appli_state != APPLICATION_DISCONNECT)) { ... }
BSP_LCD_ClearStringLine(27);
HID_KeyboardMenuProcess();
}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;
BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
BSP_LCD_DisplayStringAtLine(27, (uint8_t *)"Press User button to start");
while((BSP_PB_GetState(BUTTON_WAKEUP) != SET) && (Appli_state != APPLICATION_DISCONNECT))
{
}while ((BSP_PB_GetState(BUTTON_WAKEUP) != SET) && (Appli_state != APPLICATION_DISCONNECT)) { ... }
BSP_LCD_ClearStringLine(27);
HID_MouseMenuProcess();
}else if (USBH_HID_GetDeviceType(&hUSBHost) == HID_MOUSE) { ... }
}if (Appli_state == APPLICATION_HID) { ... }
else
{
LCD_ErrLog("No supported HID device!\n");
hid_demo.state = HID_DEMO_START;
}else { ... }
break;
case HID_DEMO_START:
case HID_DEMO_MOUSE:
if( Appli_state == APPLICATION_HID)
{
USBH_MouseDemo(&hUSBHost);
}if (Appli_state == APPLICATION_HID) { ... }
break;
case HID_DEMO_MOUSE:
case HID_DEMO_KEYBOARD:
if( Appli_state == APPLICATION_HID)
{
USBH_KeybdDemo(&hUSBHost);
}if (Appli_state == APPLICATION_HID) { ... }
break;
case HID_DEMO_KEYBOARD:
default:
break;default
}switch (hid_demo.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) { ... }
}{ ... }