STM32F769I-Discovery BSP User Manual: stm32f769i_discovery_audio.h Source File

STM32F769I-Discovery BSP Drivers

stm32f769i_discovery_audio.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f769i_discovery_audio.h
00004   * @author  MCD Application Team
00005   * @version V2.0.0
00006   * @date    30-December-2016
00007   * @brief   This file contains the common defines and functions prototypes for
00008   *          the stm32f769i_discovery_audio.c driver.
00009   ******************************************************************************
00010   * @attention
00011   *
00012   * <h2><center>&copy; COPYRIGHT(c) 2016 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 __STM32F769I_DISCOVERY_AUDIO_H
00041 #define __STM32F769I_DISCOVERY_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 "stm32f769i_discovery.h"
00051 #include <stdlib.h>
00052 
00053 /** @addtogroup BSP
00054   * @{
00055   */ 
00056 
00057 /** @addtogroup STM32F769I_DISCOVERY
00058   * @{
00059   */
00060     
00061 /** @defgroup STM32F769I_DISCOVERY_AUDIO STM32F769I_DISCOVERY_AUDIO
00062   * @{
00063   */
00064 
00065 /** @defgroup STM32F769I_DISCOVERY_AUDIO_Exported_Types STM32F769I_DISCOVERY_AUDIO Exported Types
00066   * @{
00067   */
00068 /**
00069   * @}
00070   */ 
00071 
00072 /** @defgroup STM32F769I_DISCOVERY_AUDIO_Exported_Constants STM32F769I_DISCOVERY_AUDIO Exported Constants
00073   * @{
00074   */
00075 
00076 /** @defgroup BSP_Audio_Sample_Rate BSP Audio Sample Rate
00077   * @{
00078   */
00079 #define BSP_AUDIO_FREQUENCY_96K         SAI_AUDIO_FREQUENCY_96K
00080 #define BSP_AUDIO_FREQUENCY_48K         SAI_AUDIO_FREQUENCY_48K
00081 #define BSP_AUDIO_FREQUENCY_44K         SAI_AUDIO_FREQUENCY_44K
00082 #define BSP_AUDIO_FREQUENCY_32K         SAI_AUDIO_FREQUENCY_32K
00083 #define BSP_AUDIO_FREQUENCY_22K         SAI_AUDIO_FREQUENCY_22K
00084 #define BSP_AUDIO_FREQUENCY_16K         SAI_AUDIO_FREQUENCY_16K
00085 #define BSP_AUDIO_FREQUENCY_11K         SAI_AUDIO_FREQUENCY_11K
00086 #define BSP_AUDIO_FREQUENCY_8K          SAI_AUDIO_FREQUENCY_8K
00087 /**
00088   * @}
00089   */
00090     
00091 /*------------------------------------------------------------------------------
00092                           USER SAI defines parameters
00093  -----------------------------------------------------------------------------*/
00094 /** CODEC_AudioFrame_SLOT_TDMMode In W8994 codec the Audio frame contains 4 slots : TDM Mode
00095   * TDM format :
00096   * +------------------|------------------|--------------------|-------------------+ 
00097   * | CODEC_SLOT0 Left | CODEC_SLOT1 Left | CODEC_SLOT0 Right  | CODEC_SLOT1 Right |
00098   * +------------------------------------------------------------------------------+
00099   */
00100 /* To have 2 separate audio stream in Both headphone and speaker the 4 slot must be activated */
00101 #define CODEC_AUDIOFRAME_SLOT_0123                   SAI_SLOTACTIVE_0 | SAI_SLOTACTIVE_1 | SAI_SLOTACTIVE_2 | SAI_SLOTACTIVE_3
00102 
00103 /* To have an audio stream in headphone only SAI Slot 0 and Slot 2 must be activated */ 
00104 #define CODEC_AUDIOFRAME_SLOT_02                     SAI_SLOTACTIVE_0 | SAI_SLOTACTIVE_2 
00105 /* To have an audio stream in speaker only SAI Slot 1 and Slot 3 must be activated */ 
00106 #define CODEC_AUDIOFRAME_SLOT_13                     SAI_SLOTACTIVE_1 | SAI_SLOTACTIVE_3
00107 
00108                                                        
00109 /* SAI peripheral configuration defines */
00110 #define AUDIO_OUT_SAIx                           SAI1_Block_A
00111 #define AUDIO_OUT_SAIx_CLK_ENABLE()              __HAL_RCC_SAI1_CLK_ENABLE()
00112 #define AUDIO_OUT_SAIx_CLK_DISABLE()             __HAL_RCC_SAI1_CLK_DISABLE()
00113 #define AUDIO_OUT_SAIx_AF                        GPIO_AF6_SAI1
00114 
00115 #define AUDIO_OUT_SAIx_MCLK_ENABLE()             __HAL_RCC_GPIOG_CLK_ENABLE()
00116 #define AUDIO_OUT_SAIx_MCLK_GPIO_PORT            GPIOG
00117 #define AUDIO_OUT_SAIx_MCLK_PIN                  GPIO_PIN_7
00118 #define AUDIO_OUT_SAIx_SD_FS_CLK_ENABLE()        __HAL_RCC_GPIOE_CLK_ENABLE()
00119 #define AUDIO_OUT_SAIx_SD_FS_SCK_GPIO_PORT       GPIOE
00120 #define AUDIO_OUT_SAIx_FS_PIN                    GPIO_PIN_4   
00121 #define AUDIO_OUT_SAIx_SCK_PIN                   GPIO_PIN_5
00122 #define AUDIO_OUT_SAIx_SD_PIN                    GPIO_PIN_6
00123 
00124 /* SAI DMA Stream definitions */
00125 #define AUDIO_OUT_SAIx_DMAx_CLK_ENABLE()         __HAL_RCC_DMA2_CLK_ENABLE()
00126 #define AUDIO_OUT_SAIx_DMAx_STREAM               DMA2_Stream1
00127 #define AUDIO_OUT_SAIx_DMAx_CHANNEL              DMA_CHANNEL_0
00128 #define AUDIO_OUT_SAIx_DMAx_IRQ                  DMA2_Stream1_IRQn
00129 #define AUDIO_OUT_SAIx_DMAx_PERIPH_DATA_SIZE     DMA_PDATAALIGN_HALFWORD
00130 #define AUDIO_OUT_SAIx_DMAx_MEM_DATA_SIZE        DMA_MDATAALIGN_HALFWORD
00131 #define DMA_MAX_SZE                              0xFFFF
00132    
00133 #define AUDIO_OUT_SAIx_DMAx_IRQHandler           DMA2_Stream1_IRQHandler
00134 
00135 /* Select the interrupt preemption priority and subpriority for the DMA interrupt */
00136 #define AUDIO_OUT_IRQ_PREPRIO                    ((uint32_t)0x0E) 
00137 
00138 /*------------------------------------------------------------------------------
00139                         AUDIO IN CONFIGURATION
00140 ------------------------------------------------------------------------------*/
00141 /* SAI peripheral configuration defines */
00142 #define AUDIO_IN_SAIx                           SAI1_Block_B
00143 #define AUDIO_IN_SAIx_CLK_ENABLE()              __HAL_RCC_SAI1_CLK_ENABLE()
00144 #define AUDIO_IN_SAIx_CLK_DISABLE()             __HAL_RCC_SAI1_CLK_DISABLE()
00145 #define AUDIO_IN_SAIx_AF                        GPIO_AF6_SAI1
00146 #define AUDIO_IN_SAIx_SD_ENABLE()               __HAL_RCC_GPIOE_CLK_ENABLE()
00147 #define AUDIO_IN_SAIx_SD_GPIO_PORT              GPIOE
00148 #define AUDIO_IN_SAIx_SD_PIN                    GPIO_PIN_3
00149 
00150 /* SAI DMA Stream definitions */
00151 #define AUDIO_IN_SAIx_DMAx_CLK_ENABLE()         __HAL_RCC_DMA2_CLK_ENABLE()
00152 #define AUDIO_IN_SAIx_DMAx_STREAM               DMA2_Stream4
00153 #define AUDIO_IN_SAIx_DMAx_CHANNEL              DMA_CHANNEL_1
00154 #define AUDIO_IN_SAIx_DMAx_IRQ                  DMA2_Stream4_IRQn
00155 #define AUDIO_IN_SAIx_DMAx_PERIPH_DATA_SIZE     DMA_PDATAALIGN_HALFWORD
00156 #define AUDIO_IN_SAIx_DMAx_MEM_DATA_SIZE        DMA_MDATAALIGN_HALFWORD
00157 
00158 #define AUDIO_IN_INT_GPIO_ENABLE()               __HAL_RCC_GPIOJ_CLK_ENABLE()
00159 #define AUDIO_IN_INT_GPIO_PORT                   GPIOJ
00160 #define AUDIO_IN_INT_GPIO_PIN                    GPIO_PIN_12
00161 #define AUDIO_IN_INT_IRQ                         EXTI15_10_IRQn
00162 
00163 /* DFSDM Configuration defines */
00164 #define AUDIO_DFSDMx_TOP_RIGHT_CHANNEL                  DFSDM_CHANNEL_0
00165 #define AUDIO_DFSDMx_TOP_LEFT_CHANNEL                   DFSDM_CHANNEL_1
00166 #define AUDIO_DFSDMx_BUTTOM_RIGHT_CHANNEL               DFSDM_CHANNEL_4
00167 #define AUDIO_DFSDMx_BUTTOM_LEFT_CHANNEL                DFSDM_CHANNEL_5
00168 
00169 #define AUDIO_DFSDMx_TOP_LEFT_FILTER                    DFSDM1_Filter0
00170 #define AUDIO_DFSDMx_TOP_RIGHT_FILTER                   DFSDM1_Filter1
00171 #define AUDIO_DFSDMx_BUTTOM_LEFT_FILTER                 DFSDM1_Filter2
00172 #define AUDIO_DFSDMx_BUTTOM_RIGHT_FILTER                DFSDM1_Filter3
00173    
00174 #define AUDIO_DFSDMx_CLK_ENABLE()                       __HAL_RCC_DFSDM1_CLK_ENABLE()
00175 #define AUDIO_DFSDMx_CKOUT_PIN                          GPIO_PIN_3
00176 #define AUDIO_DFSDMx_CKOUT_DMIC_GPIO_PORT               GPIOD    
00177 #define AUDIO_DFSDMx_CKOUT_DMIC_GPIO_CLK_ENABLE()       __HAL_RCC_GPIOD_CLK_ENABLE()
00178 #define AUDIO_DFSDMx_DMIC_DATIN1_PIN                    GPIO_PIN_3
00179 #define AUDIO_DFSDMx_DMIC_DATIN5_PIN                    GPIO_PIN_11   
00180 #define AUDIO_DFSDMx_DMIC_DATIN_GPIO_PORT               GPIOC
00181 #define AUDIO_DFSDMx_DMIC_DATIN_GPIO_CLK_ENABLE()       __HAL_RCC_GPIOC_CLK_ENABLE()
00182 #define AUDIO_DFSDMx_DMIC_DATIN_AF                      GPIO_AF3_DFSDM1
00183 #define AUDIO_DFSDMx_CKOUT_AF                           GPIO_AF3_DFSDM1
00184     
00185 /* DFSDM DMA Right and Left channels definitions */
00186 #define AUDIO_DFSDMx_DMAx_CLK_ENABLE()                  __HAL_RCC_DMA2_CLK_ENABLE()
00187 #define AUDIO_DFSDMx_DMAx_CHANNEL                       DMA_CHANNEL_8
00188 #define AUDIO_DFSDMx_DMAx_PERIPH_DATA_SIZE              DMA_PDATAALIGN_WORD
00189 #define AUDIO_DFSDMx_DMAx_MEM_DATA_SIZE                 DMA_MDATAALIGN_WORD
00190 
00191 #define AUDIO_DFSDMx_DMAx_TOP_LEFT_STREAM               DMA2_Stream0
00192 #define AUDIO_DFSDMx_DMAx_TOP_LEFT_IRQ                  DMA2_Stream0_IRQn   
00193 #define AUDIO_DFSDMx_DMAx_TOP_LEFT_IRQHandler           DMA2_Stream0_IRQHandler
00194 
00195 #define AUDIO_DFSDMx_DMAx_TOP_RIGHT_STREAM              DMA2_Stream5
00196 #define AUDIO_DFSDMx_DMAx_TOP_RIGHT_IRQ                 DMA2_Stream5_IRQn
00197 #define AUDIO_DFSDMx_DMAx_TOP_RIGHT_IRQHandler          DMA2_Stream5_IRQHandler
00198 
00199 #define AUDIO_DFSDMx_DMAx_BUTTOM_LEFT_STREAM            DMA2_Stream6
00200 #define AUDIO_DFSDMx_DMAx_BUTTOM_LEFT_IRQ               DMA2_Stream6_IRQn   
00201 #define AUDIO_DFSDMx_DMAx_BUTTOM_LEFT_IRQHandler        DMA2_Stream6_IRQHandler
00202 
00203 #define AUDIO_DFSDMx_DMAx_BUTTOM_RIGHT_STREAM           DMA2_Stream7
00204 #define AUDIO_DFSDMx_DMAx_BUTTOM_RIGHT_IRQ              DMA2_Stream7_IRQn
00205 #define AUDIO_DFSDMx_DMAx_BUTTOM_RIGHT_IRQHandler       DMA2_Stream7_IRQHandler
00206  
00207 /* Select the interrupt preemption priority and subpriority for the DMA interrupt */
00208 #define AUDIO_IN_IRQ_PREPRIO                ((uint32_t)0x0F)
00209 
00210 
00211 /*------------------------------------------------------------------------------
00212              CONFIGURATION: Audio Driver Configuration parameters
00213 ------------------------------------------------------------------------------*/
00214 
00215 #define AUDIODATA_SIZE                      2   /* 16-bits audio data size */
00216 
00217 /* Audio status definition */     
00218 #define AUDIO_OK                            ((uint8_t)0)
00219 #define AUDIO_ERROR                         ((uint8_t)1)
00220 #define AUDIO_TIMEOUT                       ((uint8_t)2)
00221 
00222 /* Audio In default settings */
00223 #define DEFAULT_AUDIO_IN_FREQ               BSP_AUDIO_FREQUENCY_16K
00224 #define DEFAULT_AUDIO_IN_BIT_RESOLUTION     ((uint8_t)16)
00225 #define DEFAULT_AUDIO_IN_CHANNEL_NBR        ((uint8_t)2)
00226 #define DEFAULT_AUDIO_IN_VOLUME             ((uint16_t)64)
00227 
00228 /*------------------------------------------------------------------------------
00229                             OUTPUT DEVICES definition
00230 ------------------------------------------------------------------------------*/
00231 /* Alias on existing output devices to adapt for 2 headphones output */
00232 #define OUTPUT_DEVICE_HEADPHONE1 OUTPUT_DEVICE_HEADPHONE
00233 #define OUTPUT_DEVICE_HEADPHONE2 OUTPUT_DEVICE_SPEAKER /* Headphone2 is connected to Speaker output of the wm8994 */
00234 
00235 /*------------------------------------------------------------------------------
00236                            INPUT DEVICES definition
00237 ------------------------------------------------------------------------------*/
00238 /* MP34DT01TR digital microphone on PCB top side */
00239 #define INPUT_DEVICE_DIGITAL_MIC       ((uint16_t)0)
00240 /* Analog microphone input from 3.5 audio jack connector */    
00241 #define INPUT_DEVICE_ANALOG_MIC        INPUT_DEVICE_INPUT_LINE_1  
00242 
00243 /**
00244   * @}
00245   */
00246    
00247 /** @defgroup STM32F769I_DISCOVERY_AUDIO_Exported_Macros STM32F769I_DISCOVERY_AUDIO Exported Macros
00248   * @{
00249   */
00250 #define DMA_MAX(x)           (((x) <= DMA_MAX_SZE)? (x):DMA_MAX_SZE)
00251 /**
00252   * @}
00253   */ 
00254 
00255 /** @defgroup STM32F769I_DISCOVERY_AUDIO_OUT_Exported_Functions STM32F769I_DISCOVERY_AUDIO_OUT Exported Functions
00256   * @{
00257   */
00258 uint8_t BSP_AUDIO_OUT_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq);
00259 void    BSP_AUDIO_OUT_DeInit(void);
00260 uint8_t BSP_AUDIO_OUT_Play(uint16_t* pBuffer, uint32_t Size);
00261 void    BSP_AUDIO_OUT_ChangeBuffer(uint16_t *pData, uint16_t Size);
00262 uint8_t BSP_AUDIO_OUT_Pause(void);
00263 uint8_t BSP_AUDIO_OUT_Resume(void);
00264 uint8_t BSP_AUDIO_OUT_Stop(uint32_t Option);
00265 uint8_t BSP_AUDIO_OUT_SetVolume(uint8_t Volume);
00266 void    BSP_AUDIO_OUT_SetFrequency(uint32_t AudioFreq);
00267 void    BSP_AUDIO_OUT_SetAudioFrameSlot(uint32_t AudioFrameSlot);
00268 uint8_t BSP_AUDIO_OUT_SetMute(uint32_t Cmd);
00269 uint8_t BSP_AUDIO_OUT_SetOutputMode(uint8_t Output);
00270 
00271 /* User Callbacks: user has to implement these functions in his code if they are needed. */
00272 /* This function is called when the requested data has been completely transferred.*/
00273 void    BSP_AUDIO_OUT_TransferComplete_CallBack(void);
00274 
00275 /* This function is called when half of the requested buffer has been transferred. */
00276 void    BSP_AUDIO_OUT_HalfTransfer_CallBack(void);
00277 
00278 /* This function is called when an Interrupt due to transfer error on or peripheral
00279    error occurs. */
00280 void    BSP_AUDIO_OUT_Error_CallBack(void);
00281 
00282 /* These function can be modified in case the current settings (e.g. DMA stream)
00283    need to be changed for specific application needs */
00284 void  BSP_AUDIO_OUT_ClockConfig(SAI_HandleTypeDef *hsai, uint32_t AudioFreq, void *Params);
00285 void  BSP_AUDIO_OUT_MspInit(SAI_HandleTypeDef *hsai, void *Params);
00286 void  BSP_AUDIO_OUT_MspDeInit(SAI_HandleTypeDef *hsai, void *Params);
00287 
00288 /**
00289   * @}
00290   */ 
00291 
00292 /** @defgroup STM32F769I_DISCOVERY_AUDIO_IN_Exported_Functions STM32F769I_DISCOVERY_AUDIO_IN Exported Functions
00293   * @{
00294   */
00295 uint8_t BSP_AUDIO_IN_Init(uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr);
00296 uint8_t BSP_AUDIO_IN_InitEx(uint16_t InputDevice, uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr);
00297 uint8_t BSP_AUDIO_IN_AllocScratch (int32_t *pScratch, uint32_t size);
00298 uint8_t BSP_AUDIO_IN_GetChannelNumber(void);
00299 void    BSP_AUDIO_IN_DeInit(void);
00300 uint8_t BSP_AUDIO_IN_Record(uint16_t *pData, uint32_t Size);
00301 uint8_t BSP_AUDIO_IN_Stop(void);
00302 uint8_t BSP_AUDIO_IN_Pause(void);
00303 uint8_t BSP_AUDIO_IN_Resume(void);
00304 
00305 /* User Callbacks: user has to implement these functions in his code if they are needed. */
00306 /* This function should be implemented by the user application.
00307    It is called into this driver when the current buffer is filled to prepare the next
00308    buffer pointer and its size. */
00309 void    BSP_AUDIO_IN_TransferComplete_CallBack(void);
00310 void    BSP_AUDIO_IN_HalfTransfer_CallBack(void);
00311 
00312 /* This function is called when an Interrupt due to transfer error on or peripheral
00313    error occurs. */
00314 void    BSP_AUDIO_IN_Error_CallBack(void);
00315      
00316 /* These function can be modified in case the current settings (e.g. DMA stream)
00317    need to be changed for specific application needs */
00318 void BSP_AUDIO_IN_ClockConfig(DFSDM_Filter_HandleTypeDef *hdfsdm_filter, uint32_t AudioFreq, void *Params);
00319 void BSP_AUDIO_IN_MspInit(void);
00320 void BSP_AUDIO_IN_MspDeInit(void);
00321 
00322 /**
00323   * @}
00324   */ 
00325 
00326 /**
00327   * @}
00328   */ 
00329 
00330 /**
00331   * @}
00332   */
00333 
00334 /**
00335   * @}
00336   */
00337 
00338 #ifdef __cplusplus
00339 }
00340 #endif
00341 
00342 #endif /* __STM32F769I_DISCOVERY_AUDIO_H */
00343 
00344 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Fri Dec 30 2016 18:30:07 for STM32F769I-Discovery BSP User Manual by   doxygen 1.7.6.1