/** * @brief Initializes the Wave player. * @param AudioFreq: Audio sampling frequency * @retval None */ int WavePlayerInit(uint32_t AudioFreq) { /* MEMS Accelerometer configure to manage PAUSE, RESUME operations */ BSP_ACCELERO_Click_ITConfig(); /* Initialize the Audio codec and all related peripherals (I2S, I2C, IOExpander, IOs...) */ return(BSP_AUDIO_OUT_Init(OUTPUT_DEVICE_AUTO, Volume, AudioFreq)); }
int main(void) { HAL_Init(); led_all_init(); SystemClock_Config(); if (BSP_ACCELERO_Init() != ACCELERO_OK) { Error_Handler(); } BSP_ACCELERO_Click_ITConfig(); TIM_LED_Config(); isLooping = 1; ledState = LEDS_OFF; BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI); // Link the USB Host disk I/O driver if (FATFS_LinkDriver(&USBH_Driver, usbDrivePath) == 0) { USBH_Init(&hUSBHost, usbUserProcess, 0); USBH_RegisterClass(&hUSBHost, USBH_MSC_CLASS); USBH_Start(&hUSBHost); while (1) { switch (appState) { case APP_START: startApp(); break; case APP_IDLE: default: break; } USBH_Process(&hUSBHost); } } while (1) { } }
/** * @brief Test Audio Hardware. * The main objective of this test is to check the hardware connection of the * Audio peripheral. * @param None * @retval None */ void AudioPlay_Test(void) { /* Initial volume level (from 0 (Mute) to 100 (Max)) */ __IO uint8_t volume = 70; /* Initialize MEMS Accelerometer mounted on STM32F4-Discovery board */ if(BSP_ACCELERO_Init() != ACCELERO_OK) { /* Initialization Error */ Error_Handler(); } /* MEMS Accelerometer configure to manage PAUSE, RESUME operations */ BSP_ACCELERO_Click_ITConfig(); /* Turn ON LED6: start of Audio file play */ BSP_LED_On(LED6); /* Retrieve Wave Sample rate*/ waveformat = (WAVE_FormatTypeDef*) AUDIO_FILE_ADDRESS; /* Initialize Audio Device */ if(BSP_AUDIO_OUT_Init(OUTPUT_DEVICE_AUTO, volume, waveformat->SampleRate) != 0) { Error_Handler(); } /*Set variable used to stop player before starting */ UserPressButton = 0; AudioTest = 0; /* Set the total number of data to be played */ AudioTotalSize = AUDIO_FILE_SIZE; /* Set the current audio pointer position */ CurrentPos = (uint16_t *)(AUDIO_FILE_ADDRESS); /* Start the audio player */ BSP_AUDIO_OUT_Play(CurrentPos, AudioTotalSize); /* Update the remaining number of data to be played */ AudioRemSize = AudioTotalSize - AUDIODATA_SIZE * DMA_MAX(AudioTotalSize); /* Update the current audio pointer position */ CurrentPos += DMA_MAX(AudioTotalSize); /* Infinite loop */ while(!UserPressButton) { if (PauseResumeStatus == PAUSE_STATUS) { /* Turn ON LED4: Audio play in pause */ BSP_LED_On(LED4); /* Pause playing */ BSP_AUDIO_OUT_Pause(); PauseResumeStatus = IDLE_STATUS; } else if (PauseResumeStatus == RESUME_STATUS) { /* Turn OFF LED4: Audio play running */ BSP_LED_Off(LED4); /* Resume playing */ BSP_AUDIO_OUT_Resume(); PauseResumeStatus = IDLE_STATUS; } } /* Stop Player before close Test */ if (BSP_AUDIO_OUT_Stop(CODEC_PDWN_HW) != AUDIO_OK) { /* Audio Stop error */ Error_Handler(); } }
/** * @brief Main program * @param None * @retval None */ int main(void) { /* STM32F4xx HAL library initialization: - Configure the Flash prefetch, instruction and Data caches - Configure the Systick to generate an interrupt each 1 msec - Set NVIC Group Priority to 4 - Global MSP (MCU Support Package) initialization */ HAL_Init(); /* Configure LED3, LED4, LED5 and LED6 */ BSP_LED_Init(LED3); BSP_LED_Init(LED4); BSP_LED_Init(LED5); BSP_LED_Init(LED6); /* Configure the system clock to 84 MHz */ SystemClock_Config(); /* Initialize MEMS Accelerometer mounted on STM32F4-Discovery board */ if(BSP_ACCELERO_Init() != ACCELERO_OK) { /* Initialization Error */ Error_Handler(); } /* Enable click config for pause/play */ BSP_ACCELERO_Click_ITConfig(); /* Turn ON LED4: start of application */ BSP_LED_On(LED4); /* Configure TIM4 Peripheral to manage LEDs lighting */ TIM_LED_Config(); /* Turn OFF all LEDs */ LEDsState = LEDS_OFF; /* Initialize User Button */ BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI); /*##-1- Link the USB Host disk I/O driver ##################################*/ application_init(); /*##-2- Init Host Library ################################################*/ USBH_Init(&hUSBHost, USBH_UserProcess, 0); /*##-3- Add Supported Class ##############################################*/ USBH_RegisterClass(&hUSBHost, USBH_MSC_CLASS); /*##-4- Start Host Process ###############################################*/ USBH_Start(&hUSBHost); /* Run Application (Blocking mode)*/ while (1) { application_task(); /* USBH_Background Process */ USBH_Process(&hUSBHost); } }