STM32Cube BSP FW for STM32F769I-Discovery

Dependents:   mbed-os-example-blinky-5 DISCO-F769NI_TOUCHSCREEN_demo_custom_1 Datarecorder2 DISCO-F769NI_TOUCHSCREEN_demo ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stm32f769i_discovery_audio.h Source File

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