/** * @brief Manages AUDIO Menu Process. * @param None * @retval None */ void AUDIO_MenuProcess(void) { AUDIO_ErrorTypeDef status; if(AppliState == APPLICATION_READY) { switch(AudioDemo.state) { case AUDIO_DEMO_IDLE: AUDIO_SelectItem(AUDIO_main_menu, 0); 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; } else { AudioDemo.state = AUDIO_DEMO_WAIT; } AudioDemo.select = 0; 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 Audio Playback and Record menu"); break; case AUDIO_DEMO_WAIT: if(AudioDemo.select != PrevSelect) { PrevSelect = AudioDemo.select; AUDIO_SelectItem(AUDIO_main_menu, AudioDemo.select & 0x7F); /* Handle select item */ if(AudioDemo.select & 0x80) { switch(AudioDemo.select & 0x7F) { case 0: AudioDemo.state = AUDIO_DEMO_EXPLORE; break; case 1: /* Display HMI messages */ BSP_LCD_SetTextColor(LCD_COLOR_GREEN); BSP_LCD_DisplayStringAtLine(14 ,(uint8_t *)" "); BSP_LCD_DisplayStringAtLine(15 ,(uint8_t *)" "); BSP_LCD_DisplayStringAtLine(16 ,(uint8_t *)" "); BSP_LCD_DisplayStringAtLine(17 ,(uint8_t *)" "); BSP_LCD_DisplayStringAtLine(18 ,(uint8_t *)"Use [User Key] To Stop and return from player/recorder "); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); /* Set PLAYBACK state and start playing 1st file */ AudioState = AUDIO_STATE_IDLE; AudioDemo.state = AUDIO_DEMO_PLAYBACK; AUDIO_ChangeSelectMode(AUDIO_PLAYBACK_CONTROL); break; case 2: /* Display HMI messages */ BSP_LCD_SetTextColor(LCD_COLOR_GREEN); BSP_LCD_DisplayStringAtLine(14 ,(uint8_t *)" "); BSP_LCD_DisplayStringAtLine(15 ,(uint8_t *)" "); BSP_LCD_DisplayStringAtLine(16 ,(uint8_t *)" "); BSP_LCD_DisplayStringAtLine(17 ,(uint8_t *)" "); BSP_LCD_DisplayStringAtLine(18 ,(uint8_t *)"Use [User Key] To Stop and return from player/recorder "); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); /* Set PLAYBACK state and start playing 1st file */ AudioState = AUDIO_STATE_IDLE; AudioDemo.state = AUDIO_DEMO_IN; AUDIO_ChangeSelectMode(AUDIO_PLAYBACK_CONTROL); break; default: break; } } } break; case AUDIO_DEMO_EXPLORE: if(AppliState == 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; } else { AudioDemo.state = AUDIO_DEMO_WAIT; } } else { AudioDemo.state = AUDIO_DEMO_WAIT; } break; case AUDIO_DEMO_PLAYBACK: if(AppliState == APPLICATION_READY) { if(AudioState == AUDIO_STATE_IDLE) { /* Start Playing */ AudioState = AUDIO_STATE_INIT; if(AUDIO_PLAYER_Start(0) == AUDIO_ERROR_IO) { AUDIO_ChangeSelectMode(AUDIO_SELECT_MENU); AudioDemo.state = AUDIO_DEMO_IDLE; } 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 /* Not idle */ { if(AUDIO_PLAYER_Process() == AUDIO_ERROR_IO) { AUDIO_ChangeSelectMode(AUDIO_SELECT_MENU); AudioDemo.state = AUDIO_DEMO_IDLE; } } } else { AudioDemo.state = AUDIO_DEMO_WAIT; } break; case AUDIO_DEMO_IN: if(AppliState == APPLICATION_READY) { if(AudioState == AUDIO_STATE_IDLE) { /* Start Playing */ AudioState = AUDIO_STATE_INIT; /* Configure the audio recorder: sampling frequency, bits-depth, number of channels */ if(AUDIO_REC_Start() == AUDIO_ERROR_IO) { AUDIO_ChangeSelectMode(AUDIO_SELECT_MENU); AudioDemo.state = AUDIO_DEMO_IDLE; } 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 /* Not idle */ { status = AUDIO_REC_Process(); if((status == AUDIO_ERROR_IO) || (status == AUDIO_ERROR_EOF)) { AUDIO_ChangeSelectMode(AUDIO_SELECT_MENU); AudioDemo.state = AUDIO_DEMO_IDLE; } } } else { AudioDemo.state = AUDIO_DEMO_WAIT; } break; default: break; } } if(AppliState == APPLICATION_DISCONNECT) { AppliState = APPLICATION_IDLE; AUDIO_ChangeSelectMode(AUDIO_SELECT_MENU); BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW); } AudioDemo.select &= 0x7F; }
/** * @brief Manages AUDIO Menu Process. * @param None * @retval None */ void AUDIO_MenuProcess(void) { AUDIO_ErrorTypeDef status; TS_StateTypeDef TS_State; Point PlaybackLogoPoints[] = {{TOUCH_PLAYBACK_XMIN, TOUCH_PLAYBACK_YMIN}, {TOUCH_PLAYBACK_XMAX, (TOUCH_PLAYBACK_YMIN+TOUCH_PLAYBACK_YMAX)/2}, {TOUCH_PLAYBACK_XMIN, TOUCH_PLAYBACK_YMAX}}; if(appli_state == APPLICATION_READY) { switch(AudioDemo.state) { case AUDIO_DEMO_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; } else { AudioDemo.state = AUDIO_DEMO_WAIT; } BSP_LCD_SetFont(&LCD_LOG_HEADER_FONT); BSP_LCD_ClearStringLine(13); /* Clear touch screen buttons dedicated zone */ BSP_LCD_ClearStringLine(14); BSP_LCD_ClearStringLine(15); BSP_LCD_SetTextColor(LCD_COLOR_CYAN); BSP_LCD_FillPolygon(PlaybackLogoPoints, 3); /* Playback sign */ BSP_LCD_FillCircle((TOUCH_RECORD_XMAX+TOUCH_RECORD_XMIN)/2, /* Record circle */ (TOUCH_RECORD_YMAX+TOUCH_RECORD_YMIN)/2, (TOUCH_RECORD_XMAX-TOUCH_RECORD_XMIN)/2); BSP_LCD_SetTextColor(LCD_COLOR_GREEN); BSP_LCD_SetFont(&LCD_LOG_TEXT_FONT); BSP_LCD_DisplayStringAtLine(15, (uint8_t *)"Use touch screen to enter playback or record menu"); break; case AUDIO_DEMO_WAIT: BSP_TS_GetState(&TS_State); if(TS_State.touchDetected == 1) { if ((TS_State.touchX[0] > TOUCH_RECORD_XMIN) && (TS_State.touchX[0] < TOUCH_RECORD_XMAX) && (TS_State.touchY[0] > TOUCH_RECORD_YMIN) && (TS_State.touchY[0] < TOUCH_RECORD_YMAX)) { AudioDemo.state = AUDIO_DEMO_IN; } else if ((TS_State.touchX[0] > TOUCH_PLAYBACK_XMIN) && (TS_State.touchX[0] < TOUCH_PLAYBACK_XMAX) && (TS_State.touchY[0] > TOUCH_PLAYBACK_YMIN) && (TS_State.touchY[0] < TOUCH_PLAYBACK_YMAX)) { AudioDemo.state = AUDIO_DEMO_PLAYBACK; } else { AudioDemo.state = AUDIO_DEMO_EXPLORE; } /* Wait for touch released */ do { BSP_TS_GetState(&TS_State); }while(TS_State.touchDetected > 0); } break; 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; } else { AudioDemo.state = AUDIO_DEMO_WAIT; } } else { AudioDemo.state = AUDIO_DEMO_WAIT; } break; case AUDIO_DEMO_PLAYBACK: if(appli_state == APPLICATION_READY) { if(AudioState == AUDIO_STATE_IDLE) { /* Start Playing */ AudioState = AUDIO_STATE_INIT; /* Clear the LCD */ LCD_ClearTextZone(); if(AUDIO_PLAYER_Start(0) == AUDIO_ERROR_IO) { AUDIO_ChangeSelectMode(AUDIO_SELECT_MENU); AudioDemo.state = AUDIO_DEMO_IDLE; } } else /* Not idle */ { if(AUDIO_PLAYER_Process() == AUDIO_ERROR_IO) { /* Clear the LCD */ LCD_ClearTextZone(); AUDIO_ChangeSelectMode(AUDIO_SELECT_MENU); AudioDemo.state = AUDIO_DEMO_IDLE; } } } else { AudioDemo.state = AUDIO_DEMO_WAIT; } break; case AUDIO_DEMO_IN: if(appli_state == APPLICATION_READY) { if(AudioState == AUDIO_STATE_IDLE) { /* Start Playing */ AudioState = AUDIO_STATE_INIT; /* Clear the LCD */ LCD_ClearTextZone(); /* Configure the audio recorder: sampling frequency, bits-depth, number of channels */ if(AUDIO_REC_Start() == AUDIO_ERROR_IO) { AUDIO_ChangeSelectMode(AUDIO_SELECT_MENU); AudioDemo.state = AUDIO_DEMO_IDLE; } } else /* Not idle */ { status = AUDIO_REC_Process(); if((status == AUDIO_ERROR_IO) || (status == AUDIO_ERROR_EOF)) { /* Clear the LCD */ LCD_ClearTextZone(); AUDIO_ChangeSelectMode(AUDIO_SELECT_MENU); AudioDemo.state = AUDIO_DEMO_IDLE; } } } else { AudioDemo.state = AUDIO_DEMO_WAIT; } break; default: break; } } if(appli_state == APPLICATION_DISCONNECT) { appli_state = APPLICATION_IDLE; AUDIO_ChangeSelectMode(AUDIO_SELECT_MENU); BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW); } }
/** * @brief Manages Audio process. * @param None * @retval Audio error */ AUDIO_ErrorTypeDef AUDIO_PLAYER_Process(void) { uint32_t bytesread, elapsed_time; AUDIO_ErrorTypeDef audio_error = AUDIO_ERROR_NONE; static uint32_t prev_elapsed_time = 0xFFFFFFFF; uint8_t str[10]; switch(AudioState) { case AUDIO_STATE_PLAY: if(BufferCtl.fptr >= WaveFormat.FileSize) { BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW); AudioState = AUDIO_STATE_NEXT; } if(BufferCtl.state == BUFFER_OFFSET_HALF) { if(f_read(&WavFile, &BufferCtl.buff[0], AUDIO_OUT_BUFFER_SIZE/2, (void *)&bytesread) != FR_OK) { BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW); return AUDIO_ERROR_IO; } BufferCtl.state = BUFFER_OFFSET_NONE; BufferCtl.fptr += bytesread; } if(BufferCtl.state == BUFFER_OFFSET_FULL) { if(f_read(&WavFile, &BufferCtl.buff[AUDIO_OUT_BUFFER_SIZE /2], AUDIO_OUT_BUFFER_SIZE/2, (void *)&bytesread) != FR_OK) { BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW); return AUDIO_ERROR_IO; } BufferCtl.state = BUFFER_OFFSET_NONE; BufferCtl.fptr += bytesread; } /* Display elapsed time */ elapsed_time = BufferCtl.fptr / WaveFormat.ByteRate; if(prev_elapsed_time != elapsed_time) { prev_elapsed_time = elapsed_time; sprintf((char *)str, "[%02d:%02d]", (int)(elapsed_time /60), (int)(elapsed_time%60)); BSP_LCD_SetTextColor(LCD_COLOR_CYAN); BSP_LCD_DisplayStringAt(263, LINE(8), str, LEFT_MODE); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); } break; case AUDIO_STATE_STOP: BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW); AudioState = AUDIO_STATE_IDLE; audio_error = AUDIO_ERROR_IO; break; case AUDIO_STATE_NEXT: if(++FilePos >= AUDIO_GetWavObjectNumber()) { FilePos = 0; } BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW); AUDIO_PLAYER_Start(FilePos); break; case AUDIO_STATE_PREVIOUS: if(--FilePos < 0) { FilePos = AUDIO_GetWavObjectNumber() - 1; } BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW); AUDIO_PLAYER_Start(FilePos); break; case AUDIO_STATE_PAUSE: BSP_LCD_DisplayStringAt(250, LINE(14), (uint8_t *)" [PAUSE]", LEFT_MODE); BSP_AUDIO_OUT_Pause(); AudioState = AUDIO_STATE_WAIT; break; case AUDIO_STATE_RESUME: BSP_LCD_DisplayStringAt(250, LINE(14), (uint8_t *)" [PLAY ]", LEFT_MODE); BSP_AUDIO_OUT_Resume(); AudioState = AUDIO_STATE_PLAY; break; case AUDIO_STATE_VOLUME_UP: if( uwVolume <= 90) { uwVolume += 10; } BSP_AUDIO_OUT_SetVolume(uwVolume); AudioState = AUDIO_STATE_PLAY; break; case AUDIO_STATE_VOLUME_DOWN: if( uwVolume >= 10) { uwVolume -= 10; } BSP_AUDIO_OUT_SetVolume(uwVolume); AudioState = AUDIO_STATE_PLAY; break; case AUDIO_STATE_WAIT: case AUDIO_STATE_IDLE: case AUDIO_STATE_INIT: default: /* Do Nothing */ break; } return audio_error; }
/** * @brief Manages Audio process. * @param None * @retval Audio error */ AUDIO_ErrorTypeDef AUDIO_PLAYER_Process(void) { uint32_t bytesread, elapsed_time; AUDIO_ErrorTypeDef audio_error = AUDIO_ERROR_NONE; static uint32_t prev_elapsed_time = 0xFFFFFFFF; uint8_t str[10]; switch(AudioState) { case AUDIO_STATE_PLAY: if(BufferCtl.fptr >= WaveFormat.FileSize) { BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW); AudioState = AUDIO_STATE_NEXT; } if(BufferCtl.state == BUFFER_OFFSET_HALF) { if(f_read(&WavFile, &BufferCtl.buff[0], AUDIO_OUT_BUFFER_SIZE/2, (void *)&bytesread) != FR_OK) { BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW); return AUDIO_ERROR_IO; } BufferCtl.state = BUFFER_OFFSET_NONE; BufferCtl.fptr += bytesread; } if(BufferCtl.state == BUFFER_OFFSET_FULL) { if(f_read(&WavFile, &BufferCtl.buff[AUDIO_OUT_BUFFER_SIZE /2], AUDIO_OUT_BUFFER_SIZE/2, (void *)&bytesread) != FR_OK) { BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW); return AUDIO_ERROR_IO; } BufferCtl.state = BUFFER_OFFSET_NONE; BufferCtl.fptr += bytesread; } /* Display elapsed time */ elapsed_time = BufferCtl.fptr / WaveFormat.ByteRate; if(prev_elapsed_time != elapsed_time) { prev_elapsed_time = elapsed_time; sprintf((char *)str, "[%02d:%02d]", (int)(elapsed_time /60), (int)(elapsed_time%60)); BSP_LCD_SetTextColor(LCD_COLOR_CYAN); BSP_LCD_DisplayStringAt(263, LINE(8), str, LEFT_MODE); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); } /* Update audio state machine according to touch acquisition */ AUDIO_AcquireTouchButtons(); break; case AUDIO_STATE_STOP: BSP_LCD_SetTextColor(LCD_COLOR_RED); BSP_LCD_FillRect(TOUCH_STOP_XMIN, TOUCH_STOP_YMIN , /* Stop rectangle */ TOUCH_STOP_XMAX - TOUCH_STOP_XMIN, TOUCH_STOP_YMAX - TOUCH_STOP_YMIN); BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW); AudioState = AUDIO_STATE_IDLE; audio_error = AUDIO_ERROR_IO; break; case AUDIO_STATE_NEXT: if(++FilePos >= AUDIO_GetWavObjectNumber()) { FilePos = 0; } BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW); AUDIO_PLAYER_Start(FilePos); break; case AUDIO_STATE_PREVIOUS: if(--FilePos < 0) { FilePos = AUDIO_GetWavObjectNumber() - 1; } BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW); AUDIO_PLAYER_Start(FilePos); break; case AUDIO_STATE_PAUSE: BSP_LCD_SetTextColor(LCD_COLOR_CYAN); BSP_LCD_DisplayStringAt(250, LINE(9), (uint8_t *)" [PAUSE]", LEFT_MODE); BSP_LCD_SetTextColor(LCD_COLOR_RED); /* Display red pause rectangles */ BSP_LCD_FillRect(TOUCH_PAUSE_XMIN, TOUCH_PAUSE_YMIN , 15, TOUCH_PAUSE_YMAX - TOUCH_PAUSE_YMIN); BSP_LCD_FillRect(TOUCH_PAUSE_XMIN + 20, TOUCH_PAUSE_YMIN, 15, TOUCH_PAUSE_YMAX - TOUCH_PAUSE_YMIN); BSP_AUDIO_OUT_Pause(); AudioState = AUDIO_STATE_WAIT; break; case AUDIO_STATE_RESUME: BSP_LCD_SetTextColor(LCD_COLOR_CYAN); BSP_LCD_DisplayStringAt(250, LINE(9), (uint8_t *)" [PLAY ]", LEFT_MODE); /* Display blue cyan pause rectangles */ BSP_LCD_FillRect(TOUCH_PAUSE_XMIN, TOUCH_PAUSE_YMIN , 15, TOUCH_PAUSE_YMAX - TOUCH_PAUSE_YMIN); BSP_LCD_FillRect(TOUCH_PAUSE_XMIN + 20, TOUCH_PAUSE_YMIN, 15, TOUCH_PAUSE_YMAX - TOUCH_PAUSE_YMIN); BSP_AUDIO_OUT_Resume(); AudioState = AUDIO_STATE_PLAY; break; case AUDIO_STATE_VOLUME_UP: if( uwVolume <= 90) { uwVolume += 10; } BSP_AUDIO_OUT_SetVolume(uwVolume); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); sprintf((char *)str, "Volume : %lu ", uwVolume); BSP_LCD_DisplayStringAtLine(9, str); AudioState = AUDIO_STATE_PLAY; break; case AUDIO_STATE_VOLUME_DOWN: if( uwVolume >= 10) { uwVolume -= 10; } BSP_AUDIO_OUT_SetVolume(uwVolume); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); sprintf((char *)str, "Volume : %lu ", uwVolume); BSP_LCD_DisplayStringAtLine(9, str); AudioState = AUDIO_STATE_PLAY; break; case AUDIO_STATE_WAIT: case AUDIO_STATE_IDLE: case AUDIO_STATE_INIT: default: /* Update audio state machine according to touch acquisition */ AUDIO_AcquireTouchButtons(); break; } return audio_error; }