| NUC472_NUC442_BSP V3.04.000 The Board Support Package for NUC472/NUC442

uac.h
Go to the documentation of this file.
1#ifndef __INCLUDED_UAC_H__
2#define __INCLUDED_UAC_H__
3
4#include "usbh_core.h"
5
7
8//#define USBAS_DEBUG
9
10/*
11 * Debug message
12 */
13#define USBAS_ERRMSG printf
14
15#ifdef USBAS_DEBUG
16#define USBAS_DBGMSG printf
17#else
18#define USBAS_DBGMSG(...)
19#endif
20
21
22#define UAC_IFACE_CODE 1
23
24#define SUBCLS_UNDEFINED 0x00
25#define SUBCLS_AUDIOCONTROL 0x01
26#define SUBCLS_AUDIOSTREAMING 0x02
27#define SUBCLS_MIDISTREAMING 0x03
28
29/* Audio Class-specific descritpor types */
30#define CS_UNDEFINED 0x20
31#define CS_DEVICE 0x21
32#define CS_CONFIGURATION 0x22
33#define CS_STRING 0x23
34#define CS_INTERFACE 0x24
35#define CS_ENDPOINT 0x25
36
37/* Audio Class-Specific AC Interface Descriptor Subtypes */
38#define AC_DESCRIPTOR_UNDEFINED 0x00
39#define HEADER 0x01
40#define INPUT_TERMINAL 0x02
41#define OUTPUT_TERMINAL 0x03
42#define MIXER_UNIT 0x04
43#define SELECTOR_UNIT 0x05
44#define FEATURE_UNIT 0x06
45#define PROCESSING_UNIT 0x07
46#define EXTENSION_UNIT 0x08
47
48/* Audio Class-Specific AS Interface Descriptor Subtypes */
49#define AS_DESCRIPTOR_UNDEFINED 0x00
50#define AS_GENERAL 0x01
51#define FORMAT_TYPE 0x02
52#define FORMAT_SPECIFIC 0x03
53
54/* Processing Unit Process Types */
55#define PROCESS_UNDEFINED 0x00
56#define UP_DOWNMIX_PROCESS 0x01
57#define DOLBY_PROLOGIC_PROCESS 0x02
58#define _3D_STEREO_EXTENDER_PROCESS 0x03
59#define REVERBERATION_PROCESS 0x04
60#define CHORUS_PROCESS 0x05
61#define DYN_RANGE_COMP_PROCESS 0x06
62
63/* Audio Class-Specific Endpoint Descriptor Subtypes */
64#define DESCRIPTOR_UNDEFINED 0x00
65#define EP_GENERAL 0x01
66
67/* Audio Class-Specific Request Codes */
68#define REQUEST_CODE_UNDEFINED 0x00
69#define SET_CUR 0x01
70#define GET_CUR 0x81
71#define SET_MIN 0x02
72#define GET_MIN 0x82
73#define SET_MAX 0x03
74#define GET_MAX 0x83
75#define SET_RES 0x04
76#define GET_RES 0x84
77#define SET_MEM 0x05
78#define GET_MEM 0x85
79#define GET_STAT 0xFF
80
81/* Terminal Control Selectors */
82#define TE_CONTROL_UNDEFINED 0x00
83#define COPY_PROTECT_CONTROL 0x01
84
85/* Feature Unit Control Selectors */
86#define FU_CONTROL_UNDEFINED 0x00
87#define MUTE_CONTROL 0x01
88#define VOLUME_CONTROL 0x02
89#define BASS_CONTROL 0x03
90#define MID_CONTROL 0x04
91#define TREBLE_CONTROL 0x05
92#define GRAPHIC_EQUALIZER_CONTROL 0x06
93#define AUTOMATIC_GAIN_CONTROL 0x07
94#define DELAY_CONTROL 0x08
95#define BASS_BOOST_CONTROL 0x09
96#define LOUDNESS_CONTROL 0x0A
97
98/* Up/Down-mix Processing Unit Control Selectors */
99#define UD_CONTROL_UNDEFINED 0x00
100#define UD_ENABLE_CONTROL 0x01
101#define UD_MODE_SELECT_CONTROL 0x02
102
103/* Dolby Prologic Processing Unit Control Selectors */
104#define DP_CONTROL_UNDEFINED 0x00
105#define DP_ENABLE_CONTROL 0x01
106#define DP_MODE_SELECT_CONTROL 0x02
107
108/* 3D Stereo Extender Processing Unit Control Selectors */
109#define _3D_CONTROL_UNDEFINED 0x00
110#define _3D_ENABLE_CONTROL 0x01
111#define SPACIOUSNESS_CONTROL 0x03
112
113/* Reverberation Processing Unit Control Selectors */
114#define RV_CONTROL_UNDEFINED 0x00
115#define RV_ENABLE_CONTROL 0x01
116#define REVERB_LEVEL_CONTROL 0x02
117#define REVERB_TIME_CONTROL 0x03
118#define REVERB_FEEDBACK_CONTROL 0x04
119
120/* Chorus Processing Unit Control Selectors */
121#define CH_CONTROL_UNDEFINED 0x00
122#define CH_ENABLE_CONTROL 0x01
123#define CHORUS_LEVEL_CONTROL 0x02
124#define CHORUS_RATE_CONTROL 0x03
125#define CHORUS_DEPTH_CONTROL 0x04
126
127/* Dynamic Range Compressor Processing Unit Control Selectors */
128#define DR_CONTROL_UNDEFINED 0x00
129#define DR_ENABLE_CONTROL 0x01
130#define COMPRESSION_RATE_CONTROL 0x02
131#define MAXAMPL_CONTROL 0x03
132#define THRESHOLD_CONTROL 0x04
133#define ATTACK_TIME 0x05
134#define RELEASE_TIME 0x06
135
136/* Extension Unit Control Selectors*/
137#define XU_CONTROL_UNDEFINED 0x00
138#define XU_ENABLE_CONTROL 0x01
139
140/* Endpoint Control Selectors */
141#define EP_CONTROL_UNDEFINED 0x00
142#define SAMPLING_FREQ_CONTROL 0x01
143#define PITCH_CONTROL 0x02
144
145/* Format Type Codes of Format Type Descriptor bFormatType field */
146#define FORMAT_TYPE_UNDEFINED 0x00
147#define FORMAT_TYPE_I 0x01
148#define FORMAT_TYPE_II 0x02
149#define FORMAT_TYPE_III 0x03
150
151
152/*-----------------------------------------------------------------------------------
153 * UAC Class-specific interface descriptor
154 */
155#ifdef __ICCARM__
156typedef struct ac_if_header
157{
158 __packed uint8_t bLength;
159 __packed uint8_t bDescriptorType;
160 __packed uint8_t bDescriptorSubtype;
161 __packed uint16_t bcdADC;
162 __packed uint16_t wTotalLength;
165 __packed uint8_t bInCollection;
167} AC_IF_HDR_T;
168#else
169typedef struct __attribute__((__packed__)) ac_if_header
170{
171 uint8_t bLength;
172 uint8_t bDescriptorType;
173 uint8_t bDescriptorSubtype;
174 uint16_t bcdADC;
175 uint16_t wTotalLength;
178 uint8_t bInCollection;
180} AC_IF_HDR_T;
181#endif
182
183
184/*-----------------------------------------------------------------------------------
185 * UAC Input Terminal Descriptor
186 */
187#ifdef __ICCARM__
188typedef struct ac_itd_t
189{
190 __packed uint8_t bLength;
191 __packed uint8_t bDescriptorType;
192 __packed uint8_t bDescriptorSubtype;
193 __packed uint8_t bTerminalID;
194 __packed uint16_t wTerminalType;
195 __packed uint8_t bAssocTerminal;
196 __packed uint8_t bNrChannels;
197 __packed uint16_t wChannelConfig;
198 __packed uint8_t iChannelNames;
199 __packed uint8_t iTerminal;
200} AC_IT_T;
201#else
202typedef struct __attribute__((__packed__)) ac_itd_t
203{
204 uint8_t bLength;
205 uint8_t bDescriptorType;
206 uint8_t bDescriptorSubtype;
207 uint8_t bTerminalID;
208 uint16_t wTerminalType;
209 uint8_t bAssocTerminal;
210 uint8_t bNrChannels;
211 uint16_t wChannelConfig;
212 uint8_t iChannelNames;
213 uint8_t iTerminal;
214} AC_IT_T;
215#endif
216
217
218/*-----------------------------------------------------------------------------------
219 * UAC Output Terminal Descriptor
220 */
221#ifdef __ICCARM__
222typedef struct ac_otd_t
223{
224 __packed uint8_t bLength;
225 __packed uint8_t bDescriptorType;
226 __packed uint8_t bDescriptorSubtype;
227 __packed uint8_t bTerminalID;
228 __packed uint16_t wTerminalType;
229 __packed uint8_t bAssocTerminal;
230 __packed uint8_t bSourceID;
231 __packed uint8_t iTerminal;
232} AC_OT_T;
233#else
234typedef struct __attribute__((__packed__)) ac_otd_t
235{
236 uint8_t bLength;
237 uint8_t bDescriptorType;
238 uint8_t bDescriptorSubtype;
239 uint8_t bTerminalID;
240 uint16_t wTerminalType;
241 uint8_t bAssocTerminal;
242 uint8_t bSourceID;
243 uint8_t iTerminal;
244} AC_OT_T;
245#endif
246
247
248/*---------------------------------*/
249/* Terminal Types */
250/*---------------------------------*/
251// USB Terminal Types
252#define UAC_TT_USB_UNDEFINED 0x0100 /* USB Terminal, undefined Type. */
253#define UAC_TT_USB_STREAMING 0x0101 /* A Terminal dealing with a signal carried over an endpoint in an AudioStreaming interface. The AudioStreaming interface. */
254#define UAC_TT_USB_VENDOR 0x01FF /* A Terminal dealing with a signal carried over a vendor-specific interface. */
255// Input Terminal Types
256#define UAC_TT_INPUT_UNDEFINED 0x0200 /* Input Terminal, undefined Type. */
257#define UAC_TT_MICROPHONE 0x0201 /* A generic microphone that does not fit under any of the other classifications. */
258#define UAC_TT_DESKTOP_MICROPHONE 0x0202 /* A microphone normally placed on the desktop or integrated into the monitor. */
259#define UAC_TT_PERSONAL_MICROPHONE 0x0203 /* A head-mounted or clip-on microphone. */
260#define UAC_TT_OMNI_MICROPHONE 0x0204 /* A microphone designed to pick up voice from more than one speaker at relatively long ranges. */
261#define UAC_TT_MICROPHONE_ARRAY 0x0205 /* An array of microphones designed for directional processing using host-based signal processing algorithms. */
262// Output Terminal Types
263#define UAC_TT_OUTPUT_UNDEFINED 0x0300 /* Output Terminal, undefined Type. */
264#define UAC_TT_SPEAKER 0x0301 /* A generic speaker or set of speakers that does not fit under any of the other classifications. */
265#define UAC_TT_HEADPHONES 0x0302 /* A head-mounted audio output device. */
266#define UAC_TT_HEAD_MOUNTED 0x0303 /* The audio part of a VR head mounted display. The Associated Interfaces descriptor can be used to reference the HID interface used to report the position and orientation of the HMD. */
267#define UAC_TT_DESKTOP_SPEAKER 0x0304 /* Relatively small speaker or set of speakers normally placed on the desktop or integrated into the monitor. These speakers are close to the user and have limited stereo separation. */
268#define UAC_TT_ROOM_SPEAKER 0x0305 /* Larger speaker or set of speakers that are heard well anywhere in the room. */
269#define UAC_TT_COMM_SPEAKER 0x0306 /* Speaker or set of speakers designed for voice communication. */
270#define UAC_TT_LFE_SPEAKER 0x0307 /* Speaker designed for low frequencies (subwoofer). Not capable of reproducing speech or music. */
271
272
273/*-----------------------------------------------------------------------------------
274 * UAC Mixer Unit Descriptor
275 */
276#ifdef __ICCARM__
277typedef struct ac_mxr_t
278{
279 __packed uint8_t bLength;
280 __packed uint8_t bDescriptorType;
281 __packed uint8_t bDescriptorSubtype;
282 __packed uint8_t bUnitID; /* Constant uniquely identifying the Unit within the audio function. */
283 __packed uint8_t bNrInPins; /* Number of Input Pins of this Unit: p */
284} AC_MXR_T;
285#else
286typedef struct __attribute__((__packed__)) ac_mxr_t
287{
288 uint8_t bLength;
289 uint8_t bDescriptorType;
290 uint8_t bDescriptorSubtype;
291 uint8_t bUnitID; /* Constant uniquely identifying the Unit within the audio function. */
292 uint8_t bNrInPins; /* Number of Input Pins of this Unit: p */
293} AC_MXR_T;
294#endif
295
296
297/*-----------------------------------------------------------------------------------
298 * UAC Selector Unit Descriptor
299 */
300#ifdef __ICCARM__
301typedef struct ac_su_t
302{
303 __packed uint8_t bLength;
304 __packed uint8_t bDescriptorType;
305 __packed uint8_t bDescriptorSubtype;
306 __packed uint8_t bUnitID; /* Constant uniquely identifying the Unit within the audio function. */
307 __packed uint8_t bNrInPins; /* Number of Input Pins of this Unit: p */
308} AC_SU_T;
309#else
310typedef struct __attribute__((__packed__)) ac_su_t
311{
312 uint8_t bLength;
313 uint8_t bDescriptorType;
314 uint8_t bDescriptorSubtype;
315 uint8_t bUnitID; /* Constant uniquely identifying the Unit within the audio function. */
316 uint8_t bNrInPins; /* Number of Input Pins of this Unit: p */
317} AC_SU_T;
318#endif
319
320
321/*-----------------------------------------------------------------------------------
322 * UAC Feature Unit Descriptor
323 */
324#ifdef __ICCARM__
325typedef struct ac_fu_t
326{
327 __packed uint8_t bLength;
328 __packed uint8_t bDescriptorType;
329 __packed uint8_t bDescriptorSubtype;
330 __packed uint8_t bUnitID; /* Constant uniquely identifying the Unit within the audio function. */
331 __packed uint8_t bSourceID; /* ID of the Unit or Terminal to which this Feature Unit is connected. */
332 __packed uint8_t bControlSize; /* Size in bytes of an element of the bmaControls() array: n */
333} AC_FU_T;
334#else
335typedef struct __attribute__((__packed__))ac_fu_t
336{
337 uint8_t bLength;
338 uint8_t bDescriptorType;
339 uint8_t bDescriptorSubtype;
340 uint8_t bUnitID; /* Constant uniquely identifying the Unit within the audio function. */
341 uint8_t bSourceID; /* ID of the Unit or Terminal to which this Feature Unit is connected. */
342 uint8_t bControlSize; /* Size in bytes of an element of the bmaControls() array: n */
343} AC_FU_T;
344#endif
345
346
347/* Feature Unit Control Selectors */
348#define FU_CONTROL_UNDEFINED 0x00
349#define MUTE_CONTROL 0x01 /* Feature Unit Descriptor bmaControls bit 0 */
350#define VOLUME_CONTROL 0x02 /* Feature Unit Descriptor bmaControls bit 1 */
351#define BASS_CONTROL 0x03 /* Feature Unit Descriptor bmaControls bit 2 */
352#define MID_CONTROL 0x04
353#define TREBLE_CONTROL 0x05
354#define GRAPHIC_EQUALIZER_CONTROL 0x06
355#define AUTOMATIC_GAIN_CONTROL 0x07
356#define DELAY_CONTROL 0x08
357#define BASS_BOOST_CONTROL 0x09
358#define LOUDNESS_CONTROL 0x0A
359
360/*-----------------------------------------------------------------------------------
361 * UAC AS Isochronous Audio Data Endpoint Descriptor
362 */
363#ifdef __ICCARM__
364typedef struct as_gen_t
365{
366 __packed uint8_t bLength;
367 __packed uint8_t bDescriptorType;
368 __packed uint8_t bDescriptorSubtype;
369 __packed uint8_t bTerminalLink;
370 __packed uint8_t bDelay;
371 __packed uint16_t wFormatTag;
372} AS_GEN_T;
373#else
374typedef struct __attribute__((__packed__)) as_gen_t
375{
376 uint8_t bLength;
377 uint8_t bDescriptorType;
378 uint8_t bDescriptorSubtype;
379 uint8_t bTerminalLink;
380 uint8_t bDelay;
381 uint16_t wFormatTag;
382} AS_GEN_T;
383#endif
384
385
386/*-----------------------------------------------------------------------------------
387 * UAC Processing Unit Descriptor
388 */
389#ifdef __ICCARM__
390typedef struct ac_pu_t
391{
392 __packed uint8_t bLength;
393 __packed uint8_t bDescriptorType;
394 __packed uint8_t bDescriptorSubtype;
395 __packed uint8_t bUnitID; /* Constant uniquely identifying the Unit within the audio function. */
396 __packed uint16_t wProcessType; /* Constant identifying the type of processing this Unit is performing. */
397 __packed uint8_t bNrInPins; /* Number of Input Pins of this Unit: p */
398} AC_PU_T;
399#else
400typedef struct __attribute__((__packed__)) ac_pu_t
401{
402 uint8_t bLength;
403 uint8_t bDescriptorType;
404 uint8_t bDescriptorSubtype;
405 uint8_t bUnitID; /* Constant uniquely identifying the Unit within the audio function. */
406 uint16_t wProcessType; /* Constant identifying the type of processing this Unit is performing. */
407 uint8_t bNrInPins; /* Number of Input Pins of this Unit: p */
408} AC_PU_T;
409#endif
410
411
412/*-----------------------------------------------------------------------------------
413 * UAC Class-Specific AS Isochronous Audio Data Endpoint Descriptor
414 */
415#ifdef __ICCARM__
416typedef struct as_ep_t
417{
418 __packed uint8_t bLength;
419 __packed uint8_t bDescriptorType;
420 __packed uint8_t bDescriptorSubtype;
421 __packed uint8_t bmAttributes;
422 __packed uint8_t bLockDelayUnits;
423 __packed uint16_t wLockDelay;
424} AS_EP_T;
425#else
426typedef struct __attribute__((__packed__)) as_ep_t
427{
428 uint8_t bLength;
429 uint8_t bDescriptorType;
430 uint8_t bDescriptorSubtype;
431 uint8_t bmAttributes;
432 uint8_t bLockDelayUnits;
433 uint16_t wLockDelay;
434} AS_EP_T;
435#endif
436
437
438/*-----------------------------------------------------------------------------------
439 * UAC Type I Format Type Descriptor
440 */
441#ifdef __ICCARM__
442typedef struct ac_ft1_t
443{
444 __packed uint8_t bLength;
445 __packed uint8_t bDescriptorType;
446 __packed uint8_t bDescriptorSubtype;
447 __packed uint8_t bFormatType;
448 __packed uint8_t bNrChannels;
449 __packed uint8_t bSubframeSize;
450 __packed uint8_t bBitResolution;
451 __packed uint8_t bSamFreqType;
452 __packed uint8_t tSamFreq[16][3];
453} AC_FT1_T;
454#else
455typedef struct __attribute__((__packed__)) ac_ft1_t
456{
457 uint8_t bLength;
458 uint8_t bDescriptorType;
459 uint8_t bDescriptorSubtype;
460 uint8_t bFormatType;
461 uint8_t bNrChannels;
462 uint8_t bSubframeSize;
463 uint8_t bBitResolution;
464 uint8_t bSamFreqType;
465 uint8_t tSamFreq[16][3];
466} AC_FT1_T;
467#endif
468
469
470/*-----------------------------------------------------------------------------------
471 * UAC Type 2 Format Type Descriptor
472 */
473#ifdef __ICCARM__
474typedef struct ac_ft2_t
475{
476 __packed uint8_t bLength;
477 __packed uint8_t bDescriptorType;
478 __packed uint8_t bDescriptorSubtype;
479 __packed uint8_t bFormatType;
480 __packed uint16_t wMaxBitRate;
481 __packed uint16_t wSamplesPerFrame;
482 __packed uint8_t bSamFreqType;
483} AC_FT2_T;
484#else
485typedef struct __attribute__((__packed__)) ac_ft2_t
486{
487 uint8_t bLength;
488 uint8_t bDescriptorType;
489 uint8_t bDescriptorSubtype;
490 uint8_t bFormatType;
491 uint16_t wMaxBitRate;
492 uint16_t wSamplesPerFrame;
493 uint8_t bSamFreqType;
494} AC_FT2_T;
495#endif
496
497
498/*-----------------------------------------------------------------------------------
499 * UAC Type 3 Format Type Descriptor
500 */
501#ifdef __ICCARM__
502typedef struct ac_ft3_t
503{
504 __packed uint8_t bLength;
505 __packed uint8_t bDescriptorType;
506 __packed uint8_t bDescriptorSubtype;
507 __packed uint8_t bFormatType;
508 __packed uint8_t bNrChannels;
509 __packed uint8_t bSubframeSize;
510 __packed uint8_t bBitResolution;
511 __packed uint8_t bSamFreqType;
512 __packed uint8_t tLowerSamFreq[3];
513 __packed uint8_t tUpperSamFreq[3];
514} AC_FT3_T;
515#else
516typedef struct __attribute__((__packed__)) ac_ft3_t
517{
518 uint8_t bLength;
519 uint8_t bDescriptorType;
520 uint8_t bDescriptorSubtype;
521 uint8_t bFormatType;
522 uint8_t bNrChannels;
523 uint8_t bSubframeSize;
524 uint8_t bBitResolution;
525 uint8_t bSamFreqType;
526 uint8_t tLowerSamFreq[3];
527 uint8_t tUpperSamFreq[3];
528} AC_FT3_T;
529#endif
530
531
532typedef struct uac_info_t
533{
534 uint8_t cfg_desc[MAX_CFG_DESC_SIZE];
535
536 USB_IF_DESC_T *last_ifd;
537 AS_GEN_T *last_gen;
538 AC_FT1_T *last_ft;
539
540 USB_IF_DESC_T *ifd_play;
541 USB_EP_DESC_T *epd_play;
542 AS_GEN_T *gen_play;
543 AC_FT1_T *ft_play;
544 AC_OT_T *ot_speaker; /* refer to SPEAKER OUTPUT TERMINAL */
545 AC_IT_T *it_usbs; /* refer to USB streaming INPUT TERMINAL */
546 AC_FU_T *fu_play; /* FEATURE UNIT for Speaker */
547
548 USB_IF_DESC_T *ifd_rec;
549 USB_EP_DESC_T *epd_rec;
550 AS_GEN_T *gen_rec;
551 AC_FT1_T *ft_rec;
552 AC_IT_T *it_microphone; /* refer to MICROPHONE INPUT TERMINAL */
553 AC_OT_T *ot_usbs; /* refer to USB streaming OUTPUT TERMINAL */
554 AC_FU_T *fu_rec; /* FEATURE UNIT for Microphone */
555
556} UAC_INFO_T;
557
558
559int uac_config_parser(UAC_DEV_T *audev);
560int uac_check_fu_ctrl(UAC_INFO_T *uac_info, uint8_t target, int channel, int control);
561
562
564
565
566#endif /* __INCLUDED_UAC_H__ */
567
568/*** (C) COPYRIGHT 2014 Nuvoton Technology Corp. ***/
__attribute__
void *__dso_handle __attribute__((weak))
Definition: _syscalls.c:35
MAX_CFG_DESC_SIZE
#define MAX_CFG_DESC_SIZE
Definition: usbh_uac.h:20
USB_IF_DESC_T
USB_IF_DESC_T
Definition: usbh_core.h:335
USB_EP_DESC_T
USB_EP_DESC_T
Definition: usbh_core.h:300
uac_dev_t
Definition: usbh_uac.h:100
usbh_core.h
USB Host core driver header file.