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 Jul 06 16:48:52 2017 +0200
Revision:
3:145e714557cf
Parent:
2:39d2c2c79afa
Child:
4:72a949940ad6
Child:
6:05b81d60cdae
replace HAL_Delay by wait_ms

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