STM32L4R9I_EVAL BSP User Manual
|
stm32l4r9i_eval_audio.h
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file stm32l4r9i_eval_audio.h 00004 * @author MCD Application Team 00005 * @brief This file contains the common defines and functions prototypes for 00006 * the stm32l4r9i_eval_audio.c driver. 00007 ****************************************************************************** 00008 * @attention 00009 * 00010 * <h2><center>© COPYRIGHT(c) 2017 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 __STM32L4R9I_EVAL_AUDIO_H 00039 #define __STM32L4R9I_EVAL_AUDIO_H 00040 00041 #ifdef __cplusplus 00042 extern "C" { 00043 #endif 00044 00045 /* Includes ------------------------------------------------------------------*/ 00046 #if defined(BSP_AUDIO_USE_RTOS) 00047 #include "k_mem.h" 00048 #else 00049 #include <stdlib.h> 00050 #endif 00051 /* Include audio component Driver */ 00052 #include "../Components/wm8994/wm8994.h" 00053 #include "stm32l4r9i_eval.h" 00054 00055 /** @addtogroup BSP 00056 * @{ 00057 */ 00058 00059 /** @addtogroup STM32L4R9I_EVAL 00060 * @{ 00061 */ 00062 00063 /** @addtogroup STM32L4R9I_EVAL_AUDIO 00064 * @{ 00065 */ 00066 00067 /** @defgroup STM32L4R9I_EVAL_AUDIO_Exported_Types Exported Types 00068 * @{ 00069 */ 00070 typedef void (*Audio_CallbackTypeDef)(void); 00071 00072 /** 00073 * @} 00074 */ 00075 00076 /** @defgroup STM32L4R9I_EVAL_AUDIO_Exported_Constants Exported Constants 00077 * @{ 00078 */ 00079 /** @defgroup BSP_Audio_Out_Option BSP Audio Out Option 00080 * @{ 00081 */ 00082 #define BSP_AUDIO_OUT_CIRCULARMODE ((uint32_t)0x00000001) /* BUFFER CIRCULAR MODE */ 00083 #define BSP_AUDIO_OUT_NORMALMODE ((uint32_t)0x00000002) /* BUFFER NORMAL MODE */ 00084 #define BSP_AUDIO_OUT_STEREOMODE ((uint32_t)0x00000004) /* STEREO MODE */ 00085 #define BSP_AUDIO_OUT_MONOMODE ((uint32_t)0x00000008) /* MONO MODE */ 00086 /** 00087 * @} 00088 */ 00089 00090 /** @defgroup BSP_Audio_Sample_Rate BSP Audio Sample Rate 00091 * @{ 00092 */ 00093 #define BSP_AUDIO_FREQUENCY_96K SAI_AUDIO_FREQUENCY_96K 00094 #define BSP_AUDIO_FREQUENCY_48K SAI_AUDIO_FREQUENCY_48K 00095 #define BSP_AUDIO_FREQUENCY_44K SAI_AUDIO_FREQUENCY_44K 00096 #define BSP_AUDIO_FREQUENCY_32K SAI_AUDIO_FREQUENCY_32K 00097 #define BSP_AUDIO_FREQUENCY_22K SAI_AUDIO_FREQUENCY_22K 00098 #define BSP_AUDIO_FREQUENCY_16K SAI_AUDIO_FREQUENCY_16K 00099 #define BSP_AUDIO_FREQUENCY_11K SAI_AUDIO_FREQUENCY_11K 00100 #define BSP_AUDIO_FREQUENCY_8K SAI_AUDIO_FREQUENCY_8K 00101 /** 00102 * @} 00103 */ 00104 /*------------------------------------------------------------------------------ 00105 USER SAI defines parameters 00106 -----------------------------------------------------------------------------*/ 00107 /* SAI peripheral configuration defines */ 00108 #define AUDIO_SAIx SAI1_Block_A 00109 #define AUDIO_SAIx_CLK_ENABLE() __HAL_RCC_SAI1_CLK_ENABLE() 00110 #define AUDIO_SAIx_CLK_DISABLE() __HAL_RCC_SAI1_CLK_DISABLE() 00111 #define AUDIO_SAIx_MCK_SCK_SD_FS_AF GPIO_AF13_SAI1 00112 00113 #define AUDIO_SAIx_MCK_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE() 00114 #define AUDIO_SAIx_MCK_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE() 00115 #define AUDIO_SAIx_MCK_PIN GPIO_PIN_8 00116 #define AUDIO_SAIx_MCK_GPIO_PORT GPIOB 00117 #define AUDIO_SAIx_FS_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE() 00118 #define AUDIO_SAIx_FS_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE() 00119 #define AUDIO_SAIx_FS_PIN GPIO_PIN_9 00120 #define AUDIO_SAIx_FS_GPIO_PORT GPIOB 00121 #define AUDIO_SAIx_SCK_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() 00122 #define AUDIO_SAIx_SCK_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE() 00123 #define AUDIO_SAIx_SCK_PIN GPIO_PIN_8 00124 #define AUDIO_SAIx_SCK_GPIO_PORT GPIOA 00125 #define AUDIO_SAIx_SD_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE() 00126 #define AUDIO_SAIx_SD_CLK_DISABLE() __HAL_RCC_GPIOC_CLK_DISABLE() 00127 #define AUDIO_SAIx_SD_PIN GPIO_PIN_1 00128 #define AUDIO_SAIx_SD_GPIO_PORT GPIOC 00129 00130 /* SAI DMA Channel definitions */ 00131 #define AUDIO_SAIx_DMAx_CLK_ENABLE() __HAL_RCC_DMA2_CLK_ENABLE() 00132 #define AUDIO_SAIx_DMAx_CLK_DISABLE() __HAL_RCC_DMA2_CLK_DISABLE() 00133 #define AUDIO_SAIx_DMAx_REQUEST DMA_REQUEST_SAI1_A 00134 #define AUDIO_SAIx_DMAx_CHANNEL DMA2_Channel2 00135 #define AUDIO_SAIx_DMAx_IRQ DMA2_Channel2_IRQn 00136 #define AUDIO_SAIx_DMAx_PERIPH_DATA_SIZE DMA_PDATAALIGN_HALFWORD 00137 #define AUDIO_SAIx_DMAx_MEM_DATA_SIZE DMA_MDATAALIGN_HALFWORD 00138 #define DMA_MAX_SZE (uint32_t)0xFFFF 00139 00140 #define AUDIO_SAIx_DMAx_IRQHandler DMA2_Channel2_IRQHandler 00141 00142 /* Select the interrupt preemption priority for the DMA interrupt */ 00143 #define AUDIO_OUT_IRQ_PREPRIO 5 /* Select the preemption priority level(0 is the highest) */ 00144 00145 /* Disable SAIx PLL */ 00146 #define AUDIO_SAIx_PLL_DISABLE() HAL_RCCEx_DisablePLLSAI1() 00147 00148 00149 /*------------------------------------------------------------------------------ 00150 AUDIO IN CONFIGURATION 00151 ------------------------------------------------------------------------------*/ 00152 /* DFSDM Configuration defines */ 00153 #define AUDIO_DFSDMx_LEFT_CHANNEL DFSDM1_Channel4 00154 #define AUDIO_DFSDMx_RIGHT_CHANNEL DFSDM1_Channel3 00155 #define AUDIO_DFSDMx_LEFT_FILTER DFSDM1_Filter0 00156 #define AUDIO_DFSDMx_RIGHT_FILTER DFSDM1_Filter1 00157 #define AUDIO_DFSDMx_CLK_ENABLE() __HAL_RCC_DFSDM1_CLK_ENABLE() 00158 #define AUDIO_DFSDMx_CLK_DISABLE() __HAL_RCC_DFSDM1_CLK_DISABLE() 00159 #define AUDIO_DFSDMx_CKOUT_DATIN_AF GPIO_AF6_DFSDM1 00160 #define AUDIO_DFSDMx_CKOUT_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE() 00161 #define AUDIO_DFSDMx_CKOUT_CLK_DISABLE() __HAL_RCC_GPIOF_CLK_DISABLE() 00162 #define AUDIO_DFSDMx_CKOUT_PIN GPIO_PIN_10 00163 #define AUDIO_DFSDMx_CKOUT_GPIO_PORT GPIOF 00164 #define AUDIO_DFSDMx_DATIN_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE() 00165 #define AUDIO_DFSDMx_DATIN_CLK_DISABLE() __HAL_RCC_GPIOC_CLK_DISABLE() 00166 #define AUDIO_DFSDMx_DATIN_PIN GPIO_PIN_0 00167 #define AUDIO_DFSDMx_DATIN_GPIO_PORT GPIOC 00168 00169 /* DFSDM DMA Right and Left channels definitions */ 00170 #define AUDIO_DFSDMx_DMAx_CLK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE() 00171 #define AUDIO_DFSDMx_DMAx_CLK_DISABLE() __HAL_RCC_DMA1_CLK_DISABLE() 00172 #define AUDIO_DFSDMx_DMAx_LEFT_CHANNEL DMA1_Channel4 00173 #define AUDIO_DFSDMx_DMAx_RIGHT_CHANNEL DMA1_Channel5 00174 #define AUDIO_DFSDMx_DMAx_LEFT_IRQ DMA1_Channel4_IRQn 00175 #define AUDIO_DFSDMx_DMAx_RIGHT_IRQ DMA1_Channel5_IRQn 00176 #define AUDIO_DFSDMx_DMAx_LEFT_REQUEST DMA_REQUEST_DFSDM1_FLT0 00177 #define AUDIO_DFSDMx_DMAx_RIGHT_REQUEST DMA_REQUEST_DFSDM1_FLT1 00178 #define AUDIO_DFSDMx_DMAx_PERIPH_DATA_SIZE DMA_PDATAALIGN_WORD 00179 #define AUDIO_DFSDMx_DMAx_MEM_DATA_SIZE DMA_MDATAALIGN_WORD 00180 00181 #define AUDIO_DFSDM_DMAx_LEFT_IRQHandler DMA1_Channel4_IRQHandler 00182 #define AUDIO_DFSDM_DMAx_RIGHT_IRQHandler DMA1_Channel5_IRQHandler 00183 00184 /* Select the interrupt preemption priority and subpriority for the IT/DMA interrupt */ 00185 #define AUDIO_IN_IRQ_PREPRIO 6 /* Select the preemption priority level(0 is the highest) */ 00186 00187 /*------------------------------------------------------------------------------ 00188 CONFIGURATION: Audio Driver Configuration parameters 00189 ------------------------------------------------------------------------------*/ 00190 00191 #define AUDIODATA_SIZE 2 /* 16-bits audio data size */ 00192 00193 /* Audio status definition */ 00194 #define AUDIO_OK 0 00195 #define AUDIO_ERROR 1 00196 #define AUDIO_TIMEOUT 2 00197 00198 /* AudioFreq * DataSize (2 bytes) * NumChannels (Stereo: 2) */ 00199 #define DEFAULT_AUDIO_IN_FREQ BSP_AUDIO_FREQUENCY_16K 00200 #define DEFAULT_AUDIO_IN_BIT_RESOLUTION 16 00201 #define DEFAULT_AUDIO_IN_CHANNEL_NBR 2 /* Mono = 1, Stereo = 2 */ 00202 #define DEFAULT_AUDIO_IN_VOLUME 64 00203 00204 /* PCM buffer input size in word */ 00205 #define INTERNAL_BUFF_SIZE 256 00206 00207 /*------------------------------------------------------------------------------ 00208 OPTIONAL Configuration defines parameters 00209 ------------------------------------------------------------------------------*/ 00210 00211 /* Delay for the Codec to be correctly reset */ 00212 #define CODEC_RESET_DELAY 5 00213 00214 /** 00215 * @} 00216 */ 00217 00218 /** @defgroup STM32L4R9I_EVAL_AUDIO_Exported_Variables Exported Variables 00219 * @{ 00220 */ 00221 extern SAI_HandleTypeDef BSP_AUDIO_hSai; 00222 extern DFSDM_Filter_HandleTypeDef BSP_AUDIO_hDfsdmLeftFilter; 00223 extern DFSDM_Filter_HandleTypeDef BSP_AUDIO_hDfsdmRightFilter; 00224 00225 /** 00226 * @} 00227 */ 00228 00229 /** @defgroup STM32L4R9I_EVAL_AUDIO_Exported_Macros Exported Macros 00230 * @{ 00231 */ 00232 #define DMA_MAX(_X_) (((_X_) <= DMA_MAX_SZE)? (_X_):DMA_MAX_SZE) 00233 00234 /** 00235 * @} 00236 */ 00237 00238 /* Exported functions --------------------------------------------------------*/ 00239 /** @defgroup STM32L4R9I_EVAL_AUDIO_Exported_Functions Exported Functions 00240 * @{ 00241 */ 00242 uint8_t BSP_AUDIO_OUT_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq); 00243 uint8_t BSP_AUDIO_OUT_DeInit(void); 00244 uint8_t BSP_AUDIO_OUT_Play(uint16_t* pData, uint32_t Size); 00245 uint8_t BSP_AUDIO_OUT_ChangeBuffer(uint16_t *pData, uint16_t Size); 00246 uint8_t BSP_AUDIO_OUT_Pause(void); 00247 uint8_t BSP_AUDIO_OUT_Resume(void); 00248 uint8_t BSP_AUDIO_OUT_Stop(uint32_t Option); 00249 uint8_t BSP_AUDIO_OUT_SetVolume(uint8_t Volume); 00250 uint8_t BSP_AUDIO_OUT_SetFrequency(uint32_t AudioFreq); 00251 void BSP_AUDIO_OUT_ChangeAudioConfig(uint32_t AudioOutOption); 00252 uint8_t BSP_AUDIO_OUT_SetMute(uint32_t Cmd); 00253 uint8_t BSP_AUDIO_OUT_SetOutputMode(uint8_t Output); 00254 void BSP_AUDIO_OUT_RegisterCallbacks(Audio_CallbackTypeDef ErrorCallback, 00255 Audio_CallbackTypeDef HalfTransferCallback, 00256 Audio_CallbackTypeDef TransferCompleteCallback); 00257 00258 uint8_t BSP_AUDIO_IN_Init(uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr); 00259 uint8_t BSP_AUDIO_IN_DeInit(void); 00260 uint8_t BSP_AUDIO_IN_Record(uint16_t *pData, uint32_t Size); 00261 uint8_t BSP_AUDIO_IN_SetFrequency(uint32_t AudioFreq); 00262 uint8_t BSP_AUDIO_IN_Stop(void); 00263 uint8_t BSP_AUDIO_IN_Pause(void); 00264 uint8_t BSP_AUDIO_IN_Resume(void); 00265 void BSP_AUDIO_IN_RegisterCallbacks(Audio_CallbackTypeDef ErrorCallback, 00266 Audio_CallbackTypeDef HalfTransferCallback, 00267 Audio_CallbackTypeDef TransferCompleteCallback); 00268 /** 00269 * @} 00270 */ 00271 00272 /** 00273 * @} 00274 */ 00275 00276 /** 00277 * @} 00278 */ 00279 00280 /** 00281 * @} 00282 */ 00283 00284 #ifdef __cplusplus 00285 } 00286 #endif 00287 00288 #endif /* __STM32L4R9I_EVAL_AUDIO_H */ 00289 00290 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Thu Oct 12 2017 10:53:59 for STM32L4R9I_EVAL BSP User Manual by
![doxygen](doxygen.png)