1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
22
23
24
25
29
42
49
50
51
56
62
63
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
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
133
134
135
136
137
138
158
159
160
161
162
163
169
174
175
176
181
182
183
184
185
186
187
188
189
190
191
192
200
201
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
227
228
229
230
231
232
233
234
235
236
245
246
250
251
252
254
255
256
257
263
264
265
276
277
278
279
284
285
286
287
288
289
290
291
292
310
314
315
316
317
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
343
344
345
346
347
348
349
350
351
355
359
360
361
365
369
370
371
372
373
374
375
376
377
381
385
386
387
388
389
390
391
394
395
400
417
418
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
461
462
463
464
465
470
486
487
492
/* ... */
#include "waveplayer.h"
#include "waverecorder.h"
Includes
static volatile uint8_t MfxExtiReceived = 0;
uint8_t state = 0;
Global extern variables
AUDIO_DEMO_StateMachine AudioDemo;
uint8_t PrevSelect = 0;
AUDIO_DEMO_SelectMode AudioSelectMode;
AUDIO_PLAYBACK_StateTypeDef AudioState;
uint8_t *AUDIO_main_menu[] =
{
(uint8_t *)" 1 - Explore Audio File ",
(uint8_t *)" 2 - Start Audio Player ",
(uint8_t *)" 3 - Start Audio Recorder ",
...};
Private variables
static void AUDIO_SelectItem(uint8_t **menu, uint8_t item);
static void AUDIO_MenuProbeKey(JOYState_TypeDef state);
static void AUDIO_ChangeSelectMode(AUDIO_DEMO_SelectMode select_mode);
static void LCD_ClearTextZone(void);
static void Joystick_AudioMenu(void);
Private function prototypes
/* ... */
void AUDIO_MenuInit(void)
{
AudioDemo.state = AUDIO_DEMO_IDLE;
AudioSelectMode = AUDIO_SELECT_MENU;
AUDIO_SelectItem(AUDIO_main_menu, 0);
}{ ... }
/* ... */
void AUDIO_MenuProcess(void)
{
uint32_t ITstatus = 0;
AUDIO_ErrorTypeDef status;
if(appli_state == APPLICATION_READY)
{
switch(AudioDemo.state)
{
case AUDIO_DEMO_IDLE:
AudioDemo.state = AUDIO_DEMO_WAIT;
AudioDemo.select = 0;
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 App Menu");
break;
case AUDIO_DEMO_IDLE:
case AUDIO_DEMO_WAIT:
if(AudioDemo.select != PrevSelect)
{
PrevSelect = AudioDemo.select;
AUDIO_SelectItem(AUDIO_main_menu, AudioDemo.select & 0x7F);
if(AudioDemo.select & 0x80)
{
switch(AudioDemo.select & 0x7F)
{
case 0:
AudioDemo.state = AUDIO_DEMO_EXPLORE;
break;
case 0:
case 1:
BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
BSP_LCD_DisplayStringAtLine(14 ,(uint8_t *)" ");
BSP_LCD_DisplayStringAtLine(15 ,(uint8_t *)" ");
BSP_LCD_DisplayStringAtLine(16 ,(uint8_t *)"Use [User Key] To Stop and return from player/recorder ");
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
AudioState = AUDIO_STATE_IDLE;
AudioDemo.state = AUDIO_DEMO_PLAYBACK;
AUDIO_ChangeSelectMode(AUDIO_PLAYBACK_CONTROL);
break;
case 1:
case 2:
BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
BSP_LCD_DisplayStringAtLine(14 ,(uint8_t *)" ");
BSP_LCD_DisplayStringAtLine(15 ,(uint8_t *)" ");
BSP_LCD_DisplayStringAtLine(16 ,(uint8_t *)"Use [User Key] To Stop and return from player/recorder ");
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
AudioState = AUDIO_STATE_IDLE;
AudioDemo.state = AUDIO_DEMO_IN;
AUDIO_ChangeSelectMode(AUDIO_PLAYBACK_CONTROL);
break;
case 2:
default:
break;default
}switch (AudioDemo.select & 0x7F) { ... }
}if (AudioDemo.select & 0x80) { ... }
}if (AudioDemo.select != PrevSelect) { ... }
break;
case AUDIO_DEMO_WAIT:
case AUDIO_DEMO_EXPLORE:
if(appli_state == APPLICATION_READY)
{
if(AUDIO_ShowWavFiles() > 0)
{
LCD_ErrLog("There is no WAV file on the USB Key.\n");
AUDIO_ChangeSelectMode(AUDIO_SELECT_MENU);
AudioDemo.state = AUDIO_DEMO_IDLE;
}if (AUDIO_ShowWavFiles() > 0) { ... }
else
{
AudioDemo.state = AUDIO_DEMO_WAIT;
}else { ... }
}if (appli_state == APPLICATION_READY) { ... }
else
{
AudioDemo.state = AUDIO_DEMO_WAIT;
}else { ... }
break;
case AUDIO_DEMO_EXPLORE:
case AUDIO_DEMO_PLAYBACK:
if(appli_state == APPLICATION_READY)
{
if(AudioState == AUDIO_STATE_IDLE)
{
if(AUDIO_ShowWavFiles() > 0)
{
LCD_ErrLog("There is no WAV file on the USB Key.\n");
AUDIO_ChangeSelectMode(AUDIO_SELECT_MENU);
AudioDemo.state = AUDIO_DEMO_IDLE;
}if (AUDIO_ShowWavFiles() > 0) { ... }
else
{
AudioState = AUDIO_STATE_INIT;
}else { ... }
if(AUDIO_PLAYER_Start(0) == AUDIO_ERROR_IO)
{
AUDIO_ChangeSelectMode(AUDIO_SELECT_MENU);
AudioDemo.state = AUDIO_DEMO_IDLE;
}if (AUDIO_PLAYER_Start(0) == AUDIO_ERROR_IO) { ... }
else
{
BSP_LCD_SetTextColor(LCD_COLOR_YELLOW);
BSP_LCD_DisplayStringAtLine(10, (uint8_t *)"[ UP ] : Volume +");
BSP_LCD_DisplayStringAtLine(11, (uint8_t *)"[ DOWN ] : Volume -");
BSP_LCD_DisplayStringAtLine(12, (uint8_t *)"[ LEFT ] : Previous");
BSP_LCD_DisplayStringAtLine(13, (uint8_t *)"[ RIGHT ] : Next ");
BSP_LCD_DisplayStringAtLine(14, (uint8_t *)"[ SEL ] : Pause/Resume");
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
}else { ... }
}if (AudioState == AUDIO_STATE_IDLE) { ... }
else
{
if(AUDIO_PLAYER_Process() == AUDIO_ERROR_IO)
{
AUDIO_ChangeSelectMode(AUDIO_SELECT_MENU);
AudioDemo.state = AUDIO_DEMO_IDLE;
}if (AUDIO_PLAYER_Process() == AUDIO_ERROR_IO) { ... }
}else { ... }
}if (appli_state == APPLICATION_READY) { ... }
else
{
AudioDemo.state = AUDIO_DEMO_WAIT;
}else { ... }
break;
case AUDIO_DEMO_PLAYBACK:
case AUDIO_DEMO_IN:
if(appli_state == APPLICATION_READY)
{
if(AudioState == AUDIO_STATE_IDLE)
{
AudioState = AUDIO_STATE_INIT;
LCD_ClearTextZone();
AUDIO_StorageInit();
if(AUDIO_REC_Start() == AUDIO_ERROR_IO)
{
AUDIO_ChangeSelectMode(AUDIO_SELECT_MENU);
AudioDemo.state = AUDIO_DEMO_IDLE;
}if (AUDIO_REC_Start() == AUDIO_ERROR_IO) { ... }
else
{
BSP_LCD_SetTextColor(LCD_COLOR_YELLOW);
BSP_LCD_DisplayStringAtLine(11, (uint8_t *)"[ UP ] : Volume +");
BSP_LCD_DisplayStringAtLine(12, (uint8_t *)"[ DOWN ] : Volume -");
BSP_LCD_DisplayStringAtLine(13, (uint8_t *)"[ SEL ] : Pause/Resume");
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
}else { ... }
}if (AudioState == AUDIO_STATE_IDLE) { ... }
else
{
status = AUDIO_REC_Process();
if((status == AUDIO_ERROR_IO) || (status == AUDIO_ERROR_EOF))
{
AUDIO_ChangeSelectMode(AUDIO_SELECT_MENU);
AudioDemo.state = AUDIO_DEMO_IDLE;
}if ((status == AUDIO_ERROR_IO) || (status == AUDIO_ERROR_EOF)) { ... }
}else { ... }
}if (appli_state == APPLICATION_READY) { ... }
else
{
AudioDemo.state = AUDIO_DEMO_WAIT;
}else { ... }
break;
case AUDIO_DEMO_IN:
default:
break;default
}switch (AudioDemo.state) { ... }
}if (appli_state == APPLICATION_READY) { ... }
if(appli_state == APPLICATION_DISCONNECT)
{
appli_state = APPLICATION_IDLE;
AUDIO_ChangeSelectMode(AUDIO_SELECT_MENU);
BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW);
}if (appli_state == APPLICATION_DISCONNECT) { ... }
AudioDemo.select &= 0x7F;
if (MfxExtiReceived == 1)
{
MfxExtiReceived = 0;
ITstatus = BSP_IO_ITGetStatus(JOY_ALL_PINS);
if (ITstatus)
{
Joystick_AudioMenu();
BSP_IO_ITClear();
}if (ITstatus) { ... }
}if (MfxExtiReceived == 1) { ... }
}{ ... }
/* ... */
void Joystick_AudioMenu(void)
{
static JOYState_TypeDef JoyState = JOY_NONE;
JoyState = BSP_JOY_GetState();
if(AudioSelectMode == AUDIO_SELECT_MENU)
{
AUDIO_MenuProbeKey(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) { ... }
}if (AudioSelectMode == AUDIO_SELECT_MENU) { ... }
else if(AudioSelectMode == AUDIO_PLAYBACK_CONTROL)
{
AUDIO_PlaybackProbeKey(JoyState);
}else if (AudioSelectMode == AUDIO_PLAYBACK_CONTROL) { ... }
}{ ... }
/* ... */
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
static uint32_t debounce_time = 0;
if(GPIO_Pin == MFX_IRQOUT_PIN)
{
/* ... */
/* ... */
MfxExtiReceived = 1;
}if (GPIO_Pin == MFX_IRQOUT_PIN) { ... }
if(AudioDemo.state == AUDIO_DEMO_PLAYBACK)
{
if(GPIO_Pin == KEY_BUTTON_PIN)
{
if((HAL_GetTick() - debounce_time) > 50)
{
debounce_time = HAL_GetTick();
}if ((HAL_GetTick() - debounce_time) > 50) { ... }
else
{
return;
}else { ... }
if(AudioSelectMode == AUDIO_SELECT_MENU)
{
AUDIO_ChangeSelectMode(AUDIO_PLAYBACK_CONTROL);
}if (AudioSelectMode == AUDIO_SELECT_MENU) { ... }
else if(AudioSelectMode == AUDIO_PLAYBACK_CONTROL)
{
AUDIO_PLAYER_Stop();
}else if (AudioSelectMode == AUDIO_PLAYBACK_CONTROL) { ... }
}if (GPIO_Pin == KEY_BUTTON_PIN) { ... }
}if (AudioDemo.state == AUDIO_DEMO_PLAYBACK) { ... }
if(AudioDemo.state == AUDIO_DEMO_IN)
{
if(GPIO_Pin == KEY_BUTTON_PIN)
{
if((HAL_GetTick() - debounce_time) > 50)
{
debounce_time = HAL_GetTick();
}if ((HAL_GetTick() - debounce_time) > 50) { ... }
else
{
return;
}else { ... }
AudioState = AUDIO_STATE_STOP;
}if (GPIO_Pin == KEY_BUTTON_PIN) { ... }
}if (AudioDemo.state == AUDIO_DEMO_IN) { ... }
}{ ... }
/* ... */
/* ... */
static void AUDIO_ChangeSelectMode(AUDIO_DEMO_SelectMode select_mode)
{
if(select_mode == AUDIO_SELECT_MENU)
{
AUDIO_SelectItem(AUDIO_main_menu, 0x00);
LCD_LOG_UpdateDisplay();
AudioDemo.state = AUDIO_DEMO_IDLE;
AUDIO_PLAYER_Stop();
}if (select_mode == AUDIO_SELECT_MENU) { ... }
else if(select_mode == AUDIO_PLAYBACK_CONTROL)
{
LCD_ClearTextZone();
AUDIO_SelectItem(AUDIO_main_menu, 0xFF);
}else if (select_mode == AUDIO_PLAYBACK_CONTROL) { ... }
AudioSelectMode = select_mode;
AudioDemo.select = 0;
}{ ... }
/* ... */
static void AUDIO_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_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);
}{ ... }
/* ... */
static void AUDIO_MenuProbeKey(JOYState_TypeDef state)
{
if((state == JOY_UP) && (AudioDemo.select > 0))
{
AudioDemo.select--;
}if ((state == JOY_UP) && (AudioDemo.select > 0)) { ... }
else if((state == JOY_DOWN) && (AudioDemo.select < 2))
{
AudioDemo.select++;
}else if ((state == JOY_DOWN) && (AudioDemo.select < 2)) { ... }
else if(state == JOY_SEL)
{
AudioDemo.select |= 0x80;
}else if (state == JOY_SEL) { ... }
}{ ... }
/* ... */
static void LCD_ClearTextZone(void)
{
uint8_t i = 0;
for(i= 0; i < 13; i++)
{
BSP_LCD_ClearStringLine(i + 3);
}for (i= 0; i < 13; i++) { ... }
}{ ... }