1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 
13 /**************************************************************************/
14 /**************************************************************************/
15 /**                                                                       */
16 /** USBX Component                                                        */
17 /**                                                                       */
18 /**   Audio Class                                                         */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 
24 /**************************************************************************/
25 /*                                                                        */
26 /*  COMPONENT DEFINITION                                   RELEASE        */
27 /*                                                                        */
28 /*    ux_host_class_audio.h                               PORTABLE C      */
29 /*                                                           6.1.12       */
30 /*  AUTHOR                                                                */
31 /*                                                                        */
32 /*    Chaoqiong Xiao, Microsoft Corporation                               */
33 /*                                                                        */
34 /*  DESCRIPTION                                                           */
35 /*                                                                        */
36 /*    This file contains all the header and extern functions used by the  */
37 /*    USBX audio class.                                                   */
38 /*                                                                        */
39 /*  RELEASE HISTORY                                                       */
40 /*                                                                        */
41 /*    DATE              NAME                      DESCRIPTION             */
42 /*                                                                        */
43 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
44 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
45 /*                                            used UX prefix to refer to  */
46 /*                                            TX symbols instead of using */
47 /*                                            them directly,              */
48 /*                                            resulting in version 6.1    */
49 /*  08-02-2021     Wen Wang                 Modified comment(s),          */
50 /*                                            added extern "C" keyword    */
51 /*                                            for compatibility with C++, */
52 /*                                            resulting in version 6.1.8  */
53 /*  07-29-2022     Chaoqiong Xiao           Modified comment(s),          */
54 /*                                            added interrupt support,    */
55 /*                                            used interface protocol,    */
56 /*                                            protect reentry with mutex, */
57 /*                                            added feedback support,     */
58 /*                                            added Audio 2.0 support,    */
59 /*                                            resulting in version 6.1.12 */
60 /*                                                                        */
61 /**************************************************************************/
62 
63 #ifndef UX_HOST_CLASS_AUDIO_H
64 #define UX_HOST_CLASS_AUDIO_H
65 
66 /* Determine if a C++ compiler is being used.  If so, ensure that standard
67    C is used to process the API information.  */
68 
69 #ifdef   __cplusplus
70 
71 /* Yes, C++ compiler is present.  Use standard C.  */
72 extern   "C" {
73 
74 #endif
75 
76 /* Defined, it enables UAC 2.0 support.  */
77 /* #define UX_HOST_CLASS_AUDIO_2_SUPPORT  */
78 
79 /* Defined, it enables feedback endpoint support.  */
80 /* #define UX_HOST_CLASS_AUDIO_FEEDBACK_SUPPORT  */
81 
82 /* Defined, it enables optional interrupt endpoint support.  */
83 /* #define UX_HOST_CLASS_AUDIO_INTERRUPT_SUPPORT  */
84 
85 /* Defined, it disables control_get/value_get/value_set and related code (to optimize code size).  */
86 /* #define UX_HOST_CLASS_AUDIO_DISABLE_CONTROLS  */
87 
88 #include "ux_class_audio10.h"
89 #if defined(UX_HOST_CLASS_AUDIO_2_SUPPORT)
90 #include "ux_class_audio20.h"
91 #endif
92 
93 /* Define Audio Class main constants.  */
94 
95 #define UX_HOST_CLASS_AUDIO_CLASS_TRANSFER_TIMEOUT          30
96 
97 #define UX_HOST_CLASS_AUDIO_CLASS                           1
98 #define UX_HOST_CLASS_AUDIO_SUBCLASS_UNDEFINED              0
99 #define UX_HOST_CLASS_AUDIO_SUBCLASS_CONTROL                1
100 #define UX_HOST_CLASS_AUDIO_SUBCLASS_STREAMING              2
101 #define UX_HOST_CLASS_AUDIO_SUBCLASS_MIDI_STREAMING         3
102 #define UX_HOST_CLASS_AUDIO_PROTOCOL_UNDEFINED              0
103 #define UX_HOST_CLASS_AUDIO_PROTOCOL_IP_VERSION_01_00       0x00
104 #define UX_HOST_CLASS_AUDIO_PROTOCOL_IP_VERSION_02_00       0x20
105 #define UX_HOST_CLASS_AUDIO_PROTOCOL_IP_VERSION_03_00       0x30
106 #define UX_HOST_CLASS_AUDIO_PROTOCOL_AF_VERSION_01_00       UX_HOST_CLASS_AUDIO_PROTOCOL_IP_VERSION_01_00
107 #define UX_HOST_CLASS_AUDIO_PROTOCOL_AF_VERSION_02_00       UX_HOST_CLASS_AUDIO_PROTOCOL_IP_VERSION_02_00
108 #define UX_HOST_CLASS_AUDIO_PROTOCOL_AF_VERSION_03_00       UX_HOST_CLASS_AUDIO_PROTOCOL_IP_VERSION_03_00
109 
110 #define UX_HOST_CLASS_AUDIO_FUNCTION                            UX_HOST_CLASS_AUDIO_CLASS
111 #define UX_HOST_CLASS_AUDIO_FUNCTION_SUBCLASS_UNDEFINED         0x00
112 #define UX_HOST_CLASS_AUDIO_FUNCTION_SUBCLASS_FULL_ADC_3_0      0x01
113 #define UX_HOST_CLASS_AUDIO_FUNCTION_SUBCLASS_GENERIC_I_O       0x20
114 #define UX_HOST_CLASS_AUDIO_FUNCTION_SUBCLASS_HEADPHONE         0x21
115 #define UX_HOST_CLASS_AUDIO_FUNCTION_SUBCLASS_SPEAKER           0x22
116 #define UX_HOST_CLASS_AUDIO_FUNCTION_SUBCLASS_MICROPHONE        0x23
117 #define UX_HOST_CLASS_AUDIO_FUNCTION_SUBCLASS_HEADSET           0x24
118 #define UX_HOST_CLASS_AUDIO_FUNCTION_SUBCLASS_HEADSET_ADAPTER   0x25
119 #define UX_HOST_CLASS_AUDIO_FUNCTION_SUBCLASS_SPEAKERPHONE      0x26
120 
121 /* Define Audio Class main descriptor types.  */
122 
123 #define UX_HOST_CLASS_AUDIO_CS_UNDEFINED                    0x20
124 #define UX_HOST_CLASS_AUDIO_CS_DEVICE                       0x21
125 #define UX_HOST_CLASS_AUDIO_CS_CONFIGURATION                0x22
126 #define UX_HOST_CLASS_AUDIO_CS_STRING                       0x23
127 #define UX_HOST_CLASS_AUDIO_CS_INTERFACE                    0x24
128 #define UX_HOST_CLASS_AUDIO_CS_ENDPOINT                     0x25
129 
130 
131 /* Define Audio Class specific AC interface descriptor subclasses.  */
132 
133 #define UX_HOST_CLASS_AUDIO_CS_AC_UNDEFINED                 0x00
134 #define UX_HOST_CLASS_AUDIO_CS_HEADER                       0x01
135 #define UX_HOST_CLASS_AUDIO_CS_INPUT_TERMINAL               0x02
136 #define UX_HOST_CLASS_AUDIO_CS_OUTPUT_TERMINAL              0x03
137 #define UX_HOST_CLASS_AUDIO_CS_MIXER_UNIT                   0x04
138 #define UX_HOST_CLASS_AUDIO_CS_SELECTOR_UNIT                0x05
139 #define UX_HOST_CLASS_AUDIO_CS_FEATURE_UNIT                 0x06
140 #define UX_HOST_CLASS_AUDIO_CS_PROCESSING_UNIT              0x07
141 #define UX_HOST_CLASS_AUDIO_CS_EXTENSION_UNIT               0x08
142 
143 
144 /* Define Audio Class specific AS interface descriptor subclasses.  */
145 
146 #define UX_HOST_CLASS_AUDIO_CS_AS_UNDEFINED                 0x00
147 #define UX_HOST_CLASS_AUDIO_CS_AS_GENERAL                   0x01
148 #define UX_HOST_CLASS_AUDIO_CS_FORMAT_TYPE                  0x02
149 #define UX_HOST_CLASS_AUDIO_CS_FORMAT_SPECIFIC              0x03
150 
151 
152 /* Define Audio Class specific processing unit process types.  */
153 
154 #define UX_HOST_CLASS_AUDIO_PROCESS_UNDEFINED               0x00
155 #define UX_HOST_CLASS_AUDIO_UP_DOWN_MIX_PROCESS             0x01
156 #define UX_HOST_CLASS_AUDIO_DOLBY_PROLOGIC_PROCESS          0x02
157 #define UX_HOST_CLASS_AUDIO_3D_STEREO_EXTENDED_PROCESS      0x03
158 #define UX_HOST_CLASS_AUDIO_REVERBERATION_PROCESS           0x04
159 #define UX_HOST_CLASS_AUDIO_CHORUS_PROCESS                  0x05
160 #define UX_HOST_CLASS_AUDIO_DYN_RANGE_COMP_PROCESS          0x06
161 
162 
163 /* Define Audio Class specific endpoint descriptor subtypes.  */
164 
165 #define UX_HOST_CLASS_AUDIO_DESCRIPTOR_UNDEFINED            0x00
166 #define UX_HOST_CLASS_AUDIO_EP_GENERAL                      0x01
167 
168 
169 /* Define Audio Class specific request codes.  */
170 
171 #define UX_HOST_CLASS_AUDIO_REQUEST_CODE_UNDEFINED          0x00
172 #define UX_HOST_CLASS_AUDIO_SET_CUR                         0x01
173 #define UX_HOST_CLASS_AUDIO_GET_CUR                         0x81
174 #define UX_HOST_CLASS_AUDIO_SET_MIN                         0x02
175 #define UX_HOST_CLASS_AUDIO_GET_MIN                         0x82
176 #define UX_HOST_CLASS_AUDIO_SET_MAX                         0x03
177 #define UX_HOST_CLASS_AUDIO_GET_MAX                         0x83
178 #define UX_HOST_CLASS_AUDIO_SET_RES                         0x04
179 #define UX_HOST_CLASS_AUDIO_GET_RES                         0x84
180 #define UX_HOST_CLASS_AUDIO_SET_MEM                         0x05
181 #define UX_HOST_CLASS_AUDIO_GET_MEM                         0x85
182 #define UX_HOST_CLASS_AUDIO_GET_STAT                        0xFF
183 
184 
185 /* Define Audio Class specific terminal control selectors.  */
186 
187 #define UX_HOST_CLASS_AUDIO_TE_CONTROL_UNDEFINED            0x00
188 #define UX_HOST_CLASS_AUDIO_COPY_PROTECT_CONTROL            0x01
189 
190 
191 /* Define Audio Class specific feature unit control selectors.  */
192 
193 #define UX_HOST_CLASS_AUDIO_FU_CONTROL_UNDEFINED            0x00
194 #define UX_HOST_CLASS_AUDIO_MUTE_CONTROL                    0x01
195 #define UX_HOST_CLASS_AUDIO_VOLUME_CONTROL                  0x02
196 #define UX_HOST_CLASS_AUDIO_BASS_CONTROL                    0x03
197 #define UX_HOST_CLASS_AUDIO_MID_CONTROL                     0x04
198 #define UX_HOST_CLASS_AUDIO_TREBLE_CONTROL                  0x05
199 #define UX_HOST_CLASS_AUDIO_GRAPHIC_EQUALIZER_CONTROL       0x06
200 #define UX_HOST_CLASS_AUDIO_AUTOMATIC_GAIN_CONTROL          0x07
201 #define UX_HOST_CLASS_AUDIO_DELAY_CONTROL                   0x08
202 #define UX_HOST_CLASS_AUDIO_BASS_BOOST_CONTROL              0x09
203 #define UX_HOST_CLASS_AUDIO_LOUNDNESS_CONTROL               0x0A
204 
205 
206 /* Define Audio Class input terminal types.  */
207 
208 #define UX_HOST_CLASS_AUDIO_INPUT                           0x0200
209 #define UX_HOST_CLASS_AUDIO_MICROPHONE                      0x0201
210 #define UX_HOST_CLASS_AUDIO_DESKTOP_MICROPHONE              0x0202
211 #define UX_HOST_CLASS_AUDIO_PERSONAL_MICROPHONE             0x0203
212 #define UX_HOST_CLASS_AUDIO_OMNI_DIRECTIONAL_MICROPHONE     0x0204
213 #define UX_HOST_CLASS_AUDIO_MICROPHONE_ARRAY                0x0205
214 #define UX_HOST_CLASS_AUDIO_PROCESSING_MICROPHONE_ARRAY     0x0206
215 
216 
217 /* Define Audio Class output terminal types.  */
218 
219 #define UX_HOST_CLASS_AUDIO_OUTPUT                          0x0300
220 #define UX_HOST_CLASS_AUDIO_SPEAKER                         0x0301
221 #define UX_HOST_CLASS_AUDIO_HEADPHONES                      0x0302
222 #define UX_HOST_CLASS_AUDIO_HEAD_MOUNTED_DISPLAY            0x0303
223 #define UX_HOST_CLASS_AUDIO_DESKTOP_SPEAKER                 0x0304
224 #define UX_HOST_CLASS_AUDIO_ROOM_SPEAKER                    0x0305
225 #define UX_HOST_CLASS_AUDIO_COMMUNICATION_SPEAKER           0x0306
226 #define UX_HOST_CLASS_AUDIO_LOW_FREQUENCY_SPEAKER           0x0307
227 
228 
229 /* Define Audio Class bidirectional terminal types.  */
230 
231 #define UX_HOST_CLASS_AUDIO_BIDIRECTIONAL_UNDEFINED         0x0400
232 #define UX_HOST_CLASS_AUDIO_HANDSET                         0x0401
233 #define UX_HOST_CLASS_AUDIO_HEADSET                         0x0402
234 #define UX_HOST_CLASS_AUDIO_SPEAKERPHONE                    0x0403
235 #define UX_HOST_CLASS_AUDIO_ECHO_SUPRESS_SPEAKERPHONE       0x0404
236 #define UX_HOST_CLASS_AUDIO_ECHO_CANCEL_SPEAKERPHONE        0x0405
237 
238 
239 /* Define Audio Class telephony terminal types.  */
240 
241 #define UX_HOST_CLASS_AUDIO_TELEPHONTY_UNDEFINED            0x0500
242 #define UX_HOST_CLASS_AUDIO_PHONE_LINE                      0x0501
243 #define UX_HOST_CLASS_AUDIO_TELEPHONE                       0x0502
244 #define UX_HOST_CLASS_AUDIO_DOWN_LINE_PHONE                 0x0503
245 
246 /* Define Audio Class external terminal types.  */
247 
248 /* Define Audio Class encoding format types.  */
249 
250 /* Audio 1.0 Format Type Codes.  */
251 #define UX_HOST_CLASS_AUDIO_FORMAT_TYPE_UNDEFINED                   0
252 #define UX_HOST_CLASS_AUDIO_FORMAT_TYPE_I                           1
253 #define UX_HOST_CLASS_AUDIO_FORMAT_TYPE_II                          2
254 #define UX_HOST_CLASS_AUDIO_FORMAT_TYPE_III                         3
255 
256 /* Audio 1.0 CS AS Interface Descriptor Type I wFormatTag.  */
257 #define UX_HOST_CLASS_AUDIO_FORMAT_PCM                              1
258 #define UX_HOST_CLASS_AUDIO_FORMAT_PCM8                             2
259 #define UX_HOST_CLASS_AUDIO_FORMAT_IEEE_FLOAT                       3
260 #define UX_HOST_CLASS_AUDIO_FORMAT_ALAW                             4
261 #define UX_HOST_CLASS_AUDIO_FORMAT_MULAW                            5
262 /* Audio 1.0 CS AS Interface Descriptor Type II wFormatTag.  */
263 #define UX_HOST_CLASS_AUDIO_FORMAT_TYPE_II_UNDEFINED                0x1000
264 #define UX_HOST_CLASS_AUDIO_FORMAT_MPEG                             0x1001
265 #define UX_HOST_CLASS_AUDIO_FORMAT_AC_3                             0x1002
266 /* Audio 1.0 CS AS Interface Descriptor Type III wFormatTag.  */
267 #define UX_HOST_CLASS_AUDIO_FORMAT_TYPE_III_UNDEFINED               0x2000
268 #define UX_HOST_CLASS_AUDIO_FORMAT_IEC1937_AC_3                     0x2001
269 #define UX_HOST_CLASS_AUDIO_FORMAT_IEC1937_MPEG_1_LAYER_1           0x2002
270 #define UX_HOST_CLASS_AUDIO_FORMAT_IEC1937_MPEG_1_L2_3_MPEG_2_NOEXT 0x2003
271 #define UX_HOST_CLASS_AUDIO_FORMAT_IEC1937_MPEG_2_EXT               0x2004
272 #define UX_HOST_CLASS_AUDIO_FORMAT_IEC1937_MPEG_2_LAYER_1_LS        0x2005
273 #define UX_HOST_CLASS_AUDIO_FORMAT_IEC1937_MPEG_2_LAYER_2_3_LS      0x2006
274 
275 /* Audio 1.0 descriptor structs.  */
276 
277 #define UX_HOST_CLASS_AUDIO_INTERFACE_DESCRIPTOR_ENTRIES            8
278 #define UX_HOST_CLASS_AUDIO_INTERFACE_DESCRIPTOR_LENGTH             8
279 
280 #define UX_HOST_CLASS_AUDIO_INPUT_TERMINAL_DESCRIPTOR_ENTRIES       10
281 #define UX_HOST_CLASS_AUDIO_INPUT_TERMINAL_DESCRIPTOR_LENGTH        12
282 
283 #define UX_HOST_CLASS_AUDIO_OUTPUT_TERMINAL_DESCRIPTOR_ENTRIES      8
284 #define UX_HOST_CLASS_AUDIO_OUTPUT_TERMINAL_DESCRIPTOR_LENGTH       9
285 
286 #define UX_HOST_CLASS_AUDIO_FEATURE_UNIT_DESCRIPTOR_ENTRIES         7
287 #define UX_HOST_CLASS_AUDIO_FEATURE_UNIT_DESCRIPTOR_LENGTH          7
288 
289 #define UX_HOST_CLASS_AUDIO_STREAMING_INTERFACE_DESCRIPTOR_ENTRIES  6
290 #define UX_HOST_CLASS_AUDIO_STREAMING_INTERFACE_DESCRIPTOR_LENGTH   6
291 
292 #define UX_HOST_CLASS_AUDIO_STREAMING_ENDPOINT_DESCRIPTOR_ENTRIES   6
293 #define UX_HOST_CLASS_AUDIO_STREAMING_ENDPOINT_DESCRIPTOR_LENGTH    6
294 
295 
296 /* Define Audio Class specific interface descriptor.  */
297 
298 #define UX_HOST_CLASS_AUDIO_MAX_CHANNEL                         8
299 #define UX_HOST_CLASS_AUDIO_NAME_LENGTH                         64
300 
301 typedef struct UX_HOST_CLASS_AUDIO_INTERFACE_DESCRIPTOR_STRUCT
302 {
303 
304     ULONG           bLength;
305     ULONG           bDescriptorType;
306     ULONG           bDescriptorSubType;
307     ULONG           bFormatType;
308     ULONG           bNrChannels;
309     ULONG           bSubframeSize;
310     ULONG           bBitResolution;
311     ULONG           bSamFreqType;
312 } UX_HOST_CLASS_AUDIO_INTERFACE_DESCRIPTOR;
313 
314 
315 /* Define Audio Class specific input terminal interface descriptor.  */
316 
317 typedef struct UX_HOST_CLASS_AUDIO_INPUT_TERMINAL_DESCRIPTOR_STRUCT
318 {
319 
320     ULONG           bLength;
321     ULONG           bDescriptorType;
322     ULONG           bDescriptorSubType;
323     ULONG           bTerminalID;
324     ULONG           wTerminalType;
325     ULONG           bAssocTerminal;
326     ULONG           bNrChannels;
327     ULONG           wChannelConfig;
328     ULONG           iChannelNames;
329     ULONG           iTerminal;
330 } UX_HOST_CLASS_AUDIO_INPUT_TERMINAL_DESCRIPTOR;
331 
332 
333 /* Define Audio Class specific output terminal interface descriptor.  */
334 
335 typedef struct UX_HOST_CLASS_AUDIO_OUTPUT_TERMINAL_DESCRIPTOR_STRUCT
336 {
337 
338     ULONG           bLength;
339     ULONG           bDescriptorType;
340     ULONG           bDescriptorSubType;
341     ULONG           bTerminalID;
342     ULONG           wTerminalType;
343     ULONG           bAssocTerminal;
344     ULONG           bSourceID;
345     ULONG           iTerminal;
346 } UX_HOST_CLASS_AUDIO_OUTPUT_TERMINAL_DESCRIPTOR;
347 
348 
349 /* Define Audio Class specific feature unit descriptor.  */
350 
351 typedef struct UX_HOST_CLASS_AUDIO_FEATURE_UNIT_DESCRIPTOR_STRUCT
352 {
353 
354     ULONG           bLength;
355     ULONG           bDescriptorType;
356     ULONG           bDescriptorSubType;
357     ULONG           bUnitID;
358     ULONG           bSourceID;
359     ULONG           bControlSize;
360     ULONG           bmaControls;
361 } UX_HOST_CLASS_AUDIO_FEATURE_UNIT_DESCRIPTOR;
362 
363 
364 /* Define Audio Class streaming interface descriptor.  */
365 
366 typedef struct UX_HOST_CLASS_AUDIO_STREAMING_INTERFACE_DESCRIPTOR_STRUCT
367 {
368 
369     ULONG           bLength;
370     ULONG           bDescriptorType;
371     ULONG           bDescriptorSubtype;
372     ULONG           bTerminalLink;
373     ULONG           bDelay;
374     ULONG           wFormatTag;
375 } UX_HOST_CLASS_AUDIO_STREAMING_INTERFACE_DESCRIPTOR;
376 
377 
378 /* Define Audio Class specific streaming endpoint descriptor.  */
379 
380 typedef struct UX_HOST_CLASS_AUDIO_STREAMING_ENDPOINT_DESCRIPTOR_STRUCT
381 {
382 
383     ULONG           bLength;
384     ULONG           bDescriptorType;
385     ULONG           bDescriptorSubtype;
386     ULONG           bmAttributes;
387     ULONG           bLockDelayUnits;
388     ULONG           wLockDelay;
389 } UX_HOST_CLASS_AUDIO_STREAMING_ENDPOINT_DESCRIPTOR;
390 
391 
392 /* Define Audio Class audio control (AC) instance structure.  */
393 typedef struct UX_HOST_CLASS_AUDIO_AC_STRUCT
394 {
395 
396     /* Common fields for _AUDIO and _AUDIO_AC,
397      * check pointed interface subclass (_ux_host_class_audio_subclass_get()) to
398      * see remaining fields after interface pointer.  */
399     struct UX_HOST_CLASS_AUDIO_STRUCT
400                     *ux_host_class_audio_next_instance;
401     UX_HOST_CLASS   *ux_host_class_audio_class;
402     UX_INTERFACE    *ux_host_class_audio_interface;
403 
404     UX_DEVICE       *ux_host_class_audio_device;
405     UCHAR *         ux_host_class_audio_configuration_descriptor;
406     ULONG           ux_host_class_audio_configuration_descriptor_length;
407 
408     /* Fields for _AUDIO_CONTROL_BLOCK (control instance).  */
409     UX_ENDPOINT     *ux_host_class_audio_interrupt_endpoint;
410     VOID            (*ux_host_class_audio_interrupt_callback)(struct UX_HOST_CLASS_AUDIO_AC_STRUCT*ac, UCHAR*msg, ULONG len, VOID*arg);
411     VOID            *ux_host_class_audio_interrupt_callback_arg;
412     UINT            ux_host_class_audio_interrupt_started;
413 
414     UINT            ux_host_class_audio_as_count;
415     struct UX_HOST_CLASS_AUDIO_STRUCT
416                     *ux_host_class_audio_as[2]; /* By default allocate 2, actual length depends on _audio_as_count.  */
417 } UX_HOST_CLASS_AUDIO_AC;
418 
419 /* Define Audio Class instance structure.  */
420 
421 typedef struct UX_HOST_CLASS_AUDIO_STRUCT
422 {
423 
424     /* Common fields for _AUDIO and _AUDIO_AC,
425      * check pointed interface subclass (_ux_host_class_audio_subclass_get()) to
426      * see remaining fields after interface pointer.  */
427     struct UX_HOST_CLASS_AUDIO_STRUCT
428                     *ux_host_class_audio_next_instance;
429     UX_HOST_CLASS   *ux_host_class_audio_class;
430     UX_INTERFACE    *ux_host_class_audio_streaming_interface;
431 
432     UX_DEVICE       *ux_host_class_audio_device;
433     UCHAR *         ux_host_class_audio_configuration_descriptor;
434     ULONG           ux_host_class_audio_configuration_descriptor_length;
435 
436     /* Fields for _AUDIO (streaming instance).  */
437     ULONG           ux_host_class_audio_control_interface_number;
438     UCHAR           *ux_host_class_audio_sampling_descriptor;   /* UAC1.0: FormatTypeI Descriptor, UAC2.0: Clock Source Descriptor.  */
439     UX_ENDPOINT     *ux_host_class_audio_isochronous_endpoint;
440 #if defined(UX_HOST_CLASS_AUDIO_FEEDBACK_SUPPORT)
441     UX_ENDPOINT     *ux_host_class_audio_feedback_endpoint;
442     UCHAR           ux_host_class_audio_feedback_buffer[4];     /* USB 2.0: feedback fits into 3(FS) or 4(HS).  */
443 #endif
444 #if defined(UX_HOST_CLASS_AUDIO_INTERRUPT_SUPPORT)
445     UX_HOST_CLASS_AUDIO_AC
446                     *ux_host_class_audio_ac;
447 #endif
448     struct UX_HOST_CLASS_AUDIO_TRANSFER_REQUEST_STRUCT
449                     *ux_host_class_audio_head_transfer_request;
450     struct UX_HOST_CLASS_AUDIO_TRANSFER_REQUEST_STRUCT
451                     *ux_host_class_audio_tail_transfer_request;
452     UINT            ux_host_class_audio_state;
453     ULONG           ux_host_class_audio_terminal_link;
454     ULONG           ux_host_class_audio_type;
455     ULONG           ux_host_class_audio_packet_size;
456     ULONG           ux_host_class_audio_packet_freq;
457     ULONG           ux_host_class_audio_packet_fraction;
458 #if !defined(UX_HOST_CLASS_AUDIO_DISABLE_CONTROLS)
459     ULONG           ux_host_class_audio_feature_unit_id;
460     UINT            ux_host_class_audio_channels;
461     ULONG           ux_host_class_audio_channel_control[UX_HOST_CLASS_AUDIO_MAX_CHANNEL];
462 #endif
463     UX_MUTEX        ux_host_class_audio_mutex;
464 } UX_HOST_CLASS_AUDIO;
465 
466 #define _ux_host_class_audio_interface_get(a)           (((UX_HOST_CLASS_AUDIO*)(a))->ux_host_class_audio_streaming_interface->ux_interface_descriptor.bInterfaceNumber)
467 #define _ux_host_class_audio_protocol_get(a)            (((UX_HOST_CLASS_AUDIO*)(a))->ux_host_class_audio_streaming_interface->ux_interface_descriptor.bInterfaceProtocol)
468 #define _ux_host_class_audio_subclass_get(a)            (((UX_HOST_CLASS_AUDIO*)(a))->ux_host_class_audio_streaming_interface->ux_interface_descriptor.bInterfaceSubClass)
469 
470 #define _ux_host_class_audio_speed_get(a)               ((a)->ux_host_class_audio_device->ux_device_speed)
471 #define _ux_host_class_audio_type_get(a)                ((a)->ux_host_class_audio_type)
472 #if defined(UX_HOST_CLASS_AUDIO_FEEDBACK_SUPPORT)
473 #define _ux_host_class_audio_feedback_supported(a)      ((a)->ux_host_class_audio_feedback_endpoint)
474 #else
475 #define _ux_host_class_audio_feedback_supported(a)      (UX_FALSE)
476 #endif
477 #define _ux_host_class_audio_control_interface_get(a)   ((a)->ux_host_class_audio_control_interface_number)
478 #define _ux_host_class_audio_terminal_link_get(a)       ((a)->ux_host_class_audio_terminal_link)
479 #define _ux_host_class_audio_packet_size_get(a)         ((a)->ux_host_class_audio_packet_size)
480 #define _ux_host_class_audio_packet_freq_get(a)         ((a)->ux_host_class_audio_packet_freq)
481 #define _ux_host_class_audio_packet_fraction_get(a)     ((a)->ux_host_class_audio_packet_fraction)
482 #define _ux_host_class_audio_max_packet_size_get(a)     ((a)->ux_host_class_audio_isochronous_endpoint->ux_endpoint_transfer_request.ux_transfer_request_packet_length)
483 
484 
485 /* Define Audio Class isochronous USB transfer request structure.  */
486 
487 typedef struct UX_HOST_CLASS_AUDIO_TRANSFER_REQUEST_STRUCT
488 {
489 
490     ULONG           ux_host_class_audio_transfer_request_status;
491     UCHAR           *ux_host_class_audio_transfer_request_data_pointer;
492     ULONG           ux_host_class_audio_transfer_request_requested_length;
493     ULONG           ux_host_class_audio_transfer_request_packet_size;    /* Actual packet size to use.  */
494     ULONG           ux_host_class_audio_transfer_request_actual_length;
495     VOID            (*ux_host_class_audio_transfer_request_completion_function) (struct UX_HOST_CLASS_AUDIO_TRANSFER_REQUEST_STRUCT *);
496     UX_SEMAPHORE    ux_host_class_audio_transfer_request_semaphore;
497     VOID            *ux_host_class_audio_transfer_request_class_instance;
498     UINT            ux_host_class_audio_transfer_request_completion_code;
499     struct UX_HOST_CLASS_AUDIO_TRANSFER_REQUEST_STRUCT
500                     *ux_host_class_audio_transfer_request_next_audio_transfer_request;
501     UX_TRANSFER     ux_host_class_audio_transfer_request;
502 } UX_HOST_CLASS_AUDIO_TRANSFER_REQUEST;
503 
504 
505 /* Define Audio Class channel/value control structures.  */
506 
507 typedef struct UX_HOST_CLASS_AUDIO_CONTROL_STRUCT
508 {
509 
510     ULONG           ux_host_class_audio_control;
511     ULONG           ux_host_class_audio_control_channel;
512     ULONG           ux_host_class_audio_control_min;
513     ULONG           ux_host_class_audio_control_max;
514     ULONG           ux_host_class_audio_control_res;
515     ULONG           ux_host_class_audio_control_cur;
516 
517     ULONG           ux_host_class_audio_control_entity; /* Entity ID.  */
518     ULONG           ux_host_class_audio_control_size;   /* Size of value in 1,2 or 4 bytes.  */
519 } UX_HOST_CLASS_AUDIO_CONTROL;
520 
521 
522 typedef struct UX_HOST_CLASS_AUDIO_CHANNEL_STRUCT
523 {
524 
525     ULONG           ux_host_class_audio_channel_control;
526     ULONG           ux_host_class_audio_channel;
527 } UX_HOST_CLASS_AUDIO_CHANNEL;
528 
529 
530 /* Define Audio Class sampling selection structure.  */
531 
532 typedef struct UX_HOST_CLASS_AUDIO_SAMPLING_STRUCT
533 {
534 
535     ULONG           ux_host_class_audio_sampling_channels;
536     ULONG           ux_host_class_audio_sampling_frequency;
537     ULONG           ux_host_class_audio_sampling_resolution;
538 } UX_HOST_CLASS_AUDIO_SAMPLING;
539 
540 
541 /* Define Audio Class sampling characteristics structure.  */
542 
543 typedef struct UX_HOST_CLASS_AUDIO_SAMPLING_CHARACTERISTICS_STRUCT
544 {
545 
546     ULONG           ux_host_class_audio_sampling_characteristics_channels;
547     ULONG           ux_host_class_audio_sampling_characteristics_frequency_low;
548     ULONG           ux_host_class_audio_sampling_characteristics_frequency_high;
549     ULONG           ux_host_class_audio_sampling_characteristics_resolution;
550 
551     /* UAC 1.0, must be 1s.  UAC 2.0, from actual audio schematic.  */
552     ULONG           ux_host_class_audio_sampling_characteristics_clock_mul;
553     ULONG           ux_host_class_audio_sampling_characteristics_clock_div;
554 
555     /* UAC 1.0, format type I descriptor for futher operations.  */
556     /* UAC 2.0, clock source descriptor (CSD) for futher operations.  */
557     UCHAR           *ux_host_class_audio_sampling_characteristics_descriptor;
558 } UX_HOST_CLASS_AUDIO_SAMPLING_CHARACTERISTICS;
559 
560 
561 /* Define Audio Class function prototypes.  */
562 
563 UINT    _ux_host_class_audio_activate(UX_HOST_CLASS_COMMAND *command);
564 UINT    _ux_host_class_audio_alternate_setting_locate(UX_HOST_CLASS_AUDIO *audio, UX_HOST_CLASS_AUDIO_SAMPLING *audio_sampling, UINT *alternate_setting);
565 UINT    _ux_host_class_audio_configure(UX_HOST_CLASS_AUDIO *audio);
566 UINT    _ux_host_class_audio_control_get(UX_HOST_CLASS_AUDIO *audio, UX_HOST_CLASS_AUDIO_CONTROL *audio_control);
567 UINT    _ux_host_class_audio_control_value_get(UX_HOST_CLASS_AUDIO *audio, UX_HOST_CLASS_AUDIO_CONTROL *audio_control);
568 UINT    _ux_host_class_audio_control_value_set(UX_HOST_CLASS_AUDIO *audio, UX_HOST_CLASS_AUDIO_CONTROL *audio_control);
569 UINT    _ux_host_class_audio_deactivate(UX_HOST_CLASS_COMMAND *command);
570 UINT    _ux_host_class_audio_descriptor_get(UX_HOST_CLASS_AUDIO *audio);
571 UINT    _ux_host_class_audio_device_controls_list_get(UX_HOST_CLASS_AUDIO *audio);
572 UINT    _ux_host_class_audio_device_type_get(UX_HOST_CLASS_AUDIO *audio);
573 UINT    _ux_host_class_audio_endpoints_get(UX_HOST_CLASS_AUDIO *audio);
574 UINT    _ux_host_class_audio_entry(UX_HOST_CLASS_COMMAND *command);
575 UINT    _ux_host_class_audio_read(UX_HOST_CLASS_AUDIO *audio, UX_HOST_CLASS_AUDIO_TRANSFER_REQUEST *audio_transfer_request);
576 UINT    _ux_host_class_audio_streaming_sampling_get(UX_HOST_CLASS_AUDIO *audio, UX_HOST_CLASS_AUDIO_SAMPLING_CHARACTERISTICS *audio_sampling);
577 UINT    _ux_host_class_audio_streaming_sampling_set(UX_HOST_CLASS_AUDIO *audio, UX_HOST_CLASS_AUDIO_SAMPLING *audio_sampling);
578 UINT    _ux_host_class_audio_streaming_terminal_get(UX_HOST_CLASS_AUDIO *audio);
579 UINT    _ux_host_class_audio_transfer_request(UX_HOST_CLASS_AUDIO *audio, UX_HOST_CLASS_AUDIO_TRANSFER_REQUEST *audio_transfer_request);
580 VOID    _ux_host_class_audio_transfer_request_completed(UX_TRANSFER *transfer_request);
581 UINT    _ux_host_class_audio_write(UX_HOST_CLASS_AUDIO *audio, UX_HOST_CLASS_AUDIO_TRANSFER_REQUEST *audio_transfer_request);
582 
583 UINT    _ux_host_class_audio_control_request(UX_HOST_CLASS_AUDIO *audio,
584                         UINT streaming_control,
585                         UINT request_type, UINT request,
586                         UINT request_value,
587                         UINT spec_id,
588                         UCHAR *parameter, ULONG parameter_size, ULONG *actual_size);
589 
590 UINT    _ux_host_class_audio_descriptors_parse(UX_HOST_CLASS_AUDIO *audio,
591                         UINT(*parse_function)(VOID  *arg,
592                                             UCHAR *packed_interface_descriptor,
593                                             UCHAR *packed_endpoint_descriptor,
594                                             UCHAR *packed_audio_descriptor),
595                         VOID* arg);
596 
597 UINT    _ux_host_class_audio_raw_sampling_parse(UX_HOST_CLASS_AUDIO *audio,
598                         UINT(*parse_function)(VOID  *arg,
599                                               UCHAR *packed_interface_descriptor,
600                                               UX_HOST_CLASS_AUDIO_SAMPLING_CHARACTERISTICS *sam_attr),
601                         VOID* arg);
602 
603 UINT    _ux_host_class_audio_stop(UX_HOST_CLASS_AUDIO *audio);
604 
605 VOID    _ux_host_class_audio_feedback_transfer_completed(UX_TRANSFER *transfer_request);
606 
607 UINT    _ux_host_class_audio_feedback_get(UX_HOST_CLASS_AUDIO *audio, UCHAR *feedback);
608 UINT    _ux_host_class_audio_feedback_set(UX_HOST_CLASS_AUDIO *audio, UCHAR *feedback);
609 
610 UINT    _ux_host_class_audio_entity_control_get(UX_HOST_CLASS_AUDIO *audio, UX_HOST_CLASS_AUDIO_CONTROL *audio_control);
611 UINT    _ux_host_class_audio_entity_control_value_get(UX_HOST_CLASS_AUDIO *audio, UX_HOST_CLASS_AUDIO_CONTROL *audio_control);
612 UINT    _ux_host_class_audio_entity_control_value_set(UX_HOST_CLASS_AUDIO *audio, UX_HOST_CLASS_AUDIO_CONTROL *audio_control);
613 
614 UINT    _ux_host_class_audio_interrupt_start(UX_HOST_CLASS_AUDIO_AC *audio,
615                         VOID(*callback_function)(UX_HOST_CLASS_AUDIO_AC *audio,
616                                                  UCHAR *message, ULONG length,
617                                                  VOID *arg),
618                         VOID *arg);
619 VOID    _ux_host_class_audio_interrupt_notification(UX_TRANSFER *transfer_request);
620 
621 /* Define Audio Class API prototypes.  */
622 
623 #define ux_host_class_audio_entry                   _ux_host_class_audio_entry
624 #define ux_host_class_audio_control_get             _ux_host_class_audio_control_get
625 #define ux_host_class_audio_control_value_get       _ux_host_class_audio_control_value_get
626 #define ux_host_class_audio_control_value_set       _ux_host_class_audio_control_value_set
627 #define ux_host_class_audio_read                    _ux_host_class_audio_read
628 #define ux_host_class_audio_streaming_sampling_get  _ux_host_class_audio_streaming_sampling_get
629 #define ux_host_class_audio_streaming_sampling_set  _ux_host_class_audio_streaming_sampling_set
630 #define ux_host_class_audio_streaming_terminal_get  _ux_host_class_audio_streaming_terminal_get
631 #define ux_host_class_audio_write                   _ux_host_class_audio_write
632 
633 #define ux_host_class_audio_type_get                    _ux_host_class_audio_type_get
634 #define ux_host_class_audio_speed_get                   _ux_host_class_audio_speed_get
635 #define ux_host_class_audio_protocol_get                _ux_host_class_audio_protocol_get
636 #define ux_host_class_audio_subclass_get                _ux_host_class_audio_subclass_get
637 #define ux_host_class_audio_feedback_supported          _ux_host_class_audio_feedback_supported
638 
639 #define ux_host_class_audio_interface_get               _ux_host_class_audio_interface_get
640 #define ux_host_class_audio_control_interface_get       _ux_host_class_audio_control_interface_get
641 #define ux_host_class_audio_terminal_link_get           _ux_host_class_audio_terminal_link_get
642 
643 #define ux_host_class_audio_max_packet_size_get         _ux_host_class_audio_max_packet_size_get
644 #define ux_host_class_audio_packet_size_get             _ux_host_class_audio_packet_size_get
645 #define ux_host_class_audio_packet_freq_get             _ux_host_class_audio_packet_freq_get
646 #define ux_host_class_audio_packet_fraction_get         _ux_host_class_audio_packet_fraction_get
647 
648 #define ux_host_class_audio_feedback_get                _ux_host_class_audio_feedback_get
649 #define ux_host_class_audio_feedback_set                _ux_host_class_audio_feedback_set
650 
651 #define ux_host_class_audio_control_request             _ux_host_class_audio_control_request
652 
653 #define ux_host_class_audio_descriptors_parse           _ux_host_class_audio_descriptors_parse
654 
655 #define ux_host_class_audio_entity_control_get          _ux_host_class_audio_entity_control_get
656 #define ux_host_class_audio_entity_control_value_get    _ux_host_class_audio_entity_control_value_get
657 #define ux_host_class_audio_entity_control_value_set    _ux_host_class_audio_entity_control_value_set
658 
659 #define ux_host_class_audio_raw_sampling_parse          _ux_host_class_audio_raw_sampling_parse
660 #define ux_host_class_audio_raw_sampling_start          _ux_host_class_audio_streaming_sampling_set
661 
662 #define ux_host_class_audio_stop                        _ux_host_class_audio_stop
663 
664 #define ux_host_class_audio_interrupt_start             _ux_host_class_audio_interrupt_start
665 
666 /* Determine if a C++ compiler is being used.  If so, complete the standard
667    C conditional started above.  */
668 #ifdef __cplusplus
669 }
670 #endif
671 
672 #endif
673 
674 
675