M4521_BSP V3.02.000
The Board Support Package for M4521
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 * UAC Input Terminal Descriptor
185 */
186#ifdef __ICCARM__
187typedef struct ac_itd_t
188{
189 __packed uint8_t bLength;
190 __packed uint8_t bDescriptorType;
191 __packed uint8_t bDescriptorSubtype;
192 __packed uint8_t bTerminalID;
193 __packed uint16_t wTerminalType;
194 __packed uint8_t bAssocTerminal;
195 __packed uint8_t bNrChannels;
196 __packed uint16_t wChannelConfig;
197 __packed uint8_t iChannelNames;
198 __packed uint8_t iTerminal;
199} AC_IT_T;
200#else
201typedef struct __attribute__((__packed__)) ac_itd_t
202{
203 uint8_t bLength;
204 uint8_t bDescriptorType;
205 uint8_t bDescriptorSubtype;
206 uint8_t bTerminalID;
207 uint16_t wTerminalType;
208 uint8_t bAssocTerminal;
209 uint8_t bNrChannels;
210 uint16_t wChannelConfig;
211 uint8_t iChannelNames;
212 uint8_t iTerminal;
213} AC_IT_T;
214#endif
215
216/*-----------------------------------------------------------------------------------
217 * UAC Output Terminal Descriptor
218 */
219#ifdef __ICCARM__
220typedef struct ac_otd_t
221{
222 __packed uint8_t bLength;
223 __packed uint8_t bDescriptorType;
224 __packed uint8_t bDescriptorSubtype;
225 __packed uint8_t bTerminalID;
226 __packed uint16_t wTerminalType;
227 __packed uint8_t bAssocTerminal;
228 __packed uint8_t bSourceID;
229 __packed uint8_t iTerminal;
230} AC_OT_T;
231#else
232typedef struct __attribute__((__packed__)) ac_otd_t
233{
234 uint8_t bLength;
235 uint8_t bDescriptorType;
236 uint8_t bDescriptorSubtype;
237 uint8_t bTerminalID;
238 uint16_t wTerminalType;
239 uint8_t bAssocTerminal;
240 uint8_t bSourceID;
241 uint8_t iTerminal;
242} AC_OT_T;
243#endif
244
245/*---------------------------------*/
246/* Terminal Types */
247/*---------------------------------*/
248// USB Terminal Types
249#define UAC_TT_USB_UNDEFINED 0x0100 /* USB Terminal, undefined Type. */
250#define UAC_TT_USB_STREAMING 0x0101 /* A Terminal dealing with a signal carried over an endpoint in an AudioStreaming interface. The AudioStreaming interface. */
251#define UAC_TT_USB_VENDOR 0x01FF /* A Terminal dealing with a signal carried over a vendor-specific interface. */
252// Input Terminal Types
253#define UAC_TT_INPUT_UNDEFINED 0x0200 /* Input Terminal, undefined Type. */
254#define UAC_TT_MICROPHONE 0x0201 /* A generic microphone that does not fit under any of the other classifications. */
255#define UAC_TT_DESKTOP_MICROPHONE 0x0202 /* A microphone normally placed on the desktop or integrated into the monitor. */
256#define UAC_TT_PERSONAL_MICROPHONE 0x0203 /* A head-mounted or clip-on microphone. */
257#define UAC_TT_OMNI_MICROPHONE 0x0204 /* A microphone designed to pick up voice from more than one speaker at relatively long ranges. */
258#define UAC_TT_MICROPHONE_ARRAY 0x0205 /* An array of microphones designed for directional processing using host-based signal processing algorithms. */
259// Output Terminal Types
260#define UAC_TT_OUTPUT_UNDEFINED 0x0300 /* Output Terminal, undefined Type. */
261#define UAC_TT_SPEAKER 0x0301 /* A generic speaker or set of speakers that does not fit under any of the other classifications. */
262#define UAC_TT_HEADPHONES 0x0302 /* A head-mounted audio output device. */
263#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. */
264#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. */
265#define UAC_TT_ROOM_SPEAKER 0x0305 /* Larger speaker or set of speakers that are heard well anywhere in the room. */
266#define UAC_TT_COMM_SPEAKER 0x0306 /* Speaker or set of speakers designed for voice communication. */
267#define UAC_TT_LFE_SPEAKER 0x0307 /* Speaker designed for low frequencies (subwoofer). Not capable of reproducing speech or music. */
268
269
270/*-----------------------------------------------------------------------------------
271 * UAC Mixer Unit Descriptor
272 */
273#ifdef __ICCARM__
274typedef struct ac_mxr_t
275{
276 __packed uint8_t bLength;
277 __packed uint8_t bDescriptorType;
278 __packed uint8_t bDescriptorSubtype;
279 __packed uint8_t bUnitID; /* Constant uniquely identifying the Unit within the audio function. */
280 __packed uint8_t bNrInPins; /* Number of Input Pins of this Unit: p */
281} AC_MXR_T;
282#else
283typedef struct __attribute__((__packed__)) ac_mxr_t
284{
285 uint8_t bLength;
286 uint8_t bDescriptorType;
287 uint8_t bDescriptorSubtype;
288 uint8_t bUnitID; /* Constant uniquely identifying the Unit within the audio function. */
289 uint8_t bNrInPins; /* Number of Input Pins of this Unit: p */
290} AC_MXR_T;
291#endif
292
293/*-----------------------------------------------------------------------------------
294 * UAC Selector Unit Descriptor
295 */
296#ifdef __ICCARM__
297typedef struct ac_su_t
298{
299 __packed uint8_t bLength;
300 __packed uint8_t bDescriptorType;
301 __packed uint8_t bDescriptorSubtype;
302 __packed uint8_t bUnitID; /* Constant uniquely identifying the Unit within the audio function. */
303 __packed uint8_t bNrInPins; /* Number of Input Pins of this Unit: p */
304} AC_SU_T;
305#else
306typedef struct __attribute__((__packed__)) ac_su_t
307{
308 uint8_t bLength;
309 uint8_t bDescriptorType;
310 uint8_t bDescriptorSubtype;
311 uint8_t bUnitID; /* Constant uniquely identifying the Unit within the audio function. */
312 uint8_t bNrInPins; /* Number of Input Pins of this Unit: p */
313} AC_SU_T;
314#endif
315
316/*-----------------------------------------------------------------------------------
317 * UAC Feature Unit Descriptor
318 */
319#ifdef __ICCARM__
320typedef struct ac_fu_t
321{
322 __packed uint8_t bLength;
323 __packed uint8_t bDescriptorType;
324 __packed uint8_t bDescriptorSubtype;
325 __packed uint8_t bUnitID; /* Constant uniquely identifying the Unit within the audio function. */
326 __packed uint8_t bSourceID; /* ID of the Unit or Terminal to which this Feature Unit is connected. */
327 __packed uint8_t bControlSize; /* Size in bytes of an element of the bmaControls() array: n */
328} AC_FU_T;
329#else
330typedef struct __attribute__((__packed__)) ac_fu_t
331{
332 uint8_t bLength;
333 uint8_t bDescriptorType;
334 uint8_t bDescriptorSubtype;
335 uint8_t bUnitID; /* Constant uniquely identifying the Unit within the audio function. */
336 uint8_t bSourceID; /* ID of the Unit or Terminal to which this Feature Unit is connected. */
337 uint8_t bControlSize; /* Size in bytes of an element of the bmaControls() array: n */
338} AC_FU_T;
339#endif
340
341/* Feature Unit Control Selectors */
342#define FU_CONTROL_UNDEFINED 0x00
343#define MUTE_CONTROL 0x01 /* Feature Unit Descriptor bmaControls bit 0 */
344#define VOLUME_CONTROL 0x02 /* Feature Unit Descriptor bmaControls bit 1 */
345#define BASS_CONTROL 0x03 /* Feature Unit Descriptor bmaControls bit 2 */
346#define MID_CONTROL 0x04
347#define TREBLE_CONTROL 0x05
348#define GRAPHIC_EQUALIZER_CONTROL 0x06
349#define AUTOMATIC_GAIN_CONTROL 0x07
350#define DELAY_CONTROL 0x08
351#define BASS_BOOST_CONTROL 0x09
352#define LOUDNESS_CONTROL 0x0A
353
354/*-----------------------------------------------------------------------------------
355 * UAC AS Isochronous Audio Data Endpoint Descriptor
356 */
357#ifdef __ICCARM__
358typedef struct as_gen_t
359{
360 __packed uint8_t bLength;
361 __packed uint8_t bDescriptorType;
362 __packed uint8_t bDescriptorSubtype;
363 __packed uint8_t bTerminalLink;
364 __packed uint8_t bDelay;
365 __packed uint16_t wFormatTag;
366} AS_GEN_T;
367#else
368typedef struct __attribute__((__packed__)) as_gen_t
369{
370 uint8_t bLength;
371 uint8_t bDescriptorType;
372 uint8_t bDescriptorSubtype;
373 uint8_t bTerminalLink;
374 uint8_t bDelay;
375 uint16_t wFormatTag;
376} AS_GEN_T;
377#endif
378
379/*-----------------------------------------------------------------------------------
380 * UAC Processing Unit Descriptor
381 */
382#ifdef __ICCARM__
383typedef struct ac_pu_t
384{
385 __packed uint8_t bLength;
386 __packed uint8_t bDescriptorType;
387 __packed uint8_t bDescriptorSubtype;
388 __packed uint8_t bUnitID; /* Constant uniquely identifying the Unit within the audio function. */
389 __packed uint16_t wProcessType; /* Constant identifying the type of processing this Unit is performing. */
390 __packed uint8_t bNrInPins; /* Number of Input Pins of this Unit: p */
391} AC_PU_T;
392#else
393typedef struct __attribute__((__packed__)) ac_pu_t
394{
395 uint8_t bLength;
396 uint8_t bDescriptorType;
397 uint8_t bDescriptorSubtype;
398 uint8_t bUnitID; /* Constant uniquely identifying the Unit within the audio function. */
399 uint16_t wProcessType; /* Constant identifying the type of processing this Unit is performing. */
400 uint8_t bNrInPins; /* Number of Input Pins of this Unit: p */
401} AC_PU_T;
402#endif
403
404/*-----------------------------------------------------------------------------------
405 * UAC Class-Specific AS Isochronous Audio Data Endpoint Descriptor
406 */
407#ifdef __ICCARM__
408typedef struct as_ep_t
409{
410 __packed uint8_t bLength;
411 __packed uint8_t bDescriptorType;
412 __packed uint8_t bDescriptorSubtype;
413 __packed uint8_t bmAttributes;
414 __packed uint8_t bLockDelayUnits;
415 __packed uint16_t wLockDelay;
416} AS_EP_T;
417#else
418typedef struct __attribute__((__packed__)) as_ep_t
419{
420 uint8_t bLength;
421 uint8_t bDescriptorType;
422 uint8_t bDescriptorSubtype;
423 uint8_t bmAttributes;
424 uint8_t bLockDelayUnits;
425 uint16_t wLockDelay;
426} AS_EP_T;
427#endif
428
429/*-----------------------------------------------------------------------------------
430 * UAC Type I Format Type Descriptor
431 */
432#ifdef __ICCARM__
433typedef struct ac_ft1_t
434{
435 __packed uint8_t bLength;
436 __packed uint8_t bDescriptorType;
437 __packed uint8_t bDescriptorSubtype;
438 __packed uint8_t bFormatType;
439 __packed uint8_t bNrChannels;
440 __packed uint8_t bSubframeSize;
441 __packed uint8_t bBitResolution;
442 __packed uint8_t bSamFreqType;
443 __packed uint8_t tSamFreq[16][3];
444} AC_FT1_T;
445#else
446typedef struct __attribute__((__packed__)) ac_ft1_t
447{
448 uint8_t bLength;
449 uint8_t bDescriptorType;
450 uint8_t bDescriptorSubtype;
451 uint8_t bFormatType;
452 uint8_t bNrChannels;
453 uint8_t bSubframeSize;
454 uint8_t bBitResolution;
455 uint8_t bSamFreqType;
456 uint8_t tSamFreq[16][3];
457} AC_FT1_T;
458#endif
459
460/*-----------------------------------------------------------------------------------
461 * UAC Type 2 Format Type Descriptor
462 */
463#ifdef __ICCARM__
464typedef struct ac_ft2_t
465{
466 __packed uint8_t bLength;
467 __packed uint8_t bDescriptorType;
468 __packed uint8_t bDescriptorSubtype;
469 __packed uint8_t bFormatType;
470 __packed uint16_t wMaxBitRate;
471 __packed uint16_t wSamplesPerFrame;
472 __packed uint8_t bSamFreqType;
473} AC_FT2_T;
474#else
475typedef struct __attribute__((__packed__)) ac_ft2_t
476{
477 uint8_t bLength;
478 uint8_t bDescriptorType;
479 uint8_t bDescriptorSubtype;
480 uint8_t bFormatType;
481 uint16_t wMaxBitRate;
482 uint16_t wSamplesPerFrame;
483 uint8_t bSamFreqType;
484} AC_FT2_T;
485#endif
486
487/*-----------------------------------------------------------------------------------
488 * UAC Type 3 Format Type Descriptor
489 */
490#ifdef __ICCARM__
491typedef struct ac_ft3_t
492{
493 __packed uint8_t bLength;
494 __packed uint8_t bDescriptorType;
495 __packed uint8_t bDescriptorSubtype;
496 __packed uint8_t bFormatType;
497 __packed uint8_t bNrChannels;
498 __packed uint8_t bSubframeSize;
499 __packed uint8_t bBitResolution;
500 __packed uint8_t bSamFreqType;
501 __packed uint8_t tLowerSamFreq[3];
502 __packed uint8_t tUpperSamFreq[3];
503} AC_FT3_T;
504#else
505typedef struct __attribute__((__packed__)) ac_ft3_t
506{
507 uint8_t bLength;
508 uint8_t bDescriptorType;
509 uint8_t bDescriptorSubtype;
510 uint8_t bFormatType;
511 uint8_t bNrChannels;
512 uint8_t bSubframeSize;
513 uint8_t bBitResolution;
514 uint8_t bSamFreqType;
515 uint8_t tLowerSamFreq[3];
516 uint8_t tUpperSamFreq[3];
517} AC_FT3_T;
518#endif
519
520typedef struct uac_info_t
521{
522 uint8_t cfg_desc[MAX_CFG_DESC_SIZE];
523
524 USB_IF_DESC_T *last_ifd;
525 AS_GEN_T *last_gen;
526 AC_FT1_T *last_ft;
527
528 USB_IF_DESC_T *ifd_play;
529 USB_EP_DESC_T *epd_play;
530 AS_GEN_T *gen_play;
531 AC_FT1_T *ft_play;
532 AC_OT_T *ot_speaker; /* refer to SPEAKER OUTPUT TERMINAL */
533 AC_IT_T *it_usbs; /* refer to USB streaming INPUT TERMINAL */
534 AC_FU_T *fu_play; /* FEATURE UNIT for Speaker */
535
536 USB_IF_DESC_T *ifd_rec;
537 USB_EP_DESC_T *epd_rec;
538 AS_GEN_T *gen_rec;
539 AC_FT1_T *ft_rec;
540 AC_IT_T *it_microphone; /* refer to MICROPHONE INPUT TERMINAL */
541 AC_OT_T *ot_usbs; /* refer to USB streaming OUTPUT TERMINAL */
542 AC_FU_T *fu_rec; /* FEATURE UNIT for Microphone */
543
544} UAC_INFO_T;
545
546
547int uac_config_parser(UAC_DEV_T *audev);
548int uac_check_fu_ctrl(UAC_INFO_T *uac_info, uint8_t target, int channel, int control);
549
550
552
553
554#endif /* __INCLUDED_UAC_H__ */
555
556
557
void *__dso_handle __attribute__((weak))
Definition: _syscalls.c:35
#define MAX_CFG_DESC_SIZE
Definition: usbh_uac.h:25
USB Host core driver header file.
USB_IF_DESC_T
Definition: usbh_core.h:315
USB_EP_DESC_T
Definition: usbh_core.h:282