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