USBD_Audio_DrvInit

Description

Initialize audio codec chip and different microcontroller peripherals needed to communicate with it.

Files

usbd_audio_drv_<codec-name>.h / usbd_audio_drv_<codec-name>.c

Prototype

static  void  USBD_Audio_DrvInit (USBD_AUDIO_DRV  *p_audio_drv,
                                  USBD_ERR        *p_err);


Arguments

p_audio_drv

Pointer to audio driver structure.

p_err

Pointer to variable that will receive the return error code from this function.

USBD_ERR_NONE
USBD_ERR_AUDIO_CODEC_INIT_FAILED
USBD_ERR_ALLOC

Returned Value

None.

Callers

Audio Class.

Implementation guidelines

Typical operations performed by the function USBD_Audio_DrvInit() consist in:

  • Allocating an optional internal data structure using µC/LIB memory functions (refer to Memory Allocation Functions). This structure can then be saved in the DataPtr field of USBD_AUDIO_DRV structure. 
  • Setting all clocks required by peripherals (for instance I2C, I2S controllers, etc.) communicating with the audio chip.
  • Setting any I/O required to interface peripherals to the audio chip.
  • Setting any interrupt needed by peripherals. It may also encompass installing ISR (Interrupt Service Routine) for those peripherals (for instance, an ISR for I2C communication, an ISR for I2S communication if no DMA is used).
  • Initializing the DMA controller if it is used to transfer audio data. 
  • Initializing the audio chip by configuring its registers accessed by I2C or SPI for instance.
  • Initializing any software resources needed for the driver functioning. For instance:
    • Allocating DMA descriptors if it is required by your DMA controller implementation from the heap or a dedicated memory using µC/LIB memory functions (refer to Memory Allocation Functions).
    • Allocating the silence buffer using µC/LIB memory functions if a playback stream is required and initializing it with zeros using Mem_Clr().
    • Allocating a dummy buffer using µC/LIB memory functions if a record stream is required.
  • Set p_err to USBD_ERR_AUDIO_CODEC_INIT_FAILED if any error occurs during the initialization sequence. Otherwise set it to USBD_ERR_NONE.

USBD_Audio_DrvInit() will initialize the function pointer contained in the structure USBD_AUDIO_DRV_COMMON_API.