STM32F723E-Discovery BSP User Manual
|
stm32f723e_discovery_audio.h
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file stm32f723e_discovery_audio.h 00004 * @author MCD Application Team 00005 * @brief This file contains the common defines and functions prototypes for 00006 * the stm32f723e_discovery_audio.c driver. 00007 ****************************************************************************** 00008 * @attention 00009 * 00010 * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> 00011 * 00012 * Redistribution and use in source and binary forms, with or without modification, 00013 * are permitted provided that the following conditions are met: 00014 * 1. Redistributions of source code must retain the above copyright notice, 00015 * this list of conditions and the following disclaimer. 00016 * 2. Redistributions in binary form must reproduce the above copyright notice, 00017 * this list of conditions and the following disclaimer in the documentation 00018 * and/or other materials provided with the distribution. 00019 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00020 * may be used to endorse or promote products derived from this software 00021 * without specific prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00024 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00025 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00026 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00027 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00028 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00029 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00030 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00031 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00032 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 * 00034 ****************************************************************************** 00035 */ 00036 00037 /* Define to prevent recursive inclusion -------------------------------------*/ 00038 #ifndef __STM32F723E_DISCOVERY_AUDIO_H 00039 #define __STM32F723E_DISCOVERY_AUDIO_H 00040 00041 #ifdef __cplusplus 00042 extern "C" { 00043 #endif 00044 00045 /* Includes ------------------------------------------------------------------*/ 00046 /* Include audio component Driver */ 00047 #include "../Components/wm8994/wm8994.h" 00048 #include "stm32f723e_discovery.h" 00049 #include <stdlib.h> 00050 00051 /** @addtogroup BSP 00052 * @{ 00053 */ 00054 00055 /** @addtogroup STM32F723E_DISCOVERY 00056 * @{ 00057 */ 00058 00059 /** @defgroup STM32F723E_DISCOVERY_AUDIO STM32F723E_DISCOVERY_AUDIO 00060 * @{ 00061 */ 00062 00063 /** @defgroup STM32F723E_DISCOVERY_AUDIO_Exported_Types STM32F723E_DISCOVERY_AUDIO Exported Types 00064 * @{ 00065 */ 00066 /** 00067 * @} 00068 */ 00069 00070 /** @defgroup STM32F723E_DISCOVERY_AUDIO_Exported_Constants STM32F723E_DISCOVERY_AUDIO Exported Constants 00071 * @{ 00072 */ 00073 00074 /** @defgroup BSP_Audio_Out_Option BSP Audio Out Option 00075 * @{ 00076 */ 00077 #define BSP_AUDIO_OUT_CIRCULARMODE ((uint32_t)0x00000001) /* BUFFER CIRCULAR MODE */ 00078 #define BSP_AUDIO_OUT_NORMALMODE ((uint32_t)0x00000002) /* BUFFER NORMAL MODE */ 00079 #define BSP_AUDIO_OUT_STEREOMODE ((uint32_t)0x00000004) /* STEREO MODE */ 00080 #define BSP_AUDIO_OUT_MONOMODE ((uint32_t)0x00000008) /* MONO MODE */ 00081 /** 00082 * @} 00083 */ 00084 /** @defgroup BSP_Audio_Sample_Rate BSP Audio Sample Rate 00085 * @{ 00086 */ 00087 #define BSP_AUDIO_FREQUENCY_96K SAI_AUDIO_FREQUENCY_96K 00088 #define BSP_AUDIO_FREQUENCY_48K SAI_AUDIO_FREQUENCY_48K 00089 #define BSP_AUDIO_FREQUENCY_44K SAI_AUDIO_FREQUENCY_44K 00090 #define BSP_AUDIO_FREQUENCY_32K SAI_AUDIO_FREQUENCY_32K 00091 #define BSP_AUDIO_FREQUENCY_22K SAI_AUDIO_FREQUENCY_22K 00092 #define BSP_AUDIO_FREQUENCY_16K SAI_AUDIO_FREQUENCY_16K 00093 #define BSP_AUDIO_FREQUENCY_11K SAI_AUDIO_FREQUENCY_11K 00094 #define BSP_AUDIO_FREQUENCY_8K SAI_AUDIO_FREQUENCY_8K 00095 /** 00096 * @} 00097 */ 00098 00099 /*------------------------------------------------------------------------------ 00100 USER SAI defines parameters 00101 -----------------------------------------------------------------------------*/ 00102 /** CODEC_AudioFrame_SLOT_TDMMode In W8994 codec the Audio frame contains 4 slots : TDM Mode 00103 * TDM format : 00104 * +------------------|------------------|--------------------|-------------------+ 00105 * | CODEC_SLOT0 Left | CODEC_SLOT1 Left | CODEC_SLOT0 Right | CODEC_SLOT1 Right | 00106 * +------------------------------------------------------------------------------+ 00107 */ 00108 /* To have 2 separate audio stream in Both headphone and speaker the 4 slot must be activated */ 00109 #define CODEC_AUDIOFRAME_SLOT_0123 SAI_SLOTACTIVE_0 | SAI_SLOTACTIVE_1 | SAI_SLOTACTIVE_2 | SAI_SLOTACTIVE_3 00110 00111 /* To have an audio stream in headphone only SAI Slot 0 and Slot 2 must be activated */ 00112 #define CODEC_AUDIOFRAME_SLOT_02 SAI_SLOTACTIVE_0 | SAI_SLOTACTIVE_2 00113 /* To have an audio stream in speaker only SAI Slot 1 and Slot 3 must be activated */ 00114 #define CODEC_AUDIOFRAME_SLOT_13 SAI_SLOTACTIVE_1 | SAI_SLOTACTIVE_3 00115 00116 00117 /* SAI peripheral configuration defines */ 00118 #define AUDIO_OUT_SAIx SAI2_Block_A 00119 #define AUDIO_OUT_SAIx_CLK_ENABLE() __HAL_RCC_SAI2_CLK_ENABLE() 00120 #define AUDIO_OUT_SAIx_CLK_DISABLE() __HAL_RCC_SAI2_CLK_DISABLE() 00121 #define AUDIO_OUT_SAIx_AF GPIO_AF10_SAI2 00122 00123 #define AUDIO_OUT_SAIx_MCLK_ENABLE() __HAL_RCC_GPIOI_CLK_ENABLE() 00124 #define AUDIO_OUT_SAIx_MCLK_GPIO_PORT GPIOI 00125 #define AUDIO_OUT_SAIx_MCLK_PIN GPIO_PIN_4 00126 #define AUDIO_OUT_SAIx_SD_FS_CLK_ENABLE() __HAL_RCC_GPIOI_CLK_ENABLE() 00127 #define AUDIO_OUT_SAIx_SD_FS_SCK_GPIO_PORT GPIOI 00128 #define AUDIO_OUT_SAIx_FS_PIN GPIO_PIN_7 00129 #define AUDIO_OUT_SAIx_SCK_PIN GPIO_PIN_5 00130 #define AUDIO_OUT_SAIx_SD_PIN GPIO_PIN_6 00131 00132 /* SAI DMA Stream definitions */ 00133 #define AUDIO_OUT_SAIx_DMAx_CLK_ENABLE() __HAL_RCC_DMA2_CLK_ENABLE() 00134 #define AUDIO_OUT_SAIx_DMAx_STREAM DMA2_Stream4 00135 #define AUDIO_OUT_SAIx_DMAx_CHANNEL DMA_CHANNEL_3 00136 #define AUDIO_OUT_SAIx_DMAx_IRQ DMA2_Stream4_IRQn 00137 #define AUDIO_OUT_SAIx_DMAx_PERIPH_DATA_SIZE DMA_PDATAALIGN_HALFWORD 00138 #define AUDIO_OUT_SAIx_DMAx_MEM_DATA_SIZE DMA_MDATAALIGN_HALFWORD 00139 #define DMA_MAX_SZE 0xFFFF 00140 00141 #define AUDIO_OUT_SAIx_DMAx_IRQHandler DMA2_Stream4_IRQHandler 00142 00143 /* Select the interrupt preemption priority for the DMA interrupt */ 00144 #define AUDIO_OUT_IRQ_PREPRIO ((uint32_t)0x0E) /* Select the preemption priority level(0 is the highest) */ 00145 00146 /*------------------------------------------------------------------------------ 00147 AUDIO IN CONFIGURATION 00148 ------------------------------------------------------------------------------*/ 00149 /* SAI IN peripheral configuration defines */ 00150 #define AUDIO_IN_SAIx SAI2_Block_B 00151 #define AUDIO_IN_SAIx_CLK_ENABLE() __HAL_RCC_SAI2_CLK_ENABLE() 00152 #define AUDIO_IN_SAIx_CLK_DISABLE() __HAL_RCC_SAI2_CLK_DISABLE() 00153 #define AUDIO_IN_SAIx_SD_AF GPIO_AF10_SAI2 00154 00155 #define AUDIO_IN_SAIx_SD_ENABLE() __HAL_RCC_GPIOG_CLK_ENABLE() 00156 #define AUDIO_IN_SAIx_SD_GPIO_PORT GPIOG 00157 #define AUDIO_IN_SAIx_SD_PIN GPIO_PIN_10 00158 00159 #define AUDIO_IN_INT_GPIO_ENABLE() __HAL_RCC_GPIOG_CLK_ENABLE() 00160 #define AUDIO_IN_INT_GPIO_PORT GPIOG 00161 #define AUDIO_IN_INT_GPIO_PIN GPIO_PIN_15 00162 #define AUDIO_IN_INT_IRQ EXTI15_10_IRQn 00163 00164 /* SAI DMA Stream definitions */ 00165 #define AUDIO_IN_SAIx_DMAx_CLK_ENABLE() __HAL_RCC_DMA2_CLK_ENABLE() 00166 #define AUDIO_IN_SAIx_DMAx_STREAM DMA2_Stream6 00167 #define AUDIO_IN_SAIx_DMAx_CHANNEL DMA_CHANNEL_3 00168 #define AUDIO_IN_SAIx_DMAx_IRQ DMA2_Stream6_IRQn 00169 #define AUDIO_IN_SAIx_DMAx_PERIPH_DATA_SIZE DMA_PDATAALIGN_HALFWORD 00170 #define AUDIO_IN_SAIx_DMAx_MEM_DATA_SIZE DMA_MDATAALIGN_HALFWORD 00171 00172 #define AUDIO_IN_SAIx_DMAx_IRQHandler DMA2_Stream6_IRQHandler 00173 #define AUDIO_IN_INT_IRQHandler EXTI15_10_IRQHandler 00174 00175 /* Select the interrupt preemption priority and subpriority for the IT/DMA interrupt */ 00176 #define AUDIO_IN_IRQ_PREPRIO ((uint32_t)0x0F) /* Select the preemption priority level(0 is the highest) */ 00177 00178 00179 /*------------------------------------------------------------------------------ 00180 CONFIGURATION: Audio Driver Configuration parameters 00181 ------------------------------------------------------------------------------*/ 00182 00183 #define AUDIODATA_SIZE 2 /* 16-bits audio data size */ 00184 00185 /* Audio status definition */ 00186 #define AUDIO_OK ((uint8_t)0) 00187 #define AUDIO_ERROR ((uint8_t)1) 00188 #define AUDIO_TIMEOUT ((uint8_t)2) 00189 00190 /* AudioFreq * DataSize (2 bytes) * NumChannels (Stereo: 2) */ 00191 #define DEFAULT_AUDIO_IN_FREQ BSP_AUDIO_FREQUENCY_16K 00192 #define DEFAULT_AUDIO_IN_BIT_RESOLUTION ((uint8_t)16) 00193 #define DEFAULT_AUDIO_IN_CHANNEL_NBR ((uint8_t)2) /* Mono = 1, Stereo = 2 */ 00194 #define DEFAULT_AUDIO_IN_VOLUME ((uint16_t)64) 00195 00196 /*------------------------------------------------------------------------------ 00197 OPTIONAL Configuration defines parameters 00198 ------------------------------------------------------------------------------*/ 00199 00200 /* Delay for the Codec to be correctly reset */ 00201 #define CODEC_RESET_DELAY ((uint8_t)5) 00202 00203 00204 /*------------------------------------------------------------------------------ 00205 OUTPUT DEVICES definition 00206 ------------------------------------------------------------------------------*/ 00207 /* Alias on existing output devices to adapt to headphones output */ 00208 #define OUTPUT_DEVICE_HEADPHONE1 OUTPUT_DEVICE_HEADPHONE 00209 #define OUTPUT_DEVICE_HEADPHONE2 OUTPUT_DEVICE_SPEAKER 00210 00211 /** 00212 * @} 00213 */ 00214 00215 /** @defgroup STM32F723E_DISCOVERY_AUDIO_Exported_Variables STM32F723E_DISCOVERY_AUDIO Exported Variables 00216 * @{ 00217 */ 00218 /** 00219 * @} 00220 */ 00221 00222 /** @defgroup STM32F723E_DISCOVERY_AUDIO_Exported_Macros STM32F723E_DISCOVERY_AUDIO Exported Macros 00223 * @{ 00224 */ 00225 #define DMA_MAX(x) (((x) <= DMA_MAX_SZE)? (x):DMA_MAX_SZE) 00226 /** 00227 * @} 00228 */ 00229 00230 /** @defgroup STM32F723E_DISCOVERY_AUDIO_OUT_Exported_Functions STM32F723E_DISCOVERY_AUDIO_OUT Exported Functions 00231 * @{ 00232 */ 00233 uint8_t BSP_AUDIO_OUT_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq); 00234 void BSP_AUDIO_OUT_DeInit(void); 00235 uint8_t BSP_AUDIO_OUT_Play(uint16_t* pBuffer, uint32_t Size); 00236 uint8_t BSP_AUDIO_OUT_Pause(void); 00237 uint8_t BSP_AUDIO_OUT_Resume(void); 00238 uint8_t BSP_AUDIO_OUT_Stop(uint32_t Option); 00239 uint8_t BSP_AUDIO_OUT_SetVolume(uint8_t Volume); 00240 void BSP_AUDIO_OUT_SetFrequency(uint32_t AudioFreq); 00241 void BSP_AUDIO_OUT_SetAudioFrameSlot(uint32_t AudioFrameSlot); 00242 uint8_t BSP_AUDIO_OUT_SetMute(uint32_t Cmd); 00243 uint8_t BSP_AUDIO_OUT_SetOutputMode(uint8_t Output); 00244 void BSP_AUDIO_OUT_ChangeBuffer(uint16_t *pData, uint16_t Size); 00245 00246 /* User Callbacks: user has to implement these functions in his code if they are needed. */ 00247 /* This function is called when the requested data has been completely transferred.*/ 00248 void BSP_AUDIO_OUT_TransferComplete_CallBack(void); 00249 00250 /* This function is called when half of the requested buffer has been transferred. */ 00251 void BSP_AUDIO_OUT_HalfTransfer_CallBack(void); 00252 00253 /* This function is called when an Interrupt due to transfer error on or peripheral 00254 error occurs. */ 00255 void BSP_AUDIO_OUT_Error_CallBack(void); 00256 00257 /* These function can be modified in case the current settings (e.g. DMA stream) 00258 need to be changed for specific application needs */ 00259 void BSP_AUDIO_OUT_ClockConfig(SAI_HandleTypeDef *hsai, uint32_t AudioFreq, void *Params); 00260 void BSP_AUDIO_OUT_MspInit(SAI_HandleTypeDef *hsai, void *Params); 00261 void BSP_AUDIO_OUT_MspDeInit(SAI_HandleTypeDef *hsai, void *Params); 00262 00263 /** 00264 * @} 00265 */ 00266 00267 /** @defgroup STM32F723E_DISCOVERY_AUDIO_IN_Exported_Functions STM32F723E_DISCOVERY_AUDIO_IN Exported Functions 00268 * @{ 00269 */ 00270 uint8_t BSP_AUDIO_IN_Init(uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr); 00271 uint8_t BSP_AUDIO_IN_InitEx(uint16_t InputDevice, uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr); 00272 uint8_t BSP_AUDIO_IN_OUT_Init(uint16_t InputDevice, uint16_t OutputDevice, uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr); 00273 void BSP_AUDIO_IN_DeInit(void); 00274 uint8_t BSP_AUDIO_IN_Record(uint16_t *pData, uint32_t Size); 00275 uint8_t BSP_AUDIO_IN_Stop(uint32_t Option); 00276 uint8_t BSP_AUDIO_IN_Pause(void); 00277 uint8_t BSP_AUDIO_IN_Resume(void); 00278 uint8_t BSP_AUDIO_IN_SetVolume(uint8_t Volume); 00279 void BSP_AUDIO_IN_DeInit(void); 00280 00281 /* User Callbacks: user has to implement these functions in his code if they are needed. */ 00282 /* This function should be implemented by the user application. 00283 It is called into this driver when the current buffer is filled to prepare the next 00284 buffer pointer and its size. */ 00285 void BSP_AUDIO_IN_TransferComplete_CallBack(void); 00286 void BSP_AUDIO_IN_HalfTransfer_CallBack(void); 00287 00288 /* This function is called when an Interrupt due to transfer error on or peripheral 00289 error occurs. */ 00290 void BSP_AUDIO_IN_Error_CallBack(void); 00291 00292 /* These function can be modified in case the current settings (e.g. DMA stream) 00293 need to be changed for specific application needs */ 00294 void BSP_AUDIO_IN_ClockConfig(SAI_HandleTypeDef *hsai, uint32_t AudioFreq, void *Params); 00295 void BSP_AUDIO_IN_MspInit(SAI_HandleTypeDef *hsai, void *Params); 00296 void BSP_AUDIO_IN_MspDeInit(SAI_HandleTypeDef *hsai, void *Params); 00297 00298 /** 00299 * @} 00300 */ 00301 00302 /** 00303 * @} 00304 */ 00305 00306 /** 00307 * @} 00308 */ 00309 00310 /** 00311 * @} 00312 */ 00313 00314 #ifdef __cplusplus 00315 } 00316 #endif 00317 00318 #endif /* __STM32F723E_DISCOVERY_AUDIO_H */ 00319 00320 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Tue May 30 2017 13:59:12 for STM32F723E-Discovery BSP User Manual by 1.7.6.1