STM32469I_EVAL BSP User Manual
|
stm32469i_eval_audio.h
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file stm32469i_eval_audio.h 00004 * @author MCD Application Team 00005 * @version V1.0.2 00006 * @date 12-January-2016 00007 * @brief This file contains the common defines and functions prototypes for 00008 * the stm32469i_eval_audio.c driver. 00009 ****************************************************************************** 00010 * @attention 00011 * 00012 * <h2><center>© COPYRIGHT(c) 2015 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 __STM32469I_EVAL_AUDIO_H 00041 #define __STM32469I_EVAL_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 "stm32469i_eval.h" 00051 #include "../../../Middlewares/ST/STM32_Audio/Addons/PDM/pdm_filter.h" 00052 00053 /** @addtogroup BSP 00054 * @{ 00055 */ 00056 00057 /** @addtogroup STM32469I_EVAL 00058 * @{ 00059 */ 00060 00061 /** @addtogroup STM32469I-EVAL_AUDIO 00062 * @{ 00063 */ 00064 00065 /** @defgroup STM32469I-EVAL_AUDIO_Exported_Types STM32469I EVAL AUDIO Exported Types 00066 * @{ 00067 */ 00068 /** 00069 * @} 00070 */ 00071 00072 /** @defgroup STM32469I-EVAL_AUDIO_Exported_Constants STM32469I EVAL AUDIO Exported Constants 00073 * @{ 00074 */ 00075 00076 /*------------------------------------------------------------------------------ 00077 USER SAI defines parameters 00078 -----------------------------------------------------------------------------*/ 00079 /** @defgroup CODEC_AudioFrame_SLOT_TDMMode STM32469I EVAL Audio Slot TDM mode 00080 * @brief In W8994 codec the Audio frame contains 4 slots : TDM Mode 00081 * TDM format : 00082 * +------------------|------------------|--------------------|-------------------+ 00083 * | CODEC_SLOT0 Left | CODEC_SLOT1 Left | CODEC_SLOT0 Right | CODEC_SLOT1 Right | 00084 * +------------------------------------------------------------------------------+ 00085 * @{ 00086 */ 00087 /* To have 2 separate audio stream in Both headphone and speaker the 4 slot must be activated */ 00088 #define CODEC_AUDIOFRAME_SLOT_0123 SAI_SLOTACTIVE_0 | SAI_SLOTACTIVE_1 | SAI_SLOTACTIVE_2 | SAI_SLOTACTIVE_3 00089 /* To have an audio stream in headphone only SAI Slot 0 and Slot 2 must be activated */ 00090 #define CODEC_AUDIOFRAME_SLOT_02 SAI_SLOTACTIVE_0 | SAI_SLOTACTIVE_2 00091 /* To have an audio stream in speaker only SAI Slot 1 and Slot 3 must be activated */ 00092 #define CODEC_AUDIOFRAME_SLOT_13 SAI_SLOTACTIVE_1 | SAI_SLOTACTIVE_3 00093 /** 00094 * @} 00095 */ 00096 00097 /* SAI peripheral configuration defines */ 00098 #define AUDIO_SAIx SAI1_Block_A 00099 #define AUDIO_SAIx_CLK_ENABLE() __HAL_RCC_SAI1_CLK_ENABLE() 00100 #define AUDIO_SAIx_CLK_DISABLE() __HAL_RCC_SAI1_CLK_DISABLE() 00101 #define AUDIO_SAIx_MCLK_SCK_SD_FS_AF GPIO_AF6_SAI1 00102 00103 #define AUDIO_SAIx_MCLK_ENABLE() __HAL_RCC_GPIOG_CLK_ENABLE() 00104 #define AUDIO_SAIx_MCLK_DISABLE() __HAL_RCC_GPIOG_CLK_DISABLE() 00105 00106 #define AUDIO_SAIx_MCK_PIN GPIO_PIN_7 00107 #define AUDIO_SAIx_MCLK_GPIO_PORT GPIOG 00108 00109 #define AUDIO_SAIx_SCK_SD_FS_ENABLE() __HAL_RCC_GPIOE_CLK_ENABLE() 00110 #define AUDIO_SAIx_SCK_SD_FS_DISABLE() __HAL_RCC_GPIOE_CLK_DISABLE() 00111 #define AUDIO_SAIx_FS_PIN GPIO_PIN_4 00112 #define AUDIO_SAIx_SCK_PIN GPIO_PIN_5 00113 #define AUDIO_SAIx_SD_PIN GPIO_PIN_6 00114 #define AUDIO_SAIx_SCK_SD_FS_GPIO_PORT GPIOE 00115 00116 00117 /* SAI DMA Stream definitions */ 00118 #define AUDIO_SAIx_DMAx_CLK_ENABLE() __HAL_RCC_DMA2_CLK_ENABLE() 00119 #define AUDIO_SAIx_DMAx_CLK_DISABLE() __HAL_RCC_DMA2_CLK_DISABLE() 00120 #define AUDIO_SAIx_DMAx_STREAM DMA2_Stream3 00121 #define AUDIO_SAIx_DMAx_CHANNEL DMA_CHANNEL_0 00122 #define AUDIO_SAIx_DMAx_IRQ DMA2_Stream3_IRQn 00123 #define AUDIO_SAIx_DMAx_PERIPH_DATA_SIZE DMA_PDATAALIGN_HALFWORD 00124 #define AUDIO_SAIx_DMAx_MEM_DATA_SIZE DMA_MDATAALIGN_HALFWORD 00125 #define DMA_MAX_SZE 0xFFFF 00126 00127 #define AUDIO_SAIx_DMAx_IRQHandler DMA2_Stream3_IRQHandler 00128 00129 /* Select the interrupt preemption priority for the DMA interrupt */ 00130 #define AUDIO_OUT_IRQ_PREPRIO 5 /* Select the preemption priority level(0 is the highest) */ 00131 00132 /*------------------------------------------------------------------------------ 00133 AUDIO IN CONFIGURATION 00134 ------------------------------------------------------------------------------*/ 00135 /* SPI Configuration defines */ 00136 #define AUDIO_I2Sx SPI3 00137 #define AUDIO_I2Sx_CLK_ENABLE() __HAL_RCC_SPI3_CLK_ENABLE() 00138 #define AUDIO_I2Sx_CLK_DISABLE() __HAL_RCC_SPI3_CLK_DISABLE() 00139 #define AUDIO_I2Sx_SCK_PIN GPIO_PIN_3 00140 #define AUDIO_I2Sx_SCK_GPIO_PORT GPIOB 00141 #define AUDIO_I2Sx_SCK_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE() 00142 #define AUDIO_I2Sx_SCK_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE() 00143 #define AUDIO_I2Sx_SCK_AF GPIO_AF6_SPI3 00144 00145 #define AUDIO_I2Sx_SD_PIN GPIO_PIN_6 00146 #define AUDIO_I2Sx_SD_GPIO_PORT GPIOD 00147 #define AUDIO_I2Sx_SD_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE() 00148 #define AUDIO_I2Sx_SD_GPIO_CLK_DISABLE() __HAL_RCC_GPIOD_CLK_DISABLE() 00149 #define AUDIO_I2Sx_SD_AF GPIO_AF5_I2S3ext 00150 00151 /* I2S DMA Stream Rx definitions */ 00152 #define AUDIO_I2Sx_DMAx_CLK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE() 00153 #define AUDIO_I2Sx_DMAx_CLK_DISABLE() __HAL_RCC_DMA1_CLK_DISABLE() 00154 #define AUDIO_I2Sx_DMAx_STREAM DMA1_Stream2 00155 #define AUDIO_I2Sx_DMAx_CHANNEL DMA_CHANNEL_0 00156 #define AUDIO_I2Sx_DMAx_IRQ DMA1_Stream2_IRQn 00157 #define AUDIO_I2Sx_DMAx_PERIPH_DATA_SIZE DMA_PDATAALIGN_HALFWORD 00158 #define AUDIO_I2Sx_DMAx_MEM_DATA_SIZE DMA_MDATAALIGN_HALFWORD 00159 00160 #define AUDIO_I2Sx_DMAx_IRQHandler DMA1_Stream2_IRQHandler 00161 00162 /* Select the interrupt preemption priority and subpriority for the IT/DMA interrupt */ 00163 #define AUDIO_IN_IRQ_PREPRIO ((uint32_t)6) /* Select the preemption priority level(0 is the highest) */ 00164 00165 00166 /* Two channels are used: 00167 - one channel as input which is connected to I2S SCK in stereo mode 00168 - one channel as output which divides the frequency on the input 00169 */ 00170 00171 #define AUDIO_TIMx_CLK_ENABLE() __HAL_RCC_TIM3_CLK_ENABLE() 00172 #define AUDIO_TIMx_CLK_DISABLE() __HAL_RCC_TIM3_CLK_DISABLE() 00173 #define AUDIO_TIMx TIM3 00174 #define AUDIO_TIMx_IN_CHANNEL TIM_CHANNEL_1 00175 #define AUDIO_TIMx_OUT_CHANNEL TIM_CHANNEL_2 /* Select channel 2 as output */ 00176 #define AUDIO_TIMx_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE() 00177 #define AUDIO_TIMx_GPIO_CLK_DISABLE() __HAL_RCC_GPIOC_CLK_DISABLE() 00178 #define AUDIO_TIMx_GPIO_PORT GPIOC 00179 #define AUDIO_TIMx_IN_GPIO_PIN GPIO_PIN_6 00180 #define AUDIO_TIMx_OUT_GPIO_PIN GPIO_PIN_7 00181 #define AUDIO_TIMx_AF GPIO_AF2_TIM3 00182 00183 /*------------------------------------------------------------------------------ 00184 CONFIGURATION: Audio Driver Configuration parameters 00185 ------------------------------------------------------------------------------*/ 00186 00187 #define AUDIODATA_SIZE 2 /* 16-bits audio data size */ 00188 00189 /* Audio status definition */ 00190 #define AUDIO_OK ((uint8_t)0) 00191 #define AUDIO_ERROR ((uint8_t)1) 00192 #define AUDIO_TIMEOUT ((uint8_t)2) 00193 00194 /* AudioFreq * DataSize (2 bytes) * NumChannels (Stereo: 2) */ 00195 #define DEFAULT_AUDIO_IN_FREQ I2S_AUDIOFREQ_16K 00196 #define DEFAULT_AUDIO_IN_BIT_RESOLUTION ((uint8_t)16) 00197 #define DEFAULT_AUDIO_IN_CHANNEL_NBR ((uint8_t)2) /* Mono = 1, Stereo = 2 */ 00198 #define DEFAULT_AUDIO_IN_VOLUME ((uint16_t)64) 00199 00200 /* PDM buffer input size */ 00201 #define INTERNAL_BUFF_SIZE (128*DEFAULT_AUDIO_IN_FREQ/16000*DEFAULT_AUDIO_IN_CHANNEL_NBR) 00202 /* PCM buffer output size */ 00203 #define PCM_OUT_SIZE (DEFAULT_AUDIO_IN_FREQ/1000*DEFAULT_AUDIO_IN_CHANNEL_NBR) 00204 #define CHANNEL_DEMUX_MASK ((uint8_t)0x55) 00205 00206 /*------------------------------------------------------------------------------ 00207 OPTIONAL Configuration defines parameters 00208 ------------------------------------------------------------------------------*/ 00209 00210 /* Delay for the Codec to be correctly reset */ 00211 #define CODEC_RESET_DELAY ((uint8_t)5) 00212 00213 /*------------------------------------------------------------------------------ 00214 OUTPUT DEVICES definition 00215 ------------------------------------------------------------------------------*/ 00216 00217 /** 00218 * @} 00219 */ 00220 00221 /** @defgroup STM32469I-EVAL_AUDIO_Exported_Variables STM32469I EVAL AUDIO Exported Variables 00222 * @{ 00223 */ 00224 extern __IO uint16_t AudioInVolume; 00225 /** 00226 * @} 00227 */ 00228 00229 /** @defgroup STM32469I-EVAL_AUDIO_Exported_Macros STM32469I EVAL AUDIO Exported Macros 00230 * @{ 00231 */ 00232 #define DMA_MAX(x) (((x) <= DMA_MAX_SZE)? (x):DMA_MAX_SZE) 00233 /** 00234 * @} 00235 */ 00236 00237 /** @defgroup STM32469I-EVAL_AUDIO_OUT_Exported_Functions STM32469I EVAL AUDIO OUT Exported Functions 00238 * @{ 00239 */ 00240 uint8_t BSP_AUDIO_OUT_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq); 00241 uint8_t BSP_AUDIO_OUT_Play(uint16_t* pBuffer, uint32_t Size); 00242 void BSP_AUDIO_OUT_ChangeBuffer(uint16_t *pData, uint16_t Size); 00243 uint8_t BSP_AUDIO_OUT_Pause(void); 00244 uint8_t BSP_AUDIO_OUT_Resume(void); 00245 uint8_t BSP_AUDIO_OUT_Stop(uint32_t Option); 00246 uint8_t BSP_AUDIO_OUT_SetVolume(uint8_t Volume); 00247 void BSP_AUDIO_OUT_SetFrequency(uint32_t AudioFreq); 00248 void BSP_AUDIO_OUT_SetAudioFrameSlot(uint32_t AudioFrameSlot); 00249 uint8_t BSP_AUDIO_OUT_SetMute(uint32_t Cmd); 00250 uint8_t BSP_AUDIO_OUT_SetOutputMode(uint8_t Output); 00251 void BSP_AUDIO_OUT_DeInit(void); 00252 00253 /* User Callbacks: user has to implement these functions in his code if they are needed. */ 00254 /* This function is called when the requested data has been completely transferred.*/ 00255 void BSP_AUDIO_OUT_TransferComplete_CallBack(void); 00256 00257 /* This function is called when half of the requested buffer has been transferred. */ 00258 void BSP_AUDIO_OUT_HalfTransfer_CallBack(void); 00259 00260 /* This function is called when an Interrupt due to transfer error on or peripheral 00261 error occurs. */ 00262 void BSP_AUDIO_OUT_Error_CallBack(void); 00263 00264 /* These function can be modified in case the current settings (e.g. DMA stream) 00265 need to be changed for specific application needs */ 00266 void BSP_AUDIO_OUT_ClockConfig(SAI_HandleTypeDef *hsai, uint32_t AudioFreq, void *Params); 00267 void BSP_AUDIO_OUT_MspInit(SAI_HandleTypeDef *hsai, void *Params); 00268 void BSP_AUDIO_OUT_MspDeInit(SAI_HandleTypeDef *hsai, void *Params); 00269 00270 /** 00271 * @} 00272 */ 00273 00274 /** @defgroup STM32469I-EVAL_AUDIO_IN_Exported_Functions STM32469I EVAL AUDIO IN Exported Functions 00275 * @{ 00276 */ 00277 uint8_t BSP_AUDIO_IN_Init(uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr); 00278 uint8_t BSP_AUDIO_IN_Record(uint16_t *pData, uint32_t Size); 00279 uint8_t BSP_AUDIO_IN_Stop(void); 00280 uint8_t BSP_AUDIO_IN_Pause(void); 00281 uint8_t BSP_AUDIO_IN_Resume(void); 00282 uint8_t BSP_AUDIO_IN_SetVolume(uint8_t Volume); 00283 void BSP_AUDIO_IN_DeInit(void); 00284 uint8_t BSP_AUDIO_IN_PDMToPCM(uint16_t* PDMBuf, uint16_t* PCMBuf); 00285 /* User Callbacks: user has to implement these functions in his code if they are needed. */ 00286 /* This function should be implemented by the user application. 00287 It is called into this driver when the current buffer is filled to prepare the next 00288 buffer pointer and its size. */ 00289 void BSP_AUDIO_IN_TransferComplete_CallBack(void); 00290 void BSP_AUDIO_IN_HalfTransfer_CallBack(void); 00291 00292 /* This function is called when an Interrupt due to transfer error on or peripheral 00293 error occurs. */ 00294 void BSP_AUDIO_IN_Error_Callback(void); 00295 00296 /* These function can be modified in case the current settings (e.g. DMA stream) 00297 need to be changed for specific application needs */ 00298 void BSP_AUDIO_IN_MspInit(I2S_HandleTypeDef *hi2s, void *Params); 00299 void BSP_AUDIO_IN_MspDeInit(I2S_HandleTypeDef *hi2s, void *Params); 00300 00301 /** 00302 * @} 00303 */ 00304 00305 /** 00306 * @} 00307 */ 00308 00309 /** 00310 * @} 00311 */ 00312 00313 /** 00314 * @} 00315 */ 00316 00317 #ifdef __cplusplus 00318 } 00319 #endif 00320 00321 #endif /* __STM32469I_EVAL_AUDIO_H */ 00322 00323 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Tue Jan 12 2016 17:51:25 for STM32469I_EVAL BSP User Manual by
![doxygen](doxygen.png)