Functions | Variables
stm32h747i_discovery_audio.c File Reference

This file provides the Audio driver for the STM32H747I_DISCO board. More...

#include "stm32h747i_discovery_audio.h"
#include "stm32h747i_discovery_bus.h"
Include dependency graph for stm32h747i_discovery_audio.c:

Go to the source code of this file.

Functions

int32_t BSP_AUDIO_IN_DeInit (uint32_t Instance)
 Deinit the audio IN peripherals. More...
 
__weak void BSP_AUDIO_IN_Error_CallBack (uint32_t Instance)
 Audio IN Error callback function. More...
 
int32_t BSP_AUDIO_IN_GetBitsPerSample (uint32_t Instance, uint32_t *BitsPerSample)
 Get Audio In Resolution. More...
 
int32_t BSP_AUDIO_IN_GetChannelsNbr (uint32_t Instance, uint32_t *ChannelNbr)
 Get Audio In Channel number. More...
 
int32_t BSP_AUDIO_IN_GetDevice (uint32_t Instance, uint32_t *Device)
 Get Audio In device. More...
 
int32_t BSP_AUDIO_IN_GetSampleRate (uint32_t Instance, uint32_t *SampleRate)
 Get Audio In frequency. More...
 
int32_t BSP_AUDIO_IN_GetState (uint32_t Instance, uint32_t *State)
 Get Audio In device. More...
 
int32_t BSP_AUDIO_IN_GetVolume (uint32_t Instance, uint32_t *Volume)
 Get the current audio in volume level. More...
 
__weak void BSP_AUDIO_IN_HalfTransfer_CallBack (uint32_t Instance)
 Manages the DMA Half Transfer complete event. More...
 
int32_t BSP_AUDIO_IN_Init (uint32_t Instance, BSP_AUDIO_Init_t *AudioInit)
 Initialize wave recording. More...
 
void BSP_AUDIO_IN_IRQHandler (uint32_t Instance, uint32_t InputDevice)
 This function handles Audio Out DMA interrupt requests. More...
 
int32_t BSP_AUDIO_IN_Pause (uint32_t Instance)
 Pause the audio file stream. More...
 
int32_t BSP_AUDIO_IN_PDMToPCM (uint32_t Instance, uint16_t *PDMBuf, uint16_t *PCMBuf)
 Converts audio format from PDM to PCM. More...
 
int32_t BSP_AUDIO_IN_PDMToPCM_Init (uint32_t Instance, uint32_t AudioFreq, uint32_t ChnlNbrIn, uint32_t ChnlNbrOut)
 Initialize the PDM library. More...
 
int32_t BSP_AUDIO_IN_Record (uint32_t Instance, uint8_t *pBuf, uint32_t NbrOfBytes)
 Start audio recording. More...
 
int32_t BSP_AUDIO_IN_RecordPDM (uint32_t Instance, uint8_t *pBuf, uint32_t NbrOfBytes)
 Start audio recording. More...
 
int32_t BSP_AUDIO_IN_Resume (uint32_t Instance)
 Resume the audio file stream. More...
 
int32_t BSP_AUDIO_IN_SetBitsPerSample (uint32_t Instance, uint32_t BitsPerSample)
 Set Audio In Resolution. More...
 
int32_t BSP_AUDIO_IN_SetChannelsNbr (uint32_t Instance, uint32_t ChannelNbr)
 Set Audio In Channel number. More...
 
int32_t BSP_AUDIO_IN_SetDevice (uint32_t Instance, uint32_t Device)
 Set Audio In device. More...
 
int32_t BSP_AUDIO_IN_SetSampleRate (uint32_t Instance, uint32_t SampleRate)
 Set Audio In frequency. More...
 
int32_t BSP_AUDIO_IN_SetVolume (uint32_t Instance, uint32_t Volume)
 Set the current audio in volume level. More...
 
int32_t BSP_AUDIO_IN_Stop (uint32_t Instance)
 Stop audio recording. More...
 
__weak void BSP_AUDIO_IN_TransferComplete_CallBack (uint32_t Instance)
 User callback when record buffer is filled. More...
 
int32_t BSP_AUDIO_OUT_DeInit (uint32_t Instance)
 De-initializes the audio out peripheral. More...
 
__weak void BSP_AUDIO_OUT_Error_CallBack (uint32_t Instance)
 Manages the DMA FIFO error event. More...
 
int32_t BSP_AUDIO_OUT_GetBitsPerSample (uint32_t Instance, uint32_t *BitsPerSample)
 Get the audio Resolution. More...
 
int32_t BSP_AUDIO_OUT_GetChannelsNbr (uint32_t Instance, uint32_t *ChannelNbr)
 Get the audio Channels number. More...
 
int32_t BSP_AUDIO_OUT_GetDevice (uint32_t Instance, uint32_t *Device)
 Get the Output Device. More...
 
int32_t BSP_AUDIO_OUT_GetSampleRate (uint32_t Instance, uint32_t *SampleRate)
 Get the audio frequency. More...
 
int32_t BSP_AUDIO_OUT_GetState (uint32_t Instance, uint32_t *State)
 Get Audio Out state. More...
 
int32_t BSP_AUDIO_OUT_GetVolume (uint32_t Instance, uint32_t *Volume)
 Get the current audio volume level. More...
 
__weak void BSP_AUDIO_OUT_HalfTransfer_CallBack (uint32_t Instance)
 Manages the DMA Half Transfer complete event. More...
 
int32_t BSP_AUDIO_OUT_Init (uint32_t Instance, BSP_AUDIO_Init_t *AudioInit)
 Configures the audio peripherals. More...
 
void BSP_AUDIO_OUT_IRQHandler (uint32_t Instance)
 
int32_t BSP_AUDIO_OUT_IsMute (uint32_t Instance, uint32_t *IsMute)
 Check whether the MUTE mode is enabled or not. More...
 
int32_t BSP_AUDIO_OUT_Mute (uint32_t Instance)
 Enables the MUTE. More...
 
int32_t BSP_AUDIO_OUT_Pause (uint32_t Instance)
 This function Pauses the audio file stream. In case of using DMA, the DMA Pause feature is used. More...
 
int32_t BSP_AUDIO_OUT_Play (uint32_t Instance, uint8_t *pData, uint32_t NbrOfBytes)
 Default BSP AUDIO OUT Msp Callbacks. More...
 
int32_t BSP_AUDIO_OUT_Resume (uint32_t Instance)
 Resumes the audio file stream. More...
 
int32_t BSP_AUDIO_OUT_SetBitsPerSample (uint32_t Instance, uint32_t BitsPerSample)
 Set the audio Resolution. More...
 
int32_t BSP_AUDIO_OUT_SetChannelsNbr (uint32_t Instance, uint32_t ChannelNbr)
 Set the audio Channels number. More...
 
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). More...
 
int32_t BSP_AUDIO_OUT_SetSampleRate (uint32_t Instance, uint32_t SampleRate)
 Updates the audio frequency. More...
 
int32_t BSP_AUDIO_OUT_SetVolume (uint32_t Instance, uint32_t Volume)
 Controls the current audio volume level. More...
 
int32_t BSP_AUDIO_OUT_Stop (uint32_t Instance)
 Stops audio playing and Power down the Audio Codec. More...
 
__weak void BSP_AUDIO_OUT_TransferComplete_CallBack (uint32_t Instance)
 Manages the DMA full Transfer complete event. More...
 
int32_t BSP_AUDIO_OUT_UnMute (uint32_t Instance)
 Disables the MUTE mode. More...
 
void HAL_SAI_ErrorCallback (SAI_HandleTypeDef *hsai)
 SAI error callbacks. More...
 
void HAL_SAI_RxCpltCallback (SAI_HandleTypeDef *hsai)
 Reception complete callback. More...
 
void HAL_SAI_RxHalfCpltCallback (SAI_HandleTypeDef *hsai)
 Half reception complete callback. More...
 
void HAL_SAI_TxCpltCallback (SAI_HandleTypeDef *hsai)
 Tx Transfer completed callbacks. More...
 
void HAL_SAI_TxHalfCpltCallback (SAI_HandleTypeDef *hsai)
 Tx Half Transfer completed callbacks. More...
 
__weak HAL_StatusTypeDef MX_SAI1_Block_A_Init (SAI_HandleTypeDef *hsai, MX_SAI_Config_t *MXConfig)
 Initializes the Audio Codec audio out instance (SAI). More...
 
__weak HAL_StatusTypeDef MX_SAI1_Block_B_Init (SAI_HandleTypeDef *hsai, MX_SAI_Config_t *MXConfig)
 Initializes the Audio Codec audio in instance (SAI). More...
 
__weak HAL_StatusTypeDef MX_SAI1_ClockConfig (SAI_HandleTypeDef *hsai, uint32_t SampleRate)
 SAI clock Config. More...
 
__weak HAL_StatusTypeDef MX_SAI4_Block_A_Init (SAI_HandleTypeDef *hsai, MX_SAI_Config_t *MXConfig)
 Initializes the Audio Codec audio in instance (SAI). More...
 
__weak HAL_StatusTypeDef MX_SAI4_ClockConfig (SAI_HandleTypeDef *hsai, uint32_t SampleRate)
 SAI clock Config. More...
 
static void SAI_MspDeInit (SAI_HandleTypeDef *hsai)
 Deinitializes SAI MSP. More...
 
static void SAI_MspInit (SAI_HandleTypeDef *hsai)
 Initialize BSP_AUDIO_OUT MSP. More...
 

Variables

void * Audio_CompObj = NULL
 
static AUDIO_Drv_tAudio_Drv = NULL
 
AUDIO_IN_Ctx_t Audio_In_Ctx [AUDIO_IN_INSTANCES_NBR] = {0}
 
AUDIO_OUT_Ctx_t Audio_Out_Ctx [AUDIO_OUT_INSTANCES_NBR] = {0}
 
SAI_HandleTypeDef haudio_in_sai
 
SAI_HandleTypeDef haudio_out_sai
 
static PDM_Filter_Config_t PDM_FilterConfig [2]
 
static PDM_Filter_Handler_t PDM_FilterHandler [2]
 

Detailed Description

This file provides the Audio driver for the STM32H747I_DISCO board.

Author
MCD Application Team
How To use this driver:
  -----------------------
   + This driver supports stm32h7xx devices on STM32H747I-DISCO (MB1248) boards.
   + Call the function BSP_AUDIO_OUT_Init() for AUDIO OUT initialization:
        Instance:  Select the output instance. It can only be 0 (SAI)
        AudioInit: Audio Out structure to select the following parameters
                   - Device: Select the output device (headphone, speaker, hdmi ..)
                   - SampleRate: Select the output sample rate (8Khz .. 96Khz)
                   - BitsPerSample: Select the output resolution (16 or 32bits per sample)
                   - ChannelsNbr: Select the output channels number(1 for mono, 2 for stereo)
                   - Volume: Select the output volume(0% .. 100%)

      This function configures all the hardware required for the audio application (codec, I2C, SAI,
      GPIOs, DMA and interrupt if needed). This function returns BSP_ERROR_NONE if configuration is OK.
      If the returned value is different from BSP_ERROR_NONE or the function is stuck then the communication with
      the codec has failed (try to un-plug the power or reset device in this case).
      User can update the SAI or the clock configurations by overriding the weak MX functions MX_SAI1_Block_B_Init(),
      MX_SAI4_Block_A_Init(),MX_SAI1_ClockConfig(),and  MX_SAI4_ClockConfig()
      User can override the default MSP configuration and register his own MSP callbacks (defined at application level)
      by calling BSP_AUDIO_OUT_RegisterMspCallbacks() function
      User can restore the default MSP configuration by calling BSP_AUDIO_OUT_RegisterDefaultMspCallbacks()
      To use these two functions, user have to enable USE_HAL_SAI_REGISTER_CALLBACKS within stm32h7xx_hal_conf.h file


   + Call the function BSP_AUDIO_OUT_Play() to play audio stream:
        Instance:  Select the output instance. It can only be 0 (SAI)
        pBuf: pointer to the audio data file address
        NbrOfBytes: Total size of the buffer to be sent in Bytes

   + Call the function BSP_AUDIO_OUT_Pause() to pause playing
   + Call the function BSP_AUDIO_OUT_Resume() to resume playing.
       Note. After calling BSP_AUDIO_OUT_Pause() function for pause, only BSP_AUDIO_OUT_Resume() should be called
          for resume (it is not allowed to call BSP_AUDIO_OUT_Play() in this case).
       Note. This function should be called only when the audio file is played or paused (not stopped).
   + Call the function BSP_AUDIO_OUT_Stop() to stop playing.
   + Call the function BSP_AUDIO_OUT_Mute() to mute the player.
   + Call the function BSP_AUDIO_OUT_UnMute() to unmute the player.
   + Call the function BSP_AUDIO_OUT_IsMute() to get the mute state(BSP_AUDIO_MUTE_ENABLED or BSP_AUDIO_MUTE_DISABLED).
   + Call the function BSP_AUDIO_OUT_SetDevice() to update the AUDIO OUT device.
   + Call the function BSP_AUDIO_OUT_GetDevice() to get the AUDIO OUT device.
   + Call the function BSP_AUDIO_OUT_SetSampleRate() to update the AUDIO OUT sample rate.
   + Call the function BSP_AUDIO_OUT_GetSampleRate() to get the AUDIO OUT sample rate.
   + Call the function BSP_AUDIO_OUT_SetBitsPerSample() to update the AUDIO OUT resolution.
   + Call the function BSP_AUDIO_OUT_GetBitPerSample() to get the AUDIO OUT resolution.
   + Call the function BSP_AUDIO_OUT_SetChannelsNbr() to update the AUDIO OUT number of channels.
   + Call the function BSP_AUDIO_OUT_GetChannelsNbr() to get the AUDIO OUT number of channels.
   + Call the function BSP_AUDIO_OUT_SetVolume() to update the AUDIO OUT volume.
   + Call the function BSP_AUDIO_OUT_GetVolume() to get the AUDIO OUT volume.
   + Call the function BSP_AUDIO_OUT_GetState() to get the AUDIO OUT state.

   + BSP_AUDIO_OUT_SetDevice(), BSP_AUDIO_OUT_SetSampleRate(), BSP_AUDIO_OUT_SetBitsPerSample() and
     BSP_AUDIO_OUT_SetChannelsNbr() cannot be called while the state is AUDIO_OUT_STATE_PLAYING.
   + For each mode, you may need to implement the relative callback functions into your code.
      The Callback functions are named AUDIO_OUT_XXX_CallBack() and only their prototypes are declared in
      the stm32h747i_discovery_audio.h file. (refer to the example for more details on the callbacks implementations)


   + Call the function BSP_AUDIO_IN_Init() for AUDIO IN initialization:
          Instance : Select the input instance. Can be 0 (SAI) or 1 (PDM)
        AudioInit: Audio In structure to select the following parameters
                   - Device: Select the input device (analog, digital micx)
                   - SampleRate: Select the input sample rate (8Khz .. 96Khz)
                   - BitsPerSample: Select the input resolution (16 or 32bits per sample)
                   - ChannelsNbr: Select the input channels number(1 for mono, 2 for stereo)
                   - Volume: Select the input volume(0% .. 100%)


      This function configures all the hardware required for the audio application (codec, I2C, SAI
      GPIOs, DMA and interrupt if needed). This function returns BSP_ERROR_NONE if configuration is OK.
      If the returned value is different from BSP_ERROR_NONE or the function is stuck then the communication with
      the codec or the MFX has failed (try to un-plug the power or reset device in this case).
      User can update the SAI or the clock configurations by overriding the weak MX functions MX_SAIx_Init()and
      MX_SAIx_ClockConfig() .
      User can override the default MSP configuration and register his own MSP callbacks (defined at application level)
      by calling BSP_AUDIO_IN_RegisterMspCallbacks() function
      User can restore the default MSP configuration by calling BSP_AUDIO_IN_RegisterDefaultMspCallbacks()
      To use these two functions, user have to enable USE_HAL_SAI_REGISTER_CALLBACKS  within stm32h7xx_hal_conf.h file .

   + Call the function BSP_AUDIO_IN_Record() to record audio stream. The recorded data are stored to user buffer in raw
        (L, R, L, R ...)
          Instance : Select the input instance. Can be 0 (SAI) or 1 (PDM)
        pBuf: pointer to user buffer
        NbrOfBytes: Total size of the buffer to be sent in Bytes

   + Call the function BSP_AUDIO_IN_Pause() to pause recording
   + Call the function BSP_AUDIO_IN_Resume() to resume recording.
   + Call the function BSP_AUDIO_IN_Stop() to stop recording.
   + Call the function BSP_AUDIO_IN_SetDevice() to update the AUDIO IN device.
   + Call the function BSP_AUDIO_IN_GetDevice() to get the AUDIO IN device.
   + Call the function BSP_AUDIO_IN_SetSampleRate() to update the AUDIO IN sample rate.
   + Call the function BSP_AUDIO_IN_GetSampleRate() to get the AUDIO IN sample rate.
   + Call the function BSP_AUDIO_IN_SetBitPerSample() to update the AUDIO IN resolution.
   + Call the function BSP_AUDIO_IN_GetBitPerSample() to get the AUDIO IN resolution.
   + Call the function BSP_AUDIO_IN_SetChannelsNbr() to update the AUDIO IN number of channels.
   + Call the function BSP_AUDIO_IN_GetChannelsNbr() to get the AUDIO IN number of channels.
   + Call the function BSP_AUDIO_IN_SetVolume() to update the AUDIO IN volume.
   + Call the function BSP_AUDIO_IN_GetVolume() to get the AUDIO IN volume.
   + Call the function BSP_AUDIO_IN_GetState() to get the AUDIO IN state.

   + For each mode, you may need to implement the relative callback functions into your code.
      The Callback functions are named AUDIO_IN_XXX_CallBack() and only their prototypes are declared in
      the stm32h747i_discovery_audio.h file. (refer to the example for more details on the callbacks implementations)

   + The driver API and the callback functions are at the end of the stm32h747i_discovery_audio.h file.
  Known Limitations:
  ------------------
   1- If the TDM Format used to play in parallel 2 audio Stream (the first Stream is configured in codec SLOT0 and second
      Stream in SLOT1) the Pause/Resume, volume and mute feature will control the both streams.
   2- Parsing of audio file is not implemented (in order to determine audio file properties: Mono/Stereo, Data size,
      File size, Audio Frequency, Audio Data header size ...). The configuration is fixed for the given audio file.
Attention

© Copyright (c) 2017 STMicroelectronics. All rights reserved.

This software component is licensed by ST under BSD 3-Clause license, the "License"; You may not use this file except in compliance with the License. You may obtain a copy of the License at: opensource.org/licenses/BSD-3-Clause

Definition in file stm32h747i_discovery_audio.c.



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