Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "main.h"
Private define
#define MENU_UPDATE_EVENT
Private variables
msc_demo
MenuEvent
osJoySemaphore
MSC_main_menu
Private function prototypes
Menu_Init()
MSC_MenuThread(const void *)
Joystick_MscMenu()
HAL_GPIO_EXTI_Callback(uint16_t)
MSC_SelectItem(uint8_t **, uint8_t)
MSC_DEMO_ProbeKey(JOYState_TypeDef)
Files
loading...
CodeScopeSTM32 Libraries and SamplesMSC_RTOSSrc/menu.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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file USB_Host/MSC_RTOS/Src/menu.c * @author MCD Application Team * @brief This file implements Menu Functions ****************************************************************************** * @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 -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ #define MENU_UPDATE_EVENT 0x10 Private define /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ MSC_DEMO_StateMachine msc_demo; osSemaphoreId MenuEvent; osSemaphoreId osJoySemaphore; uint8_t *MSC_main_menu[] = { (uint8_t *)" 1 - File Operations ", (uint8_t *)" 2 - Explorer Disk ", (uint8_t *)" 3 - Re-Enumerate ", ...}; Private variables /* Private function prototypes -----------------------------------------------*/ static void MSC_SelectItem(uint8_t **menu, uint8_t item); static void MSC_DEMO_ProbeKey(JOYState_TypeDef state); void Joystick_MscMenu(void); static void MSC_MenuThread(void const *argument); Private function prototypes /* Private functions ---------------------------------------------------------*/ /** * @brief Demo state machine. * @param None * @retval None *//* ... */ void Menu_Init(void) { /* Create Menu Semaphore */ osSemaphoreDef(osSem); MenuEvent = osSemaphoreCreate(osSemaphore(osSem), 1); /* Force menu to show Item 0 by default */ osSemaphoreRelease(MenuEvent); /* Menu task */ osThreadDef(Menu_Thread, MSC_MenuThread, osPriorityHigh, 0, 8 * configMINIMAL_STACK_SIZE); osThreadCreate(osThread(Menu_Thread), NULL); /* Define used semaphore for Joystick*/ osSemaphoreDef(JOY_SEM); /* Create the semaphore used by the two threads. */ osJoySemaphore = osSemaphoreCreate(osSemaphore(JOY_SEM) , 1); BSP_LCD_SetTextColor(LCD_COLOR_GREEN); BSP_LCD_DisplayStringAtLine(15, (uint8_t *)"Use [Joystick Left/Right] to scroll up/down"); BSP_LCD_DisplayStringAtLine(16, (uint8_t *)"Use [Joystick Up/Down] to scroll MSC menu"); }{ ... } /** * @brief User task * @param pvParameters not used * @retval None *//* ... */ static void MSC_MenuThread(void const *argument) { uint32_t ITstatus = 0; for(;;) { if(osSemaphoreWait(MenuEvent, 100) == osOK) { switch(msc_demo.state) { case MSC_DEMO_IDLE: MSC_SelectItem(MSC_main_menu, 0); msc_demo.state = MSC_DEMO_WAIT; msc_demo.select = 0; osSemaphoreRelease(MenuEvent); break; case MSC_DEMO_IDLE: case MSC_DEMO_WAIT: MSC_SelectItem(MSC_main_menu, msc_demo.select & 0x7F); /* Handle select item */ if(msc_demo.select & 0x80) { switch(msc_demo.select & 0x7F) { case 0: msc_demo.state = MSC_DEMO_FILE_OPERATIONS; osSemaphoreRelease(MenuEvent); break; case 0: case 1: msc_demo.state = MSC_DEMO_EXPLORER; osSemaphoreRelease(MenuEvent); break; case 1: case 2: msc_demo.state = MSC_REENUMERATE; osSemaphoreRelease(MenuEvent); break; case 2: default: break;default }switch (msc_demo.select & 0x7F) { ... } }if (msc_demo.select & 0x80) { ... } break; case MSC_DEMO_WAIT: case MSC_DEMO_FILE_OPERATIONS: /* Read and Write File Here */ if(Appli_state == APPLICATION_READY) { MSC_File_Operations(); }if (Appli_state == APPLICATION_READY) { ... } msc_demo.state = MSC_DEMO_WAIT; break; case MSC_DEMO_FILE_OPERATIONS: case MSC_DEMO_EXPLORER: /* Display disk content */ if(Appli_state == APPLICATION_READY) { Explore_Disk("0:/", 1); }if (Appli_state == APPLICATION_READY) { ... } msc_demo.state = MSC_DEMO_WAIT; break; case MSC_DEMO_EXPLORER: case MSC_REENUMERATE: /* Force MSC Device to re-enumerate */ USBH_ReEnumerate(&hUSBHost); msc_demo.state = MSC_DEMO_WAIT; break; case MSC_REENUMERATE: default: break;default }switch (msc_demo.state) { ... } msc_demo.select &= 0x7F; }if (osSemaphoreWait(MenuEvent, 100) == osOK) { ... } if (osJoySemaphore != NULL) { if(osSemaphoreWait(osJoySemaphore , 0) == osOK) { ITstatus = BSP_IO_ITGetStatus(JOY_ALL_PINS); if (ITstatus) { Joystick_MscMenu(); /* Clear joystick interrupt pending bits */ BSP_IO_ITClear(); }if (ITstatus) { ... } }if (osSemaphoreWait(osJoySemaphore , 0) == osOK) { ... } }if (osJoySemaphore != NULL) { ... } }for (;;) { ... } }{ ... } /** * @brief Joystick Msc menu * @param None * @retval None *//* ... */ void Joystick_MscMenu(void) { static JOYState_TypeDef JoyState = JOY_NONE; /* Get the Joystick State */ JoyState = BSP_JOY_GetState(); MSC_DEMO_ProbeKey(JoyState); switch(JoyState) { case JOY_LEFT: LCD_LOG_ScrollBack(); break; case JOY_LEFT: case JOY_RIGHT: LCD_LOG_ScrollForward(); break; case JOY_RIGHT: default: break; default }switch (JoyState) { ... } osSemaphoreRelease(MenuEvent); }{ ... } /** * @brief EXTI line detection callbacks. * @param GPIO_Pin: Specifies the pins connected EXTI line * @retval None *//* ... */ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { if(GPIO_Pin == MFX_IRQOUT_PIN) { /* The different functionalities of MFX (TS, Joystick, SD detection, etc. ) can be configured in exti mode to generate an IRQ on given events. The MFX IRQ_OUT pin is unique and common to all functionalities, so if several functionalities are configured in exit mode, the MCU has to enquire MFX about the IRQ source (see BSP_IO_ITGetStatus). Communication with Mfx is done by I2C. Often the sw requires ISRs (irq service routines) to be quick while communication with I2C can be considered relatively long (hundreds of usec depending on I2C clk). In order to avoid "blocking I2C communication" on interrupt service routines it is suggested to use a semaphore *//* ... */ osSemaphoreRelease(osJoySemaphore); }if (GPIO_Pin == MFX_IRQOUT_PIN) { ... } }{ ... } /** * @brief Manages the menu on the screen. * @param menu: Menu table * @param item: Selected item to be highlighted * @retval None *//* ... */ static void MSC_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(17, menu [0]); BSP_LCD_SetBackColor(LCD_COLOR_BLUE); BSP_LCD_DisplayStringAtLine(18 , menu [1]); BSP_LCD_DisplayStringAtLine(19 , menu [2]); break; case 0: case 1: BSP_LCD_SetBackColor(LCD_COLOR_BLUE); BSP_LCD_DisplayStringAtLine(17, menu [0]); BSP_LCD_SetBackColor(LCD_COLOR_MAGENTA); BSP_LCD_DisplayStringAtLine(18, menu [1]); BSP_LCD_SetBackColor(LCD_COLOR_BLUE); BSP_LCD_DisplayStringAtLine(19, menu [2]); break; case 1: case 2: BSP_LCD_SetBackColor(LCD_COLOR_BLUE); BSP_LCD_DisplayStringAtLine(17, menu [0]); BSP_LCD_SetBackColor(LCD_COLOR_BLUE); BSP_LCD_DisplayStringAtLine(18, menu [1]); BSP_LCD_SetBackColor(LCD_COLOR_MAGENTA); BSP_LCD_DisplayStringAtLine(19, menu [2]); break; case 2: default: BSP_LCD_SetBackColor(LCD_COLOR_BLUE); BSP_LCD_DisplayStringAtLine(17, menu [0]); BSP_LCD_DisplayStringAtLine(18, menu [1]); BSP_LCD_DisplayStringAtLine(19, menu [2]); break; default }switch (item) { ... } BSP_LCD_SetBackColor(LCD_COLOR_BLACK); }{ ... } /** * @brief Probes the MSC joystick state. * @param state: Joystick state * @retval None *//* ... */ static void MSC_DEMO_ProbeKey(JOYState_TypeDef state) { msc_demo.select &= 0x7F; /* Handle Menu inputs */ if((state == JOY_UP) && (msc_demo.select > 0)) { msc_demo.select--; }if ((state == JOY_UP) && (msc_demo.select > 0)) { ... } else if((state == JOY_DOWN) && (msc_demo.select < 2)) { msc_demo.select++; }else if ((state == JOY_DOWN) && (msc_demo.select < 2)) { ... } else if(state == JOY_SEL) { msc_demo.select |= 0x80; }else if (state == JOY_SEL) { ... } }{ ... }