STM32F4-Discovery BSP User Manual: stm32f4_discovery_audio.h Source File

STM32F4-Discovery BSP

stm32f4_discovery_audio.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f4_discovery_audio.h
00004   * @author  MCD Application Team
00005   * @version V2.1.2
00006   * @date    31-January-2017
00007   * @brief   This file contains the common defines and functions prototypes for
00008   *          stm32f4_discovery_audio.c driver.
00009   ******************************************************************************
00010   * @attention
00011   *
00012   * <h2><center>&copy; COPYRIGHT(c) 2017 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 __STM32F4_DISCOVERY_AUDIO_H
00041 #define __STM32F4_DISCOVERY_AUDIO_H
00042 
00043 #ifdef __cplusplus
00044  extern "C" {
00045 #endif 
00046 
00047 /* Includes ------------------------------------------------------------------*/
00048 /* Include audio component Driver */
00049 #include "../Components/cs43l22/cs43l22.h"
00050 
00051 #include "stm32f4_discovery.h"
00052 #include "../../../Middlewares/ST/STM32_Audio/Addons/PDM/pdm_filter.h"
00053 
00054 /** @addtogroup BSP
00055   * @{
00056   */
00057 
00058 /** @addtogroup STM32F4_DISCOVERY
00059   * @{
00060   */
00061     
00062 /** @addtogroup STM32F4_DISCOVERY_AUDIO
00063   * @{
00064   */    
00065 
00066 
00067 /** @defgroup STM32F4_DISCOVERY_AUDIO_Exported_Types STM32F4 DISCOVERY AUDIO Exported Types
00068   * @{
00069   */
00070 /**
00071   * @}
00072   */ 
00073 
00074 /** @defgroup STM32F4_DISCOVERY_AUDIO_OUT_Exported_Constants STM32F4 DISCOVERY AUDIO OUT Exported Constants
00075   * @{
00076   */ 
00077 
00078 /*------------------------------------------------------------------------------
00079                           AUDIO OUT CONFIGURATION
00080 ------------------------------------------------------------------------------*/
00081 
00082 /* I2S peripheral configuration defines */
00083 #define I2S3                            SPI3
00084 #define I2S3_CLK_ENABLE()               __HAL_RCC_SPI3_CLK_ENABLE()
00085 #define I2S3_CLK_DISABLE()              __HAL_RCC_SPI3_CLK_DISABLE()
00086 #define I2S3_SCK_SD_WS_AF               GPIO_AF6_SPI3
00087 #define I2S3_SCK_SD_CLK_ENABLE()        __HAL_RCC_GPIOC_CLK_ENABLE()
00088 #define I2S3_MCK_CLK_ENABLE()           __HAL_RCC_GPIOC_CLK_ENABLE()
00089 #define I2S3_WS_CLK_ENABLE()            __HAL_RCC_GPIOA_CLK_ENABLE()
00090 #define I2S3_WS_PIN                     GPIO_PIN_4
00091 #define I2S3_SCK_PIN                    GPIO_PIN_10
00092 #define I2S3_SD_PIN                     GPIO_PIN_12
00093 #define I2S3_MCK_PIN                    GPIO_PIN_7
00094 #define I2S3_SCK_SD_GPIO_PORT           GPIOC
00095 #define I2S3_WS_GPIO_PORT               GPIOA
00096 #define I2S3_MCK_GPIO_PORT              GPIOC
00097 
00098 /* I2S DMA Stream definitions */
00099 #define I2S3_DMAx_CLK_ENABLE()          __HAL_RCC_DMA1_CLK_ENABLE()
00100 #define I2S3_DMAx_CLK_DISABLE()         __HAL_RCC_DMA1_CLK_DISABLE()
00101 #define I2S3_DMAx_STREAM                DMA1_Stream7
00102 #define I2S3_DMAx_CHANNEL               DMA_CHANNEL_0
00103 #define I2S3_DMAx_IRQ                   DMA1_Stream7_IRQn
00104 #define I2S3_DMAx_PERIPH_DATA_SIZE      DMA_PDATAALIGN_HALFWORD
00105 #define I2S3_DMAx_MEM_DATA_SIZE         DMA_MDATAALIGN_HALFWORD
00106 #define DMA_MAX_SZE                     0xFFFF
00107 
00108 #define I2S3_IRQHandler                 DMA1_Stream7_IRQHandler
00109 
00110 /* Select the interrupt preemption priority and subpriority for the DMA interrupt */
00111 #define AUDIO_OUT_IRQ_PREPRIO           0x0E   /* Select the preemption priority level(0 is the highest) */
00112 
00113 /*------------------------------------------------------------------------------
00114                           AUDIO IN CONFIGURATION
00115 ------------------------------------------------------------------------------*/
00116 /* SPI Configuration defines */
00117 #define I2S2                            SPI2
00118 #define I2S2_CLK_ENABLE()               __HAL_RCC_SPI2_CLK_ENABLE()
00119 #define I2S2_CLK_DISABLE()              __HAL_RCC_SPI2_CLK_DISABLE()
00120 #define I2S2_SCK_PIN                    GPIO_PIN_10
00121 #define I2S2_SCK_GPIO_PORT              GPIOB
00122 #define I2S2_SCK_GPIO_CLK_ENABLE()      __HAL_RCC_GPIOB_CLK_ENABLE()
00123 #define I2S2_SCK_AF                     GPIO_AF5_SPI2
00124 
00125 #define I2S2_MOSI_PIN                   GPIO_PIN_3
00126 #define I2S2_MOSI_GPIO_PORT             GPIOC
00127 #define I2S2_MOSI_GPIO_CLK_ENABLE()     __HAL_RCC_GPIOC_CLK_ENABLE()
00128 #define I2S2_MOSI_AF                    GPIO_AF5_SPI2
00129 
00130 /* I2S DMA Stream Rx definitions */
00131 #define I2S2_DMAx_CLK_ENABLE()          __HAL_RCC_DMA1_CLK_ENABLE()
00132 #define I2S2_DMAx_CLK_DISABLE()         __HAL_RCC_DMA1_CLK_DISABLE()
00133 #define I2S2_DMAx_STREAM                DMA1_Stream3
00134 #define I2S2_DMAx_CHANNEL               DMA_CHANNEL_0
00135 #define I2S2_DMAx_IRQ                   DMA1_Stream3_IRQn
00136 #define I2S2_DMAx_PERIPH_DATA_SIZE      DMA_PDATAALIGN_HALFWORD
00137 #define I2S2_DMAx_MEM_DATA_SIZE         DMA_MDATAALIGN_HALFWORD
00138    
00139 #define I2S2_IRQHandler                 DMA1_Stream3_IRQHandler
00140 
00141 /* Select the interrupt preemption priority and subpriority for the IT/DMA interrupt */
00142 #define AUDIO_IN_IRQ_PREPRIO            0x0F   /* Select the preemption priority level(0 is the highest) */
00143 
00144 /*------------------------------------------------------------------------------
00145              CONFIGURATION: Audio Driver Configuration parameters
00146 ------------------------------------------------------------------------------*/
00147 
00148 #define AUDIODATA_SIZE                  2   /* 16-bits audio data size */
00149 
00150 /* Audio status definition */     
00151 #define AUDIO_OK                        0
00152 #define AUDIO_ERROR                     1
00153 #define AUDIO_TIMEOUT                   2
00154 
00155 /* AudioFreq * DataSize (2 bytes) * NumChannels (Stereo: 2) */
00156 #define DEFAULT_AUDIO_IN_FREQ                 I2S_AUDIOFREQ_16K
00157 #define DEFAULT_AUDIO_IN_BIT_RESOLUTION       16
00158 #define DEFAULT_AUDIO_IN_CHANNEL_NBR          1 /* Mono = 1, Stereo = 2 */
00159 #define DEFAULT_AUDIO_IN_VOLUME               64
00160 
00161 /* PDM buffer input size */
00162 #define INTERNAL_BUFF_SIZE                    128*DEFAULT_AUDIO_IN_FREQ/16000*DEFAULT_AUDIO_IN_CHANNEL_NBR
00163 /* PCM buffer output size */
00164 #define PCM_OUT_SIZE                          DEFAULT_AUDIO_IN_FREQ/1000
00165 #define CHANNEL_DEMUX_MASK                    0x55
00166    
00167 /*------------------------------------------------------------------------------
00168                     OPTIONAL Configuration defines parameters
00169 ------------------------------------------------------------------------------*/
00170 
00171 /**
00172   * @}
00173   */ 
00174 
00175 /** @defgroup STM32F4_DISCOVERY_AUDIO_Exported_Variables STM32F4 DISCOVERY AUDIO Exported Variables
00176   * @{
00177   */ 
00178 extern __IO uint16_t AudioInVolume;
00179 /**
00180   * @}
00181   */ 
00182 
00183 /** @defgroup STM32F4_DISCOVERY_AUDIO_Exported_Macros STM32F4 DISCOVERY AUDIO Exported Macros
00184   * @{
00185   */
00186 #define DMA_MAX(_X_)                (((_X_) <= DMA_MAX_SZE)? (_X_):DMA_MAX_SZE)
00187 /**
00188   * @}
00189   */
00190 
00191 /** @defgroup STM32F4_DISCOVERY_AUDIO_OUT_Exported_Functions  STM32F4 DISCOVERY AUDIO OUT Exported Functions
00192   * @{
00193   */ 
00194 uint8_t BSP_AUDIO_OUT_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq);
00195 uint8_t BSP_AUDIO_OUT_Play(uint16_t* pBuffer, uint32_t Size);
00196 void    BSP_AUDIO_OUT_ChangeBuffer(uint16_t *pData, uint16_t Size);
00197 uint8_t BSP_AUDIO_OUT_Pause(void);
00198 uint8_t BSP_AUDIO_OUT_Resume(void);
00199 uint8_t BSP_AUDIO_OUT_Stop(uint32_t Option);
00200 uint8_t BSP_AUDIO_OUT_SetVolume(uint8_t Volume);
00201 void    BSP_AUDIO_OUT_SetFrequency(uint32_t AudioFreq);
00202 uint8_t BSP_AUDIO_OUT_SetMute(uint32_t Cmd);
00203 uint8_t BSP_AUDIO_OUT_SetOutputMode(uint8_t Output);
00204 
00205 /* User Callbacks: user has to implement these functions in his code if they are needed. */
00206 /* This function is called when the requested data has been completely transferred. */
00207 void    BSP_AUDIO_OUT_TransferComplete_CallBack(void);
00208 
00209 /* This function is called when half of the requested buffer has been transferred. */
00210 void    BSP_AUDIO_OUT_HalfTransfer_CallBack(void);
00211 
00212 /* This function is called when an Interrupt due to transfer error on or peripheral
00213    error occurs. */
00214 void    BSP_AUDIO_OUT_Error_CallBack(void);
00215 
00216 /* These function can be modified in case the current settings (e.g. DMA stream)
00217    need to be changed for specific application needs */
00218 void  BSP_AUDIO_OUT_ClockConfig(I2S_HandleTypeDef *hi2s, uint32_t AudioFreq, void *Params);
00219 void  BSP_AUDIO_OUT_MspInit(I2S_HandleTypeDef *hi2s, void *Params);
00220 void  BSP_AUDIO_OUT_MspDeInit(I2S_HandleTypeDef *hi2s, void *Params);
00221 
00222 /**
00223   * @}
00224   */
00225 
00226 /** @defgroup STM32F4_DISCOVERY_AUDIO_IN_Exported_Functions STM32F4 DISCOVERY AUDIO IN Exported Functions
00227   * @{
00228   */ 
00229 uint8_t BSP_AUDIO_IN_Init(uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr);
00230 uint8_t BSP_AUDIO_IN_Record(uint16_t *pData, uint32_t Size);
00231 uint8_t BSP_AUDIO_IN_Stop(void);
00232 uint8_t BSP_AUDIO_IN_Pause(void);
00233 uint8_t BSP_AUDIO_IN_Resume(void);
00234 uint8_t BSP_AUDIO_IN_SetVolume(uint8_t Volume);
00235 uint8_t BSP_AUDIO_IN_PDMToPCM(uint16_t *PDMBuf, uint16_t *PCMBuf);
00236 /* User Callbacks: user has to implement these functions in his code if they are needed. */
00237 /* This function should be implemented by the user application.
00238    It is called into this driver when the current buffer is filled to prepare the next
00239    buffer pointer and its size. */
00240 void    BSP_AUDIO_IN_TransferComplete_CallBack(void);
00241 void    BSP_AUDIO_IN_HalfTransfer_CallBack(void);
00242 
00243 /* This function is called when an Interrupt due to transfer error on or peripheral
00244    error occurs. */
00245 void    BSP_AUDIO_IN_Error_Callback(void);
00246 
00247 /* These function can be modified in case the current settings (e.g. DMA stream)
00248    need to be changed for specific application needs */
00249 void  BSP_AUDIO_IN_ClockConfig(I2S_HandleTypeDef *hi2s, uint32_t AudioFreq, void *Params);   
00250 void  BSP_AUDIO_IN_MspInit(I2S_HandleTypeDef *hi2s, void *Params);
00251 void  BSP_AUDIO_IN_MspDeInit(I2S_HandleTypeDef *hi2s, void *Params);
00252 
00253 /**
00254   * @}
00255   */  
00256 
00257 /**
00258   * @}
00259   */ 
00260 
00261 /**
00262   * @}
00263   */
00264 
00265 /**
00266   * @}
00267   */
00268 
00269 #ifdef __cplusplus
00270 }
00271 #endif
00272    
00273 #endif /* __STM32F4_DISCOVERY_AUDIO_H */
00274 
00275 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Thu Jan 19 2017 15:34:14 for STM32F4-Discovery BSP User Manual by   doxygen 1.7.6.1