1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
21
22
23
24
29
32
33
34
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
62
63
64
65
66
67
68
69
70
75
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
141
/* ... */
#include "main.h"
Includes
MSC_DEMO_StateMachine msc_demo;
osSemaphoreId MenuEvent;
__IO uint8_t ExploreDisk_State = 0;
Private variables
static void MSC_MenuThread(void const *argument);
Private function prototypes
/* ... */
void Menu_Init(void)
{
osSemaphoreDef(osSem);
MenuEvent = osSemaphoreCreate(osSemaphore(osSem), 1);
osSemaphoreRelease(MenuEvent);
osThreadDef(Menu_Thread, MSC_MenuThread, osPriorityHigh, 0, 8 * configMINIMAL_STACK_SIZE);
osThreadCreate(osThread(Menu_Thread), NULL);
msc_demo.state = MSC_DEMO_IDLE;
USBH_UsrLog("Starting MSC Demo");
}{ ... }
/* ... */
void MSC_MenuThread(void const *argument)
{
for(;;)
{
if(osSemaphoreWait(MenuEvent , osWaitForever) == osOK)
{
switch(msc_demo.state)
{
case MSC_DEMO_IDLE:
msc_demo.state = MSC_DEMO_START;
osSemaphoreRelease(MenuEvent);
break;
case MSC_DEMO_IDLE:
case MSC_DEMO_START:
if(Appli_state == APPLICATION_READY)
{
BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
BSP_LCD_DisplayStringAtLine(18, (uint8_t *)"Press User button to start");
BSP_LCD_DisplayStringAtLine(19, (uint8_t *)"read and write operations");
msc_demo.state = MSC_DEMO_FILE_OPERATIONS;
osSemaphoreRelease(MenuEvent);
}if (Appli_state == APPLICATION_READY) { ... }
break;
case MSC_DEMO_START:
case MSC_DEMO_FILE_OPERATIONS:
if(Appli_state == APPLICATION_READY)
{
BSP_LCD_ClearStringLine(18);
BSP_LCD_ClearStringLine(19);
MSC_File_Operations();
BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
BSP_LCD_DisplayStringAtLine(18, (uint8_t *)"Press User button to");
BSP_LCD_DisplayStringAtLine(19, (uint8_t *)"display disk content"); msc_demo.state = MSC_DEMO_EXPLORER;
}if (Appli_state == APPLICATION_READY) { ... }
break;
case MSC_DEMO_FILE_OPERATIONS:
case MSC_DEMO_EXPLORER:
if(Appli_state == APPLICATION_READY)
{
BSP_LCD_ClearStringLine(18);
BSP_LCD_ClearStringLine(19);
ExploreDisk_State = 1;
Explore_Disk("0:/", 1);
msc_demo.state = MSC_DEMO_START;
ExploreDisk_State = 0;
BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
BSP_LCD_DisplayStringAtLine(18, (uint8_t *)"Press User button to start");
BSP_LCD_DisplayStringAtLine(19, (uint8_t *)"read and write operations");
}if (Appli_state == APPLICATION_READY) { ... }
break;
case MSC_DEMO_EXPLORER:
default:
break;default
}switch (msc_demo.state) { ... }
if(Appli_state == APPLICATION_DISCONNECT)
{
Appli_state = APPLICATION_IDLE;
LCD_LOG_ClearTextZone();
BSP_LCD_ClearStringLine(18);
BSP_LCD_ClearStringLine(19);
LCD_ErrLog("MSC device disconnected!\n");
msc_demo.state = MSC_DEMO_IDLE;
}if (Appli_state == APPLICATION_DISCONNECT) { ... }
}if (osSemaphoreWait(MenuEvent , osWaitForever) == osOK) { ... }
}for (;;) { ... }
}{ ... }
/* ... */
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if(GPIO_Pin == USER_BUTTON_PIN)
{
if(ExploreDisk_State == 0)
{
osSemaphoreRelease(MenuEvent);
}if (ExploreDisk_State == 0) { ... }
}if (GPIO_Pin == USER_BUTTON_PIN) { ... }
}{ ... }