STM32F469I-Discovery BSP User Manual: stm32469i_discovery_audio.h Source File

STM32F469I-Discovery BSP Drivers

stm32469i_discovery_audio.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32469i_discovery_audio.h
00004   * @author  MCD Application Team
00005   * @version V1.0.2
00006   * @date    13-January-2016
00007   * @brief   This file contains the common defines and functions prototypes for
00008   *          the stm32469i_discovery_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 __STM32469I_DISCOVERY_AUDIO_H
00041 #define __STM32469I_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 
00054 /* Include audio component Driver */
00055 #include "../Components/cs43l22/cs43l22.h"
00056 #include "stm32469i_discovery.h"
00057 #include "../../../Middlewares/ST/STM32_Audio/Addons/PDM/pdm_filter.h"
00058 
00059 /** @addtogroup BSP
00060   * @{
00061   */
00062 
00063 /** @addtogroup STM32469I_Discovery
00064   * @{
00065   */
00066 
00067 /** @addtogroup STM32469I-Discovery_AUDIO
00068   * @{
00069   */
00070 
00071 /** @defgroup STM32469I-Discovery_AUDIO_Exported_Types STM32469I Discovery AUDIO Exported Types
00072   * @{
00073   */
00074 /**
00075   * @}
00076   */
00077 
00078 /** @defgroup STM32469I-Discovery_AUDIO_Exported_Constants  STM32469I Discovery AUDIO Exported Constants
00079   * @{
00080   */
00081 
00082 /** @defgroup BSP_Audio_Out_Option BSP AUDIO OUT Option
00083   * @{
00084   */
00085 #define BSP_AUDIO_OUT_CIRCULARMODE      ((uint32_t)0x00000001) /* BUFFER CIRCULAR MODE */
00086 #define BSP_AUDIO_OUT_NORMALMODE        ((uint32_t)0x00000002) /* BUFFER NORMAL MODE   */
00087 #define BSP_AUDIO_OUT_STEREOMODE        ((uint32_t)0x00000004) /* STEREO MODE          */
00088 #define BSP_AUDIO_OUT_MONOMODE          ((uint32_t)0x00000008) /* MONO MODE            */
00089 /**
00090   * @}
00091   */
00092 
00093 /*------------------------------------------------------------------------------
00094                           USER SAI defines parameters
00095  -----------------------------------------------------------------------------*/
00096 /** @defgroup CODEC_AudioFrame_SLOT_TDMMode  STM32469I Discovery Audio Slot TDM mode
00097   * @brief In W8994 codec the Audio frame contains 4 slots : TDM Mode
00098   * TDM format :
00099   * +------------------|------------------|--------------------|-------------------+
00100   * | CODEC_SLOT0 Left | CODEC_SLOT1 Left | CODEC_SLOT0 Right  | CODEC_SLOT1 Right |
00101   * +------------------------------------------------------------------------------+
00102   * @{
00103   */
00104 /* To have 2 separate audio stream in Both headphone and speaker the 4 slot must be activated */
00105 #define CODEC_AUDIOFRAME_SLOT_0123                   SAI_SLOTACTIVE_0 | SAI_SLOTACTIVE_1 | SAI_SLOTACTIVE_2 | SAI_SLOTACTIVE_3
00106 /* To have an audio stream in headphone only SAI Slot 0 and Slot 2 must be activated */
00107 #define CODEC_AUDIOFRAME_SLOT_02                     SAI_SLOTACTIVE_0 | SAI_SLOTACTIVE_2
00108 /* To have an audio stream in speaker only SAI Slot 1 and Slot 3 must be activated */
00109 #define CODEC_AUDIOFRAME_SLOT_13                     SAI_SLOTACTIVE_1 | SAI_SLOTACTIVE_3
00110 /**
00111   * @}
00112   */
00113 
00114 /* SAI peripheral configuration defines */
00115 #define AUDIO_SAIx                           SAI1_Block_A
00116 #define AUDIO_SAIx_CLK_ENABLE()              __HAL_RCC_SAI1_CLK_ENABLE()
00117 #define AUDIO_SAIx_CLK_DISABLE()             __HAL_RCC_SAI1_CLK_DISABLE()
00118 #define AUDIO_SAIx_MCLK_SCK_SD_FS_AF         GPIO_AF6_SAI1
00119 
00120 #define AUDIO_SAIx_MCLK_ENABLE()             __HAL_RCC_GPIOG_CLK_ENABLE()
00121 #define AUDIO_SAIx_MCLK_DISABLE()            __HAL_RCC_GPIOG_CLK_DISABLE()
00122 
00123 #define AUDIO_SAIx_MCK_PIN                   GPIO_PIN_7
00124 #define AUDIO_SAIx_MCLK_GPIO_PORT            GPIOG
00125 
00126 #define AUDIO_SAIx_SCK_SD_FS_ENABLE()        __HAL_RCC_GPIOE_CLK_ENABLE()
00127 #define AUDIO_SAIx_SCK_SD_FS_DISABLE()       __HAL_RCC_GPIOE_CLK_DISABLE()
00128 #define AUDIO_SAIx_FS_PIN                    GPIO_PIN_4
00129 #define AUDIO_SAIx_SCK_PIN                   GPIO_PIN_5
00130 #define AUDIO_SAIx_SD_PIN                    GPIO_PIN_6
00131 #define AUDIO_SAIx_SCK_SD_FS_GPIO_PORT       GPIOE
00132 
00133 #define AUDIO_RESET_ENABLE()                 __HAL_RCC_GPIOE_CLK_ENABLE()
00134 #define AUDIO_RESET_DISABLE()                __HAL_RCC_GPIOE_CLK_DISABLE()
00135 #define AUDIO_RESET_PIN                      GPIO_PIN_2
00136 #define AUDIO_RESET_GPIO_PORT                GPIOE
00137 
00138 /* SAI DMA Stream definitions */
00139 #define AUDIO_SAIx_DMAx_CLK_ENABLE()         __HAL_RCC_DMA2_CLK_ENABLE()
00140 #define AUDIO_SAIx_DMAx_CLK_DISABLE()        __HAL_RCC_DMA2_CLK_DISABLE()
00141 #define AUDIO_SAIx_DMAx_STREAM               DMA2_Stream3
00142 #define AUDIO_SAIx_DMAx_CHANNEL              DMA_CHANNEL_0
00143 #define AUDIO_SAIx_DMAx_IRQ                  DMA2_Stream3_IRQn
00144 #define AUDIO_SAIx_DMAx_PERIPH_DATA_SIZE     DMA_PDATAALIGN_HALFWORD
00145 #define AUDIO_SAIx_DMAx_MEM_DATA_SIZE        DMA_MDATAALIGN_HALFWORD
00146 #define DMA_MAX_SZE                          0xFFFF
00147 
00148 #define AUDIO_SAIx_DMAx_IRQHandler           DMA2_Stream3_IRQHandler
00149 
00150 /* Select the interrupt preemption priority for the DMA interrupt */
00151 #define AUDIO_OUT_IRQ_PREPRIO           5   /* Select the preemption priority level(0 is the highest) */
00152 
00153 /* Disable SAIx PLL */
00154 #define AUDIO_SAIx_PLL_DISABLE()             HAL_RCCEx_DisablePLLSAI1()
00155 /*------------------------------------------------------------------------------
00156                         AUDIO IN CONFIGURATION
00157 ------------------------------------------------------------------------------*/
00158 /* SPI Configuration defines */
00159 #define AUDIO_I2Sx                           SPI3
00160 #define AUDIO_I2Sx_CLK_ENABLE()              __HAL_RCC_SPI3_CLK_ENABLE()
00161 #define AUDIO_I2Sx_CLK_DISABLE()             __HAL_RCC_SPI3_CLK_DISABLE()
00162 #define AUDIO_I2Sx_SCK_PIN                   GPIO_PIN_3
00163 #define AUDIO_I2Sx_SCK_GPIO_PORT             GPIOB
00164 #define AUDIO_I2Sx_SCK_GPIO_CLK_ENABLE()     __HAL_RCC_GPIOB_CLK_ENABLE()
00165 #define AUDIO_I2Sx_SCK_GPIO_CLK_DISABLE()    __HAL_RCC_GPIOB_CLK_DISABLE()
00166 #define AUDIO_I2Sx_SCK_AF                    GPIO_AF6_SPI3
00167 
00168 #define AUDIO_I2Sx_SD_PIN                    GPIO_PIN_6
00169 #define AUDIO_I2Sx_SD_GPIO_PORT              GPIOD
00170 #define AUDIO_I2Sx_SD_GPIO_CLK_ENABLE()      __HAL_RCC_GPIOD_CLK_ENABLE()
00171 #define AUDIO_I2Sx_SD_GPIO_CLK_DISABLE()     __HAL_RCC_GPIOD_CLK_DISABLE()
00172 #define AUDIO_I2Sx_SD_AF                     GPIO_AF5_I2S3ext
00173 
00174 /* I2S DMA Stream Rx definitions */
00175 #define AUDIO_I2Sx_DMAx_CLK_ENABLE()        __HAL_RCC_DMA1_CLK_ENABLE()
00176 #define AUDIO_I2Sx_DMAx_CLK_DISABLE()       __HAL_RCC_DMA1_CLK_DISABLE()
00177 #define AUDIO_I2Sx_DMAx_STREAM              DMA1_Stream2
00178 #define AUDIO_I2Sx_DMAx_CHANNEL             DMA_CHANNEL_0
00179 #define AUDIO_I2Sx_DMAx_IRQ                 DMA1_Stream2_IRQn
00180 #define AUDIO_I2Sx_DMAx_PERIPH_DATA_SIZE    DMA_PDATAALIGN_HALFWORD
00181 #define AUDIO_I2Sx_DMAx_MEM_DATA_SIZE       DMA_MDATAALIGN_HALFWORD
00182 
00183 #define AUDIO_I2Sx_DMAx_IRQHandler          DMA1_Stream2_IRQHandler
00184 
00185 /* Select the interrupt preemption priority and subpriority for the IT/DMA interrupt */
00186 #define AUDIO_IN_IRQ_PREPRIO                ((uint32_t)6)   /* Select the preemption priority level(0 is the highest) */
00187 
00188 
00189 /* Two channels are used:
00190    - one channel as input which is connected to I2S SCK in stereo mode
00191    - one channel as outupt which divides the frequency on the input
00192 */
00193 
00194 #define AUDIO_TIMx_CLK_ENABLE()             __HAL_RCC_TIM4_CLK_ENABLE()
00195 #define AUDIO_TIMx_CLK_DISABLE()            __HAL_RCC_TIM4_CLK_DISABLE()
00196 #define AUDIO_TIMx                          TIM4
00197 #define AUDIO_TIMx_IN_CHANNEL               TIM_CHANNEL_1
00198 #define AUDIO_TIMx_OUT_CHANNEL              TIM_CHANNEL_2 /* Select channel 2 as output */
00199 #define AUDIO_TIMx_GPIO_CLK_ENABLE()        __HAL_RCC_GPIOD_CLK_ENABLE()
00200 #define AUDIO_TIMx_GPIO_CLK_DISABLE()       __HAL_RCC_GPIOD_CLK_DISABLE()
00201 #define AUDIO_TIMx_GPIO_PORT                GPIOD
00202 #define AUDIO_TIMx_IN_GPIO_PIN              GPIO_PIN_12
00203 #define AUDIO_TIMx_OUT_GPIO_PIN             GPIO_PIN_13
00204 #define AUDIO_TIMx_AF                       GPIO_AF2_TIM4
00205 
00206 /*------------------------------------------------------------------------------
00207              CONFIGURATION: Audio Driver Configuration parameters
00208 ------------------------------------------------------------------------------*/
00209 
00210 #define AUDIODATA_SIZE                      2   /* 16-bits audio data size */
00211 
00212 /* Audio status definition */
00213 #define AUDIO_OK                            ((uint8_t)0)
00214 #define AUDIO_ERROR                         ((uint8_t)1)
00215 #define AUDIO_TIMEOUT                       ((uint8_t)2)
00216 
00217 /* AudioFreq * DataSize (2 bytes) * NumChannels (Stereo: 2) */
00218 #define DEFAULT_AUDIO_IN_FREQ               I2S_AUDIOFREQ_16K
00219 #define DEFAULT_AUDIO_IN_BIT_RESOLUTION     ((uint8_t)16)
00220 #define DEFAULT_AUDIO_IN_CHANNEL_NBR        ((uint8_t)2) /* Mono = 1, Stereo = 2 */
00221 #define DEFAULT_AUDIO_IN_VOLUME             ((uint16_t)64)
00222 
00223 /* PDM buffer input size */
00224 #define INTERNAL_BUFF_SIZE                  (128*DEFAULT_AUDIO_IN_FREQ/16000*DEFAULT_AUDIO_IN_CHANNEL_NBR)
00225 /* PCM buffer output size */
00226 #define PCM_OUT_SIZE                        (DEFAULT_AUDIO_IN_FREQ/1000*DEFAULT_AUDIO_IN_CHANNEL_NBR)
00227 #define CHANNEL_DEMUX_MASK                  ((uint8_t)0x55)
00228 
00229 /*------------------------------------------------------------------------------
00230                     OPTIONAL Configuration defines parameters
00231 ------------------------------------------------------------------------------*/
00232 
00233 /* Delay for the Codec to be correctly reset */
00234 #define CODEC_RESET_DELAY           ((uint8_t)5)
00235 
00236 /*------------------------------------------------------------------------------
00237                             OUTPUT DEVICES definition
00238 ------------------------------------------------------------------------------*/
00239 
00240 /**
00241   * @}
00242   */
00243 
00244 /** @defgroup STM32469I-Discovery_AUDIO_Exported_Variables  STM32469I-Discovery AUDIO Exported Variables
00245   * @{
00246   */
00247 extern __IO uint16_t AudioInVolume;
00248  /**
00249   * @}
00250   */
00251 
00252 /** @defgroup STM32469I-Discovery_AUDIO_Exported_Macros STM32469I-Discovery AUDIO Exported Macros
00253   * @{
00254   */
00255 #define DMA_MAX(x)           (((x) <= DMA_MAX_SZE)? (x):DMA_MAX_SZE)
00256 /**
00257   * @}
00258   */
00259 
00260 /** @defgroup STM32469I-Discovery_AUDIO_OUT_Exported_Functions  STM32469I Discovery AUDIO OUT Exported Functions
00261   * @{
00262   */
00263 uint8_t BSP_AUDIO_OUT_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq);
00264 uint8_t BSP_AUDIO_OUT_Play(uint16_t* pBuffer, uint32_t Size);
00265 void    BSP_AUDIO_OUT_ChangeBuffer(uint16_t *pData, uint16_t Size);
00266 uint8_t BSP_AUDIO_OUT_Pause(void);
00267 uint8_t BSP_AUDIO_OUT_Resume(void);
00268 uint8_t BSP_AUDIO_OUT_Stop(uint32_t Option);
00269 uint8_t BSP_AUDIO_OUT_SetVolume(uint8_t Volume);
00270 void    BSP_AUDIO_OUT_SetFrequency(uint32_t AudioFreq);
00271 void    BSP_AUDIO_OUT_SetAudioFrameSlot(uint32_t AudioFrameSlot);
00272 uint8_t BSP_AUDIO_OUT_SetMute(uint32_t Cmd);
00273 uint8_t BSP_AUDIO_OUT_SetOutputMode(uint8_t Output);
00274 void    BSP_AUDIO_OUT_DeInit(void);
00275 
00276 /* User Callbacks: user has to implement these functions in his code if they are needed. */
00277 /* This function is called when the requested data has been completely transferred.*/
00278 void    BSP_AUDIO_OUT_TransferComplete_CallBack(void);
00279 
00280 /* This function is called when half of the requested buffer has been transferred. */
00281 void    BSP_AUDIO_OUT_HalfTransfer_CallBack(void);
00282 
00283 /* This function is called when an Interrupt due to transfer error on or peripheral
00284    error occurs. */
00285 void    BSP_AUDIO_OUT_Error_CallBack(void);
00286 
00287 /* These function can be modified in case the current settings (e.g. DMA stream)
00288    need to be changed for specific application needs */
00289 void  BSP_AUDIO_OUT_ClockConfig(SAI_HandleTypeDef *hsai, uint32_t AudioFreq, void *Params);
00290 void  BSP_AUDIO_OUT_MspInit(SAI_HandleTypeDef *hsai, void *Params);
00291 void  BSP_AUDIO_OUT_MspDeInit(SAI_HandleTypeDef *hsai, void *Params);
00292 
00293 /**
00294   * @}
00295   */
00296 
00297 /** @defgroup STM32469I-Discovery_AUDIO_IN_Exported_Functions  STM32469I Discovery AUDIO IN Exported Functions
00298   * @{
00299   */
00300 uint8_t BSP_AUDIO_IN_Init(uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr);
00301 uint8_t BSP_AUDIO_IN_Record(uint16_t *pData, uint32_t Size);
00302 uint8_t BSP_AUDIO_IN_Stop(void);
00303 uint8_t BSP_AUDIO_IN_Pause(void);
00304 uint8_t BSP_AUDIO_IN_Resume(void);
00305 uint8_t BSP_AUDIO_IN_SetVolume(uint8_t Volume);
00306 void    BSP_AUDIO_IN_DeInit(void);
00307 uint8_t BSP_AUDIO_IN_PDMToPCM(uint16_t* PDMBuf, uint16_t* PCMBuf);
00308 /* User Callbacks: user has to implement these functions in his code if they are needed. */
00309 /* This function should be implemented by the user application.
00310    It is called into this driver when the current buffer is filled to prepare the next
00311    buffer pointer and its size. */
00312 void    BSP_AUDIO_IN_TransferComplete_CallBack(void);
00313 void    BSP_AUDIO_IN_HalfTransfer_CallBack(void);
00314 
00315 /* This function is called when an Interrupt due to transfer error on or peripheral
00316    error occurs. */
00317 void    BSP_AUDIO_IN_Error_Callback(void);
00318 
00319 /* These function can be modified in case the current settings (e.g. DMA stream)
00320    need to be changed for specific application needs */
00321 void  BSP_AUDIO_IN_MspInit(I2S_HandleTypeDef *hi2s, void *Params);
00322 void  BSP_AUDIO_IN_MspDeInit(I2S_HandleTypeDef *hi2s, void *Params);
00323 
00324 /**
00325   * @}
00326   */ 
00327 
00328 /**
00329   * @}
00330   */ 
00331 
00332 /**
00333   * @}
00334   */
00335 
00336 /**
00337   * @}
00338   */
00339 
00340 #ifdef __cplusplus
00341 }
00342 #endif
00343 
00344 #endif /* __STM32469I_DISCOVERY_AUDIO_H */
00345 
00346 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Wed Jan 13 2016 10:58:45 for STM32F469I-Discovery BSP User Manual by   doxygen 1.7.6.1