STM32446E_EVAL BSP User Manual
|
stm32446e_eval_audio.h
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file stm32446e_eval_audio.h 00004 * @author MCD Application Team 00005 * @version V1.1.1 00006 * @date 13-January-2016 00007 * @brief This file contains the common defines and functions prototypes for 00008 * the stm32446e_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 __STM32446E_EVAL_AUDIO_H 00041 #define __STM32446E_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 "stm32446e_eval.h" 00051 #include "../../../Middlewares/ST/STM32_Audio/Addons/PDM/pdm_filter.h" 00052 00053 /** @addtogroup BSP 00054 * @{ 00055 */ 00056 00057 /** @addtogroup STM32446E_EVAL 00058 * @{ 00059 */ 00060 00061 /** @addtogroup STM32446E_EVAL_AUDIO 00062 * @{ 00063 */ 00064 00065 /** @defgroup STM32446E_EVAL_AUDIO_Exported_Types STM32446E EVAL AUDIO Exported Types 00066 * @{ 00067 */ 00068 /** 00069 * @} 00070 */ 00071 00072 /** @defgroup STM32446E_EVAL_AUDIO_Exported_Constants STM32446E EVAL AUDIO Exported Constants 00073 * @{ 00074 */ 00075 00076 /*------------------------------------------------------------------------------ 00077 USER SAI defines parameters 00078 -----------------------------------------------------------------------------*/ 00079 /** @defgroup CODEC_AudioFrame_SLOT_TDMMode STM32446E 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 SAI2_Block_B 00099 #define AUDIO_SAIx_CLK_ENABLE() __HAL_RCC_SAI2_CLK_ENABLE() 00100 #define AUDIO_SAIx_CLK_DISABLE() __HAL_RCC_SAI2_CLK_DISABLE() 00101 #define AUDIO_SAIx_SCK_AF GPIO_AF8_SAI2 00102 #define AUDIO_SAIx_MCLK_SD_FS_AF GPIO_AF10_SAI2 00103 00104 00105 #define AUDIO_SAIx_MCLK_SCK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() 00106 #define AUDIO_SAIx_MCLK_SCK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE() 00107 #define AUDIO_SAIx_MCK_PIN GPIO_PIN_1 /* PA1 */ 00108 #define AUDIO_SAIx_SCK_PIN GPIO_PIN_2 /* PA2 */ 00109 #define AUDIO_SAIx_MCLK_SCK_GPIO_PORT GPIOA 00110 #define AUDIO_SAIx_SD_FS_ENABLE() __HAL_RCC_GPIOG_CLK_ENABLE() 00111 #define AUDIO_SAIx_SD_FS_DISABLE() __HAL_RCC_GPIOG_CLK_DISABLE() 00112 #define AUDIO_SAIx_FS_PIN GPIO_PIN_9 /* PG9 */ 00113 #define AUDIO_SAIx_SD_PIN GPIO_PIN_10 /* PG10 */ 00114 #define AUDIO_SAIx_SD_FS_GPIO_PORT GPIOG 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_Stream6 00121 #define AUDIO_SAIx_DMAx_CHANNEL DMA_CHANNEL_3 00122 #define AUDIO_SAIx_DMAx_IRQ DMA2_Stream6_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_Stream6_IRQHandler 00128 00129 /* Select the interrupt preemption priority for the DMA interrupt */ 00130 #define AUDIO_OUT_IRQ_PREPRIO ((uint32_t)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_1 00146 #define AUDIO_I2Sx_SD_GPIO_PORT GPIOC 00147 #define AUDIO_I2Sx_SD_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE() 00148 #define AUDIO_I2Sx_SD_GPIO_CLK_DISABLE() __HAL_RCC_GPIOC_CLK_DISABLE() 00149 #define AUDIO_I2Sx_SD_AF GPIO_AF5_SPI3 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_TIM4_CLK_ENABLE() 00172 #define AUDIO_TIMx_CLK_DISABLE() __HAL_RCC_TIM4_CLK_DISABLE() 00173 #define AUDIO_TIMx TIM4 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_GPIOB_CLK_ENABLE() 00177 #define AUDIO_TIMx_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE() 00178 #define AUDIO_TIMx_GPIO_PORT GPIOB 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_TIM4 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*2) 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 /*------------------------------------------------------------------------------ 00215 OUTPUT DEVICES definition 00216 ------------------------------------------------------------------------------*/ 00217 00218 /* Alias on existing output devices to adapt for 2 headphones output */ 00219 #define OUTPUT_DEVICE_HEADPHONE1 OUTPUT_DEVICE_HEADPHONE 00220 #define OUTPUT_DEVICE_HEADPHONE2 OUTPUT_DEVICE_SPEAKER /* Headphone2 is connected to Speaker output of the wm8994 */ 00221 00222 /** 00223 * @} 00224 */ 00225 00226 /** @defgroup STM32446E_EVAL_AUDIO_Exported_Variables STM32446E EVAL AUDIO Exported Variables 00227 * @{ 00228 */ 00229 extern __IO uint16_t AudioInVolume; 00230 /** 00231 * @} 00232 */ 00233 00234 /** @defgroup STM32446E_EVAL_AUDIO_Exported_Macros STM32446E EVAL AUDIO Exported Macros 00235 * @{ 00236 */ 00237 #define DMA_MAX(x) (((x) <= DMA_MAX_SZE)? (x):DMA_MAX_SZE) 00238 /** 00239 * @} 00240 */ 00241 00242 /** @defgroup STM32446E_EVAL_AUDIO_OUT_Exported_Functions STM32446E EVAL AUDIO OUT Exported Functions 00243 * @{ 00244 */ 00245 uint8_t BSP_AUDIO_OUT_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq); 00246 uint8_t BSP_AUDIO_OUT_Play(uint16_t* pBuffer, uint32_t Size); 00247 void BSP_AUDIO_OUT_ChangeBuffer(uint16_t *pData, uint16_t Size); 00248 uint8_t BSP_AUDIO_OUT_Pause(void); 00249 uint8_t BSP_AUDIO_OUT_Resume(void); 00250 uint8_t BSP_AUDIO_OUT_Stop(uint32_t Option); 00251 uint8_t BSP_AUDIO_OUT_SetVolume(uint8_t Volume); 00252 void BSP_AUDIO_OUT_SetFrequency(uint32_t AudioFreq); 00253 void BSP_AUDIO_OUT_SetAudioFrameSlot(uint32_t AudioFrameSlot); 00254 uint8_t BSP_AUDIO_OUT_SetMute(uint32_t Cmd); 00255 uint8_t BSP_AUDIO_OUT_SetOutputMode(uint8_t Output); 00256 void BSP_AUDIO_OUT_DeInit(void); 00257 00258 /* User Callbacks: user has to implement these functions in his code if they are needed. */ 00259 /* This function is called when the requested data has been completely transferred.*/ 00260 void BSP_AUDIO_OUT_TransferComplete_CallBack(void); 00261 00262 /* This function is called when half of the requested buffer has been transferred. */ 00263 void BSP_AUDIO_OUT_HalfTransfer_CallBack(void); 00264 00265 /* This function is called when an Interrupt due to transfer error on or peripheral 00266 error occurs. */ 00267 void BSP_AUDIO_OUT_Error_CallBack(void); 00268 00269 /* These function can be modified in case the current settings (e.g. DMA stream) 00270 need to be changed for specific application needs */ 00271 void BSP_AUDIO_OUT_ClockConfig(SAI_HandleTypeDef *hsai, uint32_t AudioFreq, void *Params); 00272 void BSP_AUDIO_OUT_MspInit(SAI_HandleTypeDef *hsai, void *Params); 00273 void BSP_AUDIO_OUT_MspDeInit(SAI_HandleTypeDef *hsai, void *Params); 00274 00275 /** 00276 * @} 00277 */ 00278 00279 /** @defgroup STM32446E_EVAL_AUDIO_IN_Exported_Functions STM32446E EVAL AUDIO IN Exported Functions 00280 * @{ 00281 */ 00282 uint8_t BSP_AUDIO_IN_Init(uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr); 00283 uint8_t BSP_AUDIO_IN_Record(uint16_t *pData, uint32_t Size); 00284 uint8_t BSP_AUDIO_IN_Stop(void); 00285 uint8_t BSP_AUDIO_IN_Pause(void); 00286 uint8_t BSP_AUDIO_IN_Resume(void); 00287 uint8_t BSP_AUDIO_IN_SetVolume(uint8_t Volume); 00288 void BSP_AUDIO_IN_DeInit(void); 00289 uint8_t BSP_AUDIO_IN_PDMToPCM(uint16_t* PDMBuf, uint16_t* PCMBuf); 00290 /* User Callbacks: user has to implement these functions in his code if they are needed. */ 00291 /* This function should be implemented by the user application. 00292 It is called into this driver when the current buffer is filled to prepare the next 00293 buffer pointer and its size. */ 00294 void BSP_AUDIO_IN_TransferComplete_CallBack(void); 00295 void BSP_AUDIO_IN_HalfTransfer_CallBack(void); 00296 00297 /* This function is called when an Interrupt due to transfer error on or peripheral 00298 error occurs. */ 00299 void BSP_AUDIO_IN_Error_Callback(void); 00300 00301 /* These function can be modified in case the current settings (e.g. DMA stream) 00302 need to be changed for specific application needs */ 00303 void BSP_AUDIO_IN_MspInit(I2S_HandleTypeDef *hi2s, void *Params); 00304 void BSP_AUDIO_IN_MspDeInit(I2S_HandleTypeDef *hi2s, void *Params); 00305 00306 /** 00307 * @} 00308 */ 00309 00310 /** 00311 * @} 00312 */ 00313 00314 /** 00315 * @} 00316 */ 00317 00318 /** 00319 * @} 00320 */ 00321 00322 #ifdef __cplusplus 00323 } 00324 #endif 00325 00326 #endif /* __STM32446E_EVAL_AUDIO_H */ 00327 00328 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Fri Jan 15 2016 10:06:21 for STM32446E_EVAL BSP User Manual by 1.7.6.1