Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "main.h"
Private typedef
Private define
#define HID_MOUSE_BUTTON1
#define HID_MOUSE_BUTTON2
#define HID_MOUSE_BUTTON3
#define MOUSE_TOP_DIR
#define MOUSE_BOTTOM_DIR
#define MOUSE_LEFT_DIR
#define MOUSE_RIGHT_DIR
#define MOUSE_WINDOW_X
#define MOUSE_WINDOW_Y
#define MOUSE_WINDOW_X_MAX
#define MOUSE_WINDOW_Y_MIN
#define MOUSE_WINDOW_HEIGHT
#define MOUSE_WINDOW_WIDTH
#define HID_MOUSE_BUTTON_HEIGHT
#define HID_MOUSE_BUTTON_WIDTH
#define HID_MOUSE_BUTTON1_XCHORD
#define HID_MOUSE_BUTTON2_XCHORD
#define HID_MOUSE_BUTTON3_XCHORD
#define HID_MOUSE_BUTTON_YCHORD
#define MOUSE_LEFT_MOVE
#define MOUSE_RIGHT_MOVE
#define MOUSE_UP_MOVE
#define MOUSE_DOWN_MOVE
#define HID_MOUSE_HEIGHTLSB
#define HID_MOUSE_WIDTHLSB
#define HID_MOUSE_RES_X
#define HID_MOUSE_RES_Y
Private function prototypes
HID_MouseMenuProcess()
USR_MOUSE_Init()
USR_MOUSE_ProcessData(HID_MOUSE_Info_TypeDef *)
HID_MOUSE_UpdatePosition(int8_t, int8_t)
HID_MOUSE_ButtonPressed(uint8_t)
HID_MOUSE_ButtonReleased(uint8_t)
Files
loading...
CodeScopeSTM32 Libraries and SamplesHID_StandaloneSrc/mouse.c
 
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file USB_Host/HID_Standalone/Src/mouse.c * @author MCD Application Team * @brief This file implements Functions for mouse menu ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ /* Includes ------------------------------------------------------------------*/ #include "main.h" Includes /* Private typedef -----------------------------------------------------------*/ extern USBH_HandleTypeDef hUSBHost; Private typedef /* Private define ------------------------------------------------------------*/ /* Left Button Report data */ #define HID_MOUSE_BUTTON1 0x01 /* Right Button Report data */ #define HID_MOUSE_BUTTON2 0x02 /* Middle Button Report data */ #define HID_MOUSE_BUTTON3 0x04 /* Mouse directions */ #define MOUSE_TOP_DIR 0x80 #define MOUSE_BOTTOM_DIR 0x00 #define MOUSE_LEFT_DIR 0x80 #define MOUSE_RIGHT_DIR 0x00 #define MOUSE_WINDOW_X (BSP_LCD_GetXSize() - MOUSE_WINDOW_WIDTH)/2 #define MOUSE_WINDOW_Y 70 #define MOUSE_WINDOW_X_MAX 181 #define MOUSE_WINDOW_Y_MIN 101 #define MOUSE_WINDOW_HEIGHT 70 #define MOUSE_WINDOW_WIDTH 145 #define HID_MOUSE_BUTTON_HEIGHT 10 #define HID_MOUSE_BUTTON_WIDTH 24 #define HID_MOUSE_BUTTON1_XCHORD MOUSE_WINDOW_X #define HID_MOUSE_BUTTON2_XCHORD HID_MOUSE_BUTTON1_XCHORD + 60 #define HID_MOUSE_BUTTON3_XCHORD HID_MOUSE_BUTTON2_XCHORD + 60 #define HID_MOUSE_BUTTON_YCHORD 150 #define MOUSE_LEFT_MOVE 1 #define MOUSE_RIGHT_MOVE 2 #define MOUSE_UP_MOVE 3 #define MOUSE_DOWN_MOVE 4 #define HID_MOUSE_HEIGHTLSB 2 #define HID_MOUSE_WIDTHLSB 2 #define HID_MOUSE_RES_X 4 #define HID_MOUSE_RES_Y 4 27 defines Private define/* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ static void USR_MOUSE_Init(void); static void HID_MOUSE_UpdatePosition(int8_t x, int8_t y); Private function prototypes /* Private functions ---------------------------------------------------------*/ /** * @brief Manages Mouse Menu Process. * @param None * @retval None *//* ... */ void HID_MouseMenuProcess(void) { switch(hid_demo.mouse_state) { case HID_MOUSE_IDLE: hid_demo.mouse_state = HID_MOUSE_START; HID_SelectItem(DEMO_MOUSE_menu, 0); hid_demo.select = 0; prev_select = 0; break; case HID_MOUSE_IDLE: case HID_MOUSE_WAIT: if(hid_demo.select != prev_select) { prev_select = hid_demo.select; HID_SelectItem(DEMO_MOUSE_menu, (hid_demo.select >> 4)); /* Handle select item */ switch(hid_demo.select) { case 0x0F: hid_demo.mouse_state = HID_MOUSE_START; hid_demo.select = 0; prev_select = 0; break; case 0x0F: case 0x1F: /* Return */ LCD_LOG_ClearTextZone(); hid_demo.state = HID_DEMO_REENUMERATE; hid_demo.select = 0; prev_select = 0; break; case 0x1F: default: break;default }switch (hid_demo.select) { ... } }if (hid_demo.select != prev_select) { ... } break; case HID_MOUSE_WAIT: case HID_MOUSE_START: USR_MOUSE_Init(); hid_demo.mouse_state = HID_MOUSE_WAIT; HID_MOUSE_UpdatePosition(0,0); break; case HID_MOUSE_START: default: break;default }switch (hid_demo.mouse_state) { ... } }{ ... } /** * @brief Init Mouse window. * @param None * @retval None *//* ... */ static void USR_MOUSE_Init(void) { LCD_LOG_ClearTextZone(); BSP_LCD_SetTextColor(LCD_COLOR_YELLOW); BSP_LCD_DisplayStringAtLine(4, (uint8_t *)"USB HID Host Mouse Demo... "); BSP_LCD_SetTextColor(LCD_LOG_DEFAULT_COLOR); /* Display Mouse Window */ BSP_LCD_DrawRect(MOUSE_WINDOW_X, MOUSE_WINDOW_Y, MOUSE_WINDOW_WIDTH, MOUSE_WINDOW_HEIGHT); HID_MOUSE_ButtonReleased(0); HID_MOUSE_ButtonReleased(1); HID_MOUSE_ButtonReleased(2); BSP_LCD_SetTextColor(LCD_COLOR_GREEN); BSP_LCD_SetBackColor(LCD_COLOR_BLACK); HID_MOUSE_UpdatePosition(0,0); }{ ... } /** * @brief Processes Mouse data. * @param data: Mouse data to be displayed * @retval None *//* ... */ void USR_MOUSE_ProcessData(HID_MOUSE_Info_TypeDef *data) { if((data->x != 0) && (data->y != 0)) { HID_MOUSE_UpdatePosition(data->x , data->y); }if ((data->x != 0) && (data->y != 0)) { ... } }{ ... } /** * @brief Handles mouse scroll to update the mouse position on display window. * @param x: USB HID Mouse X coordinate * @param y: USB HID Mouse Y coordinate * @retval None *//* ... */ static void HID_MOUSE_UpdatePosition(int8_t x, int8_t y) { static int16_t x_loc = 0, y_loc = 0; static int16_t prev_x = 5, prev_y = 1; if((x != 0) || (y != 0)) { x_loc += x/2; y_loc += y/10; if(y_loc > MOUSE_WINDOW_HEIGHT - 12) { y_loc = MOUSE_WINDOW_HEIGHT - 12; }if (y_loc > MOUSE_WINDOW_HEIGHT - 12) { ... } if(x_loc > MOUSE_WINDOW_WIDTH - 10) { x_loc = MOUSE_WINDOW_WIDTH - 10; }if (x_loc > MOUSE_WINDOW_WIDTH - 10) { ... } if(y_loc < 2) { y_loc = 2; }if (y_loc < 2) { ... } if(x_loc < 2) { x_loc = 2; }if (x_loc < 2) { ... } BSP_LCD_SetBackColor(LCD_COLOR_BLACK); BSP_LCD_SetTextColor(LCD_COLOR_BLACK); BSP_LCD_DisplayChar(MOUSE_WINDOW_X + prev_x, MOUSE_WINDOW_Y + prev_y, 'x'); BSP_LCD_SetTextColor(LCD_COLOR_GREEN); BSP_LCD_DisplayChar(MOUSE_WINDOW_X + x_loc, MOUSE_WINDOW_Y + y_loc, 'x'); prev_x = x_loc; prev_y = y_loc; }if ((x != 0) || (y != 0)) { ... } }{ ... } /** * @brief Handles mouse button press. * @param button_idx: Mouse button pressed * @retval None *//* ... */ void HID_MOUSE_ButtonPressed(uint8_t button_idx) { /* Set the color for button press status */ BSP_LCD_SetTextColor(LCD_COLOR_BLUE); BSP_LCD_SetBackColor(LCD_COLOR_BLUE); /* Change the color of button pressed to indicate button press */ switch(button_idx) { /* Left Button Pressed */ case 0: BSP_LCD_FillRect(HID_MOUSE_BUTTON1_XCHORD, HID_MOUSE_BUTTON_YCHORD,\ HID_MOUSE_BUTTON_WIDTH, HID_MOUSE_BUTTON_HEIGHT ); break; /* Right Button Pressed */ case 0: case 1: BSP_LCD_FillRect(HID_MOUSE_BUTTON2_XCHORD,HID_MOUSE_BUTTON_YCHORD,\ HID_MOUSE_BUTTON_WIDTH,HID_MOUSE_BUTTON_HEIGHT); break; /* Middle button Pressed */ case 1: case 2: BSP_LCD_FillRect(HID_MOUSE_BUTTON3_XCHORD,HID_MOUSE_BUTTON_YCHORD,\ HID_MOUSE_BUTTON_WIDTH,HID_MOUSE_BUTTON_HEIGHT); break; case 2: }switch (button_idx) { ... } }{ ... } /** * @brief Handles mouse button release. * @param button_idx: Mouse button released * @retval None *//* ... */ void HID_MOUSE_ButtonReleased(uint8_t button_idx) { /* Set the color for release status */ BSP_LCD_SetTextColor(LCD_COLOR_WHITE); BSP_LCD_SetBackColor(LCD_COLOR_BLACK); /* Change the color of button released to default button color */ switch(button_idx) { /* Left Button Released */ case 0: BSP_LCD_FillRect(HID_MOUSE_BUTTON1_XCHORD, HID_MOUSE_BUTTON_YCHORD,\ HID_MOUSE_BUTTON_WIDTH, HID_MOUSE_BUTTON_HEIGHT); break; /* Right Button Released */ case 0: case 1: BSP_LCD_FillRect(HID_MOUSE_BUTTON2_XCHORD, HID_MOUSE_BUTTON_YCHORD,\ HID_MOUSE_BUTTON_WIDTH, HID_MOUSE_BUTTON_HEIGHT); break; /* Middle Button Released */ case 1: case 2: BSP_LCD_FillRect(HID_MOUSE_BUTTON3_XCHORD, HID_MOUSE_BUTTON_YCHORD,\ HID_MOUSE_BUTTON_WIDTH, HID_MOUSE_BUTTON_HEIGHT); break;case 2: }switch (button_idx) { ... } }{ ... }