1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
21
22
23
24
25
38
43
44
45
50
51
52
53
54
55
56
57
58
59
60
61
62
64
65
67
68
69
70
71
72
73
74
75
76
77
78
79
84
85
86
87
88
89
90
91
92
99
128
137
146
152
154
155
156
157
158
159
160
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
206
222
223
228
229
230
231
232
233
234
235
236
237
238
239
252
253
254
255
256
/* ... */
#include "main.h"
Includes
#define MENU_UPDATE_EVENT 0x10
MSC_DEMO_StateMachine msc_demo;
osSemaphoreId MenuEvent;
uint8_t *MSC_main_menu[] = {
(uint8_t *)
" 1 - File Operations ",
(uint8_t *)
" 2 - Explorer Disk ",
(uint8_t *)
" 3 - Re-Enumerate ",
...};
Private variables
static void MSC_SelectItem(uint8_t ** menu, uint8_t item);
static void MSC_DEMO_ProbeKey(JOYState_TypeDef state);
static void MSC_MenuThread(void const *argument);
Private function prototypes
/* ... */
void Menu_Init(void)
{
osSemaphoreDef(osSem);
MenuEvent = osSemaphoreCreate(osSemaphore(osSem), 1);
osSemaphoreRelease(MenuEvent);
#if defined(__GNUC__)
osThreadDef(Menu_Thread, MSC_MenuThread, osPriorityHigh, 0,
8 * configMINIMAL_STACK_SIZE);/* ... */
#else
osThreadDef(Menu_Thread, MSC_MenuThread, osPriorityHigh, 0,
4 * configMINIMAL_STACK_SIZE);/* ... */
#endif
osThreadCreate(osThread(Menu_Thread), NULL);
BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
BSP_LCD_DisplayStringAtLine(17,
(uint8_t *)
"Use [Joystick Left/Right] to scroll up/down");
BSP_LCD_DisplayStringAtLine(18,
(uint8_t *)
"Use [Joystick Up/Down] to scroll MSC menu");
}{ ... }
/* ... */
static void MSC_MenuThread(void const *argument)
{
for (;;)
{
if (osSemaphoreWait(MenuEvent, osWaitForever) == 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);
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:
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:
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:
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, osWaitForever) == osOK) { ... }
}for (;;) { ... }
}{ ... }
/* ... */
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(19, menu[0]);
BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
BSP_LCD_DisplayStringAtLine(20, menu[1]);
BSP_LCD_DisplayStringAtLine(21, menu[2]);
break;
case 0:
case 1:
BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
BSP_LCD_DisplayStringAtLine(19, menu[0]);
BSP_LCD_SetBackColor(LCD_COLOR_MAGENTA);
BSP_LCD_DisplayStringAtLine(20, menu[1]);
BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
BSP_LCD_DisplayStringAtLine(21, menu[2]);
break;
case 1:
case 2:
BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
BSP_LCD_DisplayStringAtLine(19, menu[0]);
BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
BSP_LCD_DisplayStringAtLine(20, menu[1]);
BSP_LCD_SetBackColor(LCD_COLOR_MAGENTA);
BSP_LCD_DisplayStringAtLine(21, menu[2]);
break;case 2:
}switch (item) { ... }
BSP_LCD_SetBackColor(LCD_COLOR_BLACK);
}{ ... }
/* ... */
static void MSC_DEMO_ProbeKey(JOYState_TypeDef state)
{
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) { ... }
}{ ... }
/* ... */
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
static JOYState_TypeDef JoyState = JOY_NONE;
if (GPIO_Pin == GPIO_PIN_8)
{
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) { ... }
BSP_IO_ITClear();
osSemaphoreRelease(MenuEvent);
}if (GPIO_Pin == GPIO_PIN_8) { ... }
}{ ... }