STM32L4R9I-Discovery BSP User Manual: stm32l4r9i_discovery_audio.h Source File

STM32L4R9I-Discovery BSP

stm32l4r9i_discovery_audio.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32l4r9i_discovery_audio.h
00004   * @author  MCD Application Team
00005   * @brief   This file contains the common defines and functions prototypes for
00006   *          the stm32l4r9i_discovery_audio.c driver.
00007   ******************************************************************************
00008   * @attention
00009   *
00010   * <h2><center>&copy; COPYRIGHT(c) 2017 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 __STM32L4R9I_DISCOVERY_AUDIO_H
00039 #define __STM32L4R9I_DISCOVERY_AUDIO_H
00040 
00041 #ifdef __cplusplus
00042  extern "C" {
00043 #endif
00044 
00045 /* Includes ------------------------------------------------------------------*/
00046 #if defined(BSP_AUDIO_USE_RTOS)
00047 #include "k_mem.h"
00048 #else
00049 #include <stdlib.h>
00050 #endif
00051 /* Include audio component Driver */
00052 #include "../Components/cs42l51/cs42l51.h"
00053 #include "stm32l4r9i_discovery.h"
00054 
00055 /** @addtogroup BSP
00056   * @{
00057   */
00058 
00059 /** @addtogroup STM32L4R9I_DISCOVERY
00060   * @{
00061   */
00062 
00063 /** @addtogroup STM32L4R9I_DISCOVERY_AUDIO
00064   * @{
00065   */
00066 
00067 /** @defgroup STM32L4R9I_DISCOVERY_AUDIO_Exported_Types Exported Types
00068   * @{
00069   */
00070 typedef void (*Audio_CallbackTypeDef)(void);
00071 
00072 /**
00073   * @}
00074   */
00075 
00076 /** @defgroup STM32L4R9I_DISCOVERY_AUDIO_Exported_Constants Exported Constants
00077   * @{
00078   */
00079 /** @defgroup BSP_Audio_Out_Option BSP Audio Out Option
00080   * @{
00081   */
00082 #define BSP_AUDIO_OUT_CIRCULARMODE      ((uint32_t)0x00000001) /* BUFFER CIRCULAR MODE */
00083 #define BSP_AUDIO_OUT_NORMALMODE        ((uint32_t)0x00000002) /* BUFFER NORMAL MODE   */
00084 #define BSP_AUDIO_OUT_STEREOMODE        ((uint32_t)0x00000004) /* STEREO MODE          */
00085 #define BSP_AUDIO_OUT_MONOMODE          ((uint32_t)0x00000008) /* MONO MODE            */
00086 /**
00087   * @}
00088   */
00089 
00090 /** @defgroup BSP_Audio_Sample_Rate BSP Audio Sample Rate
00091   * @{
00092   */
00093 #define BSP_AUDIO_FREQUENCY_96K         SAI_AUDIO_FREQUENCY_96K
00094 #define BSP_AUDIO_FREQUENCY_48K         SAI_AUDIO_FREQUENCY_48K
00095 #define BSP_AUDIO_FREQUENCY_44K         SAI_AUDIO_FREQUENCY_44K
00096 #define BSP_AUDIO_FREQUENCY_32K         SAI_AUDIO_FREQUENCY_32K
00097 #define BSP_AUDIO_FREQUENCY_22K         SAI_AUDIO_FREQUENCY_22K
00098 #define BSP_AUDIO_FREQUENCY_16K         SAI_AUDIO_FREQUENCY_16K
00099 #define BSP_AUDIO_FREQUENCY_11K         SAI_AUDIO_FREQUENCY_11K
00100 #define BSP_AUDIO_FREQUENCY_8K          SAI_AUDIO_FREQUENCY_8K
00101 /**
00102   * @}
00103   */
00104 /*------------------------------------------------------------------------------
00105                           USER SAI defines parameters
00106  -----------------------------------------------------------------------------*/
00107 /* SAI DMA Channel definitions */
00108 #define DMA_MAX_SZE                          (uint32_t)0xFFFF
00109 
00110 /* Disable SAIx PLL */
00111 #define AUDIO_SAIx_PLL_DISABLE()             HAL_RCCEx_DisablePLLSAI1()
00112 
00113 /*------------------------------------------------------------------------------
00114              CONFIGURATION: Audio Driver Configuration parameters
00115 ------------------------------------------------------------------------------*/
00116 
00117 #define AUDIODATA_SIZE                      2   /* 16-bits audio data size */
00118 
00119 /* Audio status definition */
00120 #define AUDIO_OK                            0
00121 #define AUDIO_ERROR                         1
00122 #define AUDIO_TIMEOUT                       2
00123 
00124 /* Audio out parameters */
00125 #define DEFAULT_AUDIO_OUT_FREQ              BSP_AUDIO_FREQUENCY_48K
00126 #define DEFAULT_AUDIO_OUT_BIT_RESOLUTION    ((uint8_t)16)
00127 #define DEFAULT_AUDIO_OUT_CHANNEL_NBR       ((uint8_t)2) /* Mono = 1, Stereo = 2 */
00128 #define DEFAULT_AUDIO_OUT_VOLUME            ((uint16_t)80)
00129 
00130 /* AudioFreq * DataSize (2 bytes) * NumChannels (Stereo: 2) */
00131 #define DEFAULT_AUDIO_IN_FREQ               BSP_AUDIO_FREQUENCY_16K
00132 #define DEFAULT_AUDIO_IN_BIT_RESOLUTION     16
00133 #define DEFAULT_AUDIO_IN_CHANNEL_NBR        1 /* Mono = 1, Stereo = 2 */
00134 #define DEFAULT_AUDIO_IN_VOLUME             80
00135 
00136 /*------------------------------------------------------------------------------
00137                     OPTIONAL Configuration defines parameters
00138 ------------------------------------------------------------------------------*/
00139 
00140 /* Delay for the Codec to be correctly reset */
00141 #define CODEC_RESET_DELAY           5
00142 
00143 /*------------------------------------------------------------------------------
00144                            INPUT DEVICES definition
00145 ------------------------------------------------------------------------------*/
00146 /* MP34DT01TR digital microphone on PCB top side */
00147 #define INPUT_DEVICE_DIGITAL_MIC1      0x20    /* Left microphone  */
00148 #define INPUT_DEVICE_DIGITAL_MIC2      0x40    /* Right microphone */
00149 #define INPUT_DEVICE_DIGITAL_MIC       (INPUT_DEVICE_DIGITAL_MIC1 | INPUT_DEVICE_DIGITAL_MIC2)
00150 /* Analog microphone input from 3.5 audio jack connector */
00151 #define INPUT_DEVICE_ANALOG_MIC        INPUT_DEVICE_MIC1
00152 
00153 /**
00154   * @}
00155   */
00156 
00157 /** @defgroup STM32L4R9I_DISCOVERY_AUDIO_Exported_Variables Exported Variables
00158   * @{
00159   */
00160 extern SAI_HandleTypeDef          BSP_AUDIO_hSai_Tx;
00161 extern SAI_HandleTypeDef          BSP_AUDIO_hSai_Rx;
00162 extern DFSDM_Filter_HandleTypeDef BSP_AUDIO_hDfsdmLeftFilter;
00163 extern DFSDM_Filter_HandleTypeDef BSP_AUDIO_hDfsdmRightFilter;
00164 
00165  /**
00166   * @}
00167   */
00168 
00169 /** @defgroup STM32L4R9I_DISCOVERY_AUDIO_Exported_Macros Exported Macros
00170   * @{
00171   */
00172 #define DMA_MAX(_X_)                (((_X_) <= DMA_MAX_SZE)? (_X_):DMA_MAX_SZE)
00173 
00174 /**
00175   * @}
00176   */
00177 
00178 /* Exported functions --------------------------------------------------------*/
00179 /** @defgroup STM32L4R9I_DISCOVERY_AUDIO_Exported_Functions Exported Functions
00180   * @{
00181   */
00182 uint8_t BSP_AUDIO_OUT_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq);
00183 uint8_t BSP_AUDIO_OUT_DeInit(void);
00184 uint8_t BSP_AUDIO_OUT_Play(uint16_t* pData, uint32_t Size);
00185 uint8_t BSP_AUDIO_OUT_ChangeBuffer(uint16_t *pData, uint16_t Size);
00186 uint8_t BSP_AUDIO_OUT_Pause(void);
00187 uint8_t BSP_AUDIO_OUT_Resume(void);
00188 uint8_t BSP_AUDIO_OUT_Stop(uint32_t Option);
00189 uint8_t BSP_AUDIO_OUT_SetVolume(uint8_t Volume);
00190 uint8_t BSP_AUDIO_OUT_SetFrequency(uint32_t AudioFreq);
00191 void    BSP_AUDIO_OUT_ChangeAudioConfig(uint32_t AudioOutOption);
00192 uint8_t BSP_AUDIO_OUT_SetMute(uint32_t Cmd);
00193 uint8_t BSP_AUDIO_OUT_SetOutputMode(uint8_t Output);
00194 void    BSP_AUDIO_OUT_RegisterCallbacks(Audio_CallbackTypeDef ErrorCallback,
00195                                         Audio_CallbackTypeDef HalfTransferCallback,
00196                                         Audio_CallbackTypeDef TransferCompleteCallback);
00197 
00198 uint8_t BSP_AUDIO_IN_Init(uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr);
00199 uint8_t BSP_AUDIO_IN_InitEx(uint16_t InputDevice, uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr);
00200 uint8_t BSP_AUDIO_IN_DeInit(void);
00201 uint8_t BSP_AUDIO_IN_Record(uint16_t *pData, uint32_t Size);
00202 uint8_t BSP_AUDIO_IN_SetFrequency(uint32_t AudioFreq);
00203 uint8_t BSP_AUDIO_IN_Stop(void);
00204 uint8_t BSP_AUDIO_IN_Pause(void);
00205 uint8_t BSP_AUDIO_IN_Resume(void);
00206 void    BSP_AUDIO_IN_RegisterCallbacks(Audio_CallbackTypeDef ErrorCallback,
00207                                        Audio_CallbackTypeDef HalfTransferCallback,
00208                                        Audio_CallbackTypeDef TransferCompleteCallback);
00209 /**
00210   * @}
00211   */
00212 
00213 /**
00214   * @}
00215   */
00216 
00217 /**
00218   * @}
00219   */
00220 
00221 /**
00222   * @}
00223   */
00224 
00225 #ifdef __cplusplus
00226 }
00227 #endif
00228 
00229 #endif /* __STM32L4R9I_DISCOVERY_AUDIO_H */
00230 
00231 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Fri Oct 13 2017 02:37:42 for STM32L4R9I-Discovery BSP User Manual by   doxygen 1.7.6.1