Before starting the communication phase, your application needs to initialize and configure the class to suit your needs. Table - Audio Class Initialization API Summary summarizes the initialization functions provided by the audio class. For more details about the functions parameters, refer to the Audio API.
|
You need to call these functions in the order shown below to successfully initialize the audio class:
USBD_Audio_Init()
USBD_Audio_Add()
USBD_Audio_CfgAdd()
USBD_Audio_IT_Add()
USBD_Audio_OT_Add()
USBD_Audio_FU_Add()
USBD_Audio_MU_Add()
USBD_Audio_SU_Add()
USBD_Audio_IT_Assoc
USBD_Audio_OT_Assoc()
USBD_Audio_FU_Assoc()
USBD_Audio_MU_Assoc()
USBD_Audio_SU_Assoc()
USBD_Audio_MU_MixingCtrlSet
USBD_Audio_AS_IF_Cfg()
USBD_Audio_AS_IF_Add()
Listing - Audio Class Initialization Example illustrates the use of the previous functions for initializing an audio class. Note that the error handling has been omitted for clarity.
The listing does not show an example of usage of the functions |
#define APP_CFG_USBD_AUDIO_TASKS_Q_LEN 20u #define APP_CFG_USBD_AUDIO_NBR_ENTITY 6u CPU_INT08U Speaker_IT_USB_OUT_ID; (1) CPU_INT08U Speaker_OT_ID; CPU_INT08U Speaker_FU_ID; static void App_USBD_Audio_Conn (CPU_INT08U dev_nbr, CPU_INT08U cfg_nbr, CPU_INT08U terminal_id, USBD_AUDIO_AS_HANDLE as_handle); static void App_USBD_Audio_Disconn(CPU_INT08U dev_nbr, CPU_INT08U cfg_nbr, CPU_INT08U terminal_id, USBD_AUDIO_AS_HANDLE as_handle); const USBD_AUDIO_EVENT_FNCTS App_USBD_Audio_EventFncts = { App_USBD_Audio_Conn, App_USBD_Audio_Disconn }; CPU_BOOLEAN App_USBD_Audio_Init (CPU_INT08U dev_nbr, CPU_INT08U cfg_hs, CPU_INT08U cfg_fs) { USBD_ERR err; CPU_INT08U audio_nbr; USBD_AUDIO_AS_IF_HANDLE speaker_playback_as_if_handle; /* Init Audio class. */ USBD_Audio_Init(APP_CFG_USBD_AUDIO_TASKS_Q_LEN, (2) &err); if (err != USBD_ERR_NONE) { /* $$$$ Handle the error. */ } /* Create an audio class instance. */ audio_nbr = USBD_Audio_Add(APP_CFG_USBD_AUDIO_NBR_ENTITY, (3) &USBD_Audio_DrvCommonAPI_Simulation, &App_USBD_Audio_EventFncts, &err); if (err != USBD_ERR_NONE) { /* $$$$ Handle the error. */ } if (cfg_hs != USBD_CFG_NBR_NONE) { /* --------------- ADD HS CONFIGURATION --------------- */ USBD_Audio_CfgAdd(audio_nbr, (4) dev_nbr, cfg_hs, &err); if (err != USBD_ERR_NONE) { /* $$$$ Handle the error. */ } } if (cfg_fs != USBD_CFG_NBR_NONE) { /* --------------- ADD FS CONFIGURATION --------------- */ USBD_Audio_CfgAdd(audio_nbr, (5) dev_nbr, cfg_fs, &err); if (err != USBD_ERR_NONE) { /* $$$$ Handle the error. */ } } /* ----------- BUILD AUDIO FUNCTION TOPOLOGY ---------- */ /* Add terminals and units. */ Speaker_IT_USB_OUT_ID = USBD_Audio_IT_Add(audio_nbr, (6) &USBD_IT_USB_OUT_Cfg, &err); if (err != USBD_ERR_NONE) { /* $$$$ Handle the error. */ } Speaker_OT_ID = USBD_Audio_OT_Add(audio_nbr, &USBD_OT_SPEAKER_Cfg, DEF_NULL, &err); if (err != USBD_ERR_NONE) { /* $$$$ Handle the error. */ } Speaker_FU_ID = USBD_Audio_FU_Add(audio_nbr, &USBD_FU_SPEAKER_Cfg, &USBD_Audio_DrvFU_API_Simulation, &err); if (err != USBD_ERR_NONE) { /* $$$$ Handle the error. */ } /* Bind terminals and units. */ USBD_Audio_IT_Assoc(audio_nbr, (7) Speaker_IT_USB_OUT_ID, USBD_AUDIO_TERMINAL_NO_ASSOCIATION, &err); if (err != USBD_ERR_NONE) { /* $$$$ Handle the error. */ } USBD_Audio_OT_Assoc(audio_nbr, Speaker_OT_ID, Speaker_FU_ID, USBD_AUDIO_TERMINAL_NO_ASSOCIATION, &err); if (err != USBD_ERR_NONE) { /* $$$$ Handle the error. */ } USBD_Audio_FU_Assoc(audio_nbr, Speaker_FU_ID, Speaker_IT_USB_OUT_ID, &err); if (err != USBD_ERR_NONE) { /* $$$$ Handle the error. */ } /* ----------- CONFIGURE AUDIO STREAMING IF ----------- */ (8) speaker_playback_as_if_handle = USBD_Audio_AS_IF_Cfg(&USBD_SpeakerStreamCfg, &USBD_AS_IF1_SpeakerCfg, &USBD_Audio_DrvAS_API_Simulation, &App_USBD_Audio_MemSegInfo, Speaker_IT_USB_OUT_ID, DEF_NULL, &err); if (err != USBD_ERR_NONE) { /* $$$$ Handle the error. */ } if (cfg_hs != USBD_CFG_NBR_NONE) { /* -------------- ADD AUDIO STREAMING IF -------------- */ USBD_Audio_AS_IF_Add(audio_nbr, (9) cfg_hs, speaker_playback_as_if_handle, &USBD_AS_IF1_SpeakerCfg, "Speaker AudioStreaming IF", &err); if (err != USBD_ERR_NONE) { /* $$$$ Handle the error. */ } } if (cfg_fs != USBD_CFG_NBR_NONE) { /* -------------- ADD AUDIO STREAMING IF -------------- */ USBD_Audio_AS_IF_Add(audio_nbr, (10) cfg_fs, speaker_playback_as_if_handle, &USBD_AS_IF1_SpeakerCfg, "Speaker AudioStreaming IF", &err); if (err != USBD_ERR_NONE) { /* $$$$ Handle the error. */ } } return (DEF_OK); } |
(1) These global variables will contain the terminal and unit IDs assigned by the audio class. These global variables can then be accessed by the Audio Peripheral Driver when processing class requests and streaming data. (2) Initialize audio class internal structures, variables and OS layer. The queue size for the playback and record tasks is passed to the function. In this example, the constant (3) Create a new audio class instance. (4) Check if the high-speed configuration is active and proceed to add the audio instance previously created to this configuration. (5) Check if the full-speed configuration is active and proceed to add the audio instance to this configuration. (6) Build the audio function topology by adding all the required terminals and units. In this example, a speaker topology is built by adding an Input Terminal of type USB OUT, an Output Terminal of type Speaker and a Feature Unit to control the mute and volume controls of the speaker stream. This topology corresponds to the one shown in Figure - usbd_audio_dev_cfg.c - Typical Topologies Example. The audio class assigned a unique ID to each terminal and unit. Each ID can be stored in a global variable accessible by the Audio Peripheral Driver for class requests and stream data processing. The associated terminal or unit configuration structure is passed to the function (7) Build the connection between terminals and units using the ID assigned by the audio class. The terminals and units connection is based on the input pin(s). An Input Terminal has no input pin. Thus no entity source ID is passed as argument of (8) Configure the AudioStreaming interface with all the information passed as argument. In the example, the AudioStreaming interface is a speaker stream. The general speaker stream configuration structure, At the end, the function returns an handle identifying the stream. (9) Add to the high-speed configuration an AudioStreaming interface. In the example, the stream handle returned by (10) Add to the full-speed configuration an AudioStreaming interface. The different parameters passed to the function are the same as the one described in (8). |