Go to the documentation of this file.
22 #ifndef STM32H747I_DISCO_AUDIO_H
23 #define STM32H747I_DISCO_AUDIO_H
33 #if (USE_AUDIO_CODEC_WM8994 > 0U)
35 #include "../Components/wm8994/wm8994.h"
37 #include "../Components/Common/audio.h"
40 #include "pdm2pcm_glo.h"
110 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
113 pSAI_CallbackTypeDef pMspSaiInitCb;
114 pSAI_CallbackTypeDef pMspSaiDeInitCb;
118 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
121 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
136 #define AUDIO_I2C_ADDRESS 0x34U
139 #define AUDIO_OUT_INSTANCES_NBR 2U
142 #define AUDIO_FREQUENCY_192K 192000U
143 #define AUDIO_FREQUENCY_176K 176400U
144 #define AUDIO_FREQUENCY_96K 96000U
145 #define AUDIO_FREQUENCY_88K 88200U
146 #define AUDIO_FREQUENCY_48K 48000U
147 #define AUDIO_FREQUENCY_44K 44100U
148 #define AUDIO_FREQUENCY_32K 32000U
149 #define AUDIO_FREQUENCY_22K 22050U
150 #define AUDIO_FREQUENCY_16K 16000U
151 #define AUDIO_FREQUENCY_11K 11025U
152 #define AUDIO_FREQUENCY_8K 8000U
155 #define AUDIO_RESOLUTION_16B 16U
156 #define AUDIO_RESOLUTION_32B 32U
159 #define AUDIO_OUT_DEVICE_NONE 0U
160 #define AUDIO_OUT_DEVICE_SPEAKER 1U
161 #define AUDIO_OUT_DEVICE_HEADPHONE 2U
162 #define AUDIO_OUT_DEVICE_SPK_HP 3U
163 #define AUDIO_OUT_DEVICE_AUTO 4U
164 #define AUDIO_OUT_DEVICE_HDMI 5U
167 #define BSP_AUDIO_MUTE_DISABLED 0U
168 #define BSP_AUDIO_MUTE_ENABLED 1U
171 #define AUDIO_OUT_STATE_RESET 0U
172 #define AUDIO_OUT_STATE_PLAYING 1U
173 #define AUDIO_OUT_STATE_STOP 2U
174 #define AUDIO_OUT_STATE_PAUSE 3U
178 #define AUDIO_VOLUME_INPUT 0U
179 #define AUDIO_VOLUME_OUTPUT 1U
182 #define CODEC_PDWN_SW 1U
183 #define CODEC_MUTE_ON 1U
184 #define CODEC_MUTE_OFF 0U
196 #define CODEC_AUDIOFRAME_SLOT_0123 SAI_SLOTACTIVE_0 | SAI_SLOTACTIVE_1 | SAI_SLOTACTIVE_2 | SAI_SLOTACTIVE_3
198 #define CODEC_AUDIOFRAME_SLOT_02 SAI_SLOTACTIVE_0 | SAI_SLOTACTIVE_2
200 #define CODEC_AUDIOFRAME_SLOT_13 SAI_SLOTACTIVE_1 | SAI_SLOTACTIVE_3
203 #define AUDIO_OUT_SAIx SAI1_Block_A
204 #define AUDIO_OUT_SAIx_CLK_ENABLE() __HAL_RCC_SAI1_CLK_ENABLE()
205 #define AUDIO_OUT_SAIx_CLK_DISABLE() __HAL_RCC_SAI1_CLK_DISABLE()
207 #define AUDIO_OUT_SAIx_MCLK_ENABLE() __HAL_RCC_GPIOG_CLK_ENABLE()
208 #define AUDIO_OUT_SAIx_MCLK_GPIO_PORT GPIOG
209 #define AUDIO_OUT_SAIx_MCLK_PIN GPIO_PIN_7
210 #define AUDIO_OUT_SAIx_MCLK_AF GPIO_AF6_SAI1
212 #define AUDIO_OUT_SAIx_SCK_ENABLE() __HAL_RCC_GPIOE_CLK_ENABLE()
213 #define AUDIO_OUT_SAIx_SCK_GPIO_PORT GPIOE
214 #define AUDIO_OUT_SAIx_SCK_PIN GPIO_PIN_5
215 #define AUDIO_OUT_SAIx_SCK_AF GPIO_AF6_SAI1
217 #define AUDIO_OUT_SAIx_SD_ENABLE() __HAL_RCC_GPIOE_CLK_ENABLE()
218 #define AUDIO_OUT_SAIx_SD_GPIO_PORT GPIOE
219 #define AUDIO_OUT_SAIx_SD_PIN GPIO_PIN_6
220 #define AUDIO_OUT_SAIx_SD_AF GPIO_AF6_SAI1
222 #define AUDIO_OUT_SAIx_FS_ENABLE() __HAL_RCC_GPIOE_CLK_ENABLE()
223 #define AUDIO_OUT_SAIx_FS_GPIO_PORT GPIOE
224 #define AUDIO_OUT_SAIx_FS_PIN GPIO_PIN_4
225 #define AUDIO_OUT_SAIx_FS_AF GPIO_AF6_SAI1
228 #define AUDIO_OUT_SAIx_DMAx_CLK_ENABLE() __HAL_RCC_DMA2_CLK_ENABLE()
229 #define AUDIO_OUT_SAIx_DMAx_STREAM DMA2_Stream1
230 #define AUDIO_OUT_SAIx_DMAx_REQUEST DMA_REQUEST_SAI1_A
231 #define AUDIO_OUT_SAIx_DMAx_IRQ DMA2_Stream1_IRQn
232 #define AUDIO_OUT_SAIx_DMAx_PERIPH_DATA_SIZE DMA_PDATAALIGN_HALFWORD
233 #define AUDIO_OUT_SAIx_DMAx_MEM_DATA_SIZE DMA_MDATAALIGN_HALFWORD
234 #define AUDIO_OUT_SAIx_DMAx_IRQHandler DMA2_Stream1_IRQHandler
240 #define AUDIO_IN_SAIx SAI1_Block_B
241 #define AUDIO_IN_SAIx_CLK_ENABLE() __HAL_RCC_SAI1_CLK_ENABLE()
242 #define AUDIO_IN_SAIx_CLK_DISABLE() __HAL_RCC_SAI1_CLK_DISABLE()
243 #define AUDIO_IN_SAIx_AF GPIO_AF6_SAI1
244 #define AUDIO_IN_SAIx_SD_ENABLE() __HAL_RCC_GPIOE_CLK_ENABLE()
245 #define AUDIO_IN_SAIx_SD_GPIO_PORT GPIOE
246 #define AUDIO_IN_SAIx_SD_PIN GPIO_PIN_3
249 #define AUDIO_IN_SAIx_DMAx_CLK_ENABLE() __HAL_RCC_DMA2_CLK_ENABLE()
250 #define AUDIO_IN_SAIx_DMAx_STREAM DMA2_Stream4
251 #define AUDIO_IN_SAIx_DMAx_REQUEST DMA_REQUEST_SAI1_B
252 #define AUDIO_IN_SAIx_DMAx_IRQ DMA2_Stream4_IRQn
253 #define AUDIO_IN_SAIx_DMAx_PERIPH_DATA_SIZE DMA_PDATAALIGN_HALFWORD
254 #define AUDIO_IN_SAIx_DMAx_MEM_DATA_SIZE DMA_MDATAALIGN_HALFWORD
256 #define AUDIO_IN_SAIx_DMAx_IRQHandler DMA2_Stream4_IRQHandler
258 #define AUDIO_IN_INT_GPIO_ENABLE() __HAL_RCC_GPIOJ_CLK_ENABLE()
259 #define AUDIO_IN_INT_GPIO_PORT GPIOJ
260 #define AUDIO_IN_INT_GPIO_PIN GPIO_PIN_15
261 #define AUDIO_IN_INT_IRQ EXTI15_10_IRQn
264 #define AUDIO_IN_SAI_PDMx SAI4_Block_A
265 #define AUDIO_IN_SAI_PDMx_CLK_ENABLE() __HAL_RCC_SAI4_CLK_ENABLE()
266 #define AUDIO_IN_SAI_PDMx_CLK_DISABLE() __HAL_RCC_SAI4_CLK_DISABLE()
267 #define AUDIO_IN_SAI_PDMx_FS_SCK_AF GPIO_AF8_SAI4
268 #define AUDIO_IN_SAI_PDMx_FS_SCK_ENABLE() __HAL_RCC_GPIOE_CLK_ENABLE()
269 #define AUDIO_IN_SAI_PDMx_FS_SCK_GPIO_PORT GPIOE
270 #define AUDIO_IN_SAI_PDMx_FS_PIN GPIO_PIN_4
271 #define AUDIO_IN_SAI_PDMx_SCK_PIN GPIO_PIN_5
273 #define AUDIO_IN_SAI_PDMx_CLK_IN_ENABLE() __HAL_RCC_GPIOE_CLK_ENABLE()
274 #define AUDIO_IN_SAI_PDMx_CLK_IN_PIN GPIO_PIN_2
275 #define AUDIO_IN_SAI_PDMx_CLK_IN_PORT GPIOE
276 #define AUDIO_IN_SAI_PDMx_DATA_IN_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
277 #define AUDIO_IN_SAI_PDMx_DATA_IN_PIN GPIO_PIN_1
278 #define AUDIO_IN_SAI_PDMx_DATA_IN_PORT GPIOC
279 #define AUDIO_IN_SAI_PDMx_DATA_CLK_AF GPIO_AF10_SAI4
280 #define AUDIO_IN_SAI_PDMx_IRQHandler SAI4_IRQHandler
281 #define AUDIO_IN_SAI_PDMx_IRQ SAI4_IRQn
284 #define AUDIO_IN_SAI_PDMx_DMAx_CLK_ENABLE() __HAL_RCC_BDMA_CLK_ENABLE()
285 #define AUDIO_IN_SAI_PDMx_DMAx_STREAM BDMA_Channel1
286 #define AUDIO_IN_SAI_PDMx_DMAx_REQUEST BDMA_REQUEST_SAI4_A
287 #define AUDIO_IN_SAI_PDMx_DMAx_IRQ BDMA_Channel1_IRQn
288 #define AUDIO_IN_SAI_PDMx_DMAx_PERIPH_DATA_SIZE DMA_PDATAALIGN_HALFWORD
289 #define AUDIO_IN_SAI_PDMx_DMAx_MEM_DATA_SIZE DMA_MDATAALIGN_HALFWORD
290 #define AUDIO_IN_SAI_PDMx_DMAx_IRQHandler BDMA_Channel1_IRQHandler
295 #define AUDIO_IN_DEVICE_ANALOG_MIC 0x00U
297 #define AUDIO_IN_DEVICE_DIGITAL_MIC 0x10U
300 #define AUDIO_IN_STATE_RESET 0U
301 #define AUDIO_IN_STATE_RECORDING 1U
302 #define AUDIO_IN_STATE_STOP 2U
303 #define AUDIO_IN_STATE_PAUSE 3U
309 #define AUDIO_IN_INSTANCES_NBR 2U
317 #define POS_VAL(VAL) (POSITION_VAL(VAL) - 4)
318 #define VOLUME_OUT_CONVERT(Volume) (((Volume) > 100)? 63:((uint8_t)(((Volume) * 63) / 100)))
319 #define VOLUME_IN_CONVERT(Volume) (((Volume) >= 100)? 239:((uint8_t)(((Volume) * 239) / 100)))
349 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1U)
350 int32_t BSP_AUDIO_OUT_RegisterMspCallbacks (uint32_t Instance, BSP_AUDIO_OUT_Cb_t *CallBacks);
351 int32_t BSP_AUDIO_OUT_RegisterDefaultMspCallbacks (uint32_t Instance);
399 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
400 int32_t BSP_AUDIO_IN_RegisterDefaultMspCallbacks (uint32_t Instance);
401 int32_t BSP_AUDIO_IN_RegisterMspCallbacks (uint32_t Instance, BSP_AUDIO_IN_Cb_t *CallBacks);
uint8_t BSP_AUDIO_OUT_SetVolume(uint8_t Volume)
Controls the current audio volume level.
uint8_t BSP_AUDIO_IN_SetVolume(uint8_t Volume)
Controls the audio in volume level.
HAL_StatusTypeDef
HAL Status structures definition
uint8_t BSP_AUDIO_IN_PDMToPCM(uint16_t *PDMBuf, uint16_t *PCMBuf)
Converts audio format from PDM to PCM.
int32_t BSP_AUDIO_IN_SetDevice(uint32_t Instance, uint32_t Device)
Set Audio In device.
int32_t BSP_AUDIO_OUT_GetSampleRate(uint32_t Instance, uint32_t *SampleRate)
Get the audio frequency.
uint8_t BSP_AUDIO_OUT_Pause(void)
Pauses the audio file stream. In case of using DMA, the DMA Pause feature is used....
int32_t BSP_AUDIO_OUT_Mute(uint32_t Instance)
Enables the MUTE.
uint8_t BSP_AUDIO_IN_Stop(void)
Stops audio recording.
int32_t BSP_AUDIO_IN_SetChannelsNbr(uint32_t Instance, uint32_t ChannelNbr)
Set Audio In Channel number.
void BSP_AUDIO_IN_DeInit(void)
Deinit the audio IN peripherals.
uint32_t IsMspCallbacksValid
SAI_HandleTypeDef haudio_out_sai
int32_t BSP_AUDIO_IN_GetVolume(uint32_t Instance, uint32_t *Volume)
Get the current audio in volume level.
uint8_t BSP_AUDIO_IN_Init(uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr)
Initializes wave recording.
__weak HAL_StatusTypeDef MX_SAI1_Block_B_Init(SAI_HandleTypeDef *hsai, MX_SAI_Config_t *MXConfig)
Initializes the Audio Codec audio in instance (SAI).
__weak void BSP_AUDIO_OUT_TransferComplete_CallBack(void)
Manages the DMA full Transfer complete event.
int32_t BSP_AUDIO_OUT_GetChannelsNbr(uint32_t Instance, uint32_t *ChannelNbr)
Get the audio Channels number.
__weak void BSP_AUDIO_IN_Error_CallBack(void)
Audio IN Error callback function.
int32_t BSP_AUDIO_IN_PDMToPCM_Init(uint32_t Instance, uint32_t AudioFreq, uint32_t ChnlNbrIn, uint32_t ChnlNbrOut)
Initialize the PDM library.
int32_t BSP_AUDIO_OUT_GetState(uint32_t Instance, uint32_t *State)
Get Audio Out state.
uint8_t BSP_AUDIO_OUT_Play(uint16_t *pBuffer, uint32_t Size)
Starts playing audio stream from a data buffer for a determined size.
int32_t BSP_AUDIO_IN_GetBitsPerSample(uint32_t Instance, uint32_t *BitsPerSample)
Get Audio In Resolution.
void BSP_AUDIO_OUT_IRQHandler(uint32_t Instance)
int32_t BSP_AUDIO_IN_GetChannelsNbr(uint32_t Instance, uint32_t *ChannelNbr)
Get Audio In Channel number.
SAI_HandleTypeDef haudio_in_sai
uint32_t IsMspCallbacksValid
int32_t BSP_AUDIO_OUT_SetDevice(uint32_t Instance, uint32_t Device)
Switch dynamically (while audio file is played) the output target (speaker or headphone).
uint8_t BSP_AUDIO_IN_Pause(void)
Pauses the audio file stream.
int32_t BSP_AUDIO_IN_RecordPDM(uint32_t Instance, uint8_t *pBuf, uint32_t NbrOfBytes)
Start audio recording.
uint32_t ActiveFrameLength
__weak HAL_StatusTypeDef MX_SAI4_Block_A_Init(SAI_HandleTypeDef *hsai, MX_SAI_Config_t *MXConfig)
Initializes the Audio Codec audio in instance (SAI).
__weak HAL_StatusTypeDef MX_SAI1_ClockConfig(SAI_HandleTypeDef *hsai, uint32_t SampleRate)
SAI clock Config.
void BSP_AUDIO_OUT_DeInit(void)
Deinit the audio peripherals.
__weak void BSP_AUDIO_OUT_Error_CallBack(void)
Manages the DMA FIFO error event.
int32_t BSP_AUDIO_OUT_SetSampleRate(uint32_t Instance, uint32_t SampleRate)
Updates the audio frequency.
int32_t BSP_AUDIO_OUT_GetVolume(uint32_t Instance, uint32_t *Volume)
Get the current audio volume level.
__weak void BSP_AUDIO_OUT_HalfTransfer_CallBack(void)
Manages the DMA Half Transfer complete event.
int32_t BSP_AUDIO_OUT_SetBitsPerSample(uint32_t Instance, uint32_t BitsPerSample)
Set the audio Resolution.
int32_t BSP_AUDIO_IN_SetSampleRate(uint32_t Instance, uint32_t SampleRate)
Set Audio In frequency.
int32_t BSP_AUDIO_OUT_UnMute(uint32_t Instance)
Disables the MUTE mode.
uint8_t BSP_AUDIO_IN_Record(uint16_t *pbuf, uint32_t size)
Starts audio recording.
int32_t BSP_AUDIO_OUT_GetDevice(uint32_t Instance, uint32_t *Device)
Get the Output Device.
uint8_t BSP_AUDIO_OUT_Stop(uint32_t Option)
Stops audio playing and Power down the Audio Codec.
int32_t BSP_AUDIO_OUT_SetChannelsNbr(uint32_t Instance, uint32_t ChannelNbr)
Set the audio Channels number.
__weak void BSP_AUDIO_IN_TransferComplete_CallBack(void)
User callback when record buffer is filled.
uint8_t BSP_AUDIO_IN_Resume(void)
Resumes the audio file stream.
AUDIO_OUT_Ctx_t Audio_Out_Ctx[]
__weak void BSP_AUDIO_IN_HalfTransfer_CallBack(void)
Manages the DMA Half Transfer complete event.
int32_t BSP_AUDIO_OUT_GetBitsPerSample(uint32_t Instance, uint32_t *BitsPerSample)
Get the audio Resolution.
AUDIO_IN_Ctx_t Audio_In_Ctx[]
int32_t BSP_AUDIO_IN_GetState(uint32_t Instance, uint32_t *State)
Get Audio In device.
int32_t BSP_AUDIO_IN_GetSampleRate(uint32_t Instance, uint32_t *SampleRate)
Get Audio In frequency.
void BSP_AUDIO_IN_IRQHandler(uint32_t Instance, uint32_t InputDevice)
This function handles Audio Out DMA interrupt requests.
int32_t BSP_AUDIO_IN_SetBitsPerSample(uint32_t Instance, uint32_t BitsPerSample)
Set Audio In Resolution.
int32_t BSP_AUDIO_OUT_IsMute(uint32_t Instance, uint32_t *IsMute)
Check whether the MUTE mode is enabled or not.
__weak HAL_StatusTypeDef MX_SAI4_ClockConfig(SAI_HandleTypeDef *hsai, uint32_t SampleRate)
SAI clock Config.
__weak HAL_StatusTypeDef MX_SAI1_Block_A_Init(SAI_HandleTypeDef *hsai, MX_SAI_Config_t *MXConfig)
Initializes the Audio Codec audio out instance (SAI).
int32_t BSP_AUDIO_IN_GetDevice(uint32_t Instance, uint32_t *Device)
Get Audio In device.
uint8_t BSP_AUDIO_OUT_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq)
Configures the audio peripherals.
uint8_t BSP_AUDIO_OUT_Resume(void)
Resumes the audio file streaming. WARNING: When calling BSP_AUDIO_OUT_Pause() function for pause,...