stm32469i_discovery_audio.h
Go to the documentation of this file.
1 
39 /* Define to prevent recursive inclusion -------------------------------------*/
40 #ifndef __STM32469I_DISCOVERY_AUDIO_H
41 #define __STM32469I_DISCOVERY_AUDIO_H
42 
43 #ifdef __cplusplus
44  extern "C" {
45 #endif
46 
47 /* Includes ------------------------------------------------------------------*/
48 #if defined(BSP_AUDIO_USE_RTOS)
49 #include "k_mem.h"
50 #else
51 #include <stdlib.h>
52 #endif
53 
54 /* Include audio component Driver */
55 #include "../Components/cs43l22/cs43l22.h"
56 #include "stm32469i_discovery.h"
57 #include "../../../Middlewares/ST/STM32_Audio/Addons/PDM/Inc/pdm2pcm_glo.h"
58 
85 #define BSP_AUDIO_OUT_CIRCULARMODE ((uint32_t)0x00000001) /* BUFFER CIRCULAR MODE */
86 #define BSP_AUDIO_OUT_NORMALMODE ((uint32_t)0x00000002) /* BUFFER NORMAL MODE */
87 #define BSP_AUDIO_OUT_STEREOMODE ((uint32_t)0x00000004) /* STEREO MODE */
88 #define BSP_AUDIO_OUT_MONOMODE ((uint32_t)0x00000008) /* MONO MODE */
89 
93 /*------------------------------------------------------------------------------
94  USER SAI defines parameters
95  -----------------------------------------------------------------------------*/
104 /* To have 2 separate audio stream in Both headphone and speaker the 4 slot must be activated */
105 #define CODEC_AUDIOFRAME_SLOT_0123 SAI_SLOTACTIVE_0 | SAI_SLOTACTIVE_1 | SAI_SLOTACTIVE_2 | SAI_SLOTACTIVE_3
106 /* To have an audio stream in headphone only SAI Slot 0 and Slot 2 must be activated */
107 #define CODEC_AUDIOFRAME_SLOT_02 SAI_SLOTACTIVE_0 | SAI_SLOTACTIVE_2
108 /* To have an audio stream in speaker only SAI Slot 1 and Slot 3 must be activated */
109 #define CODEC_AUDIOFRAME_SLOT_13 SAI_SLOTACTIVE_1 | SAI_SLOTACTIVE_3
110 
114 /* SAI peripheral configuration defines */
115 #define AUDIO_SAIx SAI1_Block_A
116 #define AUDIO_SAIx_CLK_ENABLE() __HAL_RCC_SAI1_CLK_ENABLE()
117 #define AUDIO_SAIx_CLK_DISABLE() __HAL_RCC_SAI1_CLK_DISABLE()
118 #define AUDIO_SAIx_MCLK_SCK_SD_FS_AF GPIO_AF6_SAI1
119 
120 #define AUDIO_SAIx_MCLK_ENABLE() __HAL_RCC_GPIOG_CLK_ENABLE()
121 #define AUDIO_SAIx_MCLK_DISABLE() __HAL_RCC_GPIOG_CLK_DISABLE()
122 
123 #define AUDIO_SAIx_MCK_PIN GPIO_PIN_7
124 #define AUDIO_SAIx_MCLK_GPIO_PORT GPIOG
125 
126 #define AUDIO_SAIx_SCK_SD_FS_ENABLE() __HAL_RCC_GPIOE_CLK_ENABLE()
127 #define AUDIO_SAIx_SCK_SD_FS_DISABLE() __HAL_RCC_GPIOE_CLK_DISABLE()
128 #define AUDIO_SAIx_FS_PIN GPIO_PIN_4
129 #define AUDIO_SAIx_SCK_PIN GPIO_PIN_5
130 #define AUDIO_SAIx_SD_PIN GPIO_PIN_6
131 #define AUDIO_SAIx_SCK_SD_FS_GPIO_PORT GPIOE
132 
133 #define AUDIO_RESET_ENABLE() __HAL_RCC_GPIOE_CLK_ENABLE()
134 #define AUDIO_RESET_DISABLE() __HAL_RCC_GPIOE_CLK_DISABLE()
135 #define AUDIO_RESET_PIN GPIO_PIN_2
136 #define AUDIO_RESET_GPIO_PORT GPIOE
137 
138 /* SAI DMA Stream definitions */
139 #define AUDIO_SAIx_DMAx_CLK_ENABLE() __HAL_RCC_DMA2_CLK_ENABLE()
140 #define AUDIO_SAIx_DMAx_CLK_DISABLE() __HAL_RCC_DMA2_CLK_DISABLE()
141 #define AUDIO_SAIx_DMAx_STREAM DMA2_Stream3
142 #define AUDIO_SAIx_DMAx_CHANNEL DMA_CHANNEL_0
143 #define AUDIO_SAIx_DMAx_IRQ DMA2_Stream3_IRQn
144 #define AUDIO_SAIx_DMAx_PERIPH_DATA_SIZE DMA_PDATAALIGN_HALFWORD
145 #define AUDIO_SAIx_DMAx_MEM_DATA_SIZE DMA_MDATAALIGN_HALFWORD
146 #define DMA_MAX_SZE 0xFFFF
147 
148 #define AUDIO_SAIx_DMAx_IRQHandler DMA2_Stream3_IRQHandler
149 
150 /* Select the interrupt preemption priority for the DMA interrupt */
151 #define AUDIO_OUT_IRQ_PREPRIO 5 /* Select the preemption priority level(0 is the highest) */
152 
153 /* Disable SAIx PLL */
154 #define AUDIO_SAIx_PLL_DISABLE() HAL_RCCEx_DisablePLLSAI1()
155 /*------------------------------------------------------------------------------
156  AUDIO IN CONFIGURATION
157 ------------------------------------------------------------------------------*/
158 /* SPI Configuration defines */
159 #define AUDIO_I2Sx SPI3
160 #define AUDIO_I2Sx_CLK_ENABLE() __HAL_RCC_SPI3_CLK_ENABLE()
161 #define AUDIO_I2Sx_CLK_DISABLE() __HAL_RCC_SPI3_CLK_DISABLE()
162 #define AUDIO_I2Sx_SCK_PIN GPIO_PIN_3
163 #define AUDIO_I2Sx_SCK_GPIO_PORT GPIOB
164 #define AUDIO_I2Sx_SCK_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
165 #define AUDIO_I2Sx_SCK_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
166 #define AUDIO_I2Sx_SCK_AF GPIO_AF6_SPI3
167 
168 #define AUDIO_I2Sx_SD_PIN GPIO_PIN_6
169 #define AUDIO_I2Sx_SD_GPIO_PORT GPIOD
170 #define AUDIO_I2Sx_SD_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE()
171 #define AUDIO_I2Sx_SD_GPIO_CLK_DISABLE() __HAL_RCC_GPIOD_CLK_DISABLE()
172 #define AUDIO_I2Sx_SD_AF GPIO_AF5_I2S3ext
173 
174 /* I2S DMA Stream Rx definitions */
175 #define AUDIO_I2Sx_DMAx_CLK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE()
176 #define AUDIO_I2Sx_DMAx_CLK_DISABLE() __HAL_RCC_DMA1_CLK_DISABLE()
177 #define AUDIO_I2Sx_DMAx_STREAM DMA1_Stream2
178 #define AUDIO_I2Sx_DMAx_CHANNEL DMA_CHANNEL_0
179 #define AUDIO_I2Sx_DMAx_IRQ DMA1_Stream2_IRQn
180 #define AUDIO_I2Sx_DMAx_PERIPH_DATA_SIZE DMA_PDATAALIGN_HALFWORD
181 #define AUDIO_I2Sx_DMAx_MEM_DATA_SIZE DMA_MDATAALIGN_HALFWORD
182 
183 #define AUDIO_I2Sx_DMAx_IRQHandler DMA1_Stream2_IRQHandler
184 
185 /* Select the interrupt preemption priority and subpriority for the IT/DMA interrupt */
186 #define AUDIO_IN_IRQ_PREPRIO ((uint32_t)6) /* Select the preemption priority level(0 is the highest) */
187 
188 
189 /* Two channels are used:
190  - one channel as input which is connected to I2S SCK in stereo mode
191  - one channel as outupt which divides the frequency on the input
192 */
193 
194 #define AUDIO_TIMx_CLK_ENABLE() __HAL_RCC_TIM4_CLK_ENABLE()
195 #define AUDIO_TIMx_CLK_DISABLE() __HAL_RCC_TIM4_CLK_DISABLE()
196 #define AUDIO_TIMx TIM4
197 #define AUDIO_TIMx_IN_CHANNEL TIM_CHANNEL_1
198 #define AUDIO_TIMx_OUT_CHANNEL TIM_CHANNEL_2 /* Select channel 2 as output */
199 #define AUDIO_TIMx_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE()
200 #define AUDIO_TIMx_GPIO_CLK_DISABLE() __HAL_RCC_GPIOD_CLK_DISABLE()
201 #define AUDIO_TIMx_GPIO_PORT GPIOD
202 #define AUDIO_TIMx_IN_GPIO_PIN GPIO_PIN_12
203 #define AUDIO_TIMx_OUT_GPIO_PIN GPIO_PIN_13
204 #define AUDIO_TIMx_AF GPIO_AF2_TIM4
205 
206 /*------------------------------------------------------------------------------
207  CONFIGURATION: Audio Driver Configuration parameters
208 ------------------------------------------------------------------------------*/
209 
210 #define AUDIODATA_SIZE 2 /* 16-bits audio data size */
211 
212 /* Audio status definition */
213 #define AUDIO_OK ((uint8_t)0)
214 #define AUDIO_ERROR ((uint8_t)1)
215 #define AUDIO_TIMEOUT ((uint8_t)2)
216 
217 /* AudioFreq * DataSize (2 bytes) * NumChannels (Stereo: 2) */
218 #define DEFAULT_AUDIO_IN_FREQ I2S_AUDIOFREQ_16K
219 #define DEFAULT_AUDIO_IN_BIT_RESOLUTION ((uint8_t)16)
220 #define DEFAULT_AUDIO_IN_CHANNEL_NBR ((uint8_t)2) /* Mono = 1, Stereo = 2 */
221 #define DEFAULT_AUDIO_IN_VOLUME ((uint16_t)64)
222 
223 /* PDM buffer input size */
224 #define INTERNAL_BUFF_SIZE (128*DEFAULT_AUDIO_IN_FREQ/16000*DEFAULT_AUDIO_IN_CHANNEL_NBR)
225 /* PCM buffer output size */
226 #define PCM_OUT_SIZE (DEFAULT_AUDIO_IN_FREQ/1000*DEFAULT_AUDIO_IN_CHANNEL_NBR)
227 #define CHANNEL_DEMUX_MASK ((uint8_t)0x55)
228 
229 /*------------------------------------------------------------------------------
230  OPTIONAL Configuration defines parameters
231 ------------------------------------------------------------------------------*/
232 
233 /* Delay for the Codec to be correctly reset */
234 #define CODEC_RESET_DELAY ((uint8_t)5)
235 
236 /*------------------------------------------------------------------------------
237  OUTPUT DEVICES definition
238 ------------------------------------------------------------------------------*/
239 
247 extern __IO uint16_t AudioInVolume;
255 #define DMA_MAX(x) (((x) <= DMA_MAX_SZE)? (x):DMA_MAX_SZE)
256 
263 uint8_t BSP_AUDIO_OUT_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq);
264 uint8_t BSP_AUDIO_OUT_Play(uint16_t* pBuffer, uint32_t Size);
265 void BSP_AUDIO_OUT_ChangeBuffer(uint16_t *pData, uint16_t Size);
266 uint8_t BSP_AUDIO_OUT_Pause(void);
267 uint8_t BSP_AUDIO_OUT_Resume(void);
268 uint8_t BSP_AUDIO_OUT_Stop(uint32_t Option);
269 uint8_t BSP_AUDIO_OUT_SetVolume(uint8_t Volume);
270 void BSP_AUDIO_OUT_SetFrequency(uint32_t AudioFreq);
271 void BSP_AUDIO_OUT_SetAudioFrameSlot(uint32_t AudioFrameSlot);
272 uint8_t BSP_AUDIO_OUT_SetMute(uint32_t Cmd);
273 uint8_t BSP_AUDIO_OUT_SetOutputMode(uint8_t Output);
274 void BSP_AUDIO_OUT_DeInit(void);
275 
276 /* User Callbacks: user has to implement these functions in his code if they are needed. */
277 /* This function is called when the requested data has been completely transferred.*/
279 
280 /* This function is called when half of the requested buffer has been transferred. */
282 
283 /* This function is called when an Interrupt due to transfer error on or peripheral
284  error occurs. */
286 
287 /* These function can be modified in case the current settings (e.g. DMA stream)
288  need to be changed for specific application needs */
289 void BSP_AUDIO_OUT_ClockConfig(SAI_HandleTypeDef *hsai, uint32_t AudioFreq, void *Params);
290 void BSP_AUDIO_OUT_MspInit(SAI_HandleTypeDef *hsai, void *Params);
291 void BSP_AUDIO_OUT_MspDeInit(SAI_HandleTypeDef *hsai, void *Params);
292 
300 uint8_t BSP_AUDIO_IN_Init(uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr);
301 uint8_t BSP_AUDIO_IN_Record(uint16_t *pData, uint32_t Size);
302 uint8_t BSP_AUDIO_IN_Stop(void);
303 uint8_t BSP_AUDIO_IN_Pause(void);
304 uint8_t BSP_AUDIO_IN_Resume(void);
305 uint8_t BSP_AUDIO_IN_SetVolume(uint8_t Volume);
306 void BSP_AUDIO_IN_DeInit(void);
307 uint8_t BSP_AUDIO_IN_PDMToPCM(uint16_t* PDMBuf, uint16_t* PCMBuf);
308 /* User Callbacks: user has to implement these functions in his code if they are needed. */
309 /* This function should be implemented by the user application.
310  It is called into this driver when the current buffer is filled to prepare the next
311  buffer pointer and its size. */
314 
315 /* This function is called when an Interrupt due to transfer error on or peripheral
316  error occurs. */
317 void BSP_AUDIO_IN_Error_Callback(void);
318 
319 /* These function can be modified in case the current settings (e.g. DMA stream)
320  need to be changed for specific application needs */
321 void BSP_AUDIO_IN_ClockConfig(I2S_HandleTypeDef *hi2s, void *Params);
322 void BSP_AUDIO_IN_MspInit(I2S_HandleTypeDef *hi2s, void *Params);
323 void BSP_AUDIO_IN_MspDeInit(I2S_HandleTypeDef *hi2s, void *Params);
324 
341 #ifdef __cplusplus
342 }
343 #endif
344 
345 #endif /* __STM32469I_DISCOVERY_AUDIO_H */
346 
347 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
BSP_AUDIO_IN_Init
uint8_t BSP_AUDIO_IN_Init(uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr)
Initializes wave recording.
Definition: stm32f4_discovery_audio.c:705
__IO
#define __IO
Definition: imxrt1050/imxrt1050-evkb/CMSIS/core_cm7.h:237
BSP_AUDIO_OUT_HalfTransfer_CallBack
void BSP_AUDIO_OUT_HalfTransfer_CallBack(void)
Manages the DMA Half Transfer complete event.
Definition: stm32f4_discovery_audio.c:644
BSP_AUDIO_IN_Error_Callback
void BSP_AUDIO_IN_Error_Callback(void)
Audio IN Error callback function.
Definition: stm32f4_discovery_audio.c:1021
BSP_AUDIO_IN_DeInit
void BSP_AUDIO_IN_DeInit(void)
Deinit the audio IN peripherals.
Definition: stm32469i_discovery_audio.c:1036
I2S_HandleTypeDef
I2S handle Structure definition.
Definition: stm32f7xx_hal_i2s.h:91
BSP_AUDIO_IN_Stop
uint8_t BSP_AUDIO_IN_Stop(void)
Stops audio recording.
Definition: stm32f4_discovery_audio.c:754
BSP_AUDIO_IN_HalfTransfer_CallBack
void BSP_AUDIO_IN_HalfTransfer_CallBack(void)
Manages the DMA Half Transfer complete event.
Definition: stm32f4_discovery_audio.c:1011
BSP_AUDIO_IN_PDMToPCM
uint8_t BSP_AUDIO_IN_PDMToPCM(uint16_t *PDMBuf, uint16_t *PCMBuf)
Converts audio format from PDM to PCM.
Definition: stm32f4_discovery_audio.c:814
BSP_AUDIO_IN_Record
uint8_t BSP_AUDIO_IN_Record(uint16_t *pData, uint32_t Size)
Starts audio recording.
Definition: stm32f4_discovery_audio.c:737
BSP_AUDIO_IN_ClockConfig
void BSP_AUDIO_IN_ClockConfig(I2S_HandleTypeDef *hi2s, void *Params)
Clock Config.
Definition: stm32469i_discovery_audio.c:1114
BSP_AUDIO_IN_MspDeInit
void BSP_AUDIO_IN_MspDeInit(I2S_HandleTypeDef *hi2s, void *Params)
DeInitializes BSP_AUDIO_IN MSP.
Definition: stm32f4_discovery_audio.c:969
BSP_AUDIO_OUT_Resume
uint8_t BSP_AUDIO_OUT_Resume(void)
Resumes the audio file streaming. WARNING: When calling BSP_AUDIO_OUT_Pause() function for pause,...
Definition: stm32f4_discovery_audio.c:325
BSP_AUDIO_OUT_Stop
uint8_t BSP_AUDIO_OUT_Stop(uint32_t Option)
Stops audio playing and Power down the Audio Codec.
Definition: stm32f4_discovery_audio.c:349
BSP_AUDIO_OUT_SetMute
uint8_t BSP_AUDIO_OUT_SetMute(uint32_t Cmd)
Enables or disables the MUTE mode by software.
Definition: stm32f4_discovery_audio.c:401
BSP_AUDIO_OUT_Play
uint8_t BSP_AUDIO_OUT_Play(uint16_t *pBuffer, uint32_t Size)
Starts playing audio stream from a data buffer for a determined size.
Definition: stm32f4_discovery_audio.c:266
BSP_AUDIO_OUT_Error_CallBack
void BSP_AUDIO_OUT_Error_CallBack(void)
Manages the DMA FIFO error event.
Definition: stm32f4_discovery_audio.c:651
BSP_AUDIO_OUT_ChangeBuffer
void BSP_AUDIO_OUT_ChangeBuffer(uint16_t *pData, uint16_t Size)
Sends n-Bytes on the I2S interface.
Definition: stm32f4_discovery_audio.c:288
BSP_AUDIO_OUT_DeInit
void BSP_AUDIO_OUT_DeInit(void)
Deinit the audio peripherals.
Definition: stm32469i_discovery_audio.c:592
__SAI_HandleTypeDef
Definition: stm32f7xx_hal_sai.h:191
BSP_AUDIO_OUT_TransferComplete_CallBack
void BSP_AUDIO_OUT_TransferComplete_CallBack(void)
Manages the DMA full Transfer complete event.
Definition: stm32f4_discovery_audio.c:637
BSP_AUDIO_IN_TransferComplete_CallBack
void BSP_AUDIO_IN_TransferComplete_CallBack(void)
User callback when record buffer is filled.
Definition: stm32f4_discovery_audio.c:1001
BSP_AUDIO_IN_Pause
uint8_t BSP_AUDIO_IN_Pause(void)
Pauses the audio file stream.
Definition: stm32f4_discovery_audio.c:771
BSP_AUDIO_OUT_Init
uint8_t BSP_AUDIO_OUT_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq)
Configures the audio peripherals.
Definition: stm32f4_discovery_audio.c:214
BSP_AUDIO_OUT_Pause
uint8_t BSP_AUDIO_OUT_Pause(void)
Pauses the audio file stream. In case of using DMA, the DMA Pause feature is used....
Definition: stm32f4_discovery_audio.c:301
BSP_AUDIO_IN_Resume
uint8_t BSP_AUDIO_IN_Resume(void)
Resumes the audio file stream.
Definition: stm32f4_discovery_audio.c:784
BSP_AUDIO_OUT_MspDeInit
void BSP_AUDIO_OUT_MspDeInit(SAI_HandleTypeDef *hsai, void *Params)
Deinitializes BSP_AUDIO_OUT MSP.
Definition: stm32469i_discovery_audio.c:737
BSP_AUDIO_OUT_SetAudioFrameSlot
void BSP_AUDIO_OUT_SetAudioFrameSlot(uint32_t AudioFrameSlot)
Updates the Audio frame slot configuration.
Definition: stm32469i_discovery_audio.c:576
BSP_AUDIO_OUT_MspInit
void BSP_AUDIO_OUT_MspInit(SAI_HandleTypeDef *hsai, void *Params)
Initializes BSP_AUDIO_OUT MSP.
Definition: stm32469i_discovery_audio.c:659
BSP_AUDIO_OUT_ClockConfig
void BSP_AUDIO_OUT_ClockConfig(SAI_HandleTypeDef *hsai, uint32_t AudioFreq, void *Params)
Clock Config.
Definition: stm32469i_discovery_audio.c:783
BSP_AUDIO_IN_SetVolume
uint8_t BSP_AUDIO_IN_SetVolume(uint8_t Volume)
Controls the audio in volume level.
Definition: stm32f4_discovery_audio.c:799
BSP_AUDIO_IN_MspInit
void BSP_AUDIO_IN_MspInit(I2S_HandleTypeDef *hi2s, void *Params)
BSP AUDIO IN MSP Init.
Definition: stm32f4_discovery_audio.c:903
BSP_AUDIO_OUT_SetFrequency
void BSP_AUDIO_OUT_SetFrequency(uint32_t AudioFreq)
Update the audio frequency.
Definition: stm32f4_discovery_audio.c:443
BSP_AUDIO_OUT_SetVolume
uint8_t BSP_AUDIO_OUT_SetVolume(uint8_t Volume)
Controls the current audio volume level.
Definition: stm32f4_discovery_audio.c:381
BSP_AUDIO_OUT_SetOutputMode
uint8_t BSP_AUDIO_OUT_SetOutputMode(uint8_t Output)
Switch dynamically (while audio file is played) the output target (speaker or headphone).
Definition: stm32f4_discovery_audio.c:423
AudioInVolume
__IO uint16_t AudioInVolume
Definition: stm32f4_discovery_audio.c:187
stm32469i_discovery.h
This file contains definitions for STM32469I-Discovery LEDs, push-buttons hardware resources.


picovoice_driver
Author(s):
autogenerated on Fri Apr 1 2022 02:14:51