STM32746G-Discovery board drivers V1.0.0
Dependents: DISCO-F746NG_LCDTS_CC3000_NTP DISCO-F746NG_ROPE_WIFI F746_SpectralAnalysis_NoPhoto ecte433 ... more
stm32746g_discovery_audio.h
00001 /** 00002 ****************************************************************************** 00003 * @file stm32746g_discovery_audio.h 00004 * @author MCD Application Team 00005 * @brief This file contains the common defines and functions prototypes for 00006 * the stm32746g_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 __STM32746G_DISCOVERY_AUDIO_H 00039 #define __STM32746G_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 "stm32746g_discovery.h" 00049 00050 /** @addtogroup BSP 00051 * @{ 00052 */ 00053 00054 /** @addtogroup STM32746G_DISCOVERY 00055 * @{ 00056 */ 00057 00058 /** @defgroup STM32746G_DISCOVERY_AUDIO STM32746G_DISCOVERY_AUDIO 00059 * @{ 00060 */ 00061 00062 /** @defgroup STM32746G_DISCOVERY_AUDIO_Exported_Types STM32746G_DISCOVERY_AUDIO Exported Types 00063 * @{ 00064 */ 00065 /** 00066 * @} 00067 */ 00068 00069 /** @defgroup STM32746G_DISCOVERY_AUDIO_Exported_Constants STM32746G_DISCOVERY_AUDIO Exported Constants 00070 * @{ 00071 */ 00072 00073 /*------------------------------------------------------------------------------ 00074 USER SAI defines parameters 00075 -----------------------------------------------------------------------------*/ 00076 /* CODEC_AudioFrame_SLOT_TDMMode 00077 In W8994 codec the Audio frame contains 4 slots : TDM Mode 00078 TDM format : 00079 +------------------|------------------|--------------------|-------------------+ 00080 | CODEC_SLOT0 Left | CODEC_SLOT1 Left | CODEC_SLOT0 Right | CODEC_SLOT1 Right | 00081 +------------------------------------------------------------------------------+ 00082 */ 00083 /* To have 2 separate audio stream in Both headphone and speaker the 4 slot must be activated */ 00084 #define CODEC_AUDIOFRAME_SLOT_0123 SAI_SLOTACTIVE_0 | SAI_SLOTACTIVE_1 | SAI_SLOTACTIVE_2 | SAI_SLOTACTIVE_3 00085 /* To have an audio stream in headphone only SAI Slot 0 and Slot 2 must be activated */ 00086 #define CODEC_AUDIOFRAME_SLOT_02 SAI_SLOTACTIVE_0 | SAI_SLOTACTIVE_2 00087 /* To have an audio stream in speaker only SAI Slot 1 and Slot 3 must be activated */ 00088 #define CODEC_AUDIOFRAME_SLOT_13 SAI_SLOTACTIVE_1 | SAI_SLOTACTIVE_3 00089 00090 /* SAI OUT peripheral configuration defines */ 00091 #define AUDIO_OUT_SAIx SAI2_Block_A 00092 #define AUDIO_OUT_SAIx_CLK_ENABLE() __HAL_RCC_SAI2_CLK_ENABLE() 00093 #define AUDIO_OUT_SAIx_CLK_DISABLE() __HAL_RCC_SAI2_CLK_DISABLE() 00094 #define AUDIO_OUT_SAIx_SCK_AF GPIO_AF10_SAI2 00095 #define AUDIO_OUT_SAIx_FS_SD_MCLK_AF GPIO_AF10_SAI2 00096 00097 #define AUDIO_OUT_SAIx_MCLK_ENABLE() __HAL_RCC_GPIOI_CLK_ENABLE() 00098 #define AUDIO_OUT_SAIx_MCLK_GPIO_PORT GPIOI 00099 #define AUDIO_OUT_SAIx_MCLK_PIN GPIO_PIN_4 00100 #define AUDIO_OUT_SAIx_SCK_SD_ENABLE() __HAL_RCC_GPIOI_CLK_ENABLE() 00101 #define AUDIO_OUT_SAIx_SCK_SD_GPIO_PORT GPIOI 00102 #define AUDIO_OUT_SAIx_SCK_PIN GPIO_PIN_5 00103 #define AUDIO_OUT_SAIx_SD_PIN GPIO_PIN_6 00104 #define AUDIO_OUT_SAIx_FS_ENABLE() __HAL_RCC_GPIOI_CLK_ENABLE() 00105 #define AUDIO_OUT_SAIx_FS_GPIO_PORT GPIOI 00106 #define AUDIO_OUT_SAIx_FS_PIN GPIO_PIN_7 00107 00108 /* SAI DMA Stream definitions */ 00109 #define AUDIO_OUT_SAIx_DMAx_CLK_ENABLE() __HAL_RCC_DMA2_CLK_ENABLE() 00110 #define AUDIO_OUT_SAIx_DMAx_STREAM DMA2_Stream4 00111 #define AUDIO_OUT_SAIx_DMAx_CHANNEL DMA_CHANNEL_3 00112 #define AUDIO_OUT_SAIx_DMAx_IRQ DMA2_Stream4_IRQn 00113 #define AUDIO_OUT_SAIx_DMAx_PERIPH_DATA_SIZE DMA_PDATAALIGN_HALFWORD 00114 #define AUDIO_OUT_SAIx_DMAx_MEM_DATA_SIZE DMA_MDATAALIGN_HALFWORD 00115 #define DMA_MAX_SZE ((uint16_t)0xFFFF) 00116 00117 #define AUDIO_OUT_SAIx_DMAx_IRQHandler DMA2_Stream4_IRQHandler 00118 00119 /* Select the interrupt preemption priority for the DMA interrupt */ 00120 #define AUDIO_OUT_IRQ_PREPRIO ((uint32_t)0x0E) /* Select the preemption priority level(0 is the highest) */ 00121 00122 /*------------------------------------------------------------------------------ 00123 AUDIO IN CONFIGURATION 00124 ------------------------------------------------------------------------------*/ 00125 /* SAI IN peripheral configuration defines */ 00126 #define AUDIO_IN_SAIx SAI2_Block_B 00127 #define AUDIO_IN_SAIx_CLK_ENABLE() __HAL_RCC_SAI2_CLK_ENABLE() 00128 #define AUDIO_IN_SAIx_CLK_DISABLE() __HAL_RCC_SAI2_CLK_DISABLE() 00129 #define AUDIO_IN_SAIx_SD_AF GPIO_AF10_SAI2 00130 00131 #define AUDIO_IN_SAIx_SD_ENABLE() __HAL_RCC_GPIOG_CLK_ENABLE() 00132 #define AUDIO_IN_SAIx_SD_GPIO_PORT GPIOG 00133 #define AUDIO_IN_SAIx_SD_PIN GPIO_PIN_10 00134 00135 #define AUDIO_IN_INT_GPIO_ENABLE() __HAL_RCC_GPIOH_CLK_ENABLE() 00136 #define AUDIO_IN_INT_GPIO_PORT GPIOH 00137 #define AUDIO_IN_INT_GPIO_PIN GPIO_PIN_15 00138 #define AUDIO_IN_INT_IRQ EXTI15_10_IRQn 00139 00140 /* SAI DMA Stream definitions */ 00141 #define AUDIO_IN_SAIx_DMAx_CLK_ENABLE() __HAL_RCC_DMA2_CLK_ENABLE() 00142 #define AUDIO_IN_SAIx_DMAx_STREAM DMA2_Stream7 00143 #define AUDIO_IN_SAIx_DMAx_CHANNEL DMA_CHANNEL_0 00144 #define AUDIO_IN_SAIx_DMAx_IRQ DMA2_Stream7_IRQn 00145 #define AUDIO_IN_SAIx_DMAx_PERIPH_DATA_SIZE DMA_PDATAALIGN_HALFWORD 00146 #define AUDIO_IN_SAIx_DMAx_MEM_DATA_SIZE DMA_MDATAALIGN_HALFWORD 00147 00148 #define AUDIO_IN_SAIx_DMAx_IRQHandler DMA2_Stream7_IRQHandler 00149 #define AUDIO_IN_INT_IRQHandler EXTI15_10_IRQHandler 00150 00151 /* Select the interrupt preemption priority and subpriority for the IT/DMA interrupt */ 00152 #define AUDIO_IN_IRQ_PREPRIO ((uint32_t)0x0F) /* Select the preemption priority level(0 is the highest) */ 00153 00154 /*------------------------------------------------------------------------------ 00155 CONFIGURATION: Audio Driver Configuration parameters 00156 ------------------------------------------------------------------------------*/ 00157 00158 #define AUDIODATA_SIZE ((uint16_t)2) /* 16-bits audio data size */ 00159 00160 /* Audio status definition */ 00161 #define AUDIO_OK ((uint8_t)0) 00162 #define AUDIO_ERROR ((uint8_t)1) 00163 #define AUDIO_TIMEOUT ((uint8_t)2) 00164 00165 /* AudioFreq * DataSize (2 bytes) * NumChannels (Stereo: 2) */ 00166 #define DEFAULT_AUDIO_IN_FREQ I2S_AUDIOFREQ_16K 00167 #define DEFAULT_AUDIO_IN_BIT_RESOLUTION ((uint8_t)16) 00168 #define DEFAULT_AUDIO_IN_CHANNEL_NBR ((uint8_t)2) /* Mono = 1, Stereo = 2 */ 00169 #define DEFAULT_AUDIO_IN_VOLUME ((uint16_t)64) 00170 00171 /*------------------------------------------------------------------------------ 00172 OPTIONAL Configuration defines parameters 00173 ------------------------------------------------------------------------------*/ 00174 00175 /* Delay for the Codec to be correctly reset */ 00176 #define CODEC_RESET_DELAY ((uint8_t)5) 00177 00178 00179 /*------------------------------------------------------------------------------ 00180 OUTPUT DEVICES definition 00181 ------------------------------------------------------------------------------*/ 00182 /* Alias on existing output devices to adapt for 2 headphones output */ 00183 #define OUTPUT_DEVICE_HEADPHONE1 OUTPUT_DEVICE_HEADPHONE 00184 #define OUTPUT_DEVICE_HEADPHONE2 OUTPUT_DEVICE_SPEAKER /* Headphone2 is connected to Speaker output of the wm8994 */ 00185 00186 /** 00187 * @} 00188 */ 00189 00190 /** @defgroup STM32746G_DISCOVERY_AUDIO_Exported_Variables STM32746G_DISCOVERY_AUDIO Exported Variables 00191 * @{ 00192 */ 00193 extern __IO uint16_t AudioInVolume; 00194 /** 00195 * @} 00196 */ 00197 00198 /** @defgroup STM32746G_DISCOVERY_AUDIO_Exported_Macros STM32746G_DISCOVERY_AUDIO Exported Macros 00199 * @{ 00200 */ 00201 #define DMA_MAX(x) (((x) <= DMA_MAX_SZE)? (x):DMA_MAX_SZE) 00202 /** 00203 * @} 00204 */ 00205 00206 /** @addtogroup STM32746G_DISCOVERY_AUDIO_OUT_Exported_Functions 00207 * @{ 00208 */ 00209 uint8_t BSP_AUDIO_OUT_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq); 00210 uint8_t BSP_AUDIO_OUT_Play(uint16_t* pBuffer, uint32_t Size); 00211 void BSP_AUDIO_OUT_ChangeBuffer(uint16_t *pData, uint16_t Size); 00212 uint8_t BSP_AUDIO_OUT_Pause(void); 00213 uint8_t BSP_AUDIO_OUT_Resume(void); 00214 uint8_t BSP_AUDIO_OUT_Stop(uint32_t Option); 00215 uint8_t BSP_AUDIO_OUT_SetVolume(uint8_t Volume); 00216 void BSP_AUDIO_OUT_SetFrequency(uint32_t AudioFreq); 00217 void BSP_AUDIO_OUT_SetAudioFrameSlot(uint32_t AudioFrameSlot); 00218 uint8_t BSP_AUDIO_OUT_SetMute(uint32_t Cmd); 00219 uint8_t BSP_AUDIO_OUT_SetOutputMode(uint8_t Output); 00220 void BSP_AUDIO_OUT_DeInit(void); 00221 00222 /* User Callbacks: user has to implement these functions in his code if they are needed. */ 00223 /* This function is called when the requested data has been completely transferred.*/ 00224 void BSP_AUDIO_OUT_TransferComplete_CallBack(void); 00225 00226 /* This function is called when half of the requested buffer has been transferred. */ 00227 void BSP_AUDIO_OUT_HalfTransfer_CallBack(void); 00228 00229 /* This function is called when an Interrupt due to transfer error on or peripheral 00230 error occurs. */ 00231 void BSP_AUDIO_OUT_Error_CallBack(void); 00232 00233 /* These function can be modified in case the current settings (e.g. DMA stream) 00234 need to be changed for specific application needs */ 00235 void BSP_AUDIO_OUT_ClockConfig(SAI_HandleTypeDef *hsai, uint32_t AudioFreq, void *Params); 00236 void BSP_AUDIO_OUT_MspInit(SAI_HandleTypeDef *hsai, void *Params); 00237 void BSP_AUDIO_OUT_MspDeInit(SAI_HandleTypeDef *hsai, void *Params); 00238 00239 /** 00240 * @} 00241 */ 00242 00243 /** @defgroup STM32746G_DISCOVERY_AUDIO_IN_Exported_Functions STM32746G_DISCOVERY_AUDIO_IN Exported Functions 00244 * @{ 00245 */ 00246 uint8_t BSP_AUDIO_IN_Init(uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr); 00247 uint8_t BSP_AUDIO_IN_InitEx(uint16_t InputDevice, uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr); 00248 uint8_t BSP_AUDIO_IN_OUT_Init(uint16_t InputDevice, uint16_t OutputDevice, uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr); 00249 uint8_t BSP_AUDIO_IN_Record(uint16_t *pData, uint32_t Size); 00250 uint8_t BSP_AUDIO_IN_Stop(uint32_t Option); 00251 uint8_t BSP_AUDIO_IN_Pause(void); 00252 uint8_t BSP_AUDIO_IN_Resume(void); 00253 uint8_t BSP_AUDIO_IN_SetVolume(uint8_t Volume); 00254 void BSP_AUDIO_IN_DeInit(void); 00255 /* User Callbacks: user has to implement these functions in his code if they are needed. */ 00256 /* This function should be implemented by the user application. 00257 It is called into this driver when the current buffer is filled to prepare the next 00258 buffer pointer and its size. */ 00259 void BSP_AUDIO_IN_TransferComplete_CallBack(void); 00260 void BSP_AUDIO_IN_HalfTransfer_CallBack(void); 00261 00262 /* This function is called when an Interrupt due to transfer error on or peripheral 00263 error occurs. */ 00264 void BSP_AUDIO_IN_Error_CallBack(void); 00265 00266 /* These function can be modified in case the current settings (e.g. DMA stream) 00267 need to be changed for specific application needs */ 00268 void BSP_AUDIO_IN_MspInit(SAI_HandleTypeDef *hsai, void *Params); 00269 void BSP_AUDIO_IN_MspDeInit(SAI_HandleTypeDef *hsai, void *Params); 00270 00271 /** 00272 * @} 00273 */ 00274 00275 /** 00276 * @} 00277 */ 00278 00279 /** 00280 * @} 00281 */ 00282 00283 /** 00284 * @} 00285 */ 00286 00287 #ifdef __cplusplus 00288 } 00289 #endif 00290 00291 #endif /* __STM32746G_DISCOVERY_AUDIO_H */ 00292 00293 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 13:20:42 by 1.7.2