STM32L476G-Discovery BSP User Manual
|
stm32l476g_discovery_audio.h
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file stm32l476g_discovery_audio.h 00004 * @author MCD Application Team 00005 * @version $VERSION$ 00006 * @date $DATE$ 00007 * @brief This file contains the common defines and functions prototypes for 00008 * the stm32l476g_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 __STM32L476G_DISCOVERY_AUDIO_H 00041 #define __STM32L476G_DISCOVERY_AUDIO_H 00042 00043 #ifdef __cplusplus 00044 extern "C" { 00045 #endif 00046 00047 /* Includes ------------------------------------------------------------------*/ 00048 #if defined(BSP_AUDIO_USE_RTOS) 00049 #include "k_mem.h" 00050 #else 00051 #include <stdlib.h> 00052 #endif 00053 /* Include audio component Driver */ 00054 #include "../Components/cs43l22/cs43l22.h" 00055 #include "stm32l476g_discovery.h" 00056 00057 /** @addtogroup BSP 00058 * @{ 00059 */ 00060 00061 /** @addtogroup STM32L476G_DISCOVERY 00062 * @{ 00063 */ 00064 00065 /** @addtogroup STM32L476G_DISCOVERY_AUDIO 00066 * @{ 00067 */ 00068 00069 /** @defgroup STM32L476G_DISCOVERY_AUDIO_Exported_Types Exported Types 00070 * @{ 00071 */ 00072 typedef void (*Audio_CallbackTypeDef)(void); 00073 00074 /** 00075 * @} 00076 */ 00077 00078 /** @defgroup STM32L476G_DISCOVERY_AUDIO_Exported_Constants Exported Constants 00079 * @{ 00080 */ 00081 /** @defgroup BSP_Audio_Out_Option BSP Audio Out Option 00082 * @{ 00083 */ 00084 #define BSP_AUDIO_OUT_CIRCULARMODE ((uint32_t)0x00000001) /* BUFFER CIRCULAR MODE */ 00085 #define BSP_AUDIO_OUT_NORMALMODE ((uint32_t)0x00000002) /* BUFFER NORMAL MODE */ 00086 #define BSP_AUDIO_OUT_STEREOMODE ((uint32_t)0x00000004) /* STEREO MODE */ 00087 #define BSP_AUDIO_OUT_MONOMODE ((uint32_t)0x00000008) /* MONO MODE */ 00088 /** 00089 * @} 00090 */ 00091 00092 /** @defgroup BSP_Audio_Sample_Rate BSP Audio Sample Rate 00093 * @{ 00094 */ 00095 #define BSP_AUDIO_FREQUENCY_96K SAI_AUDIO_FREQUENCY_96K 00096 #define BSP_AUDIO_FREQUENCY_48K SAI_AUDIO_FREQUENCY_48K 00097 #define BSP_AUDIO_FREQUENCY_44K SAI_AUDIO_FREQUENCY_44K 00098 #define BSP_AUDIO_FREQUENCY_32K SAI_AUDIO_FREQUENCY_32K 00099 #define BSP_AUDIO_FREQUENCY_22K SAI_AUDIO_FREQUENCY_22K 00100 #define BSP_AUDIO_FREQUENCY_16K SAI_AUDIO_FREQUENCY_16K 00101 #define BSP_AUDIO_FREQUENCY_11K SAI_AUDIO_FREQUENCY_11K 00102 #define BSP_AUDIO_FREQUENCY_8K SAI_AUDIO_FREQUENCY_8K 00103 /** 00104 * @} 00105 */ 00106 /*------------------------------------------------------------------------------ 00107 USER SAI defines parameters 00108 -----------------------------------------------------------------------------*/ 00109 /* SAI peripheral configuration defines */ 00110 #define AUDIO_SAIx SAI1_Block_A 00111 #define AUDIO_SAIx_CLK_ENABLE() __HAL_RCC_SAI1_CLK_ENABLE() 00112 #define AUDIO_SAIx_CLK_DISABLE() __HAL_RCC_SAI1_CLK_DISABLE() 00113 #define AUDIO_SAIx_MCK_SCK_SD_FS_AF GPIO_AF13_SAI1 00114 00115 #define AUDIO_SAIx_MCK_SCK_SD_FS_ENABLE() __HAL_RCC_GPIOE_CLK_ENABLE() 00116 #define AUDIO_SAIx_MCK_SCK_SD_FS_DISABLE() __HAL_RCC_GPIOE_CLK_DISABLE() 00117 #define AUDIO_SAIx_FS_PIN GPIO_PIN_4 00118 #define AUDIO_SAIx_SCK_PIN GPIO_PIN_5 00119 #define AUDIO_SAIx_SD_PIN GPIO_PIN_6 00120 #define AUDIO_SAIx_MCK_PIN GPIO_PIN_2 00121 #define AUDIO_SAIx_MCK_SCK_SD_FS_GPIO_PORT GPIOE 00122 00123 /* SAI DMA Channel definitions */ 00124 #define AUDIO_SAIx_DMAx_CLK_ENABLE() __HAL_RCC_DMA2_CLK_ENABLE() 00125 #define AUDIO_SAIx_DMAx_CLK_DISABLE() __HAL_RCC_DMA2_CLK_DISABLE() 00126 #define AUDIO_SAIx_DMAx_CHANNEL DMA2_Channel1 00127 #define AUDIO_SAIx_DMAx_IRQ DMA2_Channel1_IRQn 00128 #define AUDIO_SAIx_DMAx_PERIPH_DATA_SIZE DMA_PDATAALIGN_HALFWORD 00129 #define AUDIO_SAIx_DMAx_MEM_DATA_SIZE DMA_MDATAALIGN_HALFWORD 00130 #define DMA_MAX_SZE (uint32_t)0xFFFF 00131 00132 #define AUDIO_SAIx_DMAx_IRQHandler DMA2_Channel1_IRQHandler 00133 00134 /* Select the interrupt preemption priority for the DMA interrupt */ 00135 #define AUDIO_OUT_IRQ_PREPRIO 5 /* Select the preemption priority level(0 is the highest) */ 00136 00137 /* Disable SAIx PLL */ 00138 #define AUDIO_SAIx_PLL_DISABLE() HAL_RCCEx_DisablePLLSAI1() 00139 00140 /*------------------------------------------------------------------------------ 00141 AUDIO IN CONFIGURATION 00142 ------------------------------------------------------------------------------*/ 00143 /* DFSDM Configuration defines */ 00144 #define AUDIO_DFSDMx_LEFT_CHANNEL DFSDM_Channel2 00145 #define AUDIO_DFSDMx_LEFT_FILTER DFSDM_Filter0 00146 #define AUDIO_DFSDMx_CLK_ENABLE() __HAL_RCC_DFSDM_CLK_ENABLE() 00147 #define AUDIO_DFSDMx_CLK_DISABLE() __HAL_RCC_DFSDM_CLK_DISABLE() 00148 #define AUDIO_DFSDMx_CKOUT_PIN GPIO_PIN_9 00149 #define AUDIO_DFSDMx_DMIC_DATIN_PIN GPIO_PIN_7 00150 #define AUDIO_DFSDMx_CKOUT_DMIC_DATIN_GPIO_PORT GPIOE 00151 #define AUDIO_DFSDMx_CKOUT_DMIC_DATIN_GPIO_CLK_ENABLE() __HAL_RCC_GPIOE_CLK_ENABLE() 00152 #define AUDIO_DFSDMx_CKOUT_DMIC_DATIN_GPIO_CLK_DISABLE() __HAL_RCC_GPIOE_CLK_DISABLE() 00153 #define AUDIO_DFSDMx_CKOUT_DMIC_DATIN_AF GPIO_AF6_DFSDM 00154 00155 /* DFSDM DMA Right and Left channels definitions */ 00156 #define AUDIO_DFSDMx_DMAx_CLK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE() 00157 #define AUDIO_DFSDMx_DMAx_CLK_DISABLE() __HAL_RCC_DMA1_CLK_DISABLE() 00158 #define AUDIO_DFSDMx_DMAx_LEFT_CHANNEL DMA1_Channel4 00159 #define AUDIO_DFSDMx_DMAx_LEFT_IRQ DMA1_Channel4_IRQn 00160 #define AUDIO_DFSDMx_DMAx_PERIPH_DATA_SIZE DMA_PDATAALIGN_WORD 00161 #define AUDIO_DFSDMx_DMAx_MEM_DATA_SIZE DMA_MDATAALIGN_WORD 00162 00163 #define AUDIO_DFSDM_DMAx_LEFT_IRQHandler DMA1_Channel4_IRQHandler 00164 00165 /* Select the interrupt preemption priority and subpriority for the IT/DMA interrupt */ 00166 #define AUDIO_IN_IRQ_PREPRIO 6 /* Select the preemption priority level(0 is the highest) */ 00167 00168 /*------------------------------------------------------------------------------ 00169 CONFIGURATION: Audio Driver Configuration parameters 00170 ------------------------------------------------------------------------------*/ 00171 00172 #define AUDIODATA_SIZE 2 /* 16-bits audio data size */ 00173 00174 /* Audio status definition */ 00175 #define AUDIO_OK 0 00176 #define AUDIO_ERROR 1 00177 #define AUDIO_TIMEOUT 2 00178 00179 /* AudioFreq * DataSize (2 bytes) * NumChannels (Stereo: 2) */ 00180 #define DEFAULT_AUDIO_IN_FREQ BSP_AUDIO_FREQUENCY_16K 00181 #define DEFAULT_AUDIO_IN_BIT_RESOLUTION 16 00182 #define DEFAULT_AUDIO_IN_CHANNEL_NBR 1 /* Mono = 1, Stereo = 2 */ 00183 #define DEFAULT_AUDIO_IN_VOLUME 64 00184 00185 /*------------------------------------------------------------------------------ 00186 OPTIONAL Configuration defines parameters 00187 ------------------------------------------------------------------------------*/ 00188 00189 /* Delay for the Codec to be correctly reset */ 00190 #define CODEC_RESET_DELAY 5 00191 00192 /** 00193 * @} 00194 */ 00195 00196 /** @defgroup STM32L476G_DISCOVERY_AUDIO_Exported_Variables Exported Variables 00197 * @{ 00198 */ 00199 extern SAI_HandleTypeDef BSP_AUDIO_hSai; 00200 extern DFSDM_Filter_HandleTypeDef BSP_AUDIO_hDfsdmLeftFilter; 00201 00202 /** 00203 * @} 00204 */ 00205 00206 /** @defgroup STM32L476G_DISCOVERY_AUDIO_Exported_Macros Exported Macros 00207 * @{ 00208 */ 00209 #define DMA_MAX(_X_) (((_X_) <= DMA_MAX_SZE)? (_X_):DMA_MAX_SZE) 00210 00211 /** 00212 * @} 00213 */ 00214 00215 /* Exported functions --------------------------------------------------------*/ 00216 /** @defgroup STM32L476G_DISCOVERY_AUDIO_Exported_Functions Exported Functions 00217 * @{ 00218 */ 00219 uint8_t BSP_AUDIO_OUT_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq); 00220 uint8_t BSP_AUDIO_OUT_DeInit(void); 00221 uint8_t BSP_AUDIO_OUT_Play(uint16_t* pData, uint32_t Size); 00222 uint8_t BSP_AUDIO_OUT_ChangeBuffer(uint16_t *pData, uint16_t Size); 00223 uint8_t BSP_AUDIO_OUT_Pause(void); 00224 uint8_t BSP_AUDIO_OUT_Resume(void); 00225 uint8_t BSP_AUDIO_OUT_Stop(uint32_t Option); 00226 uint8_t BSP_AUDIO_OUT_SetVolume(uint8_t Volume); 00227 uint8_t BSP_AUDIO_OUT_SetFrequency(uint32_t AudioFreq); 00228 void BSP_AUDIO_OUT_ChangeAudioConfig(uint32_t AudioOutOption); 00229 uint8_t BSP_AUDIO_OUT_SetMute(uint32_t Cmd); 00230 uint8_t BSP_AUDIO_OUT_SetOutputMode(uint8_t Output); 00231 void BSP_AUDIO_OUT_RegisterCallbacks(Audio_CallbackTypeDef ErrorCallback, 00232 Audio_CallbackTypeDef HalfTransferCallback, 00233 Audio_CallbackTypeDef TransferCompleteCallback); 00234 00235 uint8_t BSP_AUDIO_IN_Init(uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr); 00236 uint8_t BSP_AUDIO_IN_DeInit(void); 00237 uint8_t BSP_AUDIO_IN_Record(uint16_t *pData, uint32_t Size); 00238 uint8_t BSP_AUDIO_IN_SetFrequency(uint32_t AudioFreq); 00239 uint8_t BSP_AUDIO_IN_Stop(void); 00240 uint8_t BSP_AUDIO_IN_Pause(void); 00241 uint8_t BSP_AUDIO_IN_Resume(void); 00242 void BSP_AUDIO_IN_RegisterCallbacks(Audio_CallbackTypeDef ErrorCallback, 00243 Audio_CallbackTypeDef HalfTransferCallback, 00244 Audio_CallbackTypeDef TransferCompleteCallback); 00245 /** 00246 * @} 00247 */ 00248 00249 /** 00250 * @} 00251 */ 00252 00253 /** 00254 * @} 00255 */ 00256 00257 /** 00258 * @} 00259 */ 00260 00261 #ifdef __cplusplus 00262 } 00263 #endif 00264 00265 #endif /* __STM32L476G_DISCOVERY_AUDIO_H */ 00266 00267 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Tue Jun 23 2015 17:15:45 for STM32L476G-Discovery BSP User Manual by 1.7.6.1