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