STM32Cube BSP FW for STM32F769I-Discovery

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

Committer:
Jerome Coutant
Date:
Thu Mar 23 10:42:33 2017 +0100
Revision:
2:39d2c2c79afa
Parent:
1:3e58f8a39705
Child:
3:145e714557cf
Add IRQHandler functions for audio part

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jerome Coutant 0:c0f3bbab73d2 1 /**
Jerome Coutant 0:c0f3bbab73d2 2 ******************************************************************************
Jerome Coutant 0:c0f3bbab73d2 3 * @file stm32f769i_discovery_audio.c
Jerome Coutant 0:c0f3bbab73d2 4 * @author MCD Application Team
Jerome Coutant 1:3e58f8a39705 5 * @version V2.0.0
Jerome Coutant 1:3e58f8a39705 6 * @date 30-December-2016
Jerome Coutant 0:c0f3bbab73d2 7 * @brief This file provides the Audio driver for the STM32F769I-DISCOVERY
Jerome Coutant 0:c0f3bbab73d2 8 * board.
Jerome Coutant 0:c0f3bbab73d2 9 @verbatim
Jerome Coutant 0:c0f3bbab73d2 10 How To use this driver:
Jerome Coutant 0:c0f3bbab73d2 11 -----------------------
Jerome Coutant 0:c0f3bbab73d2 12 + This driver supports STM32F7xx devices on STM32F769I-DISCOVERY (MB1225) Evaluation boards.
Jerome Coutant 0:c0f3bbab73d2 13 + Call the function BSP_AUDIO_OUT_Init(
Jerome Coutant 0:c0f3bbab73d2 14 OutputDevice: physical output mode (OUTPUT_DEVICE_SPEAKER,
Jerome Coutant 0:c0f3bbab73d2 15 OUTPUT_DEVICE_HEADPHONE or OUTPUT_DEVICE_BOTH)
Jerome Coutant 0:c0f3bbab73d2 16 Volume : Initial volume to be set (0 is min (mute), 100 is max (100%)
Jerome Coutant 0:c0f3bbab73d2 17 AudioFreq : Audio frequency in Hz (8000, 16000, 22500, 32000...)
Jerome Coutant 0:c0f3bbab73d2 18 this parameter is relative to the audio file/stream type.
Jerome Coutant 0:c0f3bbab73d2 19 )
Jerome Coutant 0:c0f3bbab73d2 20 This function configures all the hardware required for the audio application (codec, I2C, SAI,
Jerome Coutant 0:c0f3bbab73d2 21 GPIOs, DMA and interrupt if needed). This function returns AUDIO_OK if configuration is OK.
Jerome Coutant 0:c0f3bbab73d2 22 If the returned value is different from AUDIO_OK or the function is stuck then the communication with
Jerome Coutant 0:c0f3bbab73d2 23 the codec has failed (try to un-plug the power or reset device in this case).
Jerome Coutant 0:c0f3bbab73d2 24 - OUTPUT_DEVICE_SPEAKER : only speaker will be set as output for the audio stream.
Jerome Coutant 0:c0f3bbab73d2 25 - OUTPUT_DEVICE_HEADPHONE: only headphones will be set as output for the audio stream.
Jerome Coutant 0:c0f3bbab73d2 26 - OUTPUT_DEVICE_BOTH : both Speaker and Headphone are used as outputs for the audio stream
Jerome Coutant 0:c0f3bbab73d2 27 at the same time.
Jerome Coutant 0:c0f3bbab73d2 28 Note. On STM32F769I-DISCOVERY SAI_DMA is configured in CIRCULAR mode. Due to this the application
Jerome Coutant 0:c0f3bbab73d2 29 does NOT need to call BSP_AUDIO_OUT_ChangeBuffer() to assure streaming.
Jerome Coutant 0:c0f3bbab73d2 30 + Call the function BSP_AUDIO_OUT_Play(
Jerome Coutant 0:c0f3bbab73d2 31 pBuffer: pointer to the audio data file address
Jerome Coutant 0:c0f3bbab73d2 32 Size : size of the buffer to be sent in Bytes
Jerome Coutant 0:c0f3bbab73d2 33 )
Jerome Coutant 0:c0f3bbab73d2 34 to start playing (for the first time) from the audio file/stream.
Jerome Coutant 0:c0f3bbab73d2 35 + Call the function BSP_AUDIO_OUT_Pause() to pause playing
Jerome Coutant 0:c0f3bbab73d2 36 + Call the function BSP_AUDIO_OUT_Resume() to resume playing.
Jerome Coutant 0:c0f3bbab73d2 37 Note. After calling BSP_AUDIO_OUT_Pause() function for pause, only BSP_AUDIO_OUT_Resume() should be called
Jerome Coutant 0:c0f3bbab73d2 38 for resume (it is not allowed to call BSP_AUDIO_OUT_Play() in this case).
Jerome Coutant 0:c0f3bbab73d2 39 Note. This function should be called only when the audio file is played or paused (not stopped).
Jerome Coutant 0:c0f3bbab73d2 40 + For each mode, you may need to implement the relative callback functions into your code.
Jerome Coutant 0:c0f3bbab73d2 41 The Callback functions are named BSP_AUDIO_OUT_XXX_CallBack() and only their prototypes are declared in
Jerome Coutant 0:c0f3bbab73d2 42 the stm32f769i_discovery_audio.h file. (refer to the example for more details on the callbacks implementations)
Jerome Coutant 0:c0f3bbab73d2 43 + To Stop playing, to modify the volume level, the frequency, the audio frame slot,
Jerome Coutant 0:c0f3bbab73d2 44 the device output mode the mute or the stop, use the functions: BSP_AUDIO_OUT_SetVolume(),
Jerome Coutant 0:c0f3bbab73d2 45 AUDIO_OUT_SetFrequency(), BSP_AUDIO_OUT_SetAudioFrameSlot(), BSP_AUDIO_OUT_SetOutputMode(),
Jerome Coutant 0:c0f3bbab73d2 46 BSP_AUDIO_OUT_SetMute() and BSP_AUDIO_OUT_Stop().
Jerome Coutant 0:c0f3bbab73d2 47
Jerome Coutant 0:c0f3bbab73d2 48 + Call the function BSP_AUDIO_IN_Init(
Jerome Coutant 0:c0f3bbab73d2 49 AudioFreq: Audio frequency in Hz (8000, 16000, 22500, 32000...)
Jerome Coutant 0:c0f3bbab73d2 50 this parameter is relative to the audio file/stream type.
Jerome Coutant 0:c0f3bbab73d2 51 BitRes: Bit resolution fixed to 16bit
Jerome Coutant 0:c0f3bbab73d2 52 ChnlNbr: Number of channel to be configured for the DFSDM peripheral
Jerome Coutant 0:c0f3bbab73d2 53 )
Jerome Coutant 0:c0f3bbab73d2 54 This function configures all the hardware required for the audio in application (DFSDM filters and channels,
Jerome Coutant 0:c0f3bbab73d2 55 Clock source for DFSDM periphiral, GPIOs, DMA and interrupt if needed).
Jerome Coutant 0:c0f3bbab73d2 56 This function returns AUDIO_OK if configuration is OK.If the returned value is different from AUDIO_OK then
Jerome Coutant 0:c0f3bbab73d2 57 the configuration should be wrong.
Jerome Coutant 0:c0f3bbab73d2 58 Note: On STM32F769I-DISCOVERY, four DFSDM Channel/Filters are configured and their DMA streams are configured
Jerome Coutant 0:c0f3bbab73d2 59 in CIRCULAR mode.
Jerome Coutant 0:c0f3bbab73d2 60 + Call the function BSP_AUDIO_IN_AllocScratch(
Jerome Coutant 0:c0f3bbab73d2 61 pScratch: pointer to scratch tables
Jerome Coutant 0:c0f3bbab73d2 62 size: size of scratch buffer)
Jerome Coutant 0:c0f3bbab73d2 63 This function must be called before BSP_AUDIO_IN_RECORD() to allocate buffer scratch for each DFSDM channel
Jerome Coutant 0:c0f3bbab73d2 64 and its size.
Jerome Coutant 0:c0f3bbab73d2 65 Note: These buffers scratch are used as intermidiate buffers to collect data within final record buffer.
Jerome Coutant 0:c0f3bbab73d2 66 size is the total size of the four buffers scratch; If size is 512 then the size of each is 128.
Jerome Coutant 0:c0f3bbab73d2 67 This function must be called after BSP_AUDIO_IN_Init()
Jerome Coutant 0:c0f3bbab73d2 68 + Call the function BSP_AUDIO_IN_RECORD(
Jerome Coutant 0:c0f3bbab73d2 69 pBuf: pointer to the recorded audio data file address
Jerome Coutant 0:c0f3bbab73d2 70 Size: size of the buffer to be written in Bytes
Jerome Coutant 0:c0f3bbab73d2 71 )
Jerome Coutant 0:c0f3bbab73d2 72 to start recording from microphones.
Jerome Coutant 0:c0f3bbab73d2 73
Jerome Coutant 0:c0f3bbab73d2 74 + Call the function BSP_AUDIO_IN_Pause() to pause recording
Jerome Coutant 0:c0f3bbab73d2 75 + Call the function BSP_AUDIO_IN_Resume() to recording playing.
Jerome Coutant 0:c0f3bbab73d2 76 Note. After calling BSP_AUDIO_IN_Pause() function for pause, only BSP_AUDIO_IN_Resume() should be called
Jerome Coutant 0:c0f3bbab73d2 77 for resume (it is not allowed to call BSP_AUDIO_IN_RECORD() in this case).
Jerome Coutant 0:c0f3bbab73d2 78 + Call the function BSP_AUDIO_IN_Stop() to stop recording
Jerome Coutant 0:c0f3bbab73d2 79 + For each mode, you may need to implement the relative callback functions into your code.
Jerome Coutant 0:c0f3bbab73d2 80 The Callback functions are named BSP_AUDIO_IN_XXX_CallBack() and only their prototypes are declared in
Jerome Coutant 0:c0f3bbab73d2 81 the stm32f769i_discovery_audio.h file. (refer to the example for more details on the callbacks implementations)
Jerome Coutant 0:c0f3bbab73d2 82
Jerome Coutant 0:c0f3bbab73d2 83 Driver architecture:
Jerome Coutant 0:c0f3bbab73d2 84 --------------------
Jerome Coutant 0:c0f3bbab73d2 85 + This driver provides the High Audio Layer: consists of the function API exported in the stm32f769i_discovery_audio.h file
Jerome Coutant 0:c0f3bbab73d2 86 (BSP_AUDIO_OUT_Init(), BSP_AUDIO_OUT_Play() ...)
Jerome Coutant 0:c0f3bbab73d2 87 + This driver provide also the Media Access Layer (MAL): which consists of functions allowing to access the media containing/
Jerome Coutant 0:c0f3bbab73d2 88 providing the audio file/stream. These functions are also included as local functions into
Jerome Coutant 0:c0f3bbab73d2 89 the stm32f769i_discovery_audio.c file (DFSDMx_Init(), DFSDMx_DeInit(), SAIx_Init() and SAIx_DeInit())
Jerome Coutant 0:c0f3bbab73d2 90
Jerome Coutant 0:c0f3bbab73d2 91 Known Limitations:
Jerome Coutant 0:c0f3bbab73d2 92 ------------------
Jerome Coutant 0:c0f3bbab73d2 93 1- If the TDM Format used to play in parallel 2 audio Stream (the first Stream is configured in codec SLOT0 and second
Jerome Coutant 0:c0f3bbab73d2 94 Stream in SLOT1) the Pause/Resume, volume and mute feature will control the both streams.
Jerome Coutant 0:c0f3bbab73d2 95 2- Parsing of audio file is not implemented (in order to determine audio file properties: Mono/Stereo, Data size,
Jerome Coutant 0:c0f3bbab73d2 96 File size, Audio Frequency, Audio Data header size ...). The configuration is fixed for the given audio file.
Jerome Coutant 0:c0f3bbab73d2 97 3- Supports only Stereo audio streaming.
Jerome Coutant 0:c0f3bbab73d2 98 4- Supports only 16-bits audio data size.
Jerome Coutant 0:c0f3bbab73d2 99 @endverbatim
Jerome Coutant 0:c0f3bbab73d2 100 ******************************************************************************
Jerome Coutant 0:c0f3bbab73d2 101 * @attention
Jerome Coutant 0:c0f3bbab73d2 102 *
Jerome Coutant 0:c0f3bbab73d2 103 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
Jerome Coutant 0:c0f3bbab73d2 104 *
Jerome Coutant 0:c0f3bbab73d2 105 * Redistribution and use in source and binary forms, with or without modification,
Jerome Coutant 0:c0f3bbab73d2 106 * are permitted provided that the following conditions are met:
Jerome Coutant 0:c0f3bbab73d2 107 * 1. Redistributions of source code must retain the above copyright notice,
Jerome Coutant 0:c0f3bbab73d2 108 * this list of conditions and the following disclaimer.
Jerome Coutant 0:c0f3bbab73d2 109 * 2. Redistributions in binary form must reproduce the above copyright notice,
Jerome Coutant 0:c0f3bbab73d2 110 * this list of conditions and the following disclaimer in the documentation
Jerome Coutant 0:c0f3bbab73d2 111 * and/or other materials provided with the distribution.
Jerome Coutant 0:c0f3bbab73d2 112 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Jerome Coutant 0:c0f3bbab73d2 113 * may be used to endorse or promote products derived from this software
Jerome Coutant 0:c0f3bbab73d2 114 * without specific prior written permission.
Jerome Coutant 0:c0f3bbab73d2 115 *
Jerome Coutant 0:c0f3bbab73d2 116 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Jerome Coutant 0:c0f3bbab73d2 117 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Jerome Coutant 0:c0f3bbab73d2 118 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Jerome Coutant 0:c0f3bbab73d2 119 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Jerome Coutant 0:c0f3bbab73d2 120 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Jerome Coutant 0:c0f3bbab73d2 121 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Jerome Coutant 0:c0f3bbab73d2 122 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Jerome Coutant 0:c0f3bbab73d2 123 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Jerome Coutant 0:c0f3bbab73d2 124 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Jerome Coutant 0:c0f3bbab73d2 125 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Jerome Coutant 0:c0f3bbab73d2 126 *
Jerome Coutant 0:c0f3bbab73d2 127 ******************************************************************************
Jerome Coutant 0:c0f3bbab73d2 128 */
Jerome Coutant 0:c0f3bbab73d2 129 /* Includes ------------------------------------------------------------------*/
Jerome Coutant 0:c0f3bbab73d2 130 #include "stm32f769i_discovery_audio.h"
Jerome Coutant 0:c0f3bbab73d2 131
Jerome Coutant 0:c0f3bbab73d2 132 /** @addtogroup BSP
Jerome Coutant 0:c0f3bbab73d2 133 * @{
Jerome Coutant 0:c0f3bbab73d2 134 */
Jerome Coutant 0:c0f3bbab73d2 135
Jerome Coutant 0:c0f3bbab73d2 136 /** @addtogroup STM32F769I_DISCOVERY
Jerome Coutant 0:c0f3bbab73d2 137 * @{
Jerome Coutant 0:c0f3bbab73d2 138 */
Jerome Coutant 0:c0f3bbab73d2 139
Jerome Coutant 1:3e58f8a39705 140 /** @defgroup STM32F769I_DISCOVERY_AUDIO STM32F769I_DISCOVERY AUDIO
Jerome Coutant 0:c0f3bbab73d2 141 * @brief This file includes the low layer driver for wm8994 Audio Codec
Jerome Coutant 0:c0f3bbab73d2 142 * available on STM32F769I-DISCOVERY discoveryuation board(MB1225).
Jerome Coutant 0:c0f3bbab73d2 143 * @{
Jerome Coutant 0:c0f3bbab73d2 144 */
Jerome Coutant 0:c0f3bbab73d2 145
Jerome Coutant 0:c0f3bbab73d2 146 /** @defgroup STM32F769I_DISCOVERY_AUDIO_Private_Types STM32F769I_DISCOVERY_AUDIO Private Types
Jerome Coutant 0:c0f3bbab73d2 147 * @{
Jerome Coutant 0:c0f3bbab73d2 148 */
Jerome Coutant 0:c0f3bbab73d2 149 typedef struct
Jerome Coutant 0:c0f3bbab73d2 150 {
Jerome Coutant 0:c0f3bbab73d2 151 uint16_t *pRecBuf; /* Pointer to record user buffer */
Jerome Coutant 0:c0f3bbab73d2 152 uint32_t RecSize; /* Size to record in mono, double size to record in stereo */
Jerome Coutant 0:c0f3bbab73d2 153 }AUDIOIN_TypeDef;
Jerome Coutant 0:c0f3bbab73d2 154
Jerome Coutant 0:c0f3bbab73d2 155 /**
Jerome Coutant 0:c0f3bbab73d2 156 * @}
Jerome Coutant 0:c0f3bbab73d2 157 */
Jerome Coutant 0:c0f3bbab73d2 158
Jerome Coutant 0:c0f3bbab73d2 159 /** @defgroup STM32F769I_DISCOVERY_AUDIO_Private_Defines STM32F769I_DISCOVERY_AUDIO Private Defines
Jerome Coutant 0:c0f3bbab73d2 160 * @{
Jerome Coutant 0:c0f3bbab73d2 161 */
Jerome Coutant 0:c0f3bbab73d2 162 /**
Jerome Coutant 0:c0f3bbab73d2 163 * @}
Jerome Coutant 0:c0f3bbab73d2 164 */
Jerome Coutant 0:c0f3bbab73d2 165
Jerome Coutant 0:c0f3bbab73d2 166 /** @defgroup STM32F769I_DISCOVERY_AUDIO_Private_Macros STM32F769I_DISCOVERY_AUDIO Private Macros
Jerome Coutant 0:c0f3bbab73d2 167 * @{
Jerome Coutant 0:c0f3bbab73d2 168 */
Jerome Coutant 0:c0f3bbab73d2 169 /*### RECORD ###*/
Jerome Coutant 0:c0f3bbab73d2 170 #define DFSDM_OVER_SAMPLING(__FREQUENCY__) \
Jerome Coutant 0:c0f3bbab73d2 171 (__FREQUENCY__ == AUDIO_FREQUENCY_8K) ? 256 \
Jerome Coutant 0:c0f3bbab73d2 172 : (__FREQUENCY__ == AUDIO_FREQUENCY_11K) ? 256 \
Jerome Coutant 0:c0f3bbab73d2 173 : (__FREQUENCY__ == AUDIO_FREQUENCY_16K) ? 128 \
Jerome Coutant 0:c0f3bbab73d2 174 : (__FREQUENCY__ == AUDIO_FREQUENCY_22K) ? 128 \
Jerome Coutant 0:c0f3bbab73d2 175 : (__FREQUENCY__ == AUDIO_FREQUENCY_32K) ? 64 \
Jerome Coutant 0:c0f3bbab73d2 176 : (__FREQUENCY__ == AUDIO_FREQUENCY_44K) ? 64 \
Jerome Coutant 0:c0f3bbab73d2 177 : (__FREQUENCY__ == AUDIO_FREQUENCY_48K) ? 40 : 20 \
Jerome Coutant 0:c0f3bbab73d2 178
Jerome Coutant 0:c0f3bbab73d2 179 #define DFSDM_CLOCK_DIVIDER(__FREQUENCY__) \
Jerome Coutant 0:c0f3bbab73d2 180 (__FREQUENCY__ == AUDIO_FREQUENCY_8K) ? 24 \
Jerome Coutant 0:c0f3bbab73d2 181 : (__FREQUENCY__ == AUDIO_FREQUENCY_11K) ? 4 \
Jerome Coutant 0:c0f3bbab73d2 182 : (__FREQUENCY__ == AUDIO_FREQUENCY_16K) ? 24 \
Jerome Coutant 0:c0f3bbab73d2 183 : (__FREQUENCY__ == AUDIO_FREQUENCY_22K) ? 4 \
Jerome Coutant 0:c0f3bbab73d2 184 : (__FREQUENCY__ == AUDIO_FREQUENCY_32K) ? 24 \
Jerome Coutant 0:c0f3bbab73d2 185 : (__FREQUENCY__ == AUDIO_FREQUENCY_44K) ? 4 \
Jerome Coutant 0:c0f3bbab73d2 186 : (__FREQUENCY__ == AUDIO_FREQUENCY_48K) ? 25 : 25 \
Jerome Coutant 0:c0f3bbab73d2 187
Jerome Coutant 0:c0f3bbab73d2 188 #define DFSDM_FILTER_ORDER(__FREQUENCY__) \
Jerome Coutant 0:c0f3bbab73d2 189 (__FREQUENCY__ == AUDIO_FREQUENCY_8K) ? DFSDM_FILTER_SINC3_ORDER \
Jerome Coutant 0:c0f3bbab73d2 190 : (__FREQUENCY__ == AUDIO_FREQUENCY_11K) ? DFSDM_FILTER_SINC3_ORDER \
Jerome Coutant 0:c0f3bbab73d2 191 : (__FREQUENCY__ == AUDIO_FREQUENCY_16K) ? DFSDM_FILTER_SINC3_ORDER \
Jerome Coutant 0:c0f3bbab73d2 192 : (__FREQUENCY__ == AUDIO_FREQUENCY_22K) ? DFSDM_FILTER_SINC3_ORDER \
Jerome Coutant 0:c0f3bbab73d2 193 : (__FREQUENCY__ == AUDIO_FREQUENCY_32K) ? DFSDM_FILTER_SINC4_ORDER \
Jerome Coutant 0:c0f3bbab73d2 194 : (__FREQUENCY__ == AUDIO_FREQUENCY_44K) ? DFSDM_FILTER_SINC3_ORDER \
Jerome Coutant 0:c0f3bbab73d2 195 : (__FREQUENCY__ == AUDIO_FREQUENCY_48K) ? DFSDM_FILTER_SINC3_ORDER : DFSDM_FILTER_SINC5_ORDER \
Jerome Coutant 0:c0f3bbab73d2 196
Jerome Coutant 0:c0f3bbab73d2 197 #define DFSDM_RIGHT_BIT_SHIFT(__FREQUENCY__) \
Jerome Coutant 0:c0f3bbab73d2 198 (__FREQUENCY__ == AUDIO_FREQUENCY_8K) ? 8 \
Jerome Coutant 0:c0f3bbab73d2 199 : (__FREQUENCY__ == AUDIO_FREQUENCY_11K) ? 8 \
Jerome Coutant 0:c0f3bbab73d2 200 : (__FREQUENCY__ == AUDIO_FREQUENCY_16K) ? 3 \
Jerome Coutant 0:c0f3bbab73d2 201 : (__FREQUENCY__ == AUDIO_FREQUENCY_22K) ? 4 \
Jerome Coutant 0:c0f3bbab73d2 202 : (__FREQUENCY__ == AUDIO_FREQUENCY_32K) ? 7 \
Jerome Coutant 0:c0f3bbab73d2 203 : (__FREQUENCY__ == AUDIO_FREQUENCY_44K) ? 0 \
Jerome Coutant 0:c0f3bbab73d2 204 : (__FREQUENCY__ == AUDIO_FREQUENCY_48K) ? 0 : 4 \
Jerome Coutant 0:c0f3bbab73d2 205
Jerome Coutant 0:c0f3bbab73d2 206 /* Saturate the record PCM sample */
Jerome Coutant 0:c0f3bbab73d2 207 #define SaturaLH(N, L, H) (((N)<(L))?(L):(((N)>(H))?(H):(N)))
Jerome Coutant 0:c0f3bbab73d2 208 /**
Jerome Coutant 0:c0f3bbab73d2 209 * @}
Jerome Coutant 0:c0f3bbab73d2 210 */
Jerome Coutant 0:c0f3bbab73d2 211
Jerome Coutant 0:c0f3bbab73d2 212 /** @defgroup STM32F769I_DISCOVERY_AUDIO_Private_Variables STM32F769I_DISCOVERY_AUDIO Private Variables
Jerome Coutant 0:c0f3bbab73d2 213 * @{
Jerome Coutant 0:c0f3bbab73d2 214 */
Jerome Coutant 0:c0f3bbab73d2 215 /* PLAY */
Jerome Coutant 0:c0f3bbab73d2 216 AUDIO_DrvTypeDef *audio_drv;
Jerome Coutant 0:c0f3bbab73d2 217 SAI_HandleTypeDef haudio_out_sai;
Jerome Coutant 0:c0f3bbab73d2 218 SAI_HandleTypeDef haudio_in_sai;
Jerome Coutant 0:c0f3bbab73d2 219
Jerome Coutant 0:c0f3bbab73d2 220 /* RECORD */
Jerome Coutant 0:c0f3bbab73d2 221 AUDIOIN_TypeDef hAudioIn;
Jerome Coutant 0:c0f3bbab73d2 222
Jerome Coutant 0:c0f3bbab73d2 223 DFSDM_Channel_HandleTypeDef hAudioInTopLeftChannel;
Jerome Coutant 0:c0f3bbab73d2 224 DFSDM_Channel_HandleTypeDef hAudioInTopRightChannel;
Jerome Coutant 0:c0f3bbab73d2 225 DFSDM_Filter_HandleTypeDef hAudioInTopLeftFilter;
Jerome Coutant 0:c0f3bbab73d2 226 DFSDM_Filter_HandleTypeDef hAudioInTopRightFilter;
Jerome Coutant 0:c0f3bbab73d2 227 DMA_HandleTypeDef hDmaTopLeft;
Jerome Coutant 0:c0f3bbab73d2 228 DMA_HandleTypeDef hDmaTopRight;
Jerome Coutant 0:c0f3bbab73d2 229
Jerome Coutant 0:c0f3bbab73d2 230 DFSDM_Channel_HandleTypeDef hAudioInButtomLeftChannel;
Jerome Coutant 0:c0f3bbab73d2 231 DFSDM_Channel_HandleTypeDef hAudioInButtomRightChannel;
Jerome Coutant 0:c0f3bbab73d2 232 DFSDM_Filter_HandleTypeDef hAudioInButtomLeftFilter;
Jerome Coutant 0:c0f3bbab73d2 233 DFSDM_Filter_HandleTypeDef hAudioInButtomRightFilter;
Jerome Coutant 0:c0f3bbab73d2 234 DMA_HandleTypeDef hDmaButtomLeft;
Jerome Coutant 0:c0f3bbab73d2 235 DMA_HandleTypeDef hDmaButtomRight;
Jerome Coutant 0:c0f3bbab73d2 236
Jerome Coutant 0:c0f3bbab73d2 237 /* Buffers for right and left samples */
Jerome Coutant 0:c0f3bbab73d2 238 static int32_t *pScratchBuff[2*DEFAULT_AUDIO_IN_CHANNEL_NBR];
Jerome Coutant 0:c0f3bbab73d2 239 static __IO int32_t ScratchSize;
Jerome Coutant 0:c0f3bbab73d2 240 /* Cannel number to be used: 2 channels by default */
Jerome Coutant 0:c0f3bbab73d2 241 static uint8_t AudioIn_ChannelNumber = DEFAULT_AUDIO_IN_CHANNEL_NBR;
Jerome Coutant 0:c0f3bbab73d2 242 /* Input device to be used: digital microphones by default */
Jerome Coutant 0:c0f3bbab73d2 243 static uint16_t AudioIn_Device = INPUT_DEVICE_DIGITAL_MIC;
Jerome Coutant 0:c0f3bbab73d2 244
Jerome Coutant 0:c0f3bbab73d2 245 /* Buffers status flags */
Jerome Coutant 0:c0f3bbab73d2 246 static uint32_t DmaTopLeftRecHalfCplt = 0;
Jerome Coutant 0:c0f3bbab73d2 247 static uint32_t DmaTopLeftRecCplt = 0;
Jerome Coutant 0:c0f3bbab73d2 248 static uint32_t DmaTopRightRecHalfCplt = 0;
Jerome Coutant 0:c0f3bbab73d2 249 static uint32_t DmaTopRightRecCplt = 0;
Jerome Coutant 0:c0f3bbab73d2 250 static uint32_t DmaButtomLeftRecHalfCplt = 0;
Jerome Coutant 0:c0f3bbab73d2 251 static uint32_t DmaButtomLeftRecCplt = 0;
Jerome Coutant 0:c0f3bbab73d2 252 static uint32_t DmaButtomRightRecHalfCplt = 0;
Jerome Coutant 0:c0f3bbab73d2 253 static uint32_t DmaButtomRightRecCplt = 0;
Jerome Coutant 0:c0f3bbab73d2 254
Jerome Coutant 0:c0f3bbab73d2 255 /* Application Buffer Trigger */
Jerome Coutant 0:c0f3bbab73d2 256 static __IO uint32_t AppBuffTrigger = 0;
Jerome Coutant 0:c0f3bbab73d2 257 static __IO uint32_t AppBuffHalf = 0;
Jerome Coutant 0:c0f3bbab73d2 258
Jerome Coutant 0:c0f3bbab73d2 259 /**
Jerome Coutant 0:c0f3bbab73d2 260 * @}
Jerome Coutant 0:c0f3bbab73d2 261 */
Jerome Coutant 0:c0f3bbab73d2 262
Jerome Coutant 0:c0f3bbab73d2 263 /** @defgroup STM32F769I_DISCOVERY_AUDIO_Private_Function_Prototypes STM32F769I_DISCOVERY_AUDIO Private Function Prototypes
Jerome Coutant 0:c0f3bbab73d2 264 * @{
Jerome Coutant 0:c0f3bbab73d2 265 */
Jerome Coutant 0:c0f3bbab73d2 266 static void SAIx_Out_Init(uint32_t AudioFreq);
Jerome Coutant 0:c0f3bbab73d2 267 static void SAIx_Out_DeInit(void);
Jerome Coutant 0:c0f3bbab73d2 268 static void SAI_AUDIO_IN_MspInit(SAI_HandleTypeDef *hsai, void *Params);
Jerome Coutant 0:c0f3bbab73d2 269 static void SAI_AUDIO_IN_MspDeInit(SAI_HandleTypeDef *hsai, void *Params);
Jerome Coutant 0:c0f3bbab73d2 270 static void SAIx_In_Init(uint32_t AudioFreq);
Jerome Coutant 0:c0f3bbab73d2 271 static void SAIx_In_DeInit(void);
Jerome Coutant 0:c0f3bbab73d2 272 static void DFSDMx_ChannelMspInit(void);
Jerome Coutant 0:c0f3bbab73d2 273 static void DFSDMx_FilterMspInit(void);
Jerome Coutant 0:c0f3bbab73d2 274 static void DFSDMx_ChannelMspDeInit(void);
Jerome Coutant 0:c0f3bbab73d2 275 static void DFSDMx_FilterMspDeInit(void);
Jerome Coutant 0:c0f3bbab73d2 276 static uint8_t DFSDMx_Init(uint32_t AudioFreq);
Jerome Coutant 0:c0f3bbab73d2 277 static uint8_t DFSDMx_DeInit(void);
Jerome Coutant 0:c0f3bbab73d2 278
Jerome Coutant 0:c0f3bbab73d2 279 /**
Jerome Coutant 0:c0f3bbab73d2 280 * @}
Jerome Coutant 0:c0f3bbab73d2 281 */
Jerome Coutant 0:c0f3bbab73d2 282
Jerome Coutant 0:c0f3bbab73d2 283 /** @defgroup STM32F769I_DISCOVERY_AUDIO_out_Private_Functions STM32F769I_DISCOVERY_AUDIO_Out Private Functions
Jerome Coutant 0:c0f3bbab73d2 284 * @{
Jerome Coutant 0:c0f3bbab73d2 285 */
Jerome Coutant 0:c0f3bbab73d2 286
Jerome Coutant 0:c0f3bbab73d2 287 /**
Jerome Coutant 0:c0f3bbab73d2 288 * @brief Configures the audio peripherals.
Jerome Coutant 0:c0f3bbab73d2 289 * @param OutputDevice: OUTPUT_DEVICE_SPEAKER, OUTPUT_DEVICE_HEADPHONE,
Jerome Coutant 0:c0f3bbab73d2 290 * or OUTPUT_DEVICE_BOTH.
Jerome Coutant 0:c0f3bbab73d2 291 * @param Volume: Initial volume level (from 0 (Mute) to 100 (Max))
Jerome Coutant 0:c0f3bbab73d2 292 * @param AudioFreq: Audio frequency used to play the audio stream.
Jerome Coutant 0:c0f3bbab73d2 293 * @retval AUDIO_OK if correct communication, else wrong communication
Jerome Coutant 0:c0f3bbab73d2 294 */
Jerome Coutant 0:c0f3bbab73d2 295 uint8_t BSP_AUDIO_OUT_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq)
Jerome Coutant 0:c0f3bbab73d2 296 {
Jerome Coutant 0:c0f3bbab73d2 297 uint8_t ret = AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 298 uint32_t deviceid = 0x00;
Jerome Coutant 0:c0f3bbab73d2 299
Jerome Coutant 0:c0f3bbab73d2 300 /* Disable SAI */
Jerome Coutant 0:c0f3bbab73d2 301 SAIx_Out_DeInit();
Jerome Coutant 0:c0f3bbab73d2 302
Jerome Coutant 0:c0f3bbab73d2 303 /* PLL clock is set depending by the AudioFreq (44.1khz vs 48khz groups) */
Jerome Coutant 0:c0f3bbab73d2 304 BSP_AUDIO_OUT_ClockConfig(&haudio_out_sai, AudioFreq, NULL);
Jerome Coutant 0:c0f3bbab73d2 305
Jerome Coutant 0:c0f3bbab73d2 306 /* SAI data transfer preparation:
Jerome Coutant 0:c0f3bbab73d2 307 Prepare the Media to be used for the audio transfer from memory to SAI peripheral */
Jerome Coutant 0:c0f3bbab73d2 308 haudio_out_sai.Instance = AUDIO_OUT_SAIx;
Jerome Coutant 0:c0f3bbab73d2 309 if(HAL_SAI_GetState(&haudio_out_sai) == HAL_SAI_STATE_RESET)
Jerome Coutant 0:c0f3bbab73d2 310 {
Jerome Coutant 0:c0f3bbab73d2 311 /* Init the SAI MSP: this __weak function can be redefined by the application*/
Jerome Coutant 0:c0f3bbab73d2 312 BSP_AUDIO_OUT_MspInit(&haudio_out_sai, NULL);
Jerome Coutant 0:c0f3bbab73d2 313 }
Jerome Coutant 0:c0f3bbab73d2 314 SAIx_Out_Init(AudioFreq);
Jerome Coutant 0:c0f3bbab73d2 315
Jerome Coutant 0:c0f3bbab73d2 316 /* wm8994 codec initialization */
Jerome Coutant 0:c0f3bbab73d2 317 deviceid = wm8994_drv.ReadID(AUDIO_I2C_ADDRESS);
Jerome Coutant 0:c0f3bbab73d2 318
Jerome Coutant 0:c0f3bbab73d2 319 if((deviceid) == WM8994_ID)
Jerome Coutant 0:c0f3bbab73d2 320 {
Jerome Coutant 0:c0f3bbab73d2 321 /* Reset the Codec Registers */
Jerome Coutant 0:c0f3bbab73d2 322 wm8994_drv.Reset(AUDIO_I2C_ADDRESS);
Jerome Coutant 0:c0f3bbab73d2 323 /* Initialize the audio driver structure */
Jerome Coutant 0:c0f3bbab73d2 324 audio_drv = &wm8994_drv;
Jerome Coutant 0:c0f3bbab73d2 325 ret = AUDIO_OK;
Jerome Coutant 0:c0f3bbab73d2 326 }
Jerome Coutant 0:c0f3bbab73d2 327 else
Jerome Coutant 0:c0f3bbab73d2 328 {
Jerome Coutant 0:c0f3bbab73d2 329 ret = AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 330 }
Jerome Coutant 0:c0f3bbab73d2 331
Jerome Coutant 0:c0f3bbab73d2 332 if(ret == AUDIO_OK)
Jerome Coutant 0:c0f3bbab73d2 333 {
Jerome Coutant 0:c0f3bbab73d2 334 /* Initialize the codec internal registers */
Jerome Coutant 0:c0f3bbab73d2 335 audio_drv->Init(AUDIO_I2C_ADDRESS, OutputDevice, Volume, AudioFreq);
Jerome Coutant 0:c0f3bbab73d2 336 }
Jerome Coutant 0:c0f3bbab73d2 337
Jerome Coutant 0:c0f3bbab73d2 338 return ret;
Jerome Coutant 0:c0f3bbab73d2 339 }
Jerome Coutant 0:c0f3bbab73d2 340
Jerome Coutant 0:c0f3bbab73d2 341 /**
Jerome Coutant 0:c0f3bbab73d2 342 * @brief Starts playing audio stream from a data buffer for a determined size.
Jerome Coutant 0:c0f3bbab73d2 343 * @param pBuffer: Pointer to the buffer
Jerome Coutant 0:c0f3bbab73d2 344 * @param Size: Number of audio data BYTES.
Jerome Coutant 0:c0f3bbab73d2 345 * @retval AUDIO_OK if correct communication, else wrong communication
Jerome Coutant 0:c0f3bbab73d2 346 */
Jerome Coutant 0:c0f3bbab73d2 347 uint8_t BSP_AUDIO_OUT_Play(uint16_t* pBuffer, uint32_t Size)
Jerome Coutant 0:c0f3bbab73d2 348 {
Jerome Coutant 0:c0f3bbab73d2 349 /* Call the audio Codec Play function */
Jerome Coutant 0:c0f3bbab73d2 350 if(audio_drv->Play(AUDIO_I2C_ADDRESS, (uint16_t *)pBuffer, Size) != 0)
Jerome Coutant 0:c0f3bbab73d2 351 {
Jerome Coutant 0:c0f3bbab73d2 352 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 353 }
Jerome Coutant 0:c0f3bbab73d2 354 else
Jerome Coutant 0:c0f3bbab73d2 355 {
Jerome Coutant 0:c0f3bbab73d2 356 /* Update the Media layer and enable it for play */
Jerome Coutant 0:c0f3bbab73d2 357 HAL_SAI_Transmit_DMA(&haudio_out_sai, (uint8_t*) pBuffer, DMA_MAX(Size / AUDIODATA_SIZE));
Jerome Coutant 0:c0f3bbab73d2 358
Jerome Coutant 0:c0f3bbab73d2 359 return AUDIO_OK;
Jerome Coutant 0:c0f3bbab73d2 360 }
Jerome Coutant 0:c0f3bbab73d2 361 }
Jerome Coutant 0:c0f3bbab73d2 362
Jerome Coutant 0:c0f3bbab73d2 363 /**
Jerome Coutant 0:c0f3bbab73d2 364 * @brief Sends n-Bytes on the SAI interface.
Jerome Coutant 0:c0f3bbab73d2 365 * @param pData: pointer on data address
Jerome Coutant 0:c0f3bbab73d2 366 * @param Size: number of data to be written
Jerome Coutant 0:c0f3bbab73d2 367 * @retval None
Jerome Coutant 0:c0f3bbab73d2 368 */
Jerome Coutant 0:c0f3bbab73d2 369 void BSP_AUDIO_OUT_ChangeBuffer(uint16_t *pData, uint16_t Size)
Jerome Coutant 0:c0f3bbab73d2 370 {
Jerome Coutant 0:c0f3bbab73d2 371 HAL_SAI_Transmit_DMA(&haudio_out_sai, (uint8_t*) pData, Size);
Jerome Coutant 0:c0f3bbab73d2 372 }
Jerome Coutant 0:c0f3bbab73d2 373
Jerome Coutant 0:c0f3bbab73d2 374 /**
Jerome Coutant 0:c0f3bbab73d2 375 * @brief This function Pauses the audio file stream. In case
Jerome Coutant 0:c0f3bbab73d2 376 * of using DMA, the DMA Pause feature is used.
Jerome Coutant 1:3e58f8a39705 377 * @note When calling BSP_AUDIO_OUT_Pause() function for pause, only
Jerome Coutant 0:c0f3bbab73d2 378 * BSP_AUDIO_OUT_Resume() function should be called for resume (use of BSP_AUDIO_OUT_Play()
Jerome Coutant 0:c0f3bbab73d2 379 * function for resume could lead to unexpected behaviour).
Jerome Coutant 0:c0f3bbab73d2 380 * @retval AUDIO_OK if correct communication, else wrong communication
Jerome Coutant 0:c0f3bbab73d2 381 */
Jerome Coutant 0:c0f3bbab73d2 382 uint8_t BSP_AUDIO_OUT_Pause(void)
Jerome Coutant 0:c0f3bbab73d2 383 {
Jerome Coutant 0:c0f3bbab73d2 384 /* Call the Audio Codec Pause/Resume function */
Jerome Coutant 0:c0f3bbab73d2 385 if(audio_drv->Pause(AUDIO_I2C_ADDRESS) != 0)
Jerome Coutant 0:c0f3bbab73d2 386 {
Jerome Coutant 0:c0f3bbab73d2 387 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 388 }
Jerome Coutant 0:c0f3bbab73d2 389 else
Jerome Coutant 0:c0f3bbab73d2 390 {
Jerome Coutant 0:c0f3bbab73d2 391 /* Call the Media layer pause function */
Jerome Coutant 0:c0f3bbab73d2 392 HAL_SAI_DMAPause(&haudio_out_sai);
Jerome Coutant 0:c0f3bbab73d2 393
Jerome Coutant 0:c0f3bbab73d2 394 /* Return AUDIO_OK when all operations are correctly done */
Jerome Coutant 0:c0f3bbab73d2 395 return AUDIO_OK;
Jerome Coutant 0:c0f3bbab73d2 396 }
Jerome Coutant 0:c0f3bbab73d2 397 }
Jerome Coutant 0:c0f3bbab73d2 398
Jerome Coutant 0:c0f3bbab73d2 399 /**
Jerome Coutant 0:c0f3bbab73d2 400 * @brief Resumes the audio file stream.
Jerome Coutant 1:3e58f8a39705 401 * @note When calling BSP_AUDIO_OUT_Pause() function for pause, only
Jerome Coutant 0:c0f3bbab73d2 402 * BSP_AUDIO_OUT_Resume() function should be called for resume (use of BSP_AUDIO_OUT_Play()
Jerome Coutant 0:c0f3bbab73d2 403 * function for resume could lead to unexpected behaviour).
Jerome Coutant 0:c0f3bbab73d2 404 * @retval AUDIO_OK if correct communication, else wrong communication
Jerome Coutant 0:c0f3bbab73d2 405 */
Jerome Coutant 0:c0f3bbab73d2 406 uint8_t BSP_AUDIO_OUT_Resume(void)
Jerome Coutant 0:c0f3bbab73d2 407 {
Jerome Coutant 0:c0f3bbab73d2 408 /* Call the Audio Codec Pause/Resume function */
Jerome Coutant 0:c0f3bbab73d2 409 if(audio_drv->Resume(AUDIO_I2C_ADDRESS) != 0)
Jerome Coutant 0:c0f3bbab73d2 410 {
Jerome Coutant 0:c0f3bbab73d2 411 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 412 }
Jerome Coutant 0:c0f3bbab73d2 413 else
Jerome Coutant 0:c0f3bbab73d2 414 {
Jerome Coutant 0:c0f3bbab73d2 415 /* Call the Media layer pause/resume function */
Jerome Coutant 0:c0f3bbab73d2 416 HAL_SAI_DMAResume(&haudio_out_sai);
Jerome Coutant 0:c0f3bbab73d2 417
Jerome Coutant 0:c0f3bbab73d2 418 /* Return AUDIO_OK when all operations are correctly done */
Jerome Coutant 0:c0f3bbab73d2 419 return AUDIO_OK;
Jerome Coutant 0:c0f3bbab73d2 420 }
Jerome Coutant 0:c0f3bbab73d2 421 }
Jerome Coutant 0:c0f3bbab73d2 422
Jerome Coutant 0:c0f3bbab73d2 423 /**
Jerome Coutant 0:c0f3bbab73d2 424 * @brief Stops audio playing and Power down the Audio Codec.
Jerome Coutant 0:c0f3bbab73d2 425 * @param Option: could be one of the following parameters
Jerome Coutant 0:c0f3bbab73d2 426 * - CODEC_PDWN_SW: for software power off (by writing registers).
Jerome Coutant 0:c0f3bbab73d2 427 * Then no need to reconfigure the Codec after power on.
Jerome Coutant 0:c0f3bbab73d2 428 * - CODEC_PDWN_HW: completely shut down the codec (physically).
Jerome Coutant 0:c0f3bbab73d2 429 * Then need to reconfigure the Codec after power on.
Jerome Coutant 0:c0f3bbab73d2 430 * @retval AUDIO_OK if correct communication, else wrong communication
Jerome Coutant 0:c0f3bbab73d2 431 */
Jerome Coutant 0:c0f3bbab73d2 432 uint8_t BSP_AUDIO_OUT_Stop(uint32_t Option)
Jerome Coutant 0:c0f3bbab73d2 433 {
Jerome Coutant 0:c0f3bbab73d2 434 /* Call the Media layer stop function */
Jerome Coutant 0:c0f3bbab73d2 435 HAL_SAI_DMAStop(&haudio_out_sai);
Jerome Coutant 0:c0f3bbab73d2 436
Jerome Coutant 0:c0f3bbab73d2 437 /* Call Audio Codec Stop function */
Jerome Coutant 0:c0f3bbab73d2 438 if(audio_drv->Stop(AUDIO_I2C_ADDRESS, Option) != 0)
Jerome Coutant 0:c0f3bbab73d2 439 {
Jerome Coutant 0:c0f3bbab73d2 440 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 441 }
Jerome Coutant 0:c0f3bbab73d2 442 else
Jerome Coutant 0:c0f3bbab73d2 443 {
Jerome Coutant 0:c0f3bbab73d2 444 if(Option == CODEC_PDWN_HW)
Jerome Coutant 0:c0f3bbab73d2 445 {
Jerome Coutant 0:c0f3bbab73d2 446 /* Wait at least 100us */
Jerome Coutant 0:c0f3bbab73d2 447 HAL_Delay(1);
Jerome Coutant 0:c0f3bbab73d2 448 }
Jerome Coutant 0:c0f3bbab73d2 449 /* Return AUDIO_OK when all operations are correctly done */
Jerome Coutant 0:c0f3bbab73d2 450 return AUDIO_OK;
Jerome Coutant 0:c0f3bbab73d2 451 }
Jerome Coutant 0:c0f3bbab73d2 452 }
Jerome Coutant 0:c0f3bbab73d2 453
Jerome Coutant 0:c0f3bbab73d2 454 /**
Jerome Coutant 0:c0f3bbab73d2 455 * @brief Controls the current audio volume level.
Jerome Coutant 0:c0f3bbab73d2 456 * @param Volume: Volume level to be set in percentage from 0% to 100% (0 for
Jerome Coutant 0:c0f3bbab73d2 457 * Mute and 100 for Max volume level).
Jerome Coutant 0:c0f3bbab73d2 458 * @retval AUDIO_OK if correct communication, else wrong communication
Jerome Coutant 0:c0f3bbab73d2 459 */
Jerome Coutant 0:c0f3bbab73d2 460 uint8_t BSP_AUDIO_OUT_SetVolume(uint8_t Volume)
Jerome Coutant 0:c0f3bbab73d2 461 {
Jerome Coutant 0:c0f3bbab73d2 462 /* Call the codec volume control function with converted volume value */
Jerome Coutant 0:c0f3bbab73d2 463 if(audio_drv->SetVolume(AUDIO_I2C_ADDRESS, Volume) != 0)
Jerome Coutant 0:c0f3bbab73d2 464 {
Jerome Coutant 0:c0f3bbab73d2 465 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 466 }
Jerome Coutant 0:c0f3bbab73d2 467 else
Jerome Coutant 0:c0f3bbab73d2 468 {
Jerome Coutant 0:c0f3bbab73d2 469 /* Return AUDIO_OK when all operations are correctly done */
Jerome Coutant 0:c0f3bbab73d2 470 return AUDIO_OK;
Jerome Coutant 0:c0f3bbab73d2 471 }
Jerome Coutant 0:c0f3bbab73d2 472 }
Jerome Coutant 0:c0f3bbab73d2 473
Jerome Coutant 0:c0f3bbab73d2 474 /**
Jerome Coutant 0:c0f3bbab73d2 475 * @brief Enables or disables the MUTE mode by software
Jerome Coutant 0:c0f3bbab73d2 476 * @param Cmd: Could be AUDIO_MUTE_ON to mute sound or AUDIO_MUTE_OFF to
Jerome Coutant 0:c0f3bbab73d2 477 * unmute the codec and restore previous volume level.
Jerome Coutant 0:c0f3bbab73d2 478 * @retval AUDIO_OK if correct communication, else wrong communication
Jerome Coutant 0:c0f3bbab73d2 479 */
Jerome Coutant 0:c0f3bbab73d2 480 uint8_t BSP_AUDIO_OUT_SetMute(uint32_t Cmd)
Jerome Coutant 0:c0f3bbab73d2 481 {
Jerome Coutant 0:c0f3bbab73d2 482 /* Call the Codec Mute function */
Jerome Coutant 0:c0f3bbab73d2 483 if(audio_drv->SetMute(AUDIO_I2C_ADDRESS, Cmd) != 0)
Jerome Coutant 0:c0f3bbab73d2 484 {
Jerome Coutant 0:c0f3bbab73d2 485 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 486 }
Jerome Coutant 0:c0f3bbab73d2 487 else
Jerome Coutant 0:c0f3bbab73d2 488 {
Jerome Coutant 0:c0f3bbab73d2 489 /* Return AUDIO_OK when all operations are correctly done */
Jerome Coutant 0:c0f3bbab73d2 490 return AUDIO_OK;
Jerome Coutant 0:c0f3bbab73d2 491 }
Jerome Coutant 0:c0f3bbab73d2 492 }
Jerome Coutant 0:c0f3bbab73d2 493
Jerome Coutant 0:c0f3bbab73d2 494 /**
Jerome Coutant 0:c0f3bbab73d2 495 * @brief Switch dynamically (while audio file is played) the output target
Jerome Coutant 0:c0f3bbab73d2 496 * (speaker or headphone).
Jerome Coutant 0:c0f3bbab73d2 497 * @param Output: The audio output target: OUTPUT_DEVICE_SPEAKER,
Jerome Coutant 0:c0f3bbab73d2 498 * OUTPUT_DEVICE_HEADPHONE or OUTPUT_DEVICE_BOTH
Jerome Coutant 0:c0f3bbab73d2 499 * @retval AUDIO_OK if correct communication, else wrong communication
Jerome Coutant 0:c0f3bbab73d2 500 */
Jerome Coutant 0:c0f3bbab73d2 501 uint8_t BSP_AUDIO_OUT_SetOutputMode(uint8_t Output)
Jerome Coutant 0:c0f3bbab73d2 502 {
Jerome Coutant 0:c0f3bbab73d2 503 /* Call the Codec output device function */
Jerome Coutant 0:c0f3bbab73d2 504 if(audio_drv->SetOutputMode(AUDIO_I2C_ADDRESS, Output) != 0)
Jerome Coutant 0:c0f3bbab73d2 505 {
Jerome Coutant 0:c0f3bbab73d2 506 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 507 }
Jerome Coutant 0:c0f3bbab73d2 508 else
Jerome Coutant 0:c0f3bbab73d2 509 {
Jerome Coutant 0:c0f3bbab73d2 510 /* Return AUDIO_OK when all operations are correctly done */
Jerome Coutant 0:c0f3bbab73d2 511 return AUDIO_OK;
Jerome Coutant 0:c0f3bbab73d2 512 }
Jerome Coutant 0:c0f3bbab73d2 513 }
Jerome Coutant 0:c0f3bbab73d2 514
Jerome Coutant 0:c0f3bbab73d2 515 /**
Jerome Coutant 0:c0f3bbab73d2 516 * @brief Updates the audio frequency.
Jerome Coutant 0:c0f3bbab73d2 517 * @param AudioFreq: Audio frequency used to play the audio stream.
Jerome Coutant 0:c0f3bbab73d2 518 * @note This API should be called after the BSP_AUDIO_OUT_Init() to adjust the
Jerome Coutant 0:c0f3bbab73d2 519 * audio frequency.
Jerome Coutant 0:c0f3bbab73d2 520 * @retval None
Jerome Coutant 0:c0f3bbab73d2 521 */
Jerome Coutant 0:c0f3bbab73d2 522 void BSP_AUDIO_OUT_SetFrequency(uint32_t AudioFreq)
Jerome Coutant 0:c0f3bbab73d2 523 {
Jerome Coutant 0:c0f3bbab73d2 524 /* PLL clock is set depending by the AudioFreq (44.1khz vs 48khz groups) */
Jerome Coutant 0:c0f3bbab73d2 525 BSP_AUDIO_OUT_ClockConfig(&haudio_out_sai, AudioFreq, NULL);
Jerome Coutant 0:c0f3bbab73d2 526
Jerome Coutant 0:c0f3bbab73d2 527 /* Disable SAI peripheral to allow access to SAI internal registers */
Jerome Coutant 0:c0f3bbab73d2 528 __HAL_SAI_DISABLE(&haudio_out_sai);
Jerome Coutant 0:c0f3bbab73d2 529
Jerome Coutant 0:c0f3bbab73d2 530 /* Update the SAI audio frequency configuration */
Jerome Coutant 0:c0f3bbab73d2 531 haudio_out_sai.Init.AudioFrequency = AudioFreq;
Jerome Coutant 0:c0f3bbab73d2 532 HAL_SAI_Init(&haudio_out_sai);
Jerome Coutant 0:c0f3bbab73d2 533
Jerome Coutant 0:c0f3bbab73d2 534 /* Enable SAI peripheral to generate MCLK */
Jerome Coutant 0:c0f3bbab73d2 535 __HAL_SAI_ENABLE(&haudio_out_sai);
Jerome Coutant 0:c0f3bbab73d2 536 }
Jerome Coutant 0:c0f3bbab73d2 537
Jerome Coutant 0:c0f3bbab73d2 538 /**
Jerome Coutant 0:c0f3bbab73d2 539 * @brief Updates the Audio frame slot configuration.
Jerome Coutant 0:c0f3bbab73d2 540 * @param AudioFrameSlot: specifies the audio Frame slot
Jerome Coutant 0:c0f3bbab73d2 541 * @note This API should be called after the BSP_AUDIO_OUT_Init() to adjust the
Jerome Coutant 0:c0f3bbab73d2 542 * audio frame slot.
Jerome Coutant 0:c0f3bbab73d2 543 * @retval None
Jerome Coutant 0:c0f3bbab73d2 544 */
Jerome Coutant 0:c0f3bbab73d2 545 void BSP_AUDIO_OUT_SetAudioFrameSlot(uint32_t AudioFrameSlot)
Jerome Coutant 0:c0f3bbab73d2 546 {
Jerome Coutant 0:c0f3bbab73d2 547 /* Disable SAI peripheral to allow access to SAI internal registers */
Jerome Coutant 0:c0f3bbab73d2 548 __HAL_SAI_DISABLE(&haudio_out_sai);
Jerome Coutant 0:c0f3bbab73d2 549
Jerome Coutant 0:c0f3bbab73d2 550 /* Update the SAI audio frame slot configuration */
Jerome Coutant 0:c0f3bbab73d2 551 haudio_out_sai.SlotInit.SlotActive = AudioFrameSlot;
Jerome Coutant 0:c0f3bbab73d2 552 HAL_SAI_Init(&haudio_out_sai);
Jerome Coutant 0:c0f3bbab73d2 553
Jerome Coutant 0:c0f3bbab73d2 554 /* Enable SAI peripheral to generate MCLK */
Jerome Coutant 0:c0f3bbab73d2 555 __HAL_SAI_ENABLE(&haudio_out_sai);
Jerome Coutant 0:c0f3bbab73d2 556 }
Jerome Coutant 0:c0f3bbab73d2 557
Jerome Coutant 0:c0f3bbab73d2 558 /**
Jerome Coutant 0:c0f3bbab73d2 559 * @brief De-initializes the audio out peripheral.
Jerome Coutant 0:c0f3bbab73d2 560 * @retval None
Jerome Coutant 0:c0f3bbab73d2 561 */
Jerome Coutant 0:c0f3bbab73d2 562 void BSP_AUDIO_OUT_DeInit(void)
Jerome Coutant 0:c0f3bbab73d2 563 {
Jerome Coutant 0:c0f3bbab73d2 564 SAIx_Out_DeInit();
Jerome Coutant 0:c0f3bbab73d2 565 /* DeInit the SAI MSP : this __weak function can be rewritten by the application */
Jerome Coutant 0:c0f3bbab73d2 566 BSP_AUDIO_OUT_MspDeInit(&haudio_out_sai, NULL);
Jerome Coutant 0:c0f3bbab73d2 567 }
Jerome Coutant 0:c0f3bbab73d2 568
Jerome Coutant 0:c0f3bbab73d2 569 /**
Jerome Coutant 0:c0f3bbab73d2 570 * @brief Tx Transfer completed callbacks.
Jerome Coutant 0:c0f3bbab73d2 571 * @param hsai: SAI handle
Jerome Coutant 0:c0f3bbab73d2 572 * @retval None
Jerome Coutant 0:c0f3bbab73d2 573 */
Jerome Coutant 0:c0f3bbab73d2 574 void HAL_SAI_TxCpltCallback(SAI_HandleTypeDef *hsai)
Jerome Coutant 0:c0f3bbab73d2 575 {
Jerome Coutant 0:c0f3bbab73d2 576 /* Manage the remaining file size and new address offset: This function
Jerome Coutant 0:c0f3bbab73d2 577 should be coded by user (its prototype is already declared in stm32f769i_discovery_audio.h) */
Jerome Coutant 0:c0f3bbab73d2 578 BSP_AUDIO_OUT_TransferComplete_CallBack();
Jerome Coutant 0:c0f3bbab73d2 579 }
Jerome Coutant 0:c0f3bbab73d2 580
Jerome Coutant 0:c0f3bbab73d2 581 /**
Jerome Coutant 0:c0f3bbab73d2 582 * @brief Tx Half Transfer completed callbacks.
Jerome Coutant 0:c0f3bbab73d2 583 * @param hsai: SAI handle
Jerome Coutant 0:c0f3bbab73d2 584 * @retval None
Jerome Coutant 0:c0f3bbab73d2 585 */
Jerome Coutant 0:c0f3bbab73d2 586 void HAL_SAI_TxHalfCpltCallback(SAI_HandleTypeDef *hsai)
Jerome Coutant 0:c0f3bbab73d2 587 {
Jerome Coutant 0:c0f3bbab73d2 588 /* Manage the remaining file size and new address offset: This function
Jerome Coutant 0:c0f3bbab73d2 589 should be coded by user (its prototype is already declared in stm32f769i_discovery_audio.h) */
Jerome Coutant 0:c0f3bbab73d2 590 BSP_AUDIO_OUT_HalfTransfer_CallBack();
Jerome Coutant 0:c0f3bbab73d2 591 }
Jerome Coutant 0:c0f3bbab73d2 592
Jerome Coutant 0:c0f3bbab73d2 593 /**
Jerome Coutant 0:c0f3bbab73d2 594 * @brief SAI error callbacks.
Jerome Coutant 0:c0f3bbab73d2 595 * @param hsai: SAI handle
Jerome Coutant 0:c0f3bbab73d2 596 * @retval None
Jerome Coutant 0:c0f3bbab73d2 597 */
Jerome Coutant 0:c0f3bbab73d2 598 void HAL_SAI_ErrorCallback(SAI_HandleTypeDef *hsai)
Jerome Coutant 0:c0f3bbab73d2 599 {
Jerome Coutant 0:c0f3bbab73d2 600 if(hsai->Instance == AUDIO_OUT_SAIx)
Jerome Coutant 0:c0f3bbab73d2 601 {
Jerome Coutant 0:c0f3bbab73d2 602 BSP_AUDIO_OUT_Error_CallBack();
Jerome Coutant 0:c0f3bbab73d2 603 }
Jerome Coutant 0:c0f3bbab73d2 604 else
Jerome Coutant 0:c0f3bbab73d2 605 {
Jerome Coutant 0:c0f3bbab73d2 606 BSP_AUDIO_IN_Error_CallBack();
Jerome Coutant 0:c0f3bbab73d2 607 }
Jerome Coutant 0:c0f3bbab73d2 608 }
Jerome Coutant 0:c0f3bbab73d2 609
Jerome Coutant 0:c0f3bbab73d2 610 /**
Jerome Coutant 0:c0f3bbab73d2 611 * @brief Manages the DMA full Transfer complete event.
Jerome Coutant 0:c0f3bbab73d2 612 * @retval None
Jerome Coutant 0:c0f3bbab73d2 613 */
Jerome Coutant 0:c0f3bbab73d2 614 __weak void BSP_AUDIO_OUT_TransferComplete_CallBack(void)
Jerome Coutant 0:c0f3bbab73d2 615 {
Jerome Coutant 0:c0f3bbab73d2 616 }
Jerome Coutant 0:c0f3bbab73d2 617
Jerome Coutant 0:c0f3bbab73d2 618 /**
Jerome Coutant 0:c0f3bbab73d2 619 * @brief Manages the DMA Half Transfer complete event.
Jerome Coutant 0:c0f3bbab73d2 620 * @retval None
Jerome Coutant 0:c0f3bbab73d2 621 */
Jerome Coutant 0:c0f3bbab73d2 622 __weak void BSP_AUDIO_OUT_HalfTransfer_CallBack(void)
Jerome Coutant 0:c0f3bbab73d2 623 {
Jerome Coutant 0:c0f3bbab73d2 624 }
Jerome Coutant 0:c0f3bbab73d2 625
Jerome Coutant 0:c0f3bbab73d2 626 /**
Jerome Coutant 0:c0f3bbab73d2 627 * @brief Manages the DMA FIFO error event.
Jerome Coutant 0:c0f3bbab73d2 628 * @retval None
Jerome Coutant 0:c0f3bbab73d2 629 */
Jerome Coutant 0:c0f3bbab73d2 630 __weak void BSP_AUDIO_OUT_Error_CallBack(void)
Jerome Coutant 0:c0f3bbab73d2 631 {
Jerome Coutant 0:c0f3bbab73d2 632 }
Jerome Coutant 0:c0f3bbab73d2 633
Jerome Coutant 0:c0f3bbab73d2 634 /**
Jerome Coutant 0:c0f3bbab73d2 635 * @brief Initializes BSP_AUDIO_OUT MSP.
Jerome Coutant 0:c0f3bbab73d2 636 * @param hsai: SAI handle
Jerome Coutant 1:3e58f8a39705 637 * @param Params
Jerome Coutant 0:c0f3bbab73d2 638 * @retval None
Jerome Coutant 0:c0f3bbab73d2 639 */
Jerome Coutant 0:c0f3bbab73d2 640 __weak void BSP_AUDIO_OUT_MspInit(SAI_HandleTypeDef *hsai, void *Params)
Jerome Coutant 0:c0f3bbab73d2 641 {
Jerome Coutant 0:c0f3bbab73d2 642 static DMA_HandleTypeDef hdma_sai_tx;
Jerome Coutant 0:c0f3bbab73d2 643 GPIO_InitTypeDef gpio_init_structure;
Jerome Coutant 0:c0f3bbab73d2 644
Jerome Coutant 0:c0f3bbab73d2 645 /* Enable SAI clock */
Jerome Coutant 0:c0f3bbab73d2 646 AUDIO_OUT_SAIx_CLK_ENABLE();
Jerome Coutant 0:c0f3bbab73d2 647
Jerome Coutant 0:c0f3bbab73d2 648
Jerome Coutant 0:c0f3bbab73d2 649 /* Enable GPIO clock */
Jerome Coutant 0:c0f3bbab73d2 650 AUDIO_OUT_SAIx_MCLK_ENABLE();
Jerome Coutant 0:c0f3bbab73d2 651 AUDIO_OUT_SAIx_SD_FS_CLK_ENABLE();
Jerome Coutant 0:c0f3bbab73d2 652
Jerome Coutant 0:c0f3bbab73d2 653 /* CODEC_SAI pins configuration: FS, SCK, MCK and SD pins ------------------*/
Jerome Coutant 0:c0f3bbab73d2 654 gpio_init_structure.Pin = AUDIO_OUT_SAIx_FS_PIN | AUDIO_OUT_SAIx_SCK_PIN | AUDIO_OUT_SAIx_SD_PIN;
Jerome Coutant 0:c0f3bbab73d2 655 gpio_init_structure.Mode = GPIO_MODE_AF_PP;
Jerome Coutant 0:c0f3bbab73d2 656 gpio_init_structure.Pull = GPIO_NOPULL;
Jerome Coutant 0:c0f3bbab73d2 657 gpio_init_structure.Speed = GPIO_SPEED_HIGH;
Jerome Coutant 0:c0f3bbab73d2 658 gpio_init_structure.Alternate = AUDIO_OUT_SAIx_AF;
Jerome Coutant 0:c0f3bbab73d2 659 HAL_GPIO_Init(AUDIO_OUT_SAIx_SD_FS_SCK_GPIO_PORT, &gpio_init_structure);
Jerome Coutant 0:c0f3bbab73d2 660
Jerome Coutant 0:c0f3bbab73d2 661 gpio_init_structure.Pin = AUDIO_OUT_SAIx_MCLK_PIN;
Jerome Coutant 0:c0f3bbab73d2 662 HAL_GPIO_Init(AUDIO_OUT_SAIx_MCLK_GPIO_PORT, &gpio_init_structure);
Jerome Coutant 0:c0f3bbab73d2 663
Jerome Coutant 0:c0f3bbab73d2 664 /* Enable the DMA clock */
Jerome Coutant 0:c0f3bbab73d2 665 AUDIO_OUT_SAIx_DMAx_CLK_ENABLE();
Jerome Coutant 0:c0f3bbab73d2 666
Jerome Coutant 0:c0f3bbab73d2 667 if(hsai->Instance == AUDIO_OUT_SAIx)
Jerome Coutant 0:c0f3bbab73d2 668 {
Jerome Coutant 0:c0f3bbab73d2 669 /* Configure the hdma_saiTx handle parameters */
Jerome Coutant 0:c0f3bbab73d2 670 hdma_sai_tx.Init.Channel = AUDIO_OUT_SAIx_DMAx_CHANNEL;
Jerome Coutant 0:c0f3bbab73d2 671 hdma_sai_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
Jerome Coutant 0:c0f3bbab73d2 672 hdma_sai_tx.Init.PeriphInc = DMA_PINC_DISABLE;
Jerome Coutant 0:c0f3bbab73d2 673 hdma_sai_tx.Init.MemInc = DMA_MINC_ENABLE;
Jerome Coutant 0:c0f3bbab73d2 674 hdma_sai_tx.Init.PeriphDataAlignment = AUDIO_OUT_SAIx_DMAx_PERIPH_DATA_SIZE;
Jerome Coutant 0:c0f3bbab73d2 675 hdma_sai_tx.Init.MemDataAlignment = AUDIO_OUT_SAIx_DMAx_MEM_DATA_SIZE;
Jerome Coutant 0:c0f3bbab73d2 676 hdma_sai_tx.Init.Mode = DMA_CIRCULAR;
Jerome Coutant 0:c0f3bbab73d2 677 hdma_sai_tx.Init.Priority = DMA_PRIORITY_HIGH;
Jerome Coutant 0:c0f3bbab73d2 678 hdma_sai_tx.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
Jerome Coutant 0:c0f3bbab73d2 679 hdma_sai_tx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
Jerome Coutant 0:c0f3bbab73d2 680 hdma_sai_tx.Init.MemBurst = DMA_MBURST_SINGLE;
Jerome Coutant 0:c0f3bbab73d2 681 hdma_sai_tx.Init.PeriphBurst = DMA_PBURST_SINGLE;
Jerome Coutant 0:c0f3bbab73d2 682
Jerome Coutant 0:c0f3bbab73d2 683 hdma_sai_tx.Instance = AUDIO_OUT_SAIx_DMAx_STREAM;
Jerome Coutant 0:c0f3bbab73d2 684
Jerome Coutant 0:c0f3bbab73d2 685 /* Associate the DMA handle */
Jerome Coutant 0:c0f3bbab73d2 686 __HAL_LINKDMA(hsai, hdmatx, hdma_sai_tx);
Jerome Coutant 0:c0f3bbab73d2 687
Jerome Coutant 0:c0f3bbab73d2 688 /* Deinitialize the Stream for new transfer */
Jerome Coutant 0:c0f3bbab73d2 689 HAL_DMA_DeInit(&hdma_sai_tx);
Jerome Coutant 0:c0f3bbab73d2 690
Jerome Coutant 0:c0f3bbab73d2 691 /* Configure the DMA Stream */
Jerome Coutant 0:c0f3bbab73d2 692 HAL_DMA_Init(&hdma_sai_tx);
Jerome Coutant 0:c0f3bbab73d2 693 }
Jerome Coutant 0:c0f3bbab73d2 694
Jerome Coutant 0:c0f3bbab73d2 695 /* SAI DMA IRQ Channel configuration */
Jerome Coutant 0:c0f3bbab73d2 696 HAL_NVIC_SetPriority(AUDIO_OUT_SAIx_DMAx_IRQ, AUDIO_OUT_IRQ_PREPRIO, 0);
Jerome Coutant 0:c0f3bbab73d2 697 HAL_NVIC_EnableIRQ(AUDIO_OUT_SAIx_DMAx_IRQ);
Jerome Coutant 0:c0f3bbab73d2 698 }
Jerome Coutant 0:c0f3bbab73d2 699
Jerome Coutant 0:c0f3bbab73d2 700 /**
Jerome Coutant 0:c0f3bbab73d2 701 * @brief Initializes SAI Audio IN MSP.
Jerome Coutant 0:c0f3bbab73d2 702 * @param hsai: SAI handle
Jerome Coutant 1:3e58f8a39705 703 * @param Params
Jerome Coutant 0:c0f3bbab73d2 704 * @retval None
Jerome Coutant 0:c0f3bbab73d2 705 */
Jerome Coutant 0:c0f3bbab73d2 706 static void SAI_AUDIO_IN_MspInit(SAI_HandleTypeDef *hsai, void *Params)
Jerome Coutant 0:c0f3bbab73d2 707 {
Jerome Coutant 0:c0f3bbab73d2 708 static DMA_HandleTypeDef hdma_sai_rx;
Jerome Coutant 0:c0f3bbab73d2 709 GPIO_InitTypeDef gpio_init_structure;
Jerome Coutant 0:c0f3bbab73d2 710
Jerome Coutant 0:c0f3bbab73d2 711 /* Enable SAI clock */
Jerome Coutant 0:c0f3bbab73d2 712 AUDIO_IN_SAIx_CLK_ENABLE();
Jerome Coutant 0:c0f3bbab73d2 713
Jerome Coutant 0:c0f3bbab73d2 714 /* Enable SD GPIO clock */
Jerome Coutant 0:c0f3bbab73d2 715 AUDIO_IN_SAIx_SD_ENABLE();
Jerome Coutant 0:c0f3bbab73d2 716 /* CODEC_SAI pin configuration: SD pin */
Jerome Coutant 0:c0f3bbab73d2 717 gpio_init_structure.Pin = AUDIO_IN_SAIx_SD_PIN;
Jerome Coutant 0:c0f3bbab73d2 718 gpio_init_structure.Mode = GPIO_MODE_AF_PP;
Jerome Coutant 0:c0f3bbab73d2 719 gpio_init_structure.Pull = GPIO_NOPULL;
Jerome Coutant 0:c0f3bbab73d2 720 gpio_init_structure.Speed = GPIO_SPEED_FAST;
Jerome Coutant 0:c0f3bbab73d2 721 gpio_init_structure.Alternate = AUDIO_IN_SAIx_AF;
Jerome Coutant 0:c0f3bbab73d2 722 HAL_GPIO_Init(AUDIO_IN_SAIx_SD_GPIO_PORT, &gpio_init_structure);
Jerome Coutant 0:c0f3bbab73d2 723
Jerome Coutant 0:c0f3bbab73d2 724 /* Enable Audio INT GPIO clock */
Jerome Coutant 0:c0f3bbab73d2 725 AUDIO_IN_INT_GPIO_ENABLE();
Jerome Coutant 0:c0f3bbab73d2 726 /* Audio INT pin configuration: input */
Jerome Coutant 0:c0f3bbab73d2 727 gpio_init_structure.Pin = AUDIO_IN_INT_GPIO_PIN;
Jerome Coutant 0:c0f3bbab73d2 728 gpio_init_structure.Mode = GPIO_MODE_INPUT;
Jerome Coutant 0:c0f3bbab73d2 729 gpio_init_structure.Pull = GPIO_NOPULL;
Jerome Coutant 0:c0f3bbab73d2 730 gpio_init_structure.Speed = GPIO_SPEED_FAST;
Jerome Coutant 0:c0f3bbab73d2 731 HAL_GPIO_Init(AUDIO_IN_INT_GPIO_PORT, &gpio_init_structure);
Jerome Coutant 0:c0f3bbab73d2 732
Jerome Coutant 0:c0f3bbab73d2 733 /* Enable the DMA clock */
Jerome Coutant 0:c0f3bbab73d2 734 AUDIO_IN_SAIx_DMAx_CLK_ENABLE();
Jerome Coutant 0:c0f3bbab73d2 735
Jerome Coutant 0:c0f3bbab73d2 736 if(hsai->Instance == AUDIO_IN_SAIx)
Jerome Coutant 0:c0f3bbab73d2 737 {
Jerome Coutant 0:c0f3bbab73d2 738 /* Configure the hdma_sai_rx handle parameters */
Jerome Coutant 0:c0f3bbab73d2 739 hdma_sai_rx.Init.Channel = AUDIO_IN_SAIx_DMAx_CHANNEL;
Jerome Coutant 0:c0f3bbab73d2 740 hdma_sai_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
Jerome Coutant 0:c0f3bbab73d2 741 hdma_sai_rx.Init.PeriphInc = DMA_PINC_DISABLE;
Jerome Coutant 0:c0f3bbab73d2 742 hdma_sai_rx.Init.MemInc = DMA_MINC_ENABLE;
Jerome Coutant 0:c0f3bbab73d2 743 hdma_sai_rx.Init.PeriphDataAlignment = AUDIO_IN_SAIx_DMAx_PERIPH_DATA_SIZE;
Jerome Coutant 0:c0f3bbab73d2 744 hdma_sai_rx.Init.MemDataAlignment = AUDIO_IN_SAIx_DMAx_MEM_DATA_SIZE;
Jerome Coutant 0:c0f3bbab73d2 745 hdma_sai_rx.Init.Mode = DMA_CIRCULAR;
Jerome Coutant 0:c0f3bbab73d2 746 hdma_sai_rx.Init.Priority = DMA_PRIORITY_HIGH;
Jerome Coutant 0:c0f3bbab73d2 747 hdma_sai_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
Jerome Coutant 0:c0f3bbab73d2 748 hdma_sai_rx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
Jerome Coutant 0:c0f3bbab73d2 749 hdma_sai_rx.Init.MemBurst = DMA_MBURST_SINGLE;
Jerome Coutant 0:c0f3bbab73d2 750 hdma_sai_rx.Init.PeriphBurst = DMA_MBURST_SINGLE;
Jerome Coutant 0:c0f3bbab73d2 751
Jerome Coutant 0:c0f3bbab73d2 752 hdma_sai_rx.Instance = AUDIO_IN_SAIx_DMAx_STREAM;
Jerome Coutant 0:c0f3bbab73d2 753
Jerome Coutant 0:c0f3bbab73d2 754 /* Associate the DMA handle */
Jerome Coutant 0:c0f3bbab73d2 755 __HAL_LINKDMA(hsai, hdmarx, hdma_sai_rx);
Jerome Coutant 0:c0f3bbab73d2 756
Jerome Coutant 0:c0f3bbab73d2 757 /* Deinitialize the Stream for new transfer */
Jerome Coutant 0:c0f3bbab73d2 758 HAL_DMA_DeInit(&hdma_sai_rx);
Jerome Coutant 0:c0f3bbab73d2 759
Jerome Coutant 0:c0f3bbab73d2 760 /* Configure the DMA Stream */
Jerome Coutant 0:c0f3bbab73d2 761 HAL_DMA_Init(&hdma_sai_rx);
Jerome Coutant 0:c0f3bbab73d2 762 }
Jerome Coutant 0:c0f3bbab73d2 763
Jerome Coutant 0:c0f3bbab73d2 764 /* SAI DMA IRQ Channel configuration */
Jerome Coutant 0:c0f3bbab73d2 765 HAL_NVIC_SetPriority(AUDIO_IN_SAIx_DMAx_IRQ, AUDIO_IN_IRQ_PREPRIO, 0);
Jerome Coutant 0:c0f3bbab73d2 766 HAL_NVIC_EnableIRQ(AUDIO_IN_SAIx_DMAx_IRQ);
Jerome Coutant 0:c0f3bbab73d2 767
Jerome Coutant 0:c0f3bbab73d2 768 /* Audio INT IRQ Channel configuration */
Jerome Coutant 0:c0f3bbab73d2 769 HAL_NVIC_SetPriority(AUDIO_IN_INT_IRQ, AUDIO_IN_IRQ_PREPRIO, 0);
Jerome Coutant 0:c0f3bbab73d2 770 HAL_NVIC_EnableIRQ(AUDIO_IN_INT_IRQ);
Jerome Coutant 0:c0f3bbab73d2 771 }
Jerome Coutant 0:c0f3bbab73d2 772
Jerome Coutant 0:c0f3bbab73d2 773 /**
Jerome Coutant 0:c0f3bbab73d2 774 * @brief De-Initializes SAI Audio IN MSP.
Jerome Coutant 0:c0f3bbab73d2 775 * @param hsai: SAI handle
Jerome Coutant 1:3e58f8a39705 776 * @param Params
Jerome Coutant 0:c0f3bbab73d2 777 * @retval None
Jerome Coutant 0:c0f3bbab73d2 778 */
Jerome Coutant 0:c0f3bbab73d2 779 static void SAI_AUDIO_IN_MspDeInit(SAI_HandleTypeDef *hsai, void *Params)
Jerome Coutant 0:c0f3bbab73d2 780 {
Jerome Coutant 0:c0f3bbab73d2 781 GPIO_InitTypeDef gpio_init_structure;
Jerome Coutant 0:c0f3bbab73d2 782
Jerome Coutant 0:c0f3bbab73d2 783 /* SAI DMA IRQ Channel deactivation */
Jerome Coutant 0:c0f3bbab73d2 784 HAL_NVIC_DisableIRQ(AUDIO_IN_SAIx_DMAx_IRQ);
Jerome Coutant 0:c0f3bbab73d2 785
Jerome Coutant 0:c0f3bbab73d2 786 if(hsai->Instance == AUDIO_IN_SAIx)
Jerome Coutant 0:c0f3bbab73d2 787 {
Jerome Coutant 0:c0f3bbab73d2 788 /* Deinitialize the DMA stream */
Jerome Coutant 0:c0f3bbab73d2 789 HAL_DMA_DeInit(hsai->hdmatx);
Jerome Coutant 0:c0f3bbab73d2 790 }
Jerome Coutant 0:c0f3bbab73d2 791
Jerome Coutant 0:c0f3bbab73d2 792 /* Disable SAI peripheral */
Jerome Coutant 0:c0f3bbab73d2 793 __HAL_SAI_DISABLE(hsai);
Jerome Coutant 0:c0f3bbab73d2 794
Jerome Coutant 0:c0f3bbab73d2 795 /* Deactivates CODEC_SAI pin SD by putting them in input mode */
Jerome Coutant 0:c0f3bbab73d2 796 gpio_init_structure.Pin = AUDIO_IN_SAIx_SD_PIN;
Jerome Coutant 0:c0f3bbab73d2 797 HAL_GPIO_DeInit(AUDIO_IN_SAIx_SD_GPIO_PORT, gpio_init_structure.Pin);
Jerome Coutant 0:c0f3bbab73d2 798
Jerome Coutant 0:c0f3bbab73d2 799 gpio_init_structure.Pin = AUDIO_IN_INT_GPIO_PIN;
Jerome Coutant 0:c0f3bbab73d2 800 HAL_GPIO_DeInit(AUDIO_IN_INT_GPIO_PORT, gpio_init_structure.Pin);
Jerome Coutant 0:c0f3bbab73d2 801
Jerome Coutant 0:c0f3bbab73d2 802 /* Disable SAI clock */
Jerome Coutant 0:c0f3bbab73d2 803 AUDIO_IN_SAIx_CLK_DISABLE();
Jerome Coutant 0:c0f3bbab73d2 804 }
Jerome Coutant 0:c0f3bbab73d2 805
Jerome Coutant 0:c0f3bbab73d2 806 /**
Jerome Coutant 0:c0f3bbab73d2 807 * @brief Deinitializes SAI MSP.
Jerome Coutant 0:c0f3bbab73d2 808 * @param hsai: SAI handle
Jerome Coutant 1:3e58f8a39705 809 * @param Params
Jerome Coutant 0:c0f3bbab73d2 810 * @retval None
Jerome Coutant 0:c0f3bbab73d2 811 */
Jerome Coutant 0:c0f3bbab73d2 812 __weak void BSP_AUDIO_OUT_MspDeInit(SAI_HandleTypeDef *hsai, void *Params)
Jerome Coutant 0:c0f3bbab73d2 813 {
Jerome Coutant 0:c0f3bbab73d2 814 GPIO_InitTypeDef gpio_init_structure;
Jerome Coutant 0:c0f3bbab73d2 815
Jerome Coutant 0:c0f3bbab73d2 816 /* SAI DMA IRQ Channel deactivation */
Jerome Coutant 0:c0f3bbab73d2 817 HAL_NVIC_DisableIRQ(AUDIO_OUT_SAIx_DMAx_IRQ);
Jerome Coutant 0:c0f3bbab73d2 818
Jerome Coutant 0:c0f3bbab73d2 819 if(hsai->Instance == AUDIO_OUT_SAIx)
Jerome Coutant 0:c0f3bbab73d2 820 {
Jerome Coutant 0:c0f3bbab73d2 821 /* Deinitialize the DMA stream */
Jerome Coutant 0:c0f3bbab73d2 822 HAL_DMA_DeInit(hsai->hdmatx);
Jerome Coutant 0:c0f3bbab73d2 823 }
Jerome Coutant 0:c0f3bbab73d2 824
Jerome Coutant 0:c0f3bbab73d2 825 /* Disable SAI peripheral */
Jerome Coutant 0:c0f3bbab73d2 826 __HAL_SAI_DISABLE(hsai);
Jerome Coutant 0:c0f3bbab73d2 827
Jerome Coutant 0:c0f3bbab73d2 828 /* Deactivates CODEC_SAI pins FS, SCK, MCK and SD by putting them in input mode */
Jerome Coutant 0:c0f3bbab73d2 829 gpio_init_structure.Pin = AUDIO_OUT_SAIx_FS_PIN | AUDIO_OUT_SAIx_SCK_PIN | AUDIO_OUT_SAIx_SD_PIN;
Jerome Coutant 0:c0f3bbab73d2 830 HAL_GPIO_DeInit(AUDIO_OUT_SAIx_SD_FS_SCK_GPIO_PORT, gpio_init_structure.Pin);
Jerome Coutant 0:c0f3bbab73d2 831
Jerome Coutant 0:c0f3bbab73d2 832 gpio_init_structure.Pin = AUDIO_OUT_SAIx_MCLK_PIN;
Jerome Coutant 0:c0f3bbab73d2 833 HAL_GPIO_DeInit(AUDIO_OUT_SAIx_MCLK_GPIO_PORT, gpio_init_structure.Pin);
Jerome Coutant 0:c0f3bbab73d2 834
Jerome Coutant 0:c0f3bbab73d2 835 /* Disable SAI clock */
Jerome Coutant 0:c0f3bbab73d2 836 AUDIO_OUT_SAIx_CLK_DISABLE();
Jerome Coutant 0:c0f3bbab73d2 837
Jerome Coutant 0:c0f3bbab73d2 838 /* GPIO pins clock and DMA clock can be shut down in the applic
Jerome Coutant 0:c0f3bbab73d2 839 by surcharging this __weak function */
Jerome Coutant 0:c0f3bbab73d2 840 }
Jerome Coutant 0:c0f3bbab73d2 841
Jerome Coutant 0:c0f3bbab73d2 842 /**
Jerome Coutant 0:c0f3bbab73d2 843 * @brief Clock Config.
Jerome Coutant 0:c0f3bbab73d2 844 * @param hsai: might be required to set audio peripheral predivider if any.
Jerome Coutant 0:c0f3bbab73d2 845 * @param AudioFreq: Audio frequency used to play the audio stream.
Jerome Coutant 1:3e58f8a39705 846 * @param Params
Jerome Coutant 0:c0f3bbab73d2 847 * @note This API is called by BSP_AUDIO_OUT_Init() and BSP_AUDIO_OUT_SetFrequency()
Jerome Coutant 0:c0f3bbab73d2 848 * Being __weak it can be overwritten by the application
Jerome Coutant 0:c0f3bbab73d2 849 * @retval None
Jerome Coutant 0:c0f3bbab73d2 850 */
Jerome Coutant 0:c0f3bbab73d2 851 __weak void BSP_AUDIO_OUT_ClockConfig(SAI_HandleTypeDef *hsai, uint32_t AudioFreq, void *Params)
Jerome Coutant 0:c0f3bbab73d2 852 {
Jerome Coutant 0:c0f3bbab73d2 853 RCC_PeriphCLKInitTypeDef rcc_ex_clk_init_struct;
Jerome Coutant 0:c0f3bbab73d2 854
Jerome Coutant 0:c0f3bbab73d2 855 HAL_RCCEx_GetPeriphCLKConfig(&rcc_ex_clk_init_struct);
Jerome Coutant 0:c0f3bbab73d2 856
Jerome Coutant 0:c0f3bbab73d2 857 /* Set the PLL configuration according to the audio frequency */
Jerome Coutant 0:c0f3bbab73d2 858 if((AudioFreq == AUDIO_FREQUENCY_11K) || (AudioFreq == AUDIO_FREQUENCY_22K) || (AudioFreq == AUDIO_FREQUENCY_44K))
Jerome Coutant 0:c0f3bbab73d2 859 {
Jerome Coutant 0:c0f3bbab73d2 860 /* Configure PLLSAI prescalers */
Jerome Coutant 0:c0f3bbab73d2 861 /* PLLSAI_VCO: VCO_429M
Jerome Coutant 0:c0f3bbab73d2 862 SAI_CLK(first level) = PLLSAI_VCO/PLLSAIQ = 429/2 = 214.5 Mhz
Jerome Coutant 0:c0f3bbab73d2 863 SAI_CLK_x = SAI_CLK(first level)/PLLSAIDIVQ = 214.5/19 = 11.289 Mhz */
Jerome Coutant 0:c0f3bbab73d2 864 rcc_ex_clk_init_struct.PeriphClockSelection = RCC_PERIPHCLK_SAI1;
Jerome Coutant 0:c0f3bbab73d2 865 rcc_ex_clk_init_struct.Sai1ClockSelection = RCC_SAI1CLKSOURCE_PLLI2S;
Jerome Coutant 0:c0f3bbab73d2 866 rcc_ex_clk_init_struct.PLLI2S.PLLI2SN = 429;
Jerome Coutant 0:c0f3bbab73d2 867 rcc_ex_clk_init_struct.PLLI2S.PLLI2SQ = 2;
Jerome Coutant 0:c0f3bbab73d2 868 rcc_ex_clk_init_struct.PLLI2SDivQ = 19;
Jerome Coutant 0:c0f3bbab73d2 869
Jerome Coutant 0:c0f3bbab73d2 870 HAL_RCCEx_PeriphCLKConfig(&rcc_ex_clk_init_struct);
Jerome Coutant 0:c0f3bbab73d2 871
Jerome Coutant 0:c0f3bbab73d2 872 }
Jerome Coutant 0:c0f3bbab73d2 873 else /* AUDIO_FREQUENCY_8K, AUDIO_FREQUENCY_16K, AUDIO_FREQUENCY_48K, AUDIO_FREQUENCY_96K */
Jerome Coutant 0:c0f3bbab73d2 874 {
Jerome Coutant 0:c0f3bbab73d2 875 /* SAI clock config
Jerome Coutant 0:c0f3bbab73d2 876 PLLSAI_VCO: VCO_344M
Jerome Coutant 0:c0f3bbab73d2 877 SAI_CLK(first level) = PLLSAI_VCO/PLLSAIQ = 344/7 = 49.142 Mhz
Jerome Coutant 0:c0f3bbab73d2 878 SAI_CLK_x = SAI_CLK(first level)/PLLSAIDIVQ = 49.142/1 = 49.142 Mhz */
Jerome Coutant 0:c0f3bbab73d2 879 rcc_ex_clk_init_struct.PeriphClockSelection = RCC_PERIPHCLK_SAI1;
Jerome Coutant 0:c0f3bbab73d2 880 rcc_ex_clk_init_struct.Sai1ClockSelection = RCC_SAI1CLKSOURCE_PLLI2S;
Jerome Coutant 0:c0f3bbab73d2 881 rcc_ex_clk_init_struct.PLLI2S.PLLI2SN = 344;
Jerome Coutant 0:c0f3bbab73d2 882 rcc_ex_clk_init_struct.PLLI2S.PLLI2SQ = 7;
Jerome Coutant 0:c0f3bbab73d2 883 rcc_ex_clk_init_struct.PLLI2SDivQ = 1;
Jerome Coutant 0:c0f3bbab73d2 884
Jerome Coutant 0:c0f3bbab73d2 885 HAL_RCCEx_PeriphCLKConfig(&rcc_ex_clk_init_struct);
Jerome Coutant 0:c0f3bbab73d2 886 }
Jerome Coutant 0:c0f3bbab73d2 887 }
Jerome Coutant 0:c0f3bbab73d2 888
Jerome Coutant 0:c0f3bbab73d2 889 /*******************************************************************************
Jerome Coutant 0:c0f3bbab73d2 890 Static Functions
Jerome Coutant 0:c0f3bbab73d2 891 *******************************************************************************/
Jerome Coutant 0:c0f3bbab73d2 892
Jerome Coutant 0:c0f3bbab73d2 893 /**
Jerome Coutant 0:c0f3bbab73d2 894 * @brief Initializes the Audio Codec audio interface (SAI).
Jerome Coutant 0:c0f3bbab73d2 895 * @param AudioFreq: Audio frequency to be configured for the SAI peripheral.
Jerome Coutant 0:c0f3bbab73d2 896 * @note The default SlotActive configuration is set to CODEC_AUDIOFRAME_SLOT_0123
Jerome Coutant 0:c0f3bbab73d2 897 * and user can update this configuration using
Jerome Coutant 0:c0f3bbab73d2 898 * @retval None
Jerome Coutant 0:c0f3bbab73d2 899 */
Jerome Coutant 0:c0f3bbab73d2 900 static void SAIx_Out_Init(uint32_t AudioFreq)
Jerome Coutant 0:c0f3bbab73d2 901 {
Jerome Coutant 0:c0f3bbab73d2 902 /* Initialize the haudio_out_sai Instance parameter */
Jerome Coutant 0:c0f3bbab73d2 903 haudio_out_sai.Instance = AUDIO_OUT_SAIx;
Jerome Coutant 0:c0f3bbab73d2 904
Jerome Coutant 0:c0f3bbab73d2 905 /* Disable SAI peripheral to allow access to SAI internal registers */
Jerome Coutant 0:c0f3bbab73d2 906 __HAL_SAI_DISABLE(&haudio_out_sai);
Jerome Coutant 0:c0f3bbab73d2 907
Jerome Coutant 0:c0f3bbab73d2 908 /* Configure SAI_Block_x
Jerome Coutant 0:c0f3bbab73d2 909 LSBFirst: Disabled
Jerome Coutant 0:c0f3bbab73d2 910 DataSize: 16 */
Jerome Coutant 0:c0f3bbab73d2 911 haudio_out_sai.Init.MonoStereoMode = SAI_STEREOMODE;
Jerome Coutant 0:c0f3bbab73d2 912 haudio_out_sai.Init.AudioFrequency = AudioFreq;
Jerome Coutant 0:c0f3bbab73d2 913 haudio_out_sai.Init.AudioMode = SAI_MODEMASTER_TX;
Jerome Coutant 0:c0f3bbab73d2 914 haudio_out_sai.Init.NoDivider = SAI_MASTERDIVIDER_ENABLED;
Jerome Coutant 0:c0f3bbab73d2 915 haudio_out_sai.Init.Protocol = SAI_FREE_PROTOCOL;
Jerome Coutant 0:c0f3bbab73d2 916 haudio_out_sai.Init.DataSize = SAI_DATASIZE_16;
Jerome Coutant 0:c0f3bbab73d2 917 haudio_out_sai.Init.FirstBit = SAI_FIRSTBIT_MSB;
Jerome Coutant 0:c0f3bbab73d2 918 haudio_out_sai.Init.ClockStrobing = SAI_CLOCKSTROBING_RISINGEDGE;
Jerome Coutant 0:c0f3bbab73d2 919 haudio_out_sai.Init.Synchro = SAI_ASYNCHRONOUS;
Jerome Coutant 0:c0f3bbab73d2 920 haudio_out_sai.Init.OutputDrive = SAI_OUTPUTDRIVE_ENABLED;
Jerome Coutant 0:c0f3bbab73d2 921 haudio_out_sai.Init.FIFOThreshold = SAI_FIFOTHRESHOLD_1QF;
Jerome Coutant 0:c0f3bbab73d2 922 haudio_out_sai.Init.SynchroExt = SAI_SYNCEXT_DISABLE;
Jerome Coutant 0:c0f3bbab73d2 923 haudio_out_sai.Init.CompandingMode = SAI_NOCOMPANDING;
Jerome Coutant 0:c0f3bbab73d2 924 haudio_out_sai.Init.TriState = SAI_OUTPUT_NOTRELEASED;
Jerome Coutant 0:c0f3bbab73d2 925 haudio_out_sai.Init.Mckdiv = 0;
Jerome Coutant 0:c0f3bbab73d2 926
Jerome Coutant 0:c0f3bbab73d2 927 /* Configure SAI_Block_x Frame
Jerome Coutant 0:c0f3bbab73d2 928 Frame Length: 64
Jerome Coutant 0:c0f3bbab73d2 929 Frame active Length: 32
Jerome Coutant 0:c0f3bbab73d2 930 FS Definition: Start frame + Channel Side identification
Jerome Coutant 0:c0f3bbab73d2 931 FS Polarity: FS active Low
Jerome Coutant 0:c0f3bbab73d2 932 FS Offset: FS asserted one bit before the first bit of slot 0 */
Jerome Coutant 0:c0f3bbab73d2 933 haudio_out_sai.FrameInit.FrameLength = 128;
Jerome Coutant 0:c0f3bbab73d2 934 haudio_out_sai.FrameInit.ActiveFrameLength = 64;
Jerome Coutant 0:c0f3bbab73d2 935 haudio_out_sai.FrameInit.FSDefinition = SAI_FS_CHANNEL_IDENTIFICATION;
Jerome Coutant 0:c0f3bbab73d2 936 haudio_out_sai.FrameInit.FSPolarity = SAI_FS_ACTIVE_LOW;
Jerome Coutant 0:c0f3bbab73d2 937 haudio_out_sai.FrameInit.FSOffset = SAI_FS_BEFOREFIRSTBIT;
Jerome Coutant 0:c0f3bbab73d2 938
Jerome Coutant 0:c0f3bbab73d2 939 /* Configure SAI Block_x Slot
Jerome Coutant 0:c0f3bbab73d2 940 Slot First Bit Offset: 0
Jerome Coutant 0:c0f3bbab73d2 941 Slot Size : 16
Jerome Coutant 0:c0f3bbab73d2 942 Slot Number: 4
Jerome Coutant 0:c0f3bbab73d2 943 Slot Active: All slot actives */
Jerome Coutant 0:c0f3bbab73d2 944 haudio_out_sai.SlotInit.FirstBitOffset = 0;
Jerome Coutant 0:c0f3bbab73d2 945 haudio_out_sai.SlotInit.SlotSize = SAI_SLOTSIZE_DATASIZE;
Jerome Coutant 0:c0f3bbab73d2 946 haudio_out_sai.SlotInit.SlotNumber = 4;
Jerome Coutant 0:c0f3bbab73d2 947 haudio_out_sai.SlotInit.SlotActive = CODEC_AUDIOFRAME_SLOT_0123;
Jerome Coutant 0:c0f3bbab73d2 948
Jerome Coutant 0:c0f3bbab73d2 949 HAL_SAI_Init(&haudio_out_sai);
Jerome Coutant 0:c0f3bbab73d2 950
Jerome Coutant 0:c0f3bbab73d2 951 /* Enable SAI peripheral to generate MCLK */
Jerome Coutant 0:c0f3bbab73d2 952 __HAL_SAI_ENABLE(&haudio_out_sai);
Jerome Coutant 0:c0f3bbab73d2 953 }
Jerome Coutant 0:c0f3bbab73d2 954
Jerome Coutant 0:c0f3bbab73d2 955 /**
Jerome Coutant 0:c0f3bbab73d2 956 * @brief Deinitializes the Audio Codec audio interface (SAI).
Jerome Coutant 0:c0f3bbab73d2 957 * @retval None
Jerome Coutant 0:c0f3bbab73d2 958 */
Jerome Coutant 0:c0f3bbab73d2 959 static void SAIx_Out_DeInit(void)
Jerome Coutant 0:c0f3bbab73d2 960 {
Jerome Coutant 0:c0f3bbab73d2 961 /* Initialize the haudio_out_sai Instance parameter */
Jerome Coutant 0:c0f3bbab73d2 962 haudio_out_sai.Instance = AUDIO_OUT_SAIx;
Jerome Coutant 0:c0f3bbab73d2 963
Jerome Coutant 0:c0f3bbab73d2 964 /* Disable SAI peripheral */
Jerome Coutant 0:c0f3bbab73d2 965 __HAL_SAI_DISABLE(&haudio_out_sai);
Jerome Coutant 0:c0f3bbab73d2 966
Jerome Coutant 0:c0f3bbab73d2 967 HAL_SAI_DeInit(&haudio_out_sai);
Jerome Coutant 0:c0f3bbab73d2 968 }
Jerome Coutant 0:c0f3bbab73d2 969
Jerome Coutant 0:c0f3bbab73d2 970 /**
Jerome Coutant 0:c0f3bbab73d2 971 * @brief Initializes the Audio Codec audio interface (SAI).
Jerome Coutant 0:c0f3bbab73d2 972 * @param AudioFreq: Audio frequency to be configured for the SAI peripheral.
Jerome Coutant 0:c0f3bbab73d2 973 * @note The default SlotActive configuration is set to CODEC_AUDIOFRAME_SLOT_0123
Jerome Coutant 0:c0f3bbab73d2 974 * and user can update this configuration using
Jerome Coutant 0:c0f3bbab73d2 975 * @retval None
Jerome Coutant 0:c0f3bbab73d2 976 */
Jerome Coutant 0:c0f3bbab73d2 977 static void SAIx_In_Init(uint32_t AudioFreq)
Jerome Coutant 0:c0f3bbab73d2 978 {
Jerome Coutant 0:c0f3bbab73d2 979 /* Initialize SAI1 block A in MASTER TX */
Jerome Coutant 0:c0f3bbab73d2 980 /* Initialize the haudio_out_sai Instance parameter */
Jerome Coutant 0:c0f3bbab73d2 981 haudio_out_sai.Instance = AUDIO_OUT_SAIx;
Jerome Coutant 0:c0f3bbab73d2 982
Jerome Coutant 0:c0f3bbab73d2 983 /* Disable SAI peripheral to allow access to SAI internal registers */
Jerome Coutant 0:c0f3bbab73d2 984 __HAL_SAI_DISABLE(&haudio_out_sai);
Jerome Coutant 0:c0f3bbab73d2 985
Jerome Coutant 0:c0f3bbab73d2 986 /* Configure SAI_Block_x
Jerome Coutant 0:c0f3bbab73d2 987 LSBFirst: Disabled
Jerome Coutant 0:c0f3bbab73d2 988 DataSize: 16 */
Jerome Coutant 0:c0f3bbab73d2 989 haudio_out_sai.Init.MonoStereoMode = SAI_STEREOMODE;
Jerome Coutant 0:c0f3bbab73d2 990 haudio_out_sai.Init.AudioFrequency = AudioFreq;
Jerome Coutant 0:c0f3bbab73d2 991 haudio_out_sai.Init.AudioMode = SAI_MODEMASTER_RX;
Jerome Coutant 0:c0f3bbab73d2 992 haudio_out_sai.Init.NoDivider = SAI_MASTERDIVIDER_ENABLE;
Jerome Coutant 0:c0f3bbab73d2 993 haudio_out_sai.Init.Protocol = SAI_FREE_PROTOCOL;
Jerome Coutant 0:c0f3bbab73d2 994 haudio_out_sai.Init.DataSize = SAI_DATASIZE_16;
Jerome Coutant 0:c0f3bbab73d2 995 haudio_out_sai.Init.FirstBit = SAI_FIRSTBIT_MSB;
Jerome Coutant 0:c0f3bbab73d2 996 haudio_out_sai.Init.ClockStrobing = SAI_CLOCKSTROBING_FALLINGEDGE;
Jerome Coutant 0:c0f3bbab73d2 997 haudio_out_sai.Init.Synchro = SAI_ASYNCHRONOUS;
Jerome Coutant 0:c0f3bbab73d2 998 haudio_out_sai.Init.OutputDrive = SAI_OUTPUTDRIVE_ENABLE;
Jerome Coutant 0:c0f3bbab73d2 999 haudio_out_sai.Init.FIFOThreshold = SAI_FIFOTHRESHOLD_1QF;
Jerome Coutant 0:c0f3bbab73d2 1000 haudio_out_sai.Init.SynchroExt = SAI_SYNCEXT_DISABLE;
Jerome Coutant 0:c0f3bbab73d2 1001 haudio_out_sai.Init.CompandingMode = SAI_NOCOMPANDING;
Jerome Coutant 0:c0f3bbab73d2 1002 haudio_out_sai.Init.TriState = SAI_OUTPUT_NOTRELEASED;
Jerome Coutant 0:c0f3bbab73d2 1003 haudio_out_sai.Init.Mckdiv = 0;
Jerome Coutant 0:c0f3bbab73d2 1004
Jerome Coutant 0:c0f3bbab73d2 1005 /* Configure SAI_Block_x Frame
Jerome Coutant 0:c0f3bbab73d2 1006 Frame Length: 64
Jerome Coutant 0:c0f3bbab73d2 1007 Frame active Length: 32
Jerome Coutant 0:c0f3bbab73d2 1008 FS Definition: Start frame + Channel Side identification
Jerome Coutant 0:c0f3bbab73d2 1009 FS Polarity: FS active Low
Jerome Coutant 0:c0f3bbab73d2 1010 FS Offset: FS asserted one bit before the first bit of slot 0 */
Jerome Coutant 0:c0f3bbab73d2 1011 haudio_out_sai.FrameInit.FrameLength = 64;
Jerome Coutant 0:c0f3bbab73d2 1012 haudio_out_sai.FrameInit.ActiveFrameLength = 32;
Jerome Coutant 0:c0f3bbab73d2 1013 haudio_out_sai.FrameInit.FSDefinition = SAI_FS_CHANNEL_IDENTIFICATION;
Jerome Coutant 0:c0f3bbab73d2 1014 haudio_out_sai.FrameInit.FSPolarity = SAI_FS_ACTIVE_LOW;
Jerome Coutant 0:c0f3bbab73d2 1015 haudio_out_sai.FrameInit.FSOffset = SAI_FS_BEFOREFIRSTBIT;
Jerome Coutant 0:c0f3bbab73d2 1016
Jerome Coutant 0:c0f3bbab73d2 1017 /* Configure SAI Block_x Slot
Jerome Coutant 0:c0f3bbab73d2 1018 Slot First Bit Offset: 0
Jerome Coutant 0:c0f3bbab73d2 1019 Slot Size : 16
Jerome Coutant 0:c0f3bbab73d2 1020 Slot Number: 4
Jerome Coutant 0:c0f3bbab73d2 1021 Slot Active: All slot actives */
Jerome Coutant 0:c0f3bbab73d2 1022 haudio_out_sai.SlotInit.FirstBitOffset = 0;
Jerome Coutant 0:c0f3bbab73d2 1023 haudio_out_sai.SlotInit.SlotSize = SAI_SLOTSIZE_DATASIZE;
Jerome Coutant 0:c0f3bbab73d2 1024 haudio_out_sai.SlotInit.SlotNumber = 4;
Jerome Coutant 0:c0f3bbab73d2 1025 haudio_out_sai.SlotInit.SlotActive = CODEC_AUDIOFRAME_SLOT_02;
Jerome Coutant 0:c0f3bbab73d2 1026
Jerome Coutant 0:c0f3bbab73d2 1027 HAL_SAI_Init(&haudio_out_sai);
Jerome Coutant 0:c0f3bbab73d2 1028
Jerome Coutant 0:c0f3bbab73d2 1029 /* Initialize SAI1 block B in SLAVE RX synchronous from SAI1 block A */
Jerome Coutant 0:c0f3bbab73d2 1030 /* Initialize the haudio_in_sai Instance parameter */
Jerome Coutant 0:c0f3bbab73d2 1031 haudio_in_sai.Instance = AUDIO_IN_SAIx;
Jerome Coutant 0:c0f3bbab73d2 1032
Jerome Coutant 0:c0f3bbab73d2 1033 /* Disable SAI peripheral to allow access to SAI internal registers */
Jerome Coutant 0:c0f3bbab73d2 1034 __HAL_SAI_DISABLE(&haudio_in_sai);
Jerome Coutant 0:c0f3bbab73d2 1035
Jerome Coutant 0:c0f3bbab73d2 1036 /* Configure SAI_Block_x
Jerome Coutant 0:c0f3bbab73d2 1037 LSBFirst: Disabled
Jerome Coutant 0:c0f3bbab73d2 1038 DataSize: 16 */
Jerome Coutant 0:c0f3bbab73d2 1039 haudio_in_sai.Init.MonoStereoMode = SAI_STEREOMODE;
Jerome Coutant 0:c0f3bbab73d2 1040 haudio_in_sai.Init.AudioFrequency = AudioFreq;
Jerome Coutant 0:c0f3bbab73d2 1041 haudio_in_sai.Init.AudioMode = SAI_MODESLAVE_RX;
Jerome Coutant 0:c0f3bbab73d2 1042 haudio_in_sai.Init.NoDivider = SAI_MASTERDIVIDER_ENABLE;
Jerome Coutant 0:c0f3bbab73d2 1043 haudio_in_sai.Init.Protocol = SAI_FREE_PROTOCOL;
Jerome Coutant 0:c0f3bbab73d2 1044 haudio_in_sai.Init.DataSize = SAI_DATASIZE_16;
Jerome Coutant 0:c0f3bbab73d2 1045 haudio_in_sai.Init.FirstBit = SAI_FIRSTBIT_MSB;
Jerome Coutant 0:c0f3bbab73d2 1046 haudio_in_sai.Init.ClockStrobing = SAI_CLOCKSTROBING_RISINGEDGE;
Jerome Coutant 0:c0f3bbab73d2 1047 haudio_in_sai.Init.Synchro = SAI_SYNCHRONOUS;
Jerome Coutant 0:c0f3bbab73d2 1048 haudio_in_sai.Init.OutputDrive = SAI_OUTPUTDRIVE_DISABLE;
Jerome Coutant 0:c0f3bbab73d2 1049 haudio_in_sai.Init.FIFOThreshold = SAI_FIFOTHRESHOLD_1QF;
Jerome Coutant 0:c0f3bbab73d2 1050 haudio_in_sai.Init.SynchroExt = SAI_SYNCEXT_DISABLE;
Jerome Coutant 0:c0f3bbab73d2 1051 haudio_in_sai.Init.CompandingMode = SAI_NOCOMPANDING;
Jerome Coutant 0:c0f3bbab73d2 1052 haudio_in_sai.Init.TriState = SAI_OUTPUT_RELEASED;
Jerome Coutant 0:c0f3bbab73d2 1053 haudio_in_sai.Init.Mckdiv = 0;
Jerome Coutant 0:c0f3bbab73d2 1054
Jerome Coutant 0:c0f3bbab73d2 1055 /* Configure SAI_Block_x Frame
Jerome Coutant 0:c0f3bbab73d2 1056 Frame Length: 64
Jerome Coutant 0:c0f3bbab73d2 1057 Frame active Length: 32
Jerome Coutant 0:c0f3bbab73d2 1058 FS Definition: Start frame + Channel Side identification
Jerome Coutant 0:c0f3bbab73d2 1059 FS Polarity: FS active Low
Jerome Coutant 0:c0f3bbab73d2 1060 FS Offset: FS asserted one bit before the first bit of slot 0 */
Jerome Coutant 0:c0f3bbab73d2 1061 haudio_in_sai.FrameInit.FrameLength = 64;
Jerome Coutant 0:c0f3bbab73d2 1062 haudio_in_sai.FrameInit.ActiveFrameLength = 32;
Jerome Coutant 0:c0f3bbab73d2 1063 haudio_in_sai.FrameInit.FSDefinition = SAI_FS_CHANNEL_IDENTIFICATION;
Jerome Coutant 0:c0f3bbab73d2 1064 haudio_in_sai.FrameInit.FSPolarity = SAI_FS_ACTIVE_LOW;
Jerome Coutant 0:c0f3bbab73d2 1065 haudio_in_sai.FrameInit.FSOffset = SAI_FS_BEFOREFIRSTBIT;
Jerome Coutant 0:c0f3bbab73d2 1066
Jerome Coutant 0:c0f3bbab73d2 1067 /* Configure SAI Block_x Slot
Jerome Coutant 0:c0f3bbab73d2 1068 Slot First Bit Offset: 0
Jerome Coutant 0:c0f3bbab73d2 1069 Slot Size : 16
Jerome Coutant 0:c0f3bbab73d2 1070 Slot Number: 4
Jerome Coutant 0:c0f3bbab73d2 1071 Slot Active: All slot active */
Jerome Coutant 0:c0f3bbab73d2 1072 haudio_in_sai.SlotInit.FirstBitOffset = 0;
Jerome Coutant 0:c0f3bbab73d2 1073 haudio_in_sai.SlotInit.SlotSize = SAI_SLOTSIZE_DATASIZE;
Jerome Coutant 0:c0f3bbab73d2 1074 haudio_in_sai.SlotInit.SlotNumber = 4;
Jerome Coutant 0:c0f3bbab73d2 1075 haudio_in_sai.SlotInit.SlotActive = CODEC_AUDIOFRAME_SLOT_02;
Jerome Coutant 0:c0f3bbab73d2 1076
Jerome Coutant 0:c0f3bbab73d2 1077 HAL_SAI_Init(&haudio_in_sai);
Jerome Coutant 0:c0f3bbab73d2 1078
Jerome Coutant 0:c0f3bbab73d2 1079 /* Enable SAI peripheral */
Jerome Coutant 0:c0f3bbab73d2 1080 __HAL_SAI_ENABLE(&haudio_in_sai);
Jerome Coutant 0:c0f3bbab73d2 1081
Jerome Coutant 0:c0f3bbab73d2 1082 /* Enable SAI peripheral to generate MCLK */
Jerome Coutant 0:c0f3bbab73d2 1083 __HAL_SAI_ENABLE(&haudio_out_sai);
Jerome Coutant 0:c0f3bbab73d2 1084 }
Jerome Coutant 0:c0f3bbab73d2 1085
Jerome Coutant 0:c0f3bbab73d2 1086 /**
Jerome Coutant 0:c0f3bbab73d2 1087 * @brief Deinitializes the output Audio Codec audio interface (SAI).
Jerome Coutant 0:c0f3bbab73d2 1088 * @retval None
Jerome Coutant 0:c0f3bbab73d2 1089 */
Jerome Coutant 0:c0f3bbab73d2 1090 static void SAIx_In_DeInit(void)
Jerome Coutant 0:c0f3bbab73d2 1091 {
Jerome Coutant 0:c0f3bbab73d2 1092 /* Initialize the haudio_in_sai Instance parameter */
Jerome Coutant 0:c0f3bbab73d2 1093 haudio_in_sai.Instance = AUDIO_IN_SAIx;
Jerome Coutant 0:c0f3bbab73d2 1094 haudio_out_sai.Instance = AUDIO_OUT_SAIx;
Jerome Coutant 0:c0f3bbab73d2 1095 /* Disable SAI peripheral */
Jerome Coutant 0:c0f3bbab73d2 1096 __HAL_SAI_DISABLE(&haudio_in_sai);
Jerome Coutant 0:c0f3bbab73d2 1097
Jerome Coutant 0:c0f3bbab73d2 1098 HAL_SAI_DeInit(&haudio_in_sai);
Jerome Coutant 0:c0f3bbab73d2 1099 HAL_SAI_DeInit(&haudio_out_sai);
Jerome Coutant 0:c0f3bbab73d2 1100 }
Jerome Coutant 0:c0f3bbab73d2 1101
Jerome Coutant 0:c0f3bbab73d2 1102 /**
Jerome Coutant 0:c0f3bbab73d2 1103 * @}
Jerome Coutant 0:c0f3bbab73d2 1104 */
Jerome Coutant 0:c0f3bbab73d2 1105
Jerome Coutant 0:c0f3bbab73d2 1106 /** @defgroup STM32F769I_DISCOVERY_AUDIO_In_Private_Functions STM32F769I_DISCOVERY_AUDIO_In Private Functions
Jerome Coutant 0:c0f3bbab73d2 1107 * @{
Jerome Coutant 0:c0f3bbab73d2 1108 */
Jerome Coutant 0:c0f3bbab73d2 1109
Jerome Coutant 0:c0f3bbab73d2 1110 /**
Jerome Coutant 0:c0f3bbab73d2 1111 * @brief Initialize wave recording.
Jerome Coutant 0:c0f3bbab73d2 1112 * @param AudioFreq: Audio frequency to be configured for the DFSDM peripheral.
Jerome Coutant 0:c0f3bbab73d2 1113 * @param BitRes: Audio frequency to be configured for the DFSDM peripheral.
Jerome Coutant 0:c0f3bbab73d2 1114 * @param ChnlNbr: Audio frequency to be configured for the DFSDM peripheral.
Jerome Coutant 0:c0f3bbab73d2 1115 * @retval AUDIO_OK if correct communication, else wrong communication
Jerome Coutant 0:c0f3bbab73d2 1116 */
Jerome Coutant 0:c0f3bbab73d2 1117 uint8_t BSP_AUDIO_IN_Init(uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr)
Jerome Coutant 0:c0f3bbab73d2 1118 {
Jerome Coutant 0:c0f3bbab73d2 1119 return BSP_AUDIO_IN_InitEx(INPUT_DEVICE_DIGITAL_MIC, AudioFreq, BitRes, ChnlNbr);
Jerome Coutant 0:c0f3bbab73d2 1120 }
Jerome Coutant 0:c0f3bbab73d2 1121
Jerome Coutant 0:c0f3bbab73d2 1122 /**
Jerome Coutant 0:c0f3bbab73d2 1123 * @brief Initialize wave recording.
Jerome Coutant 0:c0f3bbab73d2 1124 * @param InputDevice: INPUT_DEVICE_DIGITAL_MIC or INPUT_DEVICE_ANALOG_MIC.
Jerome Coutant 0:c0f3bbab73d2 1125 * @param AudioFreq: Audio frequency to be configured.
Jerome Coutant 0:c0f3bbab73d2 1126 * @param BitRes: Audio bit resolution to be configured..
Jerome Coutant 0:c0f3bbab73d2 1127 * @param ChnlNbr: Number of channel to be configured.
Jerome Coutant 0:c0f3bbab73d2 1128 * @retval AUDIO_OK if correct communication, else wrong communication
Jerome Coutant 0:c0f3bbab73d2 1129 */
Jerome Coutant 0:c0f3bbab73d2 1130 uint8_t BSP_AUDIO_IN_InitEx(uint16_t InputDevice, uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr)
Jerome Coutant 0:c0f3bbab73d2 1131 {
Jerome Coutant 0:c0f3bbab73d2 1132 uint8_t ret = AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1133 AudioIn_Device = InputDevice;
Jerome Coutant 0:c0f3bbab73d2 1134
Jerome Coutant 0:c0f3bbab73d2 1135 if(InputDevice == INPUT_DEVICE_DIGITAL_MIC)
Jerome Coutant 0:c0f3bbab73d2 1136 {
Jerome Coutant 0:c0f3bbab73d2 1137 AudioIn_ChannelNumber = ChnlNbr;
Jerome Coutant 0:c0f3bbab73d2 1138 /* PLL clock is set depending by the AudioFreq (44.1khz vs 48khz groups) */
Jerome Coutant 0:c0f3bbab73d2 1139 BSP_AUDIO_IN_ClockConfig(&hAudioInTopLeftFilter, AudioFreq, NULL);
Jerome Coutant 0:c0f3bbab73d2 1140
Jerome Coutant 0:c0f3bbab73d2 1141 /* Init the SAI MSP: this __weak function can be redefined by the application*/
Jerome Coutant 0:c0f3bbab73d2 1142 BSP_AUDIO_IN_MspInit();
Jerome Coutant 0:c0f3bbab73d2 1143
Jerome Coutant 0:c0f3bbab73d2 1144 /* Initializes DFSDM peripheral */
Jerome Coutant 0:c0f3bbab73d2 1145 DFSDMx_Init(AudioFreq);
Jerome Coutant 0:c0f3bbab73d2 1146 ret = AUDIO_OK;
Jerome Coutant 0:c0f3bbab73d2 1147 }
Jerome Coutant 0:c0f3bbab73d2 1148 else
Jerome Coutant 0:c0f3bbab73d2 1149 {
Jerome Coutant 0:c0f3bbab73d2 1150 /* Disable SAI */
Jerome Coutant 0:c0f3bbab73d2 1151 SAIx_In_DeInit();
Jerome Coutant 0:c0f3bbab73d2 1152
Jerome Coutant 0:c0f3bbab73d2 1153 /* PLL clock is set depending by the AudioFreq (44.1khz vs 48khz groups) */
Jerome Coutant 0:c0f3bbab73d2 1154 BSP_AUDIO_OUT_ClockConfig(&haudio_in_sai, AudioFreq, NULL);
Jerome Coutant 0:c0f3bbab73d2 1155
Jerome Coutant 0:c0f3bbab73d2 1156 haudio_in_sai.Instance = AUDIO_IN_SAIx;
Jerome Coutant 0:c0f3bbab73d2 1157 if(HAL_SAI_GetState(&haudio_in_sai) == HAL_SAI_STATE_RESET)
Jerome Coutant 0:c0f3bbab73d2 1158 {
Jerome Coutant 0:c0f3bbab73d2 1159 BSP_AUDIO_OUT_MspInit(&haudio_in_sai, NULL);
Jerome Coutant 0:c0f3bbab73d2 1160 BSP_AUDIO_IN_MspInit();
Jerome Coutant 0:c0f3bbab73d2 1161 }
Jerome Coutant 0:c0f3bbab73d2 1162
Jerome Coutant 0:c0f3bbab73d2 1163 SAIx_In_Init(AudioFreq);
Jerome Coutant 0:c0f3bbab73d2 1164
Jerome Coutant 0:c0f3bbab73d2 1165 if((wm8994_drv.ReadID(AUDIO_I2C_ADDRESS)) == WM8994_ID)
Jerome Coutant 0:c0f3bbab73d2 1166 {
Jerome Coutant 0:c0f3bbab73d2 1167 /* Reset the Codec Registers */
Jerome Coutant 0:c0f3bbab73d2 1168 wm8994_drv.Reset(AUDIO_I2C_ADDRESS);
Jerome Coutant 0:c0f3bbab73d2 1169 /* Initialize the audio driver structure */
Jerome Coutant 0:c0f3bbab73d2 1170 audio_drv = &wm8994_drv;
Jerome Coutant 0:c0f3bbab73d2 1171 ret = AUDIO_OK;
Jerome Coutant 0:c0f3bbab73d2 1172 }
Jerome Coutant 0:c0f3bbab73d2 1173 else
Jerome Coutant 0:c0f3bbab73d2 1174 {
Jerome Coutant 0:c0f3bbab73d2 1175 ret = AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1176 }
Jerome Coutant 0:c0f3bbab73d2 1177
Jerome Coutant 0:c0f3bbab73d2 1178 if(ret == AUDIO_OK)
Jerome Coutant 0:c0f3bbab73d2 1179 {
Jerome Coutant 0:c0f3bbab73d2 1180 /* Initialize the codec internal registers */
Jerome Coutant 0:c0f3bbab73d2 1181 audio_drv->Init(AUDIO_I2C_ADDRESS, InputDevice, 100, AudioFreq);
Jerome Coutant 0:c0f3bbab73d2 1182 }
Jerome Coutant 0:c0f3bbab73d2 1183 }
Jerome Coutant 0:c0f3bbab73d2 1184
Jerome Coutant 0:c0f3bbab73d2 1185 /* Return AUDIO_OK when all operations are correctly done */
Jerome Coutant 0:c0f3bbab73d2 1186 return ret;
Jerome Coutant 0:c0f3bbab73d2 1187 }
Jerome Coutant 0:c0f3bbab73d2 1188
Jerome Coutant 0:c0f3bbab73d2 1189 /**
Jerome Coutant 0:c0f3bbab73d2 1190 * @brief Allocate channel buffer scratch
Jerome Coutant 0:c0f3bbab73d2 1191 * @param pScratch : pointer to scratch tables.
Jerome Coutant 0:c0f3bbab73d2 1192 * @param size of scratch buffer
Jerome Coutant 0:c0f3bbab73d2 1193 */
Jerome Coutant 0:c0f3bbab73d2 1194 uint8_t BSP_AUDIO_IN_AllocScratch (int32_t *pScratch, uint32_t size)
Jerome Coutant 0:c0f3bbab73d2 1195 {
Jerome Coutant 0:c0f3bbab73d2 1196 uint32_t idx;
Jerome Coutant 0:c0f3bbab73d2 1197
Jerome Coutant 0:c0f3bbab73d2 1198 ScratchSize = (size / AudioIn_ChannelNumber);
Jerome Coutant 0:c0f3bbab73d2 1199
Jerome Coutant 0:c0f3bbab73d2 1200 /* copy scratch pointers */
Jerome Coutant 0:c0f3bbab73d2 1201 for (idx = 0; idx < AudioIn_ChannelNumber; idx++)
Jerome Coutant 0:c0f3bbab73d2 1202 {
Jerome Coutant 0:c0f3bbab73d2 1203 pScratchBuff[idx] = (int32_t *)(pScratch + (idx * ScratchSize));
Jerome Coutant 0:c0f3bbab73d2 1204 }
Jerome Coutant 0:c0f3bbab73d2 1205 /* Return AUDIO_OK */
Jerome Coutant 0:c0f3bbab73d2 1206 return AUDIO_OK;
Jerome Coutant 0:c0f3bbab73d2 1207 }
Jerome Coutant 0:c0f3bbab73d2 1208
Jerome Coutant 0:c0f3bbab73d2 1209 /**
Jerome Coutant 0:c0f3bbab73d2 1210 * @brief Return audio in channel number
Jerome Coutant 0:c0f3bbab73d2 1211 * @retval Number of channel
Jerome Coutant 0:c0f3bbab73d2 1212 */
Jerome Coutant 0:c0f3bbab73d2 1213 uint8_t BSP_AUDIO_IN_GetChannelNumber(void)
Jerome Coutant 0:c0f3bbab73d2 1214 {
Jerome Coutant 0:c0f3bbab73d2 1215 return AudioIn_ChannelNumber;
Jerome Coutant 0:c0f3bbab73d2 1216 }
Jerome Coutant 0:c0f3bbab73d2 1217
Jerome Coutant 0:c0f3bbab73d2 1218 /**
Jerome Coutant 0:c0f3bbab73d2 1219 * @brief Start audio recording.
Jerome Coutant 0:c0f3bbab73d2 1220 * @param pbuf: Main buffer pointer for the recorded data storing
Jerome Coutant 0:c0f3bbab73d2 1221 * @param size: Current size of the recorded buffer
Jerome Coutant 0:c0f3bbab73d2 1222 * @retval AUDIO_OK if correct communication, else wrong communication
Jerome Coutant 0:c0f3bbab73d2 1223 */
Jerome Coutant 0:c0f3bbab73d2 1224 uint8_t BSP_AUDIO_IN_Record(uint16_t* pbuf, uint32_t size)
Jerome Coutant 0:c0f3bbab73d2 1225 {
Jerome Coutant 0:c0f3bbab73d2 1226 if (AudioIn_Device == INPUT_DEVICE_DIGITAL_MIC)
Jerome Coutant 0:c0f3bbab73d2 1227 {
Jerome Coutant 0:c0f3bbab73d2 1228 hAudioIn.pRecBuf = pbuf;
Jerome Coutant 0:c0f3bbab73d2 1229 hAudioIn.RecSize = size;
Jerome Coutant 0:c0f3bbab73d2 1230 /* Reset Application Buffer Trigger */
Jerome Coutant 0:c0f3bbab73d2 1231 AppBuffTrigger = 0;
Jerome Coutant 0:c0f3bbab73d2 1232 AppBuffHalf = 0;
Jerome Coutant 0:c0f3bbab73d2 1233
Jerome Coutant 0:c0f3bbab73d2 1234 if(AudioIn_ChannelNumber > 2)
Jerome Coutant 0:c0f3bbab73d2 1235 {
Jerome Coutant 0:c0f3bbab73d2 1236 /* Call the Media layer start function for buttom right channel */
Jerome Coutant 0:c0f3bbab73d2 1237 if(HAL_OK != HAL_DFSDM_FilterRegularStart_DMA(&hAudioInButtomRightFilter, pScratchBuff[2], ScratchSize))
Jerome Coutant 0:c0f3bbab73d2 1238 {
Jerome Coutant 0:c0f3bbab73d2 1239 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1240 }
Jerome Coutant 0:c0f3bbab73d2 1241
Jerome Coutant 0:c0f3bbab73d2 1242 /* Call the Media layer start function for buttom left channel */
Jerome Coutant 0:c0f3bbab73d2 1243 if(HAL_OK != HAL_DFSDM_FilterRegularStart_DMA(&hAudioInButtomLeftFilter, pScratchBuff[3], ScratchSize))
Jerome Coutant 0:c0f3bbab73d2 1244 {
Jerome Coutant 0:c0f3bbab73d2 1245 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1246 }
Jerome Coutant 0:c0f3bbab73d2 1247 }
Jerome Coutant 0:c0f3bbab73d2 1248
Jerome Coutant 0:c0f3bbab73d2 1249 /* Call the Media layer start function for top right channel */
Jerome Coutant 0:c0f3bbab73d2 1250 if(HAL_OK != HAL_DFSDM_FilterRegularStart_DMA(&hAudioInTopRightFilter, pScratchBuff[0], ScratchSize))
Jerome Coutant 0:c0f3bbab73d2 1251 {
Jerome Coutant 0:c0f3bbab73d2 1252 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1253 }
Jerome Coutant 0:c0f3bbab73d2 1254
Jerome Coutant 0:c0f3bbab73d2 1255 /* Call the Media layer start function for top left channel */
Jerome Coutant 0:c0f3bbab73d2 1256 if(HAL_OK != HAL_DFSDM_FilterRegularStart_DMA(&hAudioInTopLeftFilter, pScratchBuff[1], ScratchSize))
Jerome Coutant 0:c0f3bbab73d2 1257 {
Jerome Coutant 0:c0f3bbab73d2 1258 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1259 }
Jerome Coutant 0:c0f3bbab73d2 1260 }
Jerome Coutant 0:c0f3bbab73d2 1261 else
Jerome Coutant 0:c0f3bbab73d2 1262 {
Jerome Coutant 0:c0f3bbab73d2 1263 /* Start the process receive DMA */
Jerome Coutant 0:c0f3bbab73d2 1264 if(HAL_OK !=HAL_SAI_Receive_DMA(&haudio_in_sai, (uint8_t*)pbuf, size))
Jerome Coutant 0:c0f3bbab73d2 1265 {
Jerome Coutant 0:c0f3bbab73d2 1266 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1267 }
Jerome Coutant 0:c0f3bbab73d2 1268 }
Jerome Coutant 0:c0f3bbab73d2 1269 /* Return AUDIO_OK when all operations are correctly done */
Jerome Coutant 0:c0f3bbab73d2 1270 return AUDIO_OK;
Jerome Coutant 0:c0f3bbab73d2 1271 }
Jerome Coutant 0:c0f3bbab73d2 1272
Jerome Coutant 0:c0f3bbab73d2 1273 /**
Jerome Coutant 0:c0f3bbab73d2 1274 * @brief Stop audio recording.
Jerome Coutant 0:c0f3bbab73d2 1275 * @retval AUDIO_OK if correct communication, else wrong communication
Jerome Coutant 0:c0f3bbab73d2 1276 */
Jerome Coutant 0:c0f3bbab73d2 1277 uint8_t BSP_AUDIO_IN_Stop(void)
Jerome Coutant 0:c0f3bbab73d2 1278 {
Jerome Coutant 0:c0f3bbab73d2 1279 if (AudioIn_Device == INPUT_DEVICE_DIGITAL_MIC)
Jerome Coutant 0:c0f3bbab73d2 1280 {
Jerome Coutant 0:c0f3bbab73d2 1281 AppBuffTrigger = 0;
Jerome Coutant 0:c0f3bbab73d2 1282 AppBuffHalf = 0;
Jerome Coutant 0:c0f3bbab73d2 1283
Jerome Coutant 0:c0f3bbab73d2 1284 if(AudioIn_ChannelNumber > 2)
Jerome Coutant 0:c0f3bbab73d2 1285 {
Jerome Coutant 0:c0f3bbab73d2 1286 /* Call the Media layer stop function for buttom right channel */
Jerome Coutant 0:c0f3bbab73d2 1287 if(HAL_OK != HAL_DFSDM_FilterRegularStop_DMA(&hAudioInButtomRightFilter))
Jerome Coutant 0:c0f3bbab73d2 1288 {
Jerome Coutant 0:c0f3bbab73d2 1289 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1290 }
Jerome Coutant 0:c0f3bbab73d2 1291
Jerome Coutant 0:c0f3bbab73d2 1292 /* Call the Media layer stop function for buttom left channel */
Jerome Coutant 0:c0f3bbab73d2 1293 if(HAL_OK != HAL_DFSDM_FilterRegularStop_DMA(&hAudioInButtomLeftFilter))
Jerome Coutant 0:c0f3bbab73d2 1294 {
Jerome Coutant 0:c0f3bbab73d2 1295 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1296 }
Jerome Coutant 0:c0f3bbab73d2 1297 }
Jerome Coutant 0:c0f3bbab73d2 1298
Jerome Coutant 0:c0f3bbab73d2 1299 /* Call the Media layer stop function for top right channel */
Jerome Coutant 0:c0f3bbab73d2 1300 if(HAL_OK != HAL_DFSDM_FilterRegularStop_DMA(&hAudioInTopRightFilter))
Jerome Coutant 0:c0f3bbab73d2 1301 {
Jerome Coutant 0:c0f3bbab73d2 1302 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1303 }
Jerome Coutant 0:c0f3bbab73d2 1304
Jerome Coutant 0:c0f3bbab73d2 1305 /* Call the Media layer stop function for top left channel */
Jerome Coutant 0:c0f3bbab73d2 1306 if(HAL_OK != HAL_DFSDM_FilterRegularStop_DMA(&hAudioInTopLeftFilter))
Jerome Coutant 0:c0f3bbab73d2 1307 {
Jerome Coutant 0:c0f3bbab73d2 1308 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1309 }
Jerome Coutant 0:c0f3bbab73d2 1310 }
Jerome Coutant 0:c0f3bbab73d2 1311 else
Jerome Coutant 0:c0f3bbab73d2 1312 {
Jerome Coutant 0:c0f3bbab73d2 1313 /* Call the Media layer stop function */
Jerome Coutant 0:c0f3bbab73d2 1314 HAL_SAI_DMAStop(&haudio_in_sai);
Jerome Coutant 0:c0f3bbab73d2 1315
Jerome Coutant 0:c0f3bbab73d2 1316 /* Call Audio Codec Stop function */
Jerome Coutant 0:c0f3bbab73d2 1317 if(audio_drv->Stop(AUDIO_I2C_ADDRESS, CODEC_PDWN_HW) != 0)
Jerome Coutant 0:c0f3bbab73d2 1318 {
Jerome Coutant 0:c0f3bbab73d2 1319 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1320 }
Jerome Coutant 0:c0f3bbab73d2 1321 else
Jerome Coutant 0:c0f3bbab73d2 1322 {
Jerome Coutant 0:c0f3bbab73d2 1323 /* Wait at least 100us */
Jerome Coutant 0:c0f3bbab73d2 1324 HAL_Delay(1);
Jerome Coutant 0:c0f3bbab73d2 1325
Jerome Coutant 0:c0f3bbab73d2 1326 /* Return AUDIO_OK when all operations are correctly done */
Jerome Coutant 0:c0f3bbab73d2 1327 return AUDIO_OK;
Jerome Coutant 0:c0f3bbab73d2 1328 }
Jerome Coutant 0:c0f3bbab73d2 1329 }
Jerome Coutant 0:c0f3bbab73d2 1330 /* Return AUDIO_OK when all operations are correctly done */
Jerome Coutant 0:c0f3bbab73d2 1331 return AUDIO_OK;
Jerome Coutant 0:c0f3bbab73d2 1332 }
Jerome Coutant 0:c0f3bbab73d2 1333
Jerome Coutant 0:c0f3bbab73d2 1334 /**
Jerome Coutant 0:c0f3bbab73d2 1335 * @brief Pause the audio file stream.
Jerome Coutant 0:c0f3bbab73d2 1336 * @retval AUDIO_OK if correct communication, else wrong communication
Jerome Coutant 0:c0f3bbab73d2 1337 */
Jerome Coutant 0:c0f3bbab73d2 1338 uint8_t BSP_AUDIO_IN_Pause(void)
Jerome Coutant 0:c0f3bbab73d2 1339 {
Jerome Coutant 0:c0f3bbab73d2 1340 if(AudioIn_ChannelNumber > 2)
Jerome Coutant 0:c0f3bbab73d2 1341 {
Jerome Coutant 0:c0f3bbab73d2 1342 /* Call the Media layer stop function */
Jerome Coutant 0:c0f3bbab73d2 1343 if(HAL_OK != HAL_DFSDM_FilterRegularStop_DMA(&hAudioInButtomRightFilter))
Jerome Coutant 0:c0f3bbab73d2 1344 {
Jerome Coutant 0:c0f3bbab73d2 1345 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1346 }
Jerome Coutant 0:c0f3bbab73d2 1347
Jerome Coutant 0:c0f3bbab73d2 1348 /* Call the Media layer stop function */
Jerome Coutant 0:c0f3bbab73d2 1349 if(HAL_OK != HAL_DFSDM_FilterRegularStop_DMA(&hAudioInButtomLeftFilter))
Jerome Coutant 0:c0f3bbab73d2 1350 {
Jerome Coutant 0:c0f3bbab73d2 1351 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1352 }
Jerome Coutant 0:c0f3bbab73d2 1353 }
Jerome Coutant 0:c0f3bbab73d2 1354 /* Call the Media layer stop function */
Jerome Coutant 0:c0f3bbab73d2 1355 if(HAL_OK != HAL_DFSDM_FilterRegularStop_DMA(&hAudioInTopRightFilter))
Jerome Coutant 0:c0f3bbab73d2 1356 {
Jerome Coutant 0:c0f3bbab73d2 1357 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1358 }
Jerome Coutant 0:c0f3bbab73d2 1359
Jerome Coutant 0:c0f3bbab73d2 1360 /* Call the Media layer stop function */
Jerome Coutant 0:c0f3bbab73d2 1361 if(HAL_OK != HAL_DFSDM_FilterRegularStop_DMA(&hAudioInTopLeftFilter))
Jerome Coutant 0:c0f3bbab73d2 1362 {
Jerome Coutant 0:c0f3bbab73d2 1363 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1364 }
Jerome Coutant 0:c0f3bbab73d2 1365
Jerome Coutant 0:c0f3bbab73d2 1366 /* Return AUDIO_OK when all operations are correctly done */
Jerome Coutant 0:c0f3bbab73d2 1367 return AUDIO_OK;
Jerome Coutant 0:c0f3bbab73d2 1368 }
Jerome Coutant 0:c0f3bbab73d2 1369
Jerome Coutant 0:c0f3bbab73d2 1370 /**
Jerome Coutant 0:c0f3bbab73d2 1371 * @brief Resume the audio file stream.
Jerome Coutant 0:c0f3bbab73d2 1372 * @retval AUDIO_OK if correct communication, else wrong communication
Jerome Coutant 0:c0f3bbab73d2 1373 */
Jerome Coutant 0:c0f3bbab73d2 1374 uint8_t BSP_AUDIO_IN_Resume(void)
Jerome Coutant 0:c0f3bbab73d2 1375 {
Jerome Coutant 0:c0f3bbab73d2 1376 if(AudioIn_ChannelNumber > 2)
Jerome Coutant 0:c0f3bbab73d2 1377 {
Jerome Coutant 0:c0f3bbab73d2 1378 /* Call the Media layer start function for buttom right channel */
Jerome Coutant 0:c0f3bbab73d2 1379 if(HAL_OK != HAL_DFSDM_FilterRegularStart_DMA(&hAudioInButtomRightFilter, pScratchBuff[2], ScratchSize))
Jerome Coutant 0:c0f3bbab73d2 1380 {
Jerome Coutant 0:c0f3bbab73d2 1381 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1382 }
Jerome Coutant 0:c0f3bbab73d2 1383
Jerome Coutant 0:c0f3bbab73d2 1384 /* Call the Media layer start function for buttom left channel */
Jerome Coutant 0:c0f3bbab73d2 1385 if(HAL_OK != HAL_DFSDM_FilterRegularStart_DMA(&hAudioInButtomLeftFilter, pScratchBuff[3], ScratchSize))
Jerome Coutant 0:c0f3bbab73d2 1386 {
Jerome Coutant 0:c0f3bbab73d2 1387 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1388 }
Jerome Coutant 0:c0f3bbab73d2 1389 }
Jerome Coutant 0:c0f3bbab73d2 1390 /* Call the Media layer start function for top right channel */
Jerome Coutant 0:c0f3bbab73d2 1391 if(HAL_OK != HAL_DFSDM_FilterRegularStart_DMA(&hAudioInTopRightFilter, pScratchBuff[0], ScratchSize))
Jerome Coutant 0:c0f3bbab73d2 1392 {
Jerome Coutant 0:c0f3bbab73d2 1393 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1394 }
Jerome Coutant 0:c0f3bbab73d2 1395
Jerome Coutant 0:c0f3bbab73d2 1396 /* Call the Media layer start function for top left channel */
Jerome Coutant 0:c0f3bbab73d2 1397 if(HAL_OK != HAL_DFSDM_FilterRegularStart_DMA(&hAudioInTopLeftFilter, pScratchBuff[1], ScratchSize))
Jerome Coutant 0:c0f3bbab73d2 1398 {
Jerome Coutant 0:c0f3bbab73d2 1399 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1400 }
Jerome Coutant 0:c0f3bbab73d2 1401
Jerome Coutant 0:c0f3bbab73d2 1402 /* Return AUDIO_OK when all operations are correctly done */
Jerome Coutant 0:c0f3bbab73d2 1403 return AUDIO_OK;
Jerome Coutant 0:c0f3bbab73d2 1404 }
Jerome Coutant 0:c0f3bbab73d2 1405
Jerome Coutant 0:c0f3bbab73d2 1406 /**
Jerome Coutant 0:c0f3bbab73d2 1407 * @brief Deinit the audio IN peripherals.
Jerome Coutant 0:c0f3bbab73d2 1408 * @retval None
Jerome Coutant 0:c0f3bbab73d2 1409 */
Jerome Coutant 0:c0f3bbab73d2 1410 void BSP_AUDIO_IN_DeInit(void)
Jerome Coutant 0:c0f3bbab73d2 1411 {
Jerome Coutant 0:c0f3bbab73d2 1412 BSP_AUDIO_IN_MspDeInit();
Jerome Coutant 0:c0f3bbab73d2 1413
Jerome Coutant 0:c0f3bbab73d2 1414 if(AudioIn_Device == INPUT_DEVICE_DIGITAL_MIC)
Jerome Coutant 0:c0f3bbab73d2 1415 {
Jerome Coutant 0:c0f3bbab73d2 1416 DFSDMx_DeInit();
Jerome Coutant 0:c0f3bbab73d2 1417 }
Jerome Coutant 0:c0f3bbab73d2 1418 else
Jerome Coutant 0:c0f3bbab73d2 1419 {
Jerome Coutant 0:c0f3bbab73d2 1420 SAIx_In_DeInit();
Jerome Coutant 0:c0f3bbab73d2 1421 }
Jerome Coutant 0:c0f3bbab73d2 1422 }
Jerome Coutant 0:c0f3bbab73d2 1423
Jerome Coutant 0:c0f3bbab73d2 1424 /**
Jerome Coutant 0:c0f3bbab73d2 1425 * @brief Regular conversion complete callback.
Jerome Coutant 0:c0f3bbab73d2 1426 * @note In interrupt mode, user has to read conversion value in this function
Jerome Coutant 0:c0f3bbab73d2 1427 using HAL_DFSDM_FilterGetRegularValue.
Jerome Coutant 0:c0f3bbab73d2 1428 * @param hdfsdm_filter : DFSDM filter handle.
Jerome Coutant 0:c0f3bbab73d2 1429 * @retval None
Jerome Coutant 0:c0f3bbab73d2 1430 */
Jerome Coutant 0:c0f3bbab73d2 1431 void HAL_DFSDM_FilterRegConvCpltCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
Jerome Coutant 0:c0f3bbab73d2 1432 {
Jerome Coutant 0:c0f3bbab73d2 1433 uint32_t index = 0;
Jerome Coutant 0:c0f3bbab73d2 1434
Jerome Coutant 0:c0f3bbab73d2 1435 if(hdfsdm_filter == &hAudioInTopLeftFilter)
Jerome Coutant 0:c0f3bbab73d2 1436 {
Jerome Coutant 0:c0f3bbab73d2 1437 DmaTopLeftRecCplt = 1;
Jerome Coutant 0:c0f3bbab73d2 1438 }
Jerome Coutant 0:c0f3bbab73d2 1439 else if(hdfsdm_filter == &hAudioInTopRightFilter)
Jerome Coutant 0:c0f3bbab73d2 1440 {
Jerome Coutant 0:c0f3bbab73d2 1441 DmaTopRightRecCplt = 1;
Jerome Coutant 0:c0f3bbab73d2 1442 }
Jerome Coutant 0:c0f3bbab73d2 1443 else if(hdfsdm_filter == &hAudioInButtomLeftFilter)
Jerome Coutant 0:c0f3bbab73d2 1444 {
Jerome Coutant 0:c0f3bbab73d2 1445 DmaButtomLeftRecCplt = 1;
Jerome Coutant 0:c0f3bbab73d2 1446 }
Jerome Coutant 0:c0f3bbab73d2 1447 else
Jerome Coutant 0:c0f3bbab73d2 1448 {
Jerome Coutant 0:c0f3bbab73d2 1449 DmaButtomRightRecCplt = 1;
Jerome Coutant 0:c0f3bbab73d2 1450 }
Jerome Coutant 0:c0f3bbab73d2 1451
Jerome Coutant 0:c0f3bbab73d2 1452 if(AudioIn_ChannelNumber > 2)
Jerome Coutant 0:c0f3bbab73d2 1453 {
Jerome Coutant 0:c0f3bbab73d2 1454 if((DmaTopLeftRecCplt == 1) && (DmaTopRightRecCplt == 1) && (DmaButtomLeftRecCplt == 1) && (DmaButtomRightRecCplt == 1))
Jerome Coutant 0:c0f3bbab73d2 1455 {
Jerome Coutant 0:c0f3bbab73d2 1456 for(index = (ScratchSize/2) ; index < ScratchSize; index++)
Jerome Coutant 0:c0f3bbab73d2 1457 {
Jerome Coutant 0:c0f3bbab73d2 1458 hAudioIn.pRecBuf[AppBuffTrigger] = (uint16_t)(SaturaLH((pScratchBuff[1][index] >> 8), -32760, 32760));
Jerome Coutant 0:c0f3bbab73d2 1459 hAudioIn.pRecBuf[AppBuffTrigger + 1] = (uint16_t)(SaturaLH((pScratchBuff[0][index] >> 8), -32760, 32760));
Jerome Coutant 0:c0f3bbab73d2 1460 hAudioIn.pRecBuf[AppBuffTrigger + 2] = (uint16_t)(SaturaLH((pScratchBuff[3][index] >> 8), -32760, 32760));
Jerome Coutant 0:c0f3bbab73d2 1461 hAudioIn.pRecBuf[AppBuffTrigger + 3] = (uint16_t)(SaturaLH((pScratchBuff[2][index] >> 8), -32760, 32760));
Jerome Coutant 0:c0f3bbab73d2 1462 AppBuffTrigger +=4;
Jerome Coutant 0:c0f3bbab73d2 1463 }
Jerome Coutant 0:c0f3bbab73d2 1464 DmaTopLeftRecCplt = 0;
Jerome Coutant 0:c0f3bbab73d2 1465 DmaTopRightRecCplt = 0;
Jerome Coutant 0:c0f3bbab73d2 1466 DmaButtomLeftRecCplt = 0;
Jerome Coutant 0:c0f3bbab73d2 1467 DmaButtomRightRecCplt = 0;
Jerome Coutant 0:c0f3bbab73d2 1468 }
Jerome Coutant 0:c0f3bbab73d2 1469 }
Jerome Coutant 0:c0f3bbab73d2 1470 else
Jerome Coutant 0:c0f3bbab73d2 1471 {
Jerome Coutant 0:c0f3bbab73d2 1472 if((DmaTopLeftRecCplt == 1) && (DmaTopRightRecCplt == 1))
Jerome Coutant 0:c0f3bbab73d2 1473 {
Jerome Coutant 0:c0f3bbab73d2 1474 for(index = (ScratchSize/2) ; index < ScratchSize; index++)
Jerome Coutant 0:c0f3bbab73d2 1475 {
Jerome Coutant 0:c0f3bbab73d2 1476 hAudioIn.pRecBuf[AppBuffTrigger] = (uint16_t)(SaturaLH((pScratchBuff[1][index] >> 8), -32760, 32760));
Jerome Coutant 0:c0f3bbab73d2 1477 hAudioIn.pRecBuf[AppBuffTrigger + 1] = (uint16_t)(SaturaLH((pScratchBuff[0][index] >> 8), -32760, 32760));
Jerome Coutant 0:c0f3bbab73d2 1478 AppBuffTrigger +=2;
Jerome Coutant 0:c0f3bbab73d2 1479 }
Jerome Coutant 0:c0f3bbab73d2 1480 DmaTopLeftRecCplt = 0;
Jerome Coutant 0:c0f3bbab73d2 1481 DmaTopRightRecCplt = 0;
Jerome Coutant 0:c0f3bbab73d2 1482 }
Jerome Coutant 0:c0f3bbab73d2 1483 }
Jerome Coutant 0:c0f3bbab73d2 1484
Jerome Coutant 0:c0f3bbab73d2 1485 /* Call Half Transfer Complete callback */
Jerome Coutant 0:c0f3bbab73d2 1486 if((AppBuffTrigger == hAudioIn.RecSize/2) && (AppBuffHalf == 0))
Jerome Coutant 0:c0f3bbab73d2 1487 {
Jerome Coutant 0:c0f3bbab73d2 1488 AppBuffHalf = 1;
Jerome Coutant 0:c0f3bbab73d2 1489 BSP_AUDIO_IN_HalfTransfer_CallBack();
Jerome Coutant 0:c0f3bbab73d2 1490 }
Jerome Coutant 0:c0f3bbab73d2 1491 /* Call Transfer Complete callback */
Jerome Coutant 0:c0f3bbab73d2 1492 if(AppBuffTrigger == hAudioIn.RecSize)
Jerome Coutant 0:c0f3bbab73d2 1493 {
Jerome Coutant 0:c0f3bbab73d2 1494 /* Reset Application Buffer Trigger */
Jerome Coutant 0:c0f3bbab73d2 1495 AppBuffTrigger = 0;
Jerome Coutant 0:c0f3bbab73d2 1496 AppBuffHalf = 0;
Jerome Coutant 0:c0f3bbab73d2 1497 /* Call the record update function to get the next buffer to fill and its size (size is ignored) */
Jerome Coutant 0:c0f3bbab73d2 1498 BSP_AUDIO_IN_TransferComplete_CallBack();
Jerome Coutant 0:c0f3bbab73d2 1499 }
Jerome Coutant 0:c0f3bbab73d2 1500 }
Jerome Coutant 0:c0f3bbab73d2 1501
Jerome Coutant 0:c0f3bbab73d2 1502 /**
Jerome Coutant 0:c0f3bbab73d2 1503 * @brief Half regular conversion complete callback.
Jerome Coutant 0:c0f3bbab73d2 1504 * @param hdfsdm_filter : DFSDM filter handle.
Jerome Coutant 0:c0f3bbab73d2 1505 * @retval None
Jerome Coutant 0:c0f3bbab73d2 1506 */
Jerome Coutant 0:c0f3bbab73d2 1507 void HAL_DFSDM_FilterRegConvHalfCpltCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
Jerome Coutant 0:c0f3bbab73d2 1508 {
Jerome Coutant 0:c0f3bbab73d2 1509 uint32_t index = 0;
Jerome Coutant 0:c0f3bbab73d2 1510
Jerome Coutant 0:c0f3bbab73d2 1511 if(hdfsdm_filter == &hAudioInTopLeftFilter)
Jerome Coutant 0:c0f3bbab73d2 1512 {
Jerome Coutant 0:c0f3bbab73d2 1513 DmaTopLeftRecHalfCplt = 1;
Jerome Coutant 0:c0f3bbab73d2 1514 }
Jerome Coutant 0:c0f3bbab73d2 1515 else if(hdfsdm_filter == &hAudioInTopRightFilter)
Jerome Coutant 0:c0f3bbab73d2 1516 {
Jerome Coutant 0:c0f3bbab73d2 1517 DmaTopRightRecHalfCplt = 1;
Jerome Coutant 0:c0f3bbab73d2 1518 }
Jerome Coutant 0:c0f3bbab73d2 1519 else if(hdfsdm_filter == &hAudioInButtomLeftFilter)
Jerome Coutant 0:c0f3bbab73d2 1520 {
Jerome Coutant 0:c0f3bbab73d2 1521 DmaButtomLeftRecHalfCplt = 1;
Jerome Coutant 0:c0f3bbab73d2 1522 }
Jerome Coutant 0:c0f3bbab73d2 1523 else
Jerome Coutant 0:c0f3bbab73d2 1524 {
Jerome Coutant 0:c0f3bbab73d2 1525 DmaButtomRightRecHalfCplt = 1;
Jerome Coutant 0:c0f3bbab73d2 1526 }
Jerome Coutant 0:c0f3bbab73d2 1527
Jerome Coutant 0:c0f3bbab73d2 1528 if(AudioIn_ChannelNumber > 2)
Jerome Coutant 0:c0f3bbab73d2 1529 {
Jerome Coutant 0:c0f3bbab73d2 1530 if((DmaTopLeftRecHalfCplt == 1) && (DmaTopRightRecHalfCplt == 1) && (DmaButtomLeftRecHalfCplt == 1) && (DmaButtomRightRecHalfCplt == 1))
Jerome Coutant 0:c0f3bbab73d2 1531 {
Jerome Coutant 0:c0f3bbab73d2 1532 for(index = 0 ; index < ScratchSize/2; index++)
Jerome Coutant 0:c0f3bbab73d2 1533 {
Jerome Coutant 0:c0f3bbab73d2 1534 hAudioIn.pRecBuf[AppBuffTrigger] = (uint16_t)(SaturaLH((pScratchBuff[1][index] >> 8), -32760, 32760));
Jerome Coutant 0:c0f3bbab73d2 1535 hAudioIn.pRecBuf[AppBuffTrigger + 1] = (uint16_t)(SaturaLH((pScratchBuff[0][index] >> 8), -32760, 32760));
Jerome Coutant 0:c0f3bbab73d2 1536 hAudioIn.pRecBuf[AppBuffTrigger + 2] = (uint16_t)(SaturaLH((pScratchBuff[3][index] >> 8), -32760, 32760));
Jerome Coutant 0:c0f3bbab73d2 1537 hAudioIn.pRecBuf[AppBuffTrigger + 3] = (uint16_t)(SaturaLH((pScratchBuff[2][index] >> 8), -32760, 32760));
Jerome Coutant 0:c0f3bbab73d2 1538 AppBuffTrigger +=4;
Jerome Coutant 0:c0f3bbab73d2 1539 }
Jerome Coutant 0:c0f3bbab73d2 1540 DmaTopLeftRecHalfCplt = 0;
Jerome Coutant 0:c0f3bbab73d2 1541 DmaTopRightRecHalfCplt = 0;
Jerome Coutant 0:c0f3bbab73d2 1542 DmaButtomLeftRecHalfCplt = 0;
Jerome Coutant 0:c0f3bbab73d2 1543 DmaButtomRightRecHalfCplt = 0;
Jerome Coutant 0:c0f3bbab73d2 1544 }
Jerome Coutant 0:c0f3bbab73d2 1545 }
Jerome Coutant 0:c0f3bbab73d2 1546 else
Jerome Coutant 0:c0f3bbab73d2 1547 {
Jerome Coutant 0:c0f3bbab73d2 1548 if((DmaTopLeftRecHalfCplt == 1) && (DmaTopRightRecHalfCplt == 1))
Jerome Coutant 0:c0f3bbab73d2 1549 {
Jerome Coutant 0:c0f3bbab73d2 1550 for(index = 0 ; index < ScratchSize/2; index++)
Jerome Coutant 0:c0f3bbab73d2 1551 {
Jerome Coutant 0:c0f3bbab73d2 1552 hAudioIn.pRecBuf[AppBuffTrigger] = (uint16_t)(SaturaLH((pScratchBuff[1][index] >> 8), -32760, 32760));
Jerome Coutant 0:c0f3bbab73d2 1553 hAudioIn.pRecBuf[AppBuffTrigger + 1] = (uint16_t)(SaturaLH((pScratchBuff[0][index] >> 8), -32760, 32760));
Jerome Coutant 0:c0f3bbab73d2 1554 AppBuffTrigger +=2;
Jerome Coutant 0:c0f3bbab73d2 1555 }
Jerome Coutant 0:c0f3bbab73d2 1556 DmaTopLeftRecHalfCplt = 0;
Jerome Coutant 0:c0f3bbab73d2 1557 DmaTopRightRecHalfCplt = 0;
Jerome Coutant 0:c0f3bbab73d2 1558 }
Jerome Coutant 0:c0f3bbab73d2 1559 }
Jerome Coutant 0:c0f3bbab73d2 1560
Jerome Coutant 0:c0f3bbab73d2 1561 /* Call Half Transfer Complete callback */
Jerome Coutant 0:c0f3bbab73d2 1562 if((AppBuffTrigger == hAudioIn.RecSize/2) && (AppBuffHalf == 0))
Jerome Coutant 0:c0f3bbab73d2 1563 {
Jerome Coutant 0:c0f3bbab73d2 1564 AppBuffHalf = 1;
Jerome Coutant 0:c0f3bbab73d2 1565 BSP_AUDIO_IN_HalfTransfer_CallBack();
Jerome Coutant 0:c0f3bbab73d2 1566 }
Jerome Coutant 0:c0f3bbab73d2 1567 /* Call Transfer Complete callback */
Jerome Coutant 0:c0f3bbab73d2 1568 if(AppBuffTrigger == hAudioIn.RecSize)
Jerome Coutant 0:c0f3bbab73d2 1569 {
Jerome Coutant 0:c0f3bbab73d2 1570 /* Reset Application Buffer Trigger */
Jerome Coutant 0:c0f3bbab73d2 1571 AppBuffTrigger = 0;
Jerome Coutant 0:c0f3bbab73d2 1572 AppBuffHalf = 0;
Jerome Coutant 0:c0f3bbab73d2 1573 /* Call the record update function to get the next buffer to fill and its size (size is ignored) */
Jerome Coutant 0:c0f3bbab73d2 1574 BSP_AUDIO_IN_TransferComplete_CallBack();
Jerome Coutant 0:c0f3bbab73d2 1575 }
Jerome Coutant 0:c0f3bbab73d2 1576 }
Jerome Coutant 0:c0f3bbab73d2 1577
Jerome Coutant 0:c0f3bbab73d2 1578 /**
Jerome Coutant 0:c0f3bbab73d2 1579 * @brief Half reception complete callback.
Jerome Coutant 1:3e58f8a39705 1580 * @param hsai : SAI handle.
Jerome Coutant 0:c0f3bbab73d2 1581 * @retval None
Jerome Coutant 0:c0f3bbab73d2 1582 */
Jerome Coutant 0:c0f3bbab73d2 1583 void HAL_SAI_RxHalfCpltCallback(SAI_HandleTypeDef *hsai)
Jerome Coutant 0:c0f3bbab73d2 1584 {
Jerome Coutant 0:c0f3bbab73d2 1585 /* Manage the remaining file size and new address offset: This function
Jerome Coutant 1:3e58f8a39705 1586 should be coded by user (its prototype is already declared in stm32769i_discovery_audio.h) */
Jerome Coutant 0:c0f3bbab73d2 1587 BSP_AUDIO_IN_HalfTransfer_CallBack();
Jerome Coutant 0:c0f3bbab73d2 1588 }
Jerome Coutant 0:c0f3bbab73d2 1589
Jerome Coutant 0:c0f3bbab73d2 1590 /**
Jerome Coutant 0:c0f3bbab73d2 1591 * @brief Reception complete callback.
Jerome Coutant 1:3e58f8a39705 1592 * @param hsai : SAI handle.
Jerome Coutant 0:c0f3bbab73d2 1593 * @retval None
Jerome Coutant 0:c0f3bbab73d2 1594 */
Jerome Coutant 0:c0f3bbab73d2 1595 void HAL_SAI_RxCpltCallback(SAI_HandleTypeDef *hsai)
Jerome Coutant 0:c0f3bbab73d2 1596 {
Jerome Coutant 0:c0f3bbab73d2 1597 /* Call the record update function to get the next buffer to fill and its size (size is ignored) */
Jerome Coutant 0:c0f3bbab73d2 1598 BSP_AUDIO_IN_TransferComplete_CallBack();
Jerome Coutant 0:c0f3bbab73d2 1599 }
Jerome Coutant 0:c0f3bbab73d2 1600
Jerome Coutant 0:c0f3bbab73d2 1601 /**
Jerome Coutant 0:c0f3bbab73d2 1602 * @brief User callback when record buffer is filled.
Jerome Coutant 0:c0f3bbab73d2 1603 * @retval None
Jerome Coutant 0:c0f3bbab73d2 1604 */
Jerome Coutant 0:c0f3bbab73d2 1605 __weak void BSP_AUDIO_IN_TransferComplete_CallBack(void)
Jerome Coutant 0:c0f3bbab73d2 1606 {
Jerome Coutant 0:c0f3bbab73d2 1607 /* This function should be implemented by the user application.
Jerome Coutant 0:c0f3bbab73d2 1608 It is called into this driver when the current buffer is filled
Jerome Coutant 0:c0f3bbab73d2 1609 to prepare the next buffer pointer and its size. */
Jerome Coutant 0:c0f3bbab73d2 1610 }
Jerome Coutant 0:c0f3bbab73d2 1611
Jerome Coutant 0:c0f3bbab73d2 1612 /**
Jerome Coutant 0:c0f3bbab73d2 1613 * @brief Manages the DMA Half Transfer complete event.
Jerome Coutant 0:c0f3bbab73d2 1614 * @retval None
Jerome Coutant 0:c0f3bbab73d2 1615 */
Jerome Coutant 0:c0f3bbab73d2 1616 __weak void BSP_AUDIO_IN_HalfTransfer_CallBack(void)
Jerome Coutant 0:c0f3bbab73d2 1617 {
Jerome Coutant 0:c0f3bbab73d2 1618 /* This function should be implemented by the user application.
Jerome Coutant 0:c0f3bbab73d2 1619 It is called into this driver when the current buffer is filled
Jerome Coutant 0:c0f3bbab73d2 1620 to prepare the next buffer pointer and its size. */
Jerome Coutant 0:c0f3bbab73d2 1621 }
Jerome Coutant 0:c0f3bbab73d2 1622
Jerome Coutant 0:c0f3bbab73d2 1623 /**
Jerome Coutant 0:c0f3bbab73d2 1624 * @brief Audio IN Error callback function.
Jerome Coutant 0:c0f3bbab73d2 1625 * @retval None
Jerome Coutant 0:c0f3bbab73d2 1626 */
Jerome Coutant 0:c0f3bbab73d2 1627 __weak void BSP_AUDIO_IN_Error_CallBack(void)
Jerome Coutant 0:c0f3bbab73d2 1628 {
Jerome Coutant 0:c0f3bbab73d2 1629 /* This function is called when an Interrupt due to transfer error on or peripheral
Jerome Coutant 0:c0f3bbab73d2 1630 error occurs. */
Jerome Coutant 0:c0f3bbab73d2 1631 }
Jerome Coutant 0:c0f3bbab73d2 1632
Jerome Coutant 0:c0f3bbab73d2 1633 /**
Jerome Coutant 0:c0f3bbab73d2 1634 * @brief Initialize BSP_AUDIO_IN MSP.
Jerome Coutant 0:c0f3bbab73d2 1635 * @retval None
Jerome Coutant 0:c0f3bbab73d2 1636 */
Jerome Coutant 0:c0f3bbab73d2 1637 __weak void BSP_AUDIO_IN_MspInit(void)
Jerome Coutant 0:c0f3bbab73d2 1638 {
Jerome Coutant 0:c0f3bbab73d2 1639 if (AudioIn_Device == INPUT_DEVICE_DIGITAL_MIC)
Jerome Coutant 0:c0f3bbab73d2 1640 {
Jerome Coutant 0:c0f3bbab73d2 1641 /* MSP channels initialization */
Jerome Coutant 0:c0f3bbab73d2 1642 DFSDMx_ChannelMspInit();
Jerome Coutant 0:c0f3bbab73d2 1643 /* MSP filters initialization */
Jerome Coutant 0:c0f3bbab73d2 1644 DFSDMx_FilterMspInit();
Jerome Coutant 0:c0f3bbab73d2 1645 }
Jerome Coutant 0:c0f3bbab73d2 1646 else
Jerome Coutant 0:c0f3bbab73d2 1647 {
Jerome Coutant 0:c0f3bbab73d2 1648 SAI_AUDIO_IN_MspInit(&haudio_in_sai, NULL);
Jerome Coutant 0:c0f3bbab73d2 1649 }
Jerome Coutant 0:c0f3bbab73d2 1650 }
Jerome Coutant 0:c0f3bbab73d2 1651
Jerome Coutant 0:c0f3bbab73d2 1652 /**
Jerome Coutant 0:c0f3bbab73d2 1653 * @brief DeInitialize BSP_AUDIO_IN MSP.
Jerome Coutant 0:c0f3bbab73d2 1654 * @retval None
Jerome Coutant 0:c0f3bbab73d2 1655 */
Jerome Coutant 0:c0f3bbab73d2 1656 __weak void BSP_AUDIO_IN_MspDeInit(void)
Jerome Coutant 0:c0f3bbab73d2 1657 {
Jerome Coutant 0:c0f3bbab73d2 1658 if (AudioIn_Device == INPUT_DEVICE_DIGITAL_MIC)
Jerome Coutant 0:c0f3bbab73d2 1659 {
Jerome Coutant 0:c0f3bbab73d2 1660 /* MSP channels initialization */
Jerome Coutant 0:c0f3bbab73d2 1661 DFSDMx_ChannelMspDeInit();
Jerome Coutant 0:c0f3bbab73d2 1662 /* MSP filters initialization */
Jerome Coutant 0:c0f3bbab73d2 1663 DFSDMx_FilterMspDeInit();
Jerome Coutant 0:c0f3bbab73d2 1664 }
Jerome Coutant 0:c0f3bbab73d2 1665 else
Jerome Coutant 0:c0f3bbab73d2 1666 {
Jerome Coutant 0:c0f3bbab73d2 1667 SAI_AUDIO_IN_MspDeInit(&haudio_in_sai, NULL);
Jerome Coutant 0:c0f3bbab73d2 1668 }
Jerome Coutant 0:c0f3bbab73d2 1669 }
Jerome Coutant 0:c0f3bbab73d2 1670
Jerome Coutant 0:c0f3bbab73d2 1671 /**
Jerome Coutant 0:c0f3bbab73d2 1672 * @brief Clock Config.
Jerome Coutant 0:c0f3bbab73d2 1673 * @param hdfsdm_filter: might be required to set audio peripheral predivider if any.
Jerome Coutant 0:c0f3bbab73d2 1674 * @param AudioFreq: Audio frequency used to play the audio stream.
Jerome Coutant 1:3e58f8a39705 1675 * @param Params
Jerome Coutant 0:c0f3bbab73d2 1676 * @note This API is called by BSP_AUDIO_IN_Init()
Jerome Coutant 0:c0f3bbab73d2 1677 * Being __weak it can be overwritten by the application
Jerome Coutant 0:c0f3bbab73d2 1678 * @retval None
Jerome Coutant 0:c0f3bbab73d2 1679 */
Jerome Coutant 0:c0f3bbab73d2 1680 __weak void BSP_AUDIO_IN_ClockConfig(DFSDM_Filter_HandleTypeDef *hdfsdm_filter, uint32_t AudioFreq, void *Params)
Jerome Coutant 0:c0f3bbab73d2 1681 {
Jerome Coutant 0:c0f3bbab73d2 1682 RCC_PeriphCLKInitTypeDef rcc_ex_clk_init_struct;
Jerome Coutant 0:c0f3bbab73d2 1683
Jerome Coutant 0:c0f3bbab73d2 1684 HAL_RCCEx_GetPeriphCLKConfig(&rcc_ex_clk_init_struct);
Jerome Coutant 0:c0f3bbab73d2 1685
Jerome Coutant 0:c0f3bbab73d2 1686 /* Set the PLL configuration according to the audio frequency */
Jerome Coutant 0:c0f3bbab73d2 1687 if((AudioFreq == AUDIO_FREQUENCY_11K) || (AudioFreq == AUDIO_FREQUENCY_22K) || (AudioFreq == AUDIO_FREQUENCY_44K))
Jerome Coutant 0:c0f3bbab73d2 1688 {
Jerome Coutant 0:c0f3bbab73d2 1689 /* Configure PLLSAI prescalers */
Jerome Coutant 0:c0f3bbab73d2 1690 /* PLLI2S_VCO: VCO_429M
Jerome Coutant 0:c0f3bbab73d2 1691 SAI_CLK(first level) = PLLI2S_VCO/PLLI2SQ = 429/2 = 214.5 Mhz
Jerome Coutant 0:c0f3bbab73d2 1692 SAI_CLK_x = SAI_CLK(first level)/PLLI2SDIVQ = 214.5/19 = 11.289 Mhz */
Jerome Coutant 0:c0f3bbab73d2 1693 rcc_ex_clk_init_struct.PeriphClockSelection = RCC_PERIPHCLK_SAI2;
Jerome Coutant 0:c0f3bbab73d2 1694 rcc_ex_clk_init_struct.Sai2ClockSelection = RCC_SAI2CLKSOURCE_PLLI2S;
Jerome Coutant 0:c0f3bbab73d2 1695 rcc_ex_clk_init_struct.PLLI2S.PLLI2SN = 429;
Jerome Coutant 0:c0f3bbab73d2 1696 rcc_ex_clk_init_struct.PLLI2S.PLLI2SQ = 2;
Jerome Coutant 0:c0f3bbab73d2 1697 rcc_ex_clk_init_struct.PLLI2SDivQ = 19;
Jerome Coutant 0:c0f3bbab73d2 1698
Jerome Coutant 0:c0f3bbab73d2 1699 HAL_RCCEx_PeriphCLKConfig(&rcc_ex_clk_init_struct);
Jerome Coutant 0:c0f3bbab73d2 1700
Jerome Coutant 0:c0f3bbab73d2 1701 }
Jerome Coutant 0:c0f3bbab73d2 1702 else /* AUDIO_FREQUENCY_8K, AUDIO_FREQUENCY_16K, AUDIO_FREQUENCY_32K, AUDIO_FREQUENCY_48K, AUDIO_FREQUENCY_96K */
Jerome Coutant 0:c0f3bbab73d2 1703 {
Jerome Coutant 0:c0f3bbab73d2 1704 /* SAI clock config
Jerome Coutant 0:c0f3bbab73d2 1705 PLLI2S_VCO: VCO_344M
Jerome Coutant 0:c0f3bbab73d2 1706 SAI_CLK(first level) = PLLI2S_VCO/PLLI2SQ = 344/7 = 49.142 Mhz
Jerome Coutant 0:c0f3bbab73d2 1707 SAI_CLK_x = SAI_CLK(first level)/PLLI2SDIVQ = 49.142/1 = 49.142 Mhz */
Jerome Coutant 0:c0f3bbab73d2 1708 rcc_ex_clk_init_struct.PeriphClockSelection = RCC_PERIPHCLK_SAI2;
Jerome Coutant 0:c0f3bbab73d2 1709 rcc_ex_clk_init_struct.Sai2ClockSelection = RCC_SAI2CLKSOURCE_PLLI2S;
Jerome Coutant 0:c0f3bbab73d2 1710 rcc_ex_clk_init_struct.PLLI2S.PLLI2SN = 344;
Jerome Coutant 0:c0f3bbab73d2 1711 rcc_ex_clk_init_struct.PLLI2S.PLLI2SQ = 7;
Jerome Coutant 0:c0f3bbab73d2 1712 rcc_ex_clk_init_struct.PLLI2SDivQ = 1;
Jerome Coutant 0:c0f3bbab73d2 1713 HAL_RCCEx_PeriphCLKConfig(&rcc_ex_clk_init_struct);
Jerome Coutant 0:c0f3bbab73d2 1714 }
Jerome Coutant 0:c0f3bbab73d2 1715
Jerome Coutant 0:c0f3bbab73d2 1716 rcc_ex_clk_init_struct.PeriphClockSelection = RCC_PERIPHCLK_DFSDM1_AUDIO;
Jerome Coutant 0:c0f3bbab73d2 1717 rcc_ex_clk_init_struct.Dfsdm1AudioClockSelection = RCC_DFSDM1AUDIOCLKSOURCE_SAI2;
Jerome Coutant 0:c0f3bbab73d2 1718 HAL_RCCEx_PeriphCLKConfig(&rcc_ex_clk_init_struct);
Jerome Coutant 0:c0f3bbab73d2 1719 }
Jerome Coutant 0:c0f3bbab73d2 1720
Jerome Coutant 0:c0f3bbab73d2 1721 /*******************************************************************************
Jerome Coutant 0:c0f3bbab73d2 1722 Static Functions
Jerome Coutant 0:c0f3bbab73d2 1723 *******************************************************************************/
Jerome Coutant 0:c0f3bbab73d2 1724 /**
Jerome Coutant 0:c0f3bbab73d2 1725 * @brief Initialize the Digital Filter for Sigma-Delta Modulators interface (DFSDM).
Jerome Coutant 0:c0f3bbab73d2 1726 * @param AudioFreq: Audio frequency to be used to set correctly the DFSDM peripheral.
Jerome Coutant 0:c0f3bbab73d2 1727 * @note Channel output Clock Divider and Filter Oversampling are calculated as follow:
Jerome Coutant 0:c0f3bbab73d2 1728 * - Clock_Divider = CLK(input DFSDM)/CLK(micro) with
Jerome Coutant 0:c0f3bbab73d2 1729 * 1MHZ < CLK(micro) < 3.2MHZ (TYP 2.4MHZ for MP34DT01TR)
Jerome Coutant 0:c0f3bbab73d2 1730 * - Oversampling = CLK(input DFSDM)/(Clock_Divider * AudioFreq)
Jerome Coutant 0:c0f3bbab73d2 1731 * @retval AUDIO_OK if correct communication, else wrong communication
Jerome Coutant 0:c0f3bbab73d2 1732 */
Jerome Coutant 0:c0f3bbab73d2 1733 static uint8_t DFSDMx_Init(uint32_t AudioFreq)
Jerome Coutant 0:c0f3bbab73d2 1734 {
Jerome Coutant 0:c0f3bbab73d2 1735 /****************************************************************************/
Jerome Coutant 0:c0f3bbab73d2 1736 /********************** Channels configuration *****************************/
Jerome Coutant 0:c0f3bbab73d2 1737 /****************************************************************************/
Jerome Coutant 0:c0f3bbab73d2 1738 /* CHANNEL 1 configuration */
Jerome Coutant 0:c0f3bbab73d2 1739 __HAL_DFSDM_CHANNEL_RESET_HANDLE_STATE(&hAudioInTopLeftChannel);
Jerome Coutant 0:c0f3bbab73d2 1740 hAudioInTopLeftChannel.Instance = DFSDM1_Channel1;
Jerome Coutant 0:c0f3bbab73d2 1741 hAudioInTopLeftChannel.Init.OutputClock.Activation = ENABLE;
Jerome Coutant 0:c0f3bbab73d2 1742 hAudioInTopLeftChannel.Init.OutputClock.Selection = DFSDM_CHANNEL_OUTPUT_CLOCK_AUDIO;
Jerome Coutant 0:c0f3bbab73d2 1743 /* Set the DFSDM clock OUT audio frequency configuration */
Jerome Coutant 0:c0f3bbab73d2 1744 hAudioInTopLeftChannel.Init.OutputClock.Divider = DFSDM_CLOCK_DIVIDER(AudioFreq);
Jerome Coutant 0:c0f3bbab73d2 1745 hAudioInTopLeftChannel.Init.Input.Multiplexer = DFSDM_CHANNEL_EXTERNAL_INPUTS;
Jerome Coutant 0:c0f3bbab73d2 1746 hAudioInTopLeftChannel.Init.Input.DataPacking = DFSDM_CHANNEL_STANDARD_MODE;
Jerome Coutant 0:c0f3bbab73d2 1747 hAudioInTopLeftChannel.Init.Input.Pins = DFSDM_CHANNEL_SAME_CHANNEL_PINS;
Jerome Coutant 0:c0f3bbab73d2 1748 /* Request to sample stable data for LEFT micro on Rising edge */
Jerome Coutant 0:c0f3bbab73d2 1749 hAudioInTopLeftChannel.Init.SerialInterface.Type = DFSDM_CHANNEL_SPI_RISING;
Jerome Coutant 0:c0f3bbab73d2 1750 hAudioInTopLeftChannel.Init.SerialInterface.SpiClock = DFSDM_CHANNEL_SPI_CLOCK_INTERNAL;
Jerome Coutant 0:c0f3bbab73d2 1751 hAudioInTopLeftChannel.Init.Awd.FilterOrder = DFSDM_CHANNEL_FASTSINC_ORDER;
Jerome Coutant 0:c0f3bbab73d2 1752 hAudioInTopLeftChannel.Init.Awd.Oversampling = 10;
Jerome Coutant 0:c0f3bbab73d2 1753 hAudioInTopLeftChannel.Init.Offset = 0;
Jerome Coutant 0:c0f3bbab73d2 1754 hAudioInTopLeftChannel.Init.RightBitShift = DFSDM_RIGHT_BIT_SHIFT(AudioFreq);
Jerome Coutant 0:c0f3bbab73d2 1755 if(HAL_OK != HAL_DFSDM_ChannelInit(&hAudioInTopLeftChannel))
Jerome Coutant 0:c0f3bbab73d2 1756 {
Jerome Coutant 0:c0f3bbab73d2 1757 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1758 }
Jerome Coutant 0:c0f3bbab73d2 1759
Jerome Coutant 0:c0f3bbab73d2 1760 /* CHANNEL 0 configuration */
Jerome Coutant 0:c0f3bbab73d2 1761 __HAL_DFSDM_CHANNEL_RESET_HANDLE_STATE(&hAudioInTopRightChannel);
Jerome Coutant 0:c0f3bbab73d2 1762 hAudioInTopRightChannel.Instance = DFSDM1_Channel0;
Jerome Coutant 0:c0f3bbab73d2 1763 hAudioInTopRightChannel.Init.OutputClock.Activation = ENABLE;
Jerome Coutant 0:c0f3bbab73d2 1764 hAudioInTopRightChannel.Init.OutputClock.Selection = DFSDM_CHANNEL_OUTPUT_CLOCK_AUDIO;
Jerome Coutant 0:c0f3bbab73d2 1765 /* Set the DFSDM clock OUT audio frequency configuration */
Jerome Coutant 0:c0f3bbab73d2 1766 hAudioInTopRightChannel.Init.OutputClock.Divider = DFSDM_CLOCK_DIVIDER(AudioFreq);
Jerome Coutant 0:c0f3bbab73d2 1767 hAudioInTopRightChannel.Init.Input.Multiplexer = DFSDM_CHANNEL_EXTERNAL_INPUTS;
Jerome Coutant 0:c0f3bbab73d2 1768 hAudioInTopRightChannel.Init.Input.DataPacking = DFSDM_CHANNEL_STANDARD_MODE;
Jerome Coutant 0:c0f3bbab73d2 1769 hAudioInTopRightChannel.Init.Input.Pins = DFSDM_CHANNEL_FOLLOWING_CHANNEL_PINS;
Jerome Coutant 0:c0f3bbab73d2 1770 /* Request to sample stable data for RIGHT micro on Falling edge */
Jerome Coutant 0:c0f3bbab73d2 1771 hAudioInTopRightChannel.Init.SerialInterface.Type = DFSDM_CHANNEL_SPI_FALLING;
Jerome Coutant 0:c0f3bbab73d2 1772 hAudioInTopRightChannel.Init.SerialInterface.SpiClock = DFSDM_CHANNEL_SPI_CLOCK_INTERNAL;
Jerome Coutant 0:c0f3bbab73d2 1773 hAudioInTopRightChannel.Init.Awd.FilterOrder = DFSDM_CHANNEL_FASTSINC_ORDER;
Jerome Coutant 0:c0f3bbab73d2 1774 hAudioInTopRightChannel.Init.Awd.Oversampling = 10;
Jerome Coutant 0:c0f3bbab73d2 1775 hAudioInTopRightChannel.Init.Offset = 0;
Jerome Coutant 0:c0f3bbab73d2 1776 hAudioInTopRightChannel.Init.RightBitShift = DFSDM_RIGHT_BIT_SHIFT(AudioFreq);
Jerome Coutant 0:c0f3bbab73d2 1777 if(HAL_OK != HAL_DFSDM_ChannelInit(&hAudioInTopRightChannel))
Jerome Coutant 0:c0f3bbab73d2 1778 {
Jerome Coutant 0:c0f3bbab73d2 1779 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1780 }
Jerome Coutant 0:c0f3bbab73d2 1781
Jerome Coutant 0:c0f3bbab73d2 1782 if(AudioIn_ChannelNumber > 2)
Jerome Coutant 0:c0f3bbab73d2 1783 {
Jerome Coutant 0:c0f3bbab73d2 1784 /* CHANNEL 5 configuration */
Jerome Coutant 0:c0f3bbab73d2 1785 __HAL_DFSDM_CHANNEL_RESET_HANDLE_STATE(&hAudioInButtomLeftChannel);
Jerome Coutant 0:c0f3bbab73d2 1786 hAudioInButtomLeftChannel.Instance = DFSDM1_Channel5;
Jerome Coutant 0:c0f3bbab73d2 1787 hAudioInButtomLeftChannel.Init.OutputClock.Activation = ENABLE;
Jerome Coutant 0:c0f3bbab73d2 1788 hAudioInButtomLeftChannel.Init.OutputClock.Selection = DFSDM_CHANNEL_OUTPUT_CLOCK_AUDIO;
Jerome Coutant 0:c0f3bbab73d2 1789 /* Set the DFSDM clock OUT audio frequency configuration */
Jerome Coutant 0:c0f3bbab73d2 1790 hAudioInButtomLeftChannel.Init.OutputClock.Divider = DFSDM_CLOCK_DIVIDER(AudioFreq);
Jerome Coutant 0:c0f3bbab73d2 1791 hAudioInButtomLeftChannel.Init.Input.Multiplexer = DFSDM_CHANNEL_EXTERNAL_INPUTS;
Jerome Coutant 0:c0f3bbab73d2 1792 hAudioInButtomLeftChannel.Init.Input.DataPacking = DFSDM_CHANNEL_STANDARD_MODE;
Jerome Coutant 0:c0f3bbab73d2 1793 hAudioInButtomLeftChannel.Init.Input.Pins = DFSDM_CHANNEL_SAME_CHANNEL_PINS;
Jerome Coutant 0:c0f3bbab73d2 1794 /* Request to sample stable data for LEFT micro on Rising edge */
Jerome Coutant 0:c0f3bbab73d2 1795 hAudioInButtomLeftChannel.Init.SerialInterface.Type = DFSDM_CHANNEL_SPI_RISING;
Jerome Coutant 0:c0f3bbab73d2 1796 hAudioInButtomLeftChannel.Init.SerialInterface.SpiClock = DFSDM_CHANNEL_SPI_CLOCK_INTERNAL;
Jerome Coutant 0:c0f3bbab73d2 1797 hAudioInButtomLeftChannel.Init.Awd.FilterOrder = DFSDM_CHANNEL_FASTSINC_ORDER;
Jerome Coutant 0:c0f3bbab73d2 1798 hAudioInButtomLeftChannel.Init.Awd.Oversampling = 10;
Jerome Coutant 0:c0f3bbab73d2 1799 hAudioInButtomLeftChannel.Init.Offset = 0;
Jerome Coutant 0:c0f3bbab73d2 1800 hAudioInButtomLeftChannel.Init.RightBitShift = DFSDM_RIGHT_BIT_SHIFT(AudioFreq);
Jerome Coutant 0:c0f3bbab73d2 1801 if(HAL_OK != HAL_DFSDM_ChannelInit(&hAudioInButtomLeftChannel))
Jerome Coutant 0:c0f3bbab73d2 1802 {
Jerome Coutant 0:c0f3bbab73d2 1803 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1804 }
Jerome Coutant 0:c0f3bbab73d2 1805
Jerome Coutant 0:c0f3bbab73d2 1806 /* CHANNEL 4 configuration */
Jerome Coutant 0:c0f3bbab73d2 1807 __HAL_DFSDM_CHANNEL_RESET_HANDLE_STATE(&hAudioInButtomRightChannel);
Jerome Coutant 0:c0f3bbab73d2 1808 hAudioInButtomRightChannel.Instance = DFSDM1_Channel4;
Jerome Coutant 0:c0f3bbab73d2 1809 hAudioInButtomRightChannel.Init.OutputClock.Activation = ENABLE;
Jerome Coutant 0:c0f3bbab73d2 1810 hAudioInButtomRightChannel.Init.OutputClock.Selection = DFSDM_CHANNEL_OUTPUT_CLOCK_AUDIO;
Jerome Coutant 0:c0f3bbab73d2 1811 /* Set the DFSDM clock OUT audio frequency configuration */
Jerome Coutant 0:c0f3bbab73d2 1812 hAudioInButtomRightChannel.Init.OutputClock.Divider = DFSDM_CLOCK_DIVIDER(AudioFreq);
Jerome Coutant 0:c0f3bbab73d2 1813 hAudioInButtomRightChannel.Init.Input.Multiplexer = DFSDM_CHANNEL_EXTERNAL_INPUTS;
Jerome Coutant 0:c0f3bbab73d2 1814 hAudioInButtomRightChannel.Init.Input.DataPacking = DFSDM_CHANNEL_STANDARD_MODE;
Jerome Coutant 0:c0f3bbab73d2 1815 hAudioInButtomRightChannel.Init.Input.Pins = DFSDM_CHANNEL_FOLLOWING_CHANNEL_PINS;
Jerome Coutant 0:c0f3bbab73d2 1816 /* Request to sample stable data for RIGHT micro on Falling edge */
Jerome Coutant 0:c0f3bbab73d2 1817 hAudioInButtomRightChannel.Init.SerialInterface.Type = DFSDM_CHANNEL_SPI_FALLING;
Jerome Coutant 0:c0f3bbab73d2 1818 hAudioInButtomRightChannel.Init.SerialInterface.SpiClock = DFSDM_CHANNEL_SPI_CLOCK_INTERNAL;
Jerome Coutant 0:c0f3bbab73d2 1819 hAudioInButtomRightChannel.Init.Awd.FilterOrder = DFSDM_CHANNEL_FASTSINC_ORDER;
Jerome Coutant 0:c0f3bbab73d2 1820 hAudioInButtomRightChannel.Init.Awd.Oversampling = 10;
Jerome Coutant 0:c0f3bbab73d2 1821 hAudioInButtomRightChannel.Init.Offset = 0;
Jerome Coutant 0:c0f3bbab73d2 1822 hAudioInButtomRightChannel.Init.RightBitShift = DFSDM_RIGHT_BIT_SHIFT(AudioFreq);
Jerome Coutant 0:c0f3bbab73d2 1823 if(HAL_OK != HAL_DFSDM_ChannelInit(&hAudioInButtomRightChannel))
Jerome Coutant 0:c0f3bbab73d2 1824 {
Jerome Coutant 0:c0f3bbab73d2 1825 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1826 }
Jerome Coutant 0:c0f3bbab73d2 1827 }
Jerome Coutant 0:c0f3bbab73d2 1828 /****************************************************************************/
Jerome Coutant 0:c0f3bbab73d2 1829 /********************** Filters configuration ******************************/
Jerome Coutant 0:c0f3bbab73d2 1830 /****************************************************************************/
Jerome Coutant 0:c0f3bbab73d2 1831
Jerome Coutant 0:c0f3bbab73d2 1832 /* FILTER 0 configuration */
Jerome Coutant 0:c0f3bbab73d2 1833 __HAL_DFSDM_FILTER_RESET_HANDLE_STATE(&hAudioInTopLeftFilter);
Jerome Coutant 0:c0f3bbab73d2 1834 hAudioInTopLeftFilter.Instance = AUDIO_DFSDMx_TOP_LEFT_FILTER;
Jerome Coutant 0:c0f3bbab73d2 1835 hAudioInTopLeftFilter.Init.RegularParam.Trigger = DFSDM_FILTER_SW_TRIGGER;
Jerome Coutant 0:c0f3bbab73d2 1836 hAudioInTopLeftFilter.Init.RegularParam.FastMode = ENABLE;
Jerome Coutant 0:c0f3bbab73d2 1837 hAudioInTopLeftFilter.Init.RegularParam.DmaMode = ENABLE;
Jerome Coutant 0:c0f3bbab73d2 1838 hAudioInTopLeftFilter.Init.InjectedParam.Trigger = DFSDM_FILTER_SW_TRIGGER;
Jerome Coutant 0:c0f3bbab73d2 1839 hAudioInTopLeftFilter.Init.InjectedParam.ScanMode = ENABLE;
Jerome Coutant 0:c0f3bbab73d2 1840 hAudioInTopLeftFilter.Init.InjectedParam.DmaMode = DISABLE;
Jerome Coutant 0:c0f3bbab73d2 1841 hAudioInTopLeftFilter.Init.InjectedParam.ExtTrigger = DFSDM_FILTER_EXT_TRIG_TIM1_TRGO;
Jerome Coutant 0:c0f3bbab73d2 1842 hAudioInTopLeftFilter.Init.InjectedParam.ExtTriggerEdge = DFSDM_FILTER_EXT_TRIG_RISING_EDGE;
Jerome Coutant 0:c0f3bbab73d2 1843 hAudioInTopLeftFilter.Init.FilterParam.SincOrder = DFSDM_FILTER_ORDER(AudioFreq);
Jerome Coutant 0:c0f3bbab73d2 1844 /* Set the DFSDM Filters Oversampling to have correct sample rate */
Jerome Coutant 0:c0f3bbab73d2 1845 hAudioInTopLeftFilter.Init.FilterParam.Oversampling = DFSDM_OVER_SAMPLING(AudioFreq);
Jerome Coutant 0:c0f3bbab73d2 1846 hAudioInTopLeftFilter.Init.FilterParam.IntOversampling = 1;
Jerome Coutant 0:c0f3bbab73d2 1847 if(HAL_OK != HAL_DFSDM_FilterInit(&hAudioInTopLeftFilter))
Jerome Coutant 0:c0f3bbab73d2 1848 {
Jerome Coutant 0:c0f3bbab73d2 1849 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1850 }
Jerome Coutant 0:c0f3bbab73d2 1851
Jerome Coutant 0:c0f3bbab73d2 1852 /* Configure injected channel */
Jerome Coutant 0:c0f3bbab73d2 1853 if(HAL_OK != HAL_DFSDM_FilterConfigRegChannel(&hAudioInTopLeftFilter, AUDIO_DFSDMx_TOP_LEFT_CHANNEL, DFSDM_CONTINUOUS_CONV_ON))
Jerome Coutant 0:c0f3bbab73d2 1854 {
Jerome Coutant 0:c0f3bbab73d2 1855 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1856 }
Jerome Coutant 0:c0f3bbab73d2 1857
Jerome Coutant 0:c0f3bbab73d2 1858 /* FILTER 1 configuration */
Jerome Coutant 0:c0f3bbab73d2 1859 __HAL_DFSDM_FILTER_RESET_HANDLE_STATE(&hAudioInTopRightFilter);
Jerome Coutant 0:c0f3bbab73d2 1860 hAudioInTopRightFilter.Instance = AUDIO_DFSDMx_TOP_RIGHT_FILTER;
Jerome Coutant 0:c0f3bbab73d2 1861 hAudioInTopRightFilter.Init.RegularParam.Trigger = DFSDM_FILTER_SYNC_TRIGGER;
Jerome Coutant 0:c0f3bbab73d2 1862 hAudioInTopRightFilter.Init.RegularParam.FastMode = ENABLE;
Jerome Coutant 0:c0f3bbab73d2 1863 hAudioInTopRightFilter.Init.RegularParam.DmaMode = ENABLE;
Jerome Coutant 0:c0f3bbab73d2 1864 hAudioInTopRightFilter.Init.InjectedParam.Trigger = DFSDM_FILTER_SW_TRIGGER;
Jerome Coutant 0:c0f3bbab73d2 1865 hAudioInTopRightFilter.Init.InjectedParam.ScanMode = DISABLE;
Jerome Coutant 0:c0f3bbab73d2 1866 hAudioInTopRightFilter.Init.InjectedParam.DmaMode = DISABLE;
Jerome Coutant 0:c0f3bbab73d2 1867 hAudioInTopRightFilter.Init.InjectedParam.ExtTrigger = DFSDM_FILTER_EXT_TRIG_TIM1_TRGO;
Jerome Coutant 0:c0f3bbab73d2 1868 hAudioInTopRightFilter.Init.InjectedParam.ExtTriggerEdge = DFSDM_FILTER_EXT_TRIG_RISING_EDGE;
Jerome Coutant 0:c0f3bbab73d2 1869 hAudioInTopRightFilter.Init.FilterParam.SincOrder = DFSDM_FILTER_ORDER(AudioFreq);
Jerome Coutant 0:c0f3bbab73d2 1870 /* Set the DFSDM Filters Oversampling to have correct sample rate */
Jerome Coutant 0:c0f3bbab73d2 1871 hAudioInTopRightFilter.Init.FilterParam.Oversampling = DFSDM_OVER_SAMPLING(AudioFreq);
Jerome Coutant 0:c0f3bbab73d2 1872 hAudioInTopRightFilter.Init.FilterParam.IntOversampling = 1;
Jerome Coutant 0:c0f3bbab73d2 1873 if(HAL_OK != HAL_DFSDM_FilterInit(&hAudioInTopRightFilter))
Jerome Coutant 0:c0f3bbab73d2 1874 {
Jerome Coutant 0:c0f3bbab73d2 1875 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1876 }
Jerome Coutant 0:c0f3bbab73d2 1877 /* Configure injected channel */
Jerome Coutant 0:c0f3bbab73d2 1878 if(HAL_OK != HAL_DFSDM_FilterConfigRegChannel(&hAudioInTopRightFilter, AUDIO_DFSDMx_TOP_RIGHT_CHANNEL, DFSDM_CONTINUOUS_CONV_ON))
Jerome Coutant 0:c0f3bbab73d2 1879 {
Jerome Coutant 0:c0f3bbab73d2 1880 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1881 }
Jerome Coutant 0:c0f3bbab73d2 1882
Jerome Coutant 0:c0f3bbab73d2 1883 if(AudioIn_ChannelNumber > 2)
Jerome Coutant 0:c0f3bbab73d2 1884 {
Jerome Coutant 0:c0f3bbab73d2 1885 /* FILTER 2 configuration */
Jerome Coutant 0:c0f3bbab73d2 1886 __HAL_DFSDM_FILTER_RESET_HANDLE_STATE(&hAudioInButtomLeftFilter);
Jerome Coutant 0:c0f3bbab73d2 1887 hAudioInButtomLeftFilter.Instance = AUDIO_DFSDMx_BUTTOM_LEFT_FILTER;
Jerome Coutant 0:c0f3bbab73d2 1888 hAudioInButtomLeftFilter.Init.RegularParam.Trigger = DFSDM_FILTER_SYNC_TRIGGER;
Jerome Coutant 0:c0f3bbab73d2 1889 hAudioInButtomLeftFilter.Init.RegularParam.FastMode = ENABLE;
Jerome Coutant 0:c0f3bbab73d2 1890 hAudioInButtomLeftFilter.Init.RegularParam.DmaMode = ENABLE;
Jerome Coutant 0:c0f3bbab73d2 1891 hAudioInButtomLeftFilter.Init.InjectedParam.Trigger = DFSDM_FILTER_SW_TRIGGER;
Jerome Coutant 0:c0f3bbab73d2 1892 hAudioInButtomLeftFilter.Init.InjectedParam.ScanMode = ENABLE;
Jerome Coutant 0:c0f3bbab73d2 1893 hAudioInButtomLeftFilter.Init.InjectedParam.DmaMode = DISABLE;
Jerome Coutant 0:c0f3bbab73d2 1894 hAudioInButtomLeftFilter.Init.InjectedParam.ExtTrigger = DFSDM_FILTER_EXT_TRIG_TIM1_TRGO;
Jerome Coutant 0:c0f3bbab73d2 1895 hAudioInButtomLeftFilter.Init.InjectedParam.ExtTriggerEdge = DFSDM_FILTER_EXT_TRIG_RISING_EDGE;
Jerome Coutant 0:c0f3bbab73d2 1896 hAudioInButtomLeftFilter.Init.FilterParam.SincOrder = DFSDM_FILTER_ORDER(AudioFreq);
Jerome Coutant 0:c0f3bbab73d2 1897 /* Set the DFSDM Filters Oversampling to have correct sample rate */
Jerome Coutant 0:c0f3bbab73d2 1898 hAudioInButtomLeftFilter.Init.FilterParam.Oversampling = DFSDM_OVER_SAMPLING(AudioFreq);
Jerome Coutant 0:c0f3bbab73d2 1899 hAudioInButtomLeftFilter.Init.FilterParam.IntOversampling = 1;
Jerome Coutant 0:c0f3bbab73d2 1900 if(HAL_OK != HAL_DFSDM_FilterInit(&hAudioInButtomLeftFilter))
Jerome Coutant 0:c0f3bbab73d2 1901 {
Jerome Coutant 0:c0f3bbab73d2 1902 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1903 }
Jerome Coutant 0:c0f3bbab73d2 1904
Jerome Coutant 0:c0f3bbab73d2 1905 /* Configure injected channel */
Jerome Coutant 0:c0f3bbab73d2 1906 if(HAL_OK != HAL_DFSDM_FilterConfigRegChannel(&hAudioInButtomLeftFilter, AUDIO_DFSDMx_BUTTOM_LEFT_CHANNEL, DFSDM_CONTINUOUS_CONV_ON))
Jerome Coutant 0:c0f3bbab73d2 1907 {
Jerome Coutant 0:c0f3bbab73d2 1908 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1909 }
Jerome Coutant 0:c0f3bbab73d2 1910
Jerome Coutant 0:c0f3bbab73d2 1911 /* FILTER 3 configuration */
Jerome Coutant 0:c0f3bbab73d2 1912 __HAL_DFSDM_FILTER_RESET_HANDLE_STATE(&hAudioInButtomRightFilter);
Jerome Coutant 0:c0f3bbab73d2 1913 hAudioInButtomRightFilter.Instance = AUDIO_DFSDMx_BUTTOM_RIGHT_FILTER;
Jerome Coutant 0:c0f3bbab73d2 1914 hAudioInButtomRightFilter.Init.RegularParam.Trigger = DFSDM_FILTER_SYNC_TRIGGER;
Jerome Coutant 0:c0f3bbab73d2 1915 hAudioInButtomRightFilter.Init.RegularParam.FastMode = ENABLE;
Jerome Coutant 0:c0f3bbab73d2 1916 hAudioInButtomRightFilter.Init.RegularParam.DmaMode = ENABLE;
Jerome Coutant 0:c0f3bbab73d2 1917 hAudioInButtomRightFilter.Init.InjectedParam.Trigger = DFSDM_FILTER_SW_TRIGGER;
Jerome Coutant 0:c0f3bbab73d2 1918 hAudioInButtomRightFilter.Init.InjectedParam.ScanMode = DISABLE;
Jerome Coutant 0:c0f3bbab73d2 1919 hAudioInButtomRightFilter.Init.InjectedParam.DmaMode = DISABLE;
Jerome Coutant 0:c0f3bbab73d2 1920 hAudioInButtomRightFilter.Init.InjectedParam.ExtTrigger = DFSDM_FILTER_EXT_TRIG_TIM1_TRGO;
Jerome Coutant 0:c0f3bbab73d2 1921 hAudioInButtomRightFilter.Init.InjectedParam.ExtTriggerEdge = DFSDM_FILTER_EXT_TRIG_RISING_EDGE;
Jerome Coutant 0:c0f3bbab73d2 1922 hAudioInButtomRightFilter.Init.FilterParam.SincOrder = DFSDM_FILTER_ORDER(AudioFreq);
Jerome Coutant 0:c0f3bbab73d2 1923 /* Set the DFSDM Filters Oversampling to have correct sample rate */
Jerome Coutant 0:c0f3bbab73d2 1924 hAudioInButtomRightFilter.Init.FilterParam.Oversampling = DFSDM_OVER_SAMPLING(AudioFreq);
Jerome Coutant 0:c0f3bbab73d2 1925 hAudioInButtomRightFilter.Init.FilterParam.IntOversampling = 1;
Jerome Coutant 0:c0f3bbab73d2 1926 if(HAL_OK != HAL_DFSDM_FilterInit(&hAudioInButtomRightFilter))
Jerome Coutant 0:c0f3bbab73d2 1927 {
Jerome Coutant 0:c0f3bbab73d2 1928 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1929 }
Jerome Coutant 0:c0f3bbab73d2 1930 /* Configure injected channel */
Jerome Coutant 0:c0f3bbab73d2 1931 if(HAL_OK != HAL_DFSDM_FilterConfigRegChannel(&hAudioInButtomRightFilter, AUDIO_DFSDMx_BUTTOM_RIGHT_CHANNEL, DFSDM_CONTINUOUS_CONV_ON))
Jerome Coutant 0:c0f3bbab73d2 1932 {
Jerome Coutant 0:c0f3bbab73d2 1933 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1934 }
Jerome Coutant 0:c0f3bbab73d2 1935 }
Jerome Coutant 0:c0f3bbab73d2 1936 return AUDIO_OK;
Jerome Coutant 0:c0f3bbab73d2 1937 }
Jerome Coutant 0:c0f3bbab73d2 1938
Jerome Coutant 0:c0f3bbab73d2 1939 /**
Jerome Coutant 0:c0f3bbab73d2 1940 * @brief De-initialize the Digital Filter for Sigma-Delta Modulators interface (DFSDM).
Jerome Coutant 0:c0f3bbab73d2 1941 * @retval AUDIO_OK if correct communication, else wrong communication
Jerome Coutant 0:c0f3bbab73d2 1942 */
Jerome Coutant 0:c0f3bbab73d2 1943 static uint8_t DFSDMx_DeInit(void)
Jerome Coutant 0:c0f3bbab73d2 1944 {
Jerome Coutant 0:c0f3bbab73d2 1945 /* De-initializes the DFSDM filters to allow access to DFSDM internal registers */
Jerome Coutant 0:c0f3bbab73d2 1946 if(HAL_OK != HAL_DFSDM_FilterDeInit(&hAudioInTopLeftFilter))
Jerome Coutant 0:c0f3bbab73d2 1947 {
Jerome Coutant 0:c0f3bbab73d2 1948 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1949 }
Jerome Coutant 0:c0f3bbab73d2 1950
Jerome Coutant 0:c0f3bbab73d2 1951 if(HAL_OK != HAL_DFSDM_FilterDeInit(&hAudioInTopRightFilter))
Jerome Coutant 0:c0f3bbab73d2 1952 {
Jerome Coutant 0:c0f3bbab73d2 1953 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1954 }
Jerome Coutant 0:c0f3bbab73d2 1955
Jerome Coutant 0:c0f3bbab73d2 1956 /* De-initializes the DFSDM channels to allow access to DFSDM internal registers */
Jerome Coutant 0:c0f3bbab73d2 1957 if(HAL_OK != HAL_DFSDM_ChannelDeInit(&hAudioInTopLeftChannel))
Jerome Coutant 0:c0f3bbab73d2 1958 {
Jerome Coutant 0:c0f3bbab73d2 1959 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1960 }
Jerome Coutant 0:c0f3bbab73d2 1961
Jerome Coutant 0:c0f3bbab73d2 1962 if(HAL_OK != HAL_DFSDM_ChannelDeInit(&hAudioInTopRightChannel))
Jerome Coutant 0:c0f3bbab73d2 1963 {
Jerome Coutant 0:c0f3bbab73d2 1964 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1965 }
Jerome Coutant 0:c0f3bbab73d2 1966
Jerome Coutant 0:c0f3bbab73d2 1967 if(AudioIn_ChannelNumber > 2)
Jerome Coutant 0:c0f3bbab73d2 1968 {
Jerome Coutant 0:c0f3bbab73d2 1969 /* De-initializes the DFSDM filters to allow access to DFSDM internal registers */
Jerome Coutant 0:c0f3bbab73d2 1970 if(HAL_OK != HAL_DFSDM_FilterDeInit(&hAudioInButtomLeftFilter))
Jerome Coutant 0:c0f3bbab73d2 1971 {
Jerome Coutant 0:c0f3bbab73d2 1972 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1973 }
Jerome Coutant 0:c0f3bbab73d2 1974
Jerome Coutant 0:c0f3bbab73d2 1975 if(HAL_OK != HAL_DFSDM_FilterDeInit(&hAudioInButtomRightFilter))
Jerome Coutant 0:c0f3bbab73d2 1976 {
Jerome Coutant 0:c0f3bbab73d2 1977 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1978 }
Jerome Coutant 0:c0f3bbab73d2 1979
Jerome Coutant 0:c0f3bbab73d2 1980 /* De-initializes the DFSDM channels to allow access to DFSDM internal registers */
Jerome Coutant 0:c0f3bbab73d2 1981 if(HAL_OK != HAL_DFSDM_ChannelDeInit(&hAudioInButtomLeftChannel))
Jerome Coutant 0:c0f3bbab73d2 1982 {
Jerome Coutant 0:c0f3bbab73d2 1983 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1984 }
Jerome Coutant 0:c0f3bbab73d2 1985
Jerome Coutant 0:c0f3bbab73d2 1986 if(HAL_OK != HAL_DFSDM_ChannelDeInit(&hAudioInButtomRightChannel))
Jerome Coutant 0:c0f3bbab73d2 1987 {
Jerome Coutant 0:c0f3bbab73d2 1988 return AUDIO_ERROR;
Jerome Coutant 0:c0f3bbab73d2 1989 }
Jerome Coutant 0:c0f3bbab73d2 1990 }
Jerome Coutant 0:c0f3bbab73d2 1991
Jerome Coutant 0:c0f3bbab73d2 1992 return AUDIO_OK;
Jerome Coutant 0:c0f3bbab73d2 1993 }
Jerome Coutant 0:c0f3bbab73d2 1994
Jerome Coutant 0:c0f3bbab73d2 1995 /**
Jerome Coutant 0:c0f3bbab73d2 1996 * @brief Initialize the DFSDM channel MSP.
Jerome Coutant 0:c0f3bbab73d2 1997 * @retval None
Jerome Coutant 0:c0f3bbab73d2 1998 */
Jerome Coutant 0:c0f3bbab73d2 1999 static void DFSDMx_ChannelMspInit(void)
Jerome Coutant 0:c0f3bbab73d2 2000 {
Jerome Coutant 0:c0f3bbab73d2 2001 GPIO_InitTypeDef GPIO_InitStruct;
Jerome Coutant 0:c0f3bbab73d2 2002
Jerome Coutant 0:c0f3bbab73d2 2003 /* Enable DFSDM clock */
Jerome Coutant 0:c0f3bbab73d2 2004 AUDIO_DFSDMx_CLK_ENABLE();
Jerome Coutant 0:c0f3bbab73d2 2005
Jerome Coutant 0:c0f3bbab73d2 2006 /* Enable GPIO clock */
Jerome Coutant 0:c0f3bbab73d2 2007 AUDIO_DFSDMx_DMIC_DATIN_GPIO_CLK_ENABLE();
Jerome Coutant 0:c0f3bbab73d2 2008 AUDIO_DFSDMx_CKOUT_DMIC_GPIO_CLK_ENABLE();
Jerome Coutant 0:c0f3bbab73d2 2009
Jerome Coutant 0:c0f3bbab73d2 2010 /* DFSDM pins configuration: DFSDM_CKOUT, DMIC_DATIN1 pins ------------------*/
Jerome Coutant 0:c0f3bbab73d2 2011 GPIO_InitStruct.Pin = AUDIO_DFSDMx_CKOUT_PIN;
Jerome Coutant 0:c0f3bbab73d2 2012 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
Jerome Coutant 0:c0f3bbab73d2 2013 GPIO_InitStruct.Pull = GPIO_NOPULL;
Jerome Coutant 0:c0f3bbab73d2 2014 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
Jerome Coutant 0:c0f3bbab73d2 2015 GPIO_InitStruct.Alternate = AUDIO_DFSDMx_CKOUT_AF;
Jerome Coutant 0:c0f3bbab73d2 2016 HAL_GPIO_Init(AUDIO_DFSDMx_CKOUT_DMIC_GPIO_PORT, &GPIO_InitStruct);
Jerome Coutant 0:c0f3bbab73d2 2017
Jerome Coutant 0:c0f3bbab73d2 2018 /* DFSDM pin configuration: DMIC_DATIN1 pin --------------------------------*/
Jerome Coutant 0:c0f3bbab73d2 2019 GPIO_InitStruct.Pin = AUDIO_DFSDMx_DMIC_DATIN1_PIN;
Jerome Coutant 0:c0f3bbab73d2 2020 GPIO_InitStruct.Alternate = AUDIO_DFSDMx_DMIC_DATIN_AF;
Jerome Coutant 0:c0f3bbab73d2 2021 HAL_GPIO_Init(AUDIO_DFSDMx_DMIC_DATIN_GPIO_PORT, &GPIO_InitStruct);
Jerome Coutant 0:c0f3bbab73d2 2022
Jerome Coutant 0:c0f3bbab73d2 2023 if(AudioIn_ChannelNumber > 2)
Jerome Coutant 0:c0f3bbab73d2 2024 {
Jerome Coutant 0:c0f3bbab73d2 2025 /* DFSDM pin configuration: DMIC_DATIN5 pin --------------------------------*/
Jerome Coutant 0:c0f3bbab73d2 2026 GPIO_InitStruct.Pin = AUDIO_DFSDMx_DMIC_DATIN5_PIN;
Jerome Coutant 0:c0f3bbab73d2 2027 GPIO_InitStruct.Alternate = AUDIO_DFSDMx_DMIC_DATIN_AF;
Jerome Coutant 0:c0f3bbab73d2 2028 HAL_GPIO_Init(AUDIO_DFSDMx_DMIC_DATIN_GPIO_PORT, &GPIO_InitStruct);
Jerome Coutant 0:c0f3bbab73d2 2029 }
Jerome Coutant 0:c0f3bbab73d2 2030 }
Jerome Coutant 0:c0f3bbab73d2 2031
Jerome Coutant 0:c0f3bbab73d2 2032 /**
Jerome Coutant 0:c0f3bbab73d2 2033 * @brief DeInitialize the DFSDM channel MSP.
Jerome Coutant 0:c0f3bbab73d2 2034 * @retval None
Jerome Coutant 0:c0f3bbab73d2 2035 */
Jerome Coutant 0:c0f3bbab73d2 2036 static void DFSDMx_ChannelMspDeInit(void)
Jerome Coutant 0:c0f3bbab73d2 2037 {
Jerome Coutant 0:c0f3bbab73d2 2038 GPIO_InitTypeDef GPIO_InitStruct;
Jerome Coutant 0:c0f3bbab73d2 2039
Jerome Coutant 0:c0f3bbab73d2 2040 /* DFSDM pin configuration: DMIC_DATIN1 pin --------------------------------*/
Jerome Coutant 0:c0f3bbab73d2 2041 GPIO_InitStruct.Pin = AUDIO_DFSDMx_CKOUT_PIN;
Jerome Coutant 0:c0f3bbab73d2 2042 HAL_GPIO_DeInit(AUDIO_DFSDMx_CKOUT_DMIC_GPIO_PORT, GPIO_InitStruct.Pin);
Jerome Coutant 0:c0f3bbab73d2 2043 GPIO_InitStruct.Pin = AUDIO_DFSDMx_DMIC_DATIN1_PIN;
Jerome Coutant 0:c0f3bbab73d2 2044 HAL_GPIO_DeInit(AUDIO_DFSDMx_DMIC_DATIN_GPIO_PORT, GPIO_InitStruct.Pin);
Jerome Coutant 0:c0f3bbab73d2 2045
Jerome Coutant 0:c0f3bbab73d2 2046 if(AudioIn_ChannelNumber > 2)
Jerome Coutant 0:c0f3bbab73d2 2047 {
Jerome Coutant 0:c0f3bbab73d2 2048 /* DFSDM pin configuration: DMIC_DATIN5 pin ------------------------------*/
Jerome Coutant 0:c0f3bbab73d2 2049 GPIO_InitStruct.Pin = AUDIO_DFSDMx_CKOUT_PIN;
Jerome Coutant 0:c0f3bbab73d2 2050 HAL_GPIO_DeInit(AUDIO_DFSDMx_CKOUT_DMIC_GPIO_PORT, GPIO_InitStruct.Pin);
Jerome Coutant 0:c0f3bbab73d2 2051 GPIO_InitStruct.Pin = AUDIO_DFSDMx_DMIC_DATIN5_PIN;
Jerome Coutant 0:c0f3bbab73d2 2052 HAL_GPIO_DeInit(AUDIO_DFSDMx_DMIC_DATIN_GPIO_PORT, GPIO_InitStruct.Pin);
Jerome Coutant 0:c0f3bbab73d2 2053 }
Jerome Coutant 0:c0f3bbab73d2 2054 }
Jerome Coutant 0:c0f3bbab73d2 2055
Jerome Coutant 0:c0f3bbab73d2 2056 /**
Jerome Coutant 0:c0f3bbab73d2 2057 * @brief Initialize the DFSDM filter MSP.
Jerome Coutant 0:c0f3bbab73d2 2058 * @retval None
Jerome Coutant 0:c0f3bbab73d2 2059 */
Jerome Coutant 0:c0f3bbab73d2 2060 static void DFSDMx_FilterMspInit(void)
Jerome Coutant 0:c0f3bbab73d2 2061 {
Jerome Coutant 0:c0f3bbab73d2 2062 /* Enable DFSDM clock */
Jerome Coutant 0:c0f3bbab73d2 2063 AUDIO_DFSDMx_CLK_ENABLE();
Jerome Coutant 0:c0f3bbab73d2 2064
Jerome Coutant 0:c0f3bbab73d2 2065 /* Enable the DMA clock */
Jerome Coutant 0:c0f3bbab73d2 2066 AUDIO_DFSDMx_DMAx_CLK_ENABLE();
Jerome Coutant 0:c0f3bbab73d2 2067
Jerome Coutant 0:c0f3bbab73d2 2068 /*********** Configure DMA stream for TOP LEFT microphone *******************/
Jerome Coutant 0:c0f3bbab73d2 2069 hDmaTopLeft.Init.Direction = DMA_PERIPH_TO_MEMORY;
Jerome Coutant 0:c0f3bbab73d2 2070 hDmaTopLeft.Init.PeriphInc = DMA_PINC_DISABLE;
Jerome Coutant 0:c0f3bbab73d2 2071 hDmaTopLeft.Init.MemInc = DMA_MINC_ENABLE;
Jerome Coutant 0:c0f3bbab73d2 2072 hDmaTopLeft.Init.PeriphDataAlignment = AUDIO_DFSDMx_DMAx_PERIPH_DATA_SIZE;
Jerome Coutant 0:c0f3bbab73d2 2073 hDmaTopLeft.Init.MemDataAlignment = AUDIO_DFSDMx_DMAx_MEM_DATA_SIZE;
Jerome Coutant 0:c0f3bbab73d2 2074 hDmaTopLeft.Init.Mode = DMA_CIRCULAR;
Jerome Coutant 0:c0f3bbab73d2 2075 hDmaTopLeft.Init.Priority = DMA_PRIORITY_HIGH;
Jerome Coutant 0:c0f3bbab73d2 2076 hDmaTopLeft.Instance = AUDIO_DFSDMx_DMAx_TOP_LEFT_STREAM;
Jerome Coutant 0:c0f3bbab73d2 2077 hDmaTopLeft.Init.Channel = AUDIO_DFSDMx_DMAx_CHANNEL;
Jerome Coutant 0:c0f3bbab73d2 2078
Jerome Coutant 0:c0f3bbab73d2 2079 /* Associate the DMA handle */
Jerome Coutant 0:c0f3bbab73d2 2080 __HAL_LINKDMA(&hAudioInTopLeftFilter, hdmaReg, hDmaTopLeft);
Jerome Coutant 0:c0f3bbab73d2 2081
Jerome Coutant 0:c0f3bbab73d2 2082 /* Reset DMA handle state */
Jerome Coutant 0:c0f3bbab73d2 2083 __HAL_DMA_RESET_HANDLE_STATE(&hDmaTopLeft);
Jerome Coutant 0:c0f3bbab73d2 2084
Jerome Coutant 0:c0f3bbab73d2 2085 /* Configure the DMA Channel */
Jerome Coutant 0:c0f3bbab73d2 2086 HAL_DMA_Init(&hDmaTopLeft);
Jerome Coutant 0:c0f3bbab73d2 2087
Jerome Coutant 0:c0f3bbab73d2 2088 /* DMA IRQ Channel configuration */
Jerome Coutant 0:c0f3bbab73d2 2089 HAL_NVIC_SetPriority(AUDIO_DFSDMx_DMAx_TOP_LEFT_IRQ, AUDIO_OUT_IRQ_PREPRIO, 0);
Jerome Coutant 0:c0f3bbab73d2 2090 HAL_NVIC_EnableIRQ(AUDIO_DFSDMx_DMAx_TOP_LEFT_IRQ);
Jerome Coutant 0:c0f3bbab73d2 2091
Jerome Coutant 0:c0f3bbab73d2 2092
Jerome Coutant 0:c0f3bbab73d2 2093 /*********** Configure DMA stream for TOP RIGHT microphone ******************/
Jerome Coutant 0:c0f3bbab73d2 2094 hDmaTopRight.Init.Direction = DMA_PERIPH_TO_MEMORY;
Jerome Coutant 0:c0f3bbab73d2 2095 hDmaTopRight.Init.PeriphInc = DMA_PINC_DISABLE;
Jerome Coutant 0:c0f3bbab73d2 2096 hDmaTopRight.Init.MemInc = DMA_MINC_ENABLE;
Jerome Coutant 0:c0f3bbab73d2 2097 hDmaTopRight.Init.PeriphDataAlignment = AUDIO_DFSDMx_DMAx_PERIPH_DATA_SIZE;
Jerome Coutant 0:c0f3bbab73d2 2098 hDmaTopRight.Init.MemDataAlignment = AUDIO_DFSDMx_DMAx_MEM_DATA_SIZE;
Jerome Coutant 0:c0f3bbab73d2 2099 hDmaTopRight.Init.Mode = DMA_CIRCULAR;
Jerome Coutant 0:c0f3bbab73d2 2100 hDmaTopRight.Init.Priority = DMA_PRIORITY_HIGH;
Jerome Coutant 0:c0f3bbab73d2 2101 hDmaTopRight.Instance = AUDIO_DFSDMx_DMAx_TOP_RIGHT_STREAM;
Jerome Coutant 0:c0f3bbab73d2 2102 hDmaTopRight.Init.Channel = AUDIO_DFSDMx_DMAx_CHANNEL;
Jerome Coutant 0:c0f3bbab73d2 2103
Jerome Coutant 0:c0f3bbab73d2 2104 /* Associate the DMA handle */
Jerome Coutant 0:c0f3bbab73d2 2105 __HAL_LINKDMA(&hAudioInTopRightFilter, hdmaReg, hDmaTopRight);
Jerome Coutant 0:c0f3bbab73d2 2106
Jerome Coutant 0:c0f3bbab73d2 2107 /* Reset DMA handle state */
Jerome Coutant 0:c0f3bbab73d2 2108 __HAL_DMA_RESET_HANDLE_STATE(&hDmaTopRight);
Jerome Coutant 0:c0f3bbab73d2 2109
Jerome Coutant 0:c0f3bbab73d2 2110 /* Configure the DMA Channel */
Jerome Coutant 0:c0f3bbab73d2 2111 HAL_DMA_Init(&hDmaTopRight);
Jerome Coutant 0:c0f3bbab73d2 2112
Jerome Coutant 0:c0f3bbab73d2 2113 /* DMA IRQ Channel configuration */
Jerome Coutant 0:c0f3bbab73d2 2114 HAL_NVIC_SetPriority(AUDIO_DFSDMx_DMAx_TOP_RIGHT_IRQ, AUDIO_OUT_IRQ_PREPRIO, 0);
Jerome Coutant 0:c0f3bbab73d2 2115 HAL_NVIC_EnableIRQ(AUDIO_DFSDMx_DMAx_TOP_RIGHT_IRQ);
Jerome Coutant 0:c0f3bbab73d2 2116
Jerome Coutant 0:c0f3bbab73d2 2117 if(AudioIn_ChannelNumber > 2)
Jerome Coutant 0:c0f3bbab73d2 2118 {
Jerome Coutant 0:c0f3bbab73d2 2119 /*********** Configure DMA stream for BUTTOM LEFT microphone ****************/
Jerome Coutant 0:c0f3bbab73d2 2120 hDmaButtomLeft.Init.Direction = DMA_PERIPH_TO_MEMORY;
Jerome Coutant 0:c0f3bbab73d2 2121 hDmaButtomLeft.Init.PeriphInc = DMA_PINC_DISABLE;
Jerome Coutant 0:c0f3bbab73d2 2122 hDmaButtomLeft.Init.MemInc = DMA_MINC_ENABLE;
Jerome Coutant 0:c0f3bbab73d2 2123 hDmaButtomLeft.Init.PeriphDataAlignment = AUDIO_DFSDMx_DMAx_PERIPH_DATA_SIZE;
Jerome Coutant 0:c0f3bbab73d2 2124 hDmaButtomLeft.Init.MemDataAlignment = AUDIO_DFSDMx_DMAx_MEM_DATA_SIZE;
Jerome Coutant 0:c0f3bbab73d2 2125 hDmaButtomLeft.Init.Mode = DMA_CIRCULAR;
Jerome Coutant 0:c0f3bbab73d2 2126 hDmaButtomLeft.Init.Priority = DMA_PRIORITY_HIGH;
Jerome Coutant 0:c0f3bbab73d2 2127 hDmaButtomLeft.Instance = AUDIO_DFSDMx_DMAx_BUTTOM_LEFT_STREAM;
Jerome Coutant 0:c0f3bbab73d2 2128 hDmaButtomLeft.Init.Channel = AUDIO_DFSDMx_DMAx_CHANNEL;
Jerome Coutant 0:c0f3bbab73d2 2129
Jerome Coutant 0:c0f3bbab73d2 2130 /* Associate the DMA handle */
Jerome Coutant 0:c0f3bbab73d2 2131 __HAL_LINKDMA(&hAudioInButtomLeftFilter, hdmaReg, hDmaButtomLeft);
Jerome Coutant 0:c0f3bbab73d2 2132
Jerome Coutant 0:c0f3bbab73d2 2133 /* Reset DMA handle state */
Jerome Coutant 0:c0f3bbab73d2 2134 __HAL_DMA_RESET_HANDLE_STATE(&hDmaButtomLeft);
Jerome Coutant 0:c0f3bbab73d2 2135
Jerome Coutant 0:c0f3bbab73d2 2136 /* Configure the DMA Channel */
Jerome Coutant 0:c0f3bbab73d2 2137 HAL_DMA_Init(&hDmaButtomLeft);
Jerome Coutant 0:c0f3bbab73d2 2138
Jerome Coutant 0:c0f3bbab73d2 2139 /* DMA IRQ Channel configuration */
Jerome Coutant 0:c0f3bbab73d2 2140 HAL_NVIC_SetPriority(AUDIO_DFSDMx_DMAx_BUTTOM_LEFT_IRQ, AUDIO_OUT_IRQ_PREPRIO, 0);
Jerome Coutant 0:c0f3bbab73d2 2141 HAL_NVIC_EnableIRQ(AUDIO_DFSDMx_DMAx_BUTTOM_LEFT_IRQ);
Jerome Coutant 0:c0f3bbab73d2 2142
Jerome Coutant 0:c0f3bbab73d2 2143
Jerome Coutant 0:c0f3bbab73d2 2144 /*********** Configure DMA stream for BUTTOM RIGHT microphone ***************/
Jerome Coutant 0:c0f3bbab73d2 2145 hDmaButtomRight.Init.Direction = DMA_PERIPH_TO_MEMORY;
Jerome Coutant 0:c0f3bbab73d2 2146 hDmaButtomRight.Init.PeriphInc = DMA_PINC_DISABLE;
Jerome Coutant 0:c0f3bbab73d2 2147 hDmaButtomRight.Init.MemInc = DMA_MINC_ENABLE;
Jerome Coutant 0:c0f3bbab73d2 2148 hDmaButtomRight.Init.PeriphDataAlignment = AUDIO_DFSDMx_DMAx_PERIPH_DATA_SIZE;
Jerome Coutant 0:c0f3bbab73d2 2149 hDmaButtomRight.Init.MemDataAlignment = AUDIO_DFSDMx_DMAx_MEM_DATA_SIZE;
Jerome Coutant 0:c0f3bbab73d2 2150 hDmaButtomRight.Init.Mode = DMA_CIRCULAR;
Jerome Coutant 0:c0f3bbab73d2 2151 hDmaButtomRight.Init.Priority = DMA_PRIORITY_HIGH;
Jerome Coutant 0:c0f3bbab73d2 2152 hDmaButtomRight.Instance = AUDIO_DFSDMx_DMAx_BUTTOM_RIGHT_STREAM;
Jerome Coutant 0:c0f3bbab73d2 2153 hDmaButtomRight.Init.Channel = AUDIO_DFSDMx_DMAx_CHANNEL;
Jerome Coutant 0:c0f3bbab73d2 2154
Jerome Coutant 0:c0f3bbab73d2 2155 /* Associate the DMA handle */
Jerome Coutant 0:c0f3bbab73d2 2156 __HAL_LINKDMA(&hAudioInButtomRightFilter, hdmaReg, hDmaButtomRight);
Jerome Coutant 0:c0f3bbab73d2 2157
Jerome Coutant 0:c0f3bbab73d2 2158 /* Reset DMA handle state */
Jerome Coutant 0:c0f3bbab73d2 2159 __HAL_DMA_RESET_HANDLE_STATE(&hDmaButtomRight);
Jerome Coutant 0:c0f3bbab73d2 2160
Jerome Coutant 0:c0f3bbab73d2 2161 /* Configure the DMA Channel */
Jerome Coutant 0:c0f3bbab73d2 2162 HAL_DMA_Init(&hDmaButtomRight);
Jerome Coutant 0:c0f3bbab73d2 2163
Jerome Coutant 0:c0f3bbab73d2 2164 /* DMA IRQ Channel configuration */
Jerome Coutant 0:c0f3bbab73d2 2165 HAL_NVIC_SetPriority(AUDIO_DFSDMx_DMAx_BUTTOM_RIGHT_IRQ, AUDIO_OUT_IRQ_PREPRIO, 0);
Jerome Coutant 0:c0f3bbab73d2 2166 HAL_NVIC_EnableIRQ(AUDIO_DFSDMx_DMAx_BUTTOM_RIGHT_IRQ);
Jerome Coutant 0:c0f3bbab73d2 2167 }
Jerome Coutant 0:c0f3bbab73d2 2168 }
Jerome Coutant 0:c0f3bbab73d2 2169
Jerome Coutant 0:c0f3bbab73d2 2170 /**
Jerome Coutant 0:c0f3bbab73d2 2171 * @brief DeInitialize the DFSDM filter MSP.
Jerome Coutant 0:c0f3bbab73d2 2172 * @retval None
Jerome Coutant 0:c0f3bbab73d2 2173 */
Jerome Coutant 0:c0f3bbab73d2 2174 static void DFSDMx_FilterMspDeInit(void)
Jerome Coutant 0:c0f3bbab73d2 2175 {
Jerome Coutant 0:c0f3bbab73d2 2176 /* Configure the DMA Channel */
Jerome Coutant 0:c0f3bbab73d2 2177 HAL_DMA_DeInit(&hDmaTopLeft);
Jerome Coutant 0:c0f3bbab73d2 2178 HAL_DMA_DeInit(&hDmaTopRight);
Jerome Coutant 0:c0f3bbab73d2 2179 if(AudioIn_ChannelNumber > 2)
Jerome Coutant 0:c0f3bbab73d2 2180 {
Jerome Coutant 0:c0f3bbab73d2 2181 HAL_DMA_DeInit(&hDmaButtomLeft);
Jerome Coutant 0:c0f3bbab73d2 2182 HAL_DMA_DeInit(&hDmaButtomRight);
Jerome Coutant 0:c0f3bbab73d2 2183 }
Jerome Coutant 0:c0f3bbab73d2 2184 }
Jerome Coutant 0:c0f3bbab73d2 2185
Jerome Coutant 0:c0f3bbab73d2 2186 /**
Jerome Coutant 2:39d2c2c79afa 2187 * @brief This function handles DMA2 Stream 0 interrupt request.
Jerome Coutant 2:39d2c2c79afa 2188 * @param None
Jerome Coutant 2:39d2c2c79afa 2189 * @retval None
Jerome Coutant 2:39d2c2c79afa 2190 */
Jerome Coutant 2:39d2c2c79afa 2191 void AUDIO_DFSDMx_DMAx_TOP_LEFT_IRQHandler(void) // DMA2_Stream0_IRQHandler
Jerome Coutant 2:39d2c2c79afa 2192 {
Jerome Coutant 2:39d2c2c79afa 2193 HAL_DMA_IRQHandler(hAudioInTopLeftFilter.hdmaReg);
Jerome Coutant 2:39d2c2c79afa 2194 }
Jerome Coutant 2:39d2c2c79afa 2195
Jerome Coutant 2:39d2c2c79afa 2196 /**
Jerome Coutant 2:39d2c2c79afa 2197 * @brief This function handles DMA2 Stream 5 interrupt request.
Jerome Coutant 2:39d2c2c79afa 2198 * @param None
Jerome Coutant 2:39d2c2c79afa 2199 * @retval None
Jerome Coutant 2:39d2c2c79afa 2200 */
Jerome Coutant 2:39d2c2c79afa 2201 void AUDIO_DFSDMx_DMAx_TOP_RIGHT_IRQHandler(void) // DMA2_Stream5_IRQHandler
Jerome Coutant 2:39d2c2c79afa 2202 {
Jerome Coutant 2:39d2c2c79afa 2203 HAL_DMA_IRQHandler(hAudioInTopRightFilter.hdmaReg);
Jerome Coutant 2:39d2c2c79afa 2204 }
Jerome Coutant 2:39d2c2c79afa 2205
Jerome Coutant 2:39d2c2c79afa 2206 /**
Jerome Coutant 2:39d2c2c79afa 2207 * @brief This function handles DMA2 Stream 1 interrupt request.
Jerome Coutant 2:39d2c2c79afa 2208 * @param None
Jerome Coutant 2:39d2c2c79afa 2209 * @retval None
Jerome Coutant 2:39d2c2c79afa 2210 */
Jerome Coutant 2:39d2c2c79afa 2211 void AUDIO_OUT_SAIx_DMAx_IRQHandler(void) // DMA2_Stream1_IRQHandler
Jerome Coutant 2:39d2c2c79afa 2212 {
Jerome Coutant 2:39d2c2c79afa 2213 HAL_DMA_IRQHandler(haudio_out_sai.hdmatx);
Jerome Coutant 2:39d2c2c79afa 2214 }
Jerome Coutant 2:39d2c2c79afa 2215
Jerome Coutant 2:39d2c2c79afa 2216 /**
Jerome Coutant 2:39d2c2c79afa 2217 * @brief This function handles DMA2 Stream 6 interrupt request.
Jerome Coutant 2:39d2c2c79afa 2218 * @param None
Jerome Coutant 2:39d2c2c79afa 2219 * @retval None
Jerome Coutant 2:39d2c2c79afa 2220 */
Jerome Coutant 2:39d2c2c79afa 2221 void AUDIO_DFSDMx_DMAx_BUTTOM_LEFT_IRQHandler(void) // DMA2_Stream6_IRQHandler
Jerome Coutant 2:39d2c2c79afa 2222 {
Jerome Coutant 2:39d2c2c79afa 2223 HAL_DMA_IRQHandler(hAudioInButtomLeftFilter.hdmaReg);
Jerome Coutant 2:39d2c2c79afa 2224 }
Jerome Coutant 2:39d2c2c79afa 2225
Jerome Coutant 2:39d2c2c79afa 2226 /**
Jerome Coutant 2:39d2c2c79afa 2227 * @brief This function handles DMA2 Stream 7 interrupt request.
Jerome Coutant 2:39d2c2c79afa 2228 * @param None
Jerome Coutant 2:39d2c2c79afa 2229 * @retval None
Jerome Coutant 2:39d2c2c79afa 2230 */
Jerome Coutant 2:39d2c2c79afa 2231 void AUDIO_DFSDMx_DMAx_BUTTOM_RIGHT_IRQHandler(void) // DMA2_Stream7_IRQHandler
Jerome Coutant 2:39d2c2c79afa 2232 {
Jerome Coutant 2:39d2c2c79afa 2233 HAL_DMA_IRQHandler(hAudioInButtomRightFilter.hdmaReg);
Jerome Coutant 2:39d2c2c79afa 2234 }
Jerome Coutant 2:39d2c2c79afa 2235
Jerome Coutant 2:39d2c2c79afa 2236
Jerome Coutant 2:39d2c2c79afa 2237 /**
Jerome Coutant 0:c0f3bbab73d2 2238 * @}
Jerome Coutant 0:c0f3bbab73d2 2239 */
Jerome Coutant 0:c0f3bbab73d2 2240
Jerome Coutant 0:c0f3bbab73d2 2241 /**
Jerome Coutant 0:c0f3bbab73d2 2242 * @}
Jerome Coutant 0:c0f3bbab73d2 2243 */
Jerome Coutant 0:c0f3bbab73d2 2244
Jerome Coutant 0:c0f3bbab73d2 2245 /**
Jerome Coutant 0:c0f3bbab73d2 2246 * @}
Jerome Coutant 0:c0f3bbab73d2 2247 */
Jerome Coutant 0:c0f3bbab73d2 2248
Jerome Coutant 0:c0f3bbab73d2 2249 /**
Jerome Coutant 0:c0f3bbab73d2 2250 * @}
Jerome Coutant 0:c0f3bbab73d2 2251 */
Jerome Coutant 0:c0f3bbab73d2 2252
Jerome Coutant 0:c0f3bbab73d2 2253 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/