STM32756G_EVAL BSP User Manual: stm32756g_eval_audio.h Source File

STM32756G EVAL BSP Drivers

stm32756g_eval_audio.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32756g_eval_audio.h
00004   * @author  MCD Application Team
00005   * @version V1.0.0
00006   * @date    22-May-2015
00007   * @brief   This file contains the common defines and functions prototypes for
00008   *          the stm32756g_eval_audio.c driver.
00009   ******************************************************************************
00010   * @attention
00011   *
00012   * <h2><center>&copy; 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 __STM32756G_EVAL_AUDIO_H
00041 #define __STM32756G_EVAL_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 "stm32756g_eval.h"
00051 #include "../../../Middlewares/ST/STM32_Audio/Addons/PDM/pdm_filter.h"
00052 
00053 /** @addtogroup BSP
00054   * @{
00055   */ 
00056 
00057 /** @addtogroup STM32756G_EVAL
00058   * @{
00059   */
00060     
00061 /** @defgroup STM32756G_EVAL_AUDIO STM32756G_EVAL_AUDIO
00062   * @{
00063   */
00064 
00065 /** @defgroup STM32756G_EVAL_AUDIO_Exported_Types STM32756G_EVAL_AUDIO Exported Types
00066   * @{
00067   */
00068 /**
00069   * @}
00070   */ 
00071 
00072 /** @defgroup STM32756G_EVAL_AUDIO_Exported_Constants STM32756G_EVAL_AUDIO Exported Constants
00073   * @{
00074   */
00075  
00076 /*------------------------------------------------------------------------------
00077                           USER SAI defines parameters
00078  -----------------------------------------------------------------------------*/
00079 /** CODEC_AudioFrame_SLOT_TDMMode 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 peripheral configuration defines */
00093 #define AUDIO_SAIx                           SAI2_Block_B
00094 #define AUDIO_SAIx_CLK_ENABLE()              __HAL_RCC_SAI2_CLK_ENABLE()
00095 #define AUDIO_SAIx_CLK_DISABLE()             __HAL_RCC_SAI2_CLK_DISABLE()
00096 #define AUDIO_SAIx_SCK_AF                    GPIO_AF8_SAI2
00097 #define AUDIO_SAIx_FS_SD_MCLK_AF             GPIO_AF10_SAI2
00098 
00099 #define AUDIO_SAIx_MCLK_ENABLE()             __HAL_RCC_GPIOE_CLK_ENABLE()
00100 #define AUDIO_SAIx_MCLK_GPIO_PORT            GPIOE
00101 #define AUDIO_SAIx_MCLK_PIN                  GPIO_PIN_6
00102 #define AUDIO_SAIx_SCK_SD_ENABLE()           __HAL_RCC_GPIOA_CLK_ENABLE()
00103 #define AUDIO_SAIx_SCK_SD_GPIO_PORT          GPIOA
00104 #define AUDIO_SAIx_SCK_PIN                   GPIO_PIN_2
00105 #define AUDIO_SAIx_SD_PIN                    GPIO_PIN_0
00106 #define AUDIO_SAIx_FS_ENABLE()               __HAL_RCC_GPIOG_CLK_ENABLE()
00107 #define AUDIO_SAIx_FS_GPIO_PORT              GPIOG
00108 #define AUDIO_SAIx_FS_PIN                    GPIO_PIN_9
00109 
00110 
00111 /* SAI DMA Stream definitions */
00112 #define AUDIO_SAIx_DMAx_CLK_ENABLE()         __HAL_RCC_DMA2_CLK_ENABLE()
00113 #define AUDIO_SAIx_DMAx_STREAM               DMA2_Stream6
00114 #define AUDIO_SAIx_DMAx_CHANNEL              DMA_CHANNEL_3
00115 #define AUDIO_SAIx_DMAx_IRQ                  DMA2_Stream6_IRQn
00116 #define AUDIO_SAIx_DMAx_PERIPH_DATA_SIZE     DMA_PDATAALIGN_HALFWORD
00117 #define AUDIO_SAIx_DMAx_MEM_DATA_SIZE        DMA_MDATAALIGN_HALFWORD
00118 #define DMA_MAX_SZE                          0xFFFF
00119    
00120 #define AUDIO_SAIx_DMAx_IRQHandler           DMA2_Stream6_IRQHandler
00121 
00122 /* Select the interrupt preemption priority for the DMA interrupt */
00123 #define AUDIO_OUT_IRQ_PREPRIO                ((uint32_t)5)   /* Select the preemption priority level(0 is the highest) */   
00124 
00125 /*------------------------------------------------------------------------------
00126                         AUDIO IN CONFIGURATION
00127 ------------------------------------------------------------------------------*/
00128 /* SPI Configuration defines */
00129 #define AUDIO_I2Sx                          SPI3
00130 #define AUDIO_I2Sx_CLK_ENABLE()             __HAL_RCC_SPI3_CLK_ENABLE()
00131 #define AUDIO_I2Sx_CLK_DISABLE()            __HAL_RCC_SPI3_CLK_DISABLE()
00132 #define AUDIO_I2Sx_SCK_PIN                   GPIO_PIN_3
00133 #define AUDIO_I2Sx_SCK_GPIO_PORT             GPIOB
00134 #define AUDIO_I2Sx_SCK_GPIO_CLK_ENABLE()     __HAL_RCC_GPIOB_CLK_ENABLE()
00135 #define AUDIO_I2Sx_SCK_GPIO_CLK_DISABLE()    __HAL_RCC_GPIOB_CLK_DISABLE()
00136 #define AUDIO_I2Sx_SCK_AF                    GPIO_AF6_SPI3
00137 
00138 #define AUDIO_I2Sx_SD_PIN                   GPIO_PIN_6
00139 #define AUDIO_I2Sx_SD_GPIO_PORT             GPIOD
00140 #define AUDIO_I2Sx_SD_GPIO_CLK_ENABLE()     __HAL_RCC_GPIOD_CLK_ENABLE()
00141 #define AUDIO_I2Sx_SD_GPIO_CLK_DISABLE()    __HAL_RCC_GPIOD_CLK_DISABLE()
00142 #define AUDIO_I2Sx_SD_AF                    GPIO_AF5_SPI3
00143 
00144 /* I2S DMA Stream Rx definitions */
00145 #define AUDIO_I2Sx_DMAx_CLK_ENABLE()        __HAL_RCC_DMA1_CLK_ENABLE()
00146 #define AUDIO_I2Sx_DMAx_CLK_DISABLE()       __HAL_RCC_DMA1_CLK_DISABLE()
00147 #define AUDIO_I2Sx_DMAx_STREAM              DMA1_Stream2
00148 #define AUDIO_I2Sx_DMAx_CHANNEL             DMA_CHANNEL_0
00149 #define AUDIO_I2Sx_DMAx_IRQ                 DMA1_Stream2_IRQn
00150 #define AUDIO_I2Sx_DMAx_PERIPH_DATA_SIZE    DMA_PDATAALIGN_HALFWORD
00151 #define AUDIO_I2Sx_DMAx_MEM_DATA_SIZE       DMA_MDATAALIGN_HALFWORD
00152    
00153 #define AUDIO_I2Sx_DMAx_IRQHandler          DMA1_Stream2_IRQHandler
00154   
00155 /* Select the interrupt preemption priority and subpriority for the IT/DMA interrupt */
00156 #define AUDIO_IN_IRQ_PREPRIO                ((uint32_t)6)   /* Select the preemption priority level(0 is the highest) */
00157 
00158 
00159 /* Two channels are used:
00160    - one channel as input which is connected to I2S SCK in stereo mode 
00161    - one channel as outupt which divides the frequency on the input
00162 */
00163 
00164 #define AUDIO_TIMx_CLK_ENABLE()             __HAL_RCC_TIM3_CLK_ENABLE()
00165 #define AUDIO_TIMx_CLK_DISABLE()            __HAL_RCC_TIM3_CLK_DISABLE()
00166 #define AUDIO_TIMx                          TIM3
00167 #define AUDIO_TIMx_IN_CHANNEL               TIM_CHANNEL_1
00168 #define AUDIO_TIMx_OUT_CHANNEL              TIM_CHANNEL_2 /* Select channel 2 as output */
00169 #define AUDIO_TIMx_GPIO_CLK_ENABLE()        __HAL_RCC_GPIOC_CLK_ENABLE()
00170 #define AUDIO_TIMx_GPIO_CLK_DISABLE()       __HAL_RCC_GPIOC_CLK_DISABLE()
00171 #define AUDIO_TIMx_GPIO_PORT                GPIOC
00172 #define AUDIO_TIMx_IN_GPIO_PIN              GPIO_PIN_6
00173 #define AUDIO_TIMx_OUT_GPIO_PIN             GPIO_PIN_7
00174 #define AUDIO_TIMx_AF                       GPIO_AF2_TIM3
00175 
00176 /*------------------------------------------------------------------------------
00177              CONFIGURATION: Audio Driver Configuration parameters
00178 ------------------------------------------------------------------------------*/
00179 
00180 #define AUDIODATA_SIZE                      2   /* 16-bits audio data size */
00181 
00182 /* Audio status definition */     
00183 #define AUDIO_OK                            ((uint8_t)0)
00184 #define AUDIO_ERROR                         ((uint8_t)1)
00185 #define AUDIO_TIMEOUT                       ((uint8_t)2)
00186 
00187 /* AudioFreq * DataSize (2 bytes) * NumChannels (Stereo: 2) */
00188 #define DEFAULT_AUDIO_IN_FREQ               I2S_AUDIOFREQ_16K
00189 #define DEFAULT_AUDIO_IN_BIT_RESOLUTION     ((uint8_t)16)
00190 #define DEFAULT_AUDIO_IN_CHANNEL_NBR        ((uint8_t)2) /* Mono = 1, Stereo = 2 */
00191 #define DEFAULT_AUDIO_IN_VOLUME             ((uint16_t)64)
00192 
00193 /* PDM buffer input size */
00194 #define INTERNAL_BUFF_SIZE                  (128*DEFAULT_AUDIO_IN_FREQ/16000*DEFAULT_AUDIO_IN_CHANNEL_NBR)
00195 /* PCM buffer output size */
00196 #define PCM_OUT_SIZE                        (DEFAULT_AUDIO_IN_FREQ/1000*2)
00197 #define CHANNEL_DEMUX_MASK                  ((uint8_t)0x55)
00198    
00199 /*------------------------------------------------------------------------------
00200                     OPTIONAL Configuration defines parameters
00201 ------------------------------------------------------------------------------*/
00202 
00203 /* Delay for the Codec to be correctly reset */
00204 #define CODEC_RESET_DELAY                   ((uint8_t)5)
00205    
00206 
00207 /*------------------------------------------------------------------------------
00208                             OUTPUT DEVICES definition
00209 ------------------------------------------------------------------------------*/
00210 
00211 /* Alias on existing output devices to adapt to Birdie eval board 2 headphones output */
00212 #define OUTPUT_DEVICE_HEADPHONE1 OUTPUT_DEVICE_HEADPHONE
00213 #define OUTPUT_DEVICE_HEADPHONE2 OUTPUT_DEVICE_SPEAKER /* Headphone2 is connected to Speaker output of the wm8994 */
00214    
00215 /**
00216   * @}
00217   */
00218  
00219 /** @defgroup STM32756G_EVAL_AUDIO_Exported_Variables STM32756G_EVAL_AUDIO Exported Variables
00220   * @{
00221   */
00222 extern __IO uint16_t AudioInVolume;
00223  /**
00224   * @}
00225   */
00226    
00227 /** @defgroup STM32756G_EVAL_AUDIO_Exported_Macros STM32756G_EVAL_AUDIO Exported Macros
00228   * @{
00229   */
00230 #define DMA_MAX(x)           (((x) <= DMA_MAX_SZE)? (x):DMA_MAX_SZE)
00231 /**
00232   * @}
00233   */ 
00234 
00235 /** @defgroup STM32756G_EVAL_AUDIO_OUT_Exported_Functions STM32756G_EVAL_AUDIO_OUT Exported Functions
00236   * @{
00237   */
00238 uint8_t BSP_AUDIO_OUT_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq);
00239 uint8_t BSP_AUDIO_OUT_Play(uint16_t* pBuffer, uint32_t Size);
00240 void    BSP_AUDIO_OUT_ChangeBuffer(uint16_t *pData, uint16_t Size);
00241 uint8_t BSP_AUDIO_OUT_Pause(void);
00242 uint8_t BSP_AUDIO_OUT_Resume(void);
00243 uint8_t BSP_AUDIO_OUT_Stop(uint32_t Option);
00244 uint8_t BSP_AUDIO_OUT_SetVolume(uint8_t Volume);
00245 void    BSP_AUDIO_OUT_SetFrequency(uint32_t AudioFreq);
00246 void    BSP_AUDIO_OUT_SetAudioFrameSlot(uint32_t AudioFrameSlot);
00247 uint8_t BSP_AUDIO_OUT_SetMute(uint32_t Cmd);
00248 uint8_t BSP_AUDIO_OUT_SetOutputMode(uint8_t Output);
00249 void    BSP_AUDIO_OUT_DeInit(void);
00250 
00251 /* User Callbacks: user has to implement these functions in his code if they are needed. */
00252 /* This function is called when the requested data has been completely transferred.*/
00253 void    BSP_AUDIO_OUT_TransferComplete_CallBack(void);
00254 
00255 /* This function is called when half of the requested buffer has been transferred. */
00256 void    BSP_AUDIO_OUT_HalfTransfer_CallBack(void);
00257 
00258 /* This function is called when an Interrupt due to transfer error on or peripheral
00259    error occurs. */
00260 void    BSP_AUDIO_OUT_Error_CallBack(void);
00261 
00262 /* These function can be modified in case the current settings (e.g. DMA stream)
00263    need to be changed for specific application needs */
00264 void  BSP_AUDIO_OUT_ClockConfig(SAI_HandleTypeDef *hsai, uint32_t AudioFreq, void *Params);
00265 void  BSP_AUDIO_OUT_MspInit(SAI_HandleTypeDef *hsai, void *Params);
00266 void  BSP_AUDIO_OUT_MspDeInit(SAI_HandleTypeDef *hsai, void *Params);
00267 
00268 /**
00269   * @}
00270   */ 
00271 
00272 /** @defgroup STM32756G_EVAL_AUDIO_IN_Exported_Functions STM32756G_EVAL_AUDIO_IN Exported Functions
00273   * @{
00274   */
00275 uint8_t BSP_AUDIO_IN_Init(uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr);
00276 uint8_t BSP_AUDIO_IN_Record(uint16_t *pData, uint32_t Size);
00277 uint8_t BSP_AUDIO_IN_Stop(void);
00278 uint8_t BSP_AUDIO_IN_Pause(void);
00279 uint8_t BSP_AUDIO_IN_Resume(void);
00280 uint8_t BSP_AUDIO_IN_SetVolume(uint8_t Volume);
00281 void    BSP_AUDIO_IN_DeInit(void);
00282 uint8_t BSP_AUDIO_IN_PDMToPCM(uint16_t* PDMBuf, uint16_t* PCMBuf);
00283 /* User Callbacks: user has to implement these functions in his code if they are needed. */
00284 /* This function should be implemented by the user application.
00285    It is called into this driver when the current buffer is filled to prepare the next
00286    buffer pointer and its size. */
00287 void    BSP_AUDIO_IN_TransferComplete_CallBack(void);
00288 void    BSP_AUDIO_IN_HalfTransfer_CallBack(void);
00289 
00290 /* This function is called when an Interrupt due to transfer error on or peripheral
00291    error occurs. */
00292 void    BSP_AUDIO_IN_Error_Callback(void);
00293 
00294 /* These function can be modified in case the current settings (e.g. DMA stream)
00295    need to be changed for specific application needs */
00296 void  BSP_AUDIO_IN_MspInit(I2S_HandleTypeDef *hi2s, void *Params);
00297 void  BSP_AUDIO_IN_MspDeInit(I2S_HandleTypeDef *hi2s, void *Params);
00298 
00299 /**
00300   * @}
00301   */ 
00302 
00303 /**
00304   * @}
00305   */ 
00306 
00307 /**
00308   * @}
00309   */
00310 
00311 /**
00312   * @}
00313   */
00314 
00315 #ifdef __cplusplus
00316 }
00317 #endif
00318 
00319 #endif /* __STM32756G_EVAL_AUDIO_H */
00320 
00321 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Fri May 22 2015 13:59:20 for STM32756G_EVAL BSP User Manual by   doxygen 1.7.6.1