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 /**   Device Audio Class                                                  */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 
24 /**************************************************************************/
25 /*                                                                        */
26 /*  COMPONENT DEFINITION                                   RELEASE        */
27 /*                                                                        */
28 /*    ux_device_class_audio10.h                           PORTABLE C      */
29 /*                                                           6.2.1        */
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 version 1.0.                                       */
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 /*                                            resulting in version 6.1    */
46 /*  04-02-2021     Chaoqiong Xiao           Modified comment(s),          */
47 /*                                            added volume RES support,   */
48 /*                                            resulting in version 6.1.6  */
49 /*  08-02-2021     Chaoqiong Xiao           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 sampling control,     */
55 /*                                            resulting in version 6.1.12 */
56 /*  03-08-2023     Chaoqiong Xiao           Modified comment(s),          */
57 /*                                            added error checks support, */
58 /*                                            fixed a macro name,         */
59 /*                                            resulting in version 6.2.1  */
60 /*                                                                        */
61 /**************************************************************************/
62 
63 #ifndef UX_DEVICE_CLASS_AUDIO10_H
64 #define UX_DEVICE_CLASS_AUDIO10_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 
77 /* Internal option: enable the basic USBX error checking. This define is typically used
78    while debugging application.  */
79 #if defined(UX_ENABLE_ERROR_CHECKING) && !defined(UX_DEVICE_CLASS_AUDIO_ENABLE_ERROR_CHECKING)
80 #define UX_DEVICE_CLASS_AUDIO_ENABLE_ERROR_CHECKING
81 #endif
82 
83 
84 /* Define Audio Class specific AC interface descriptor subclasses.  */
85 
86 #define UX_DEVICE_CLASS_AUDIO10_AC_UNDEFINED                      0x00
87 #define UX_DEVICE_CLASS_AUDIO10_AC_HEADER                         0x01
88 #define UX_DEVICE_CLASS_AUDIO10_AC_INPUT_TERMINAL                 0x02
89 #define UX_DEVICE_CLASS_AUDIO10_AC_OUTPUT_TERMINAL                0x03
90 #define UX_DEVICE_CLASS_AUDIO10_AC_MIXER_UNIT                     0x04
91 #define UX_DEVICE_CLASS_AUDIO10_AC_SELECTOR_UNIT                  0x05
92 #define UX_DEVICE_CLASS_AUDIO10_AC_FEATURE_UNIT                   0x06
93 #define UX_DEVICE_CLASS_AUDIO10_AC_PROCESSING_UNIT                0x07
94 #define UX_DEVICE_CLASS_AUDIO10_AC_EXTENSION_UNIT                 0x08
95 
96 
97 /* Define Audio Class specific AS interface descriptor subclasses.  */
98 
99 #define UX_DEVICE_CLASS_AUDIO10_AS_UNDEFINED                      0x00
100 #define UX_DEVICE_CLASS_AUDIO10_AS_GENERAL                        0x01
101 #define UX_DEVICE_CLASS_AUDIO10_AS_FORMAT_TYPE                    0x02
102 #define UX_DEVICE_CLASS_AUDIO10_AS_FORMAT_SPECIFIC                0x03
103 
104 
105 /* Define Audio Class specific endpoint descriptor subtypes.  */
106 
107 #define UX_DEVICE_CLASS_AUDIO10_EP_UNDEFINED                      0x00
108 #define UX_DEVICE_CLASS_AUDIO10_EP_GENERAL                        0x01
109 
110 
111 /* Define Audio Class specific request codes.  */
112 
113 #define UX_DEVICE_CLASS_AUDIO10_REQUEST_CODE_UNDEFINED            0x00
114 #define UX_DEVICE_CLASS_AUDIO10_SET_CUR                           0x01
115 #define UX_DEVICE_CLASS_AUDIO10_GET_CUR                           0x81
116 #define UX_DEVICE_CLASS_AUDIO10_SET_MIN                           0x02
117 #define UX_DEVICE_CLASS_AUDIO10_GET_MIN                           0x82
118 #define UX_DEVICE_CLASS_AUDIO10_SET_MAX                           0x03
119 #define UX_DEVICE_CLASS_AUDIO10_GET_MAX                           0x83
120 #define UX_DEVICE_CLASS_AUDIO10_SET_RES                           0x04
121 #define UX_DEVICE_CLASS_AUDIO10_GET_RES                           0x84
122 #define UX_DEVICE_CLASS_AUDIO10_SET_MEM                           0x05
123 #define UX_DEVICE_CLASS_AUDIO10_GET_MEM                           0x85
124 #define UX_DEVICE_CLASS_AUDIO10_GET_STAT                          0xFF
125 
126 
127 /* Define Audio Class specific terminal control selectors.  */
128 
129 #define UX_DEVICE_CLASS_AUDIO10_TE_CONTROL_UNDEFINED              0x00
130 #define UX_DEVICE_CLASS_AUDIO10_TE_COPY_PROTECT_CONTROL           0x01
131 
132 
133 /* Define Audio Class specific feature unit control selectors.  */
134 
135 #define UX_DEVICE_CLASS_AUDIO10_FU_CONTROL_UNDEFINED              0x00
136 #define UX_DEVICE_CLASS_AUDIO10_FU_MUTE_CONTROL                   0x01
137 #define UX_DEVICE_CLASS_AUDIO10_FU_VOLUME_CONTROL                 0x02
138 #define UX_DEVICE_CLASS_AUDIO10_FU_BASS_CONTROL                   0x03
139 #define UX_DEVICE_CLASS_AUDIO10_FU_MID_CONTROL                    0x04
140 #define UX_DEVICE_CLASS_AUDIO10_FU_TREBLE_CONTROL                 0x05
141 #define UX_DEVICE_CLASS_AUDIO10_FU_GRAPHIC_EQUALIZER_CONTROL      0x06
142 #define UX_DEVICE_CLASS_AUDIO10_FU_AUTOMATIC_GAIN_CONTROL         0x07
143 #define UX_DEVICE_CLASS_AUDIO10_FU_DELAY_CONTROL                  0x08
144 #define UX_DEVICE_CLASS_AUDIO10_FU_BASS_BOOST_CONTROL             0x09
145 #define UX_DEVICE_CLASS_AUDIO10_FU_LOUNDNESS_CONTROL              0x0A
146 
147 
148 /* Define Audio Class specific endpoint control selectors.  */
149 
150 #define UX_DEVICE_CLASS_AUDIO10_EP_CONTROL_UNDEFINED              0x00
151 #define UX_DEVICE_CLASS_AUDIO10_EP_SAMPLING_FREQ_CONTROL          0x01
152 #define UX_DEVICE_CLASS_AUDIO10_EP_PITCH_CONTROL                  0x02
153 
154 
155 /* Define Audio Class encoding format types.  */
156 
157 #define UX_DEVICE_CLASS_AUDIO10_FORMAT_PCM                        1
158 #define UX_DEVICE_CLASS_AUDIO10_FORMAT_PCM8                       2
159 #define UX_DEVICE_CLASS_AUDIO10_FORMAT_IEEE_FLOAT                 3
160 #define UX_DEVICE_CLASS_AUDIO10_FORMAT_ALAW                       4
161 #define UX_DEVICE_CLASS_AUDIO10_FORMAT_MULAW                      5
162 
163 
164 /* Audio Class Control interface structures.  */
165 
166 typedef struct UX_DEVICE_CLASS_AUDIO10_AC_HEADER1_DESCRIPTOR_STRUCT
167 {
168 
169     ULONG           bLength;
170     ULONG           bDescriptorType;
171     ULONG           bDescriptorSubtype;
172     ULONG           bcdADC;
173     ULONG           wTotalLength;
174     ULONG           bInCollection;
175     ULONG           baInterfaceNr1;
176 } UX_DEVICE_CLASS_AUDIO10_AC_HEADER1_DESCRIPTOR;
177 
178 typedef struct UX_DEVICE_CLASS_AUDIO10_AC_HEADER2_DESCRIPTOR_STRUCT
179 {
180 
181     ULONG           bLength;
182     ULONG           bDescriptorType;
183     ULONG           bDescriptorSubtype;
184     ULONG           bcdADC;
185     ULONG           wTotalLength;
186     ULONG           bInCollection;
187     ULONG           baInterfaceNr1;
188     ULONG           baInterfaceNr2;
189 } UX_DEVICE_CLASS_AUDIO10_AC_HEADER2_DESCRIPTOR;
190 
191 typedef struct UX_DEVICE_CLASS_AUDIO10_AC_HEADER3_DESCRIPTOR_STRUCT
192 {
193 
194     ULONG           bLength;
195     ULONG           bDescriptorType;
196     ULONG           bDescriptorSubtype;
197     ULONG           bcdADC;
198     ULONG           wTotalLength;
199     ULONG           bInCollection;
200     ULONG           baInterfaceNr1;
201     ULONG           baInterfaceNr2;
202     ULONG           baInterfaceNr3;
203 } UX_DEVICE_CLASS_AUDIO10_AC_HEADER3_DESCRIPTOR;
204 
205 typedef struct UX_DEVICE_CLASS_AUDIO10_AC_HEADER6_DESCRIPTOR_STRUCT
206 {
207 
208     ULONG           bLength;
209     ULONG           bDescriptorType;
210     ULONG           bDescriptorSubtype;
211     ULONG           bcdADC;
212     ULONG           wTotalLength;
213     ULONG           bInCollection;
214     ULONG           baInterfaceNr1;
215     ULONG           baInterfaceNr2;
216     ULONG           baInterfaceNr3;
217     ULONG           baInterfaceNr4;
218     ULONG           baInterfaceNr5;
219     ULONG           baInterfaceNr6;
220 } UX_DEVICE_CLASS_AUDIO10_AC_HEADER6_DESCRIPTOR;
221 
222 typedef struct UX_DEVICE_CLASS_AUDIO10_AC_HEADER7_DESCRIPTOR_STRUCT
223 {
224 
225     ULONG           bLength;
226     ULONG           bDescriptorType;
227     ULONG           bDescriptorSubtype;
228     ULONG           bcdADC;
229     ULONG           wTotalLength;
230     ULONG           bInCollection;
231     ULONG           baInterfaceNr1;
232     ULONG           baInterfaceNr2;
233     ULONG           baInterfaceNr3;
234     ULONG           baInterfaceNr4;
235     ULONG           baInterfaceNr5;
236     ULONG           baInterfaceNr6;
237     ULONG           baInterfaceNr7;
238 } UX_DEVICE_CLASS_AUDIO10_AC_HEADER7_DESCRIPTOR;
239 
240 typedef struct UX_DEVICE_CLASS_AUDIO10_AC_HEADER8_DESCRIPTOR_STRUCT
241 {
242 
243     ULONG           bLength;
244     ULONG           bDescriptorType;
245     ULONG           bDescriptorSubtype;
246     ULONG           bcdADC;
247     ULONG           wTotalLength;
248     ULONG           bInCollection;
249     ULONG           baInterfaceNr1;
250     ULONG           baInterfaceNr2;
251     ULONG           baInterfaceNr3;
252     ULONG           baInterfaceNr4;
253     ULONG           baInterfaceNr5;
254     ULONG           baInterfaceNr6;
255     ULONG           baInterfaceNr7;
256     ULONG           baInterfaceNr8;
257 } UX_DEVICE_CLASS_AUDIO10_AC_HEADER8_DESCRIPTOR;
258 
259 
260 /* Define Audio Class specific input terminal interface descriptor.  */
261 
262 typedef struct UX_DEVICE_CLASS_AUDIO10_AC_INPUT_TERMINAL_DESCRIPTOR_STRUCT
263 {
264 
265     ULONG           bLength;
266     ULONG           bDescriptorType;
267     ULONG           bDescriptorSubType;
268     ULONG           bTerminalID;
269     ULONG           wTerminalType;
270     ULONG           bAssocTerminal;
271     ULONG           bNrChannels;
272     ULONG           wChannelConfig;
273     ULONG           iChannelNames;
274     ULONG           iTerminal;
275 } UX_DEVICE_CLASS_AUDIO10_AC_INPUT_TERMINAL_DESCRIPTOR;
276 
277 
278 /* Define Audio Class specific output terminal interface descriptor.  */
279 
280 typedef struct UX_DEVICE_CLASS_AUDIO10_AC_OUTPUT_TERMINAL_DESCRIPTOR_STRUCT
281 {
282 
283     ULONG           bLength;
284     ULONG           bDescriptorType;
285     ULONG           bDescriptorSubType;
286     ULONG           bTerminalID;
287     ULONG           wTerminalType;
288     ULONG           bAssocTerminal;
289     ULONG           bSourceID;
290     ULONG           iTerminal;
291 } UX_DEVICE_CLASS_AUDIO10_AC_OUTPUT_TERMINAL_DESCRIPTOR;
292 
293 
294 /* Define Audio Class specific feature unit descriptor.  */
295 
296 typedef struct UX_DEVICE_CLASS_AUDIO10_AC_FEATURE_UNIT_DESCRIPTOR_STRUCT
297 {
298 
299     ULONG           bLength;
300     ULONG           bDescriptorType;
301     ULONG           bDescriptorSubType;
302     ULONG           bUnitID;
303     ULONG           bSourceID;
304     ULONG           bControlSize;
305     ULONG           bmaControls;
306 } UX_DEVICE_CLASS_AUDIO10_AC_FEATURE_UNIT_DESCRIPTOR;
307 
308 
309 /* Define Audio Class streaming interface descriptor.  */
310 
311 typedef struct UX_DEVICE_CLASS_AUDIO10_AS_INTERFACE_DESCRIPTOR_STRUCT
312 {
313 
314     ULONG           bLength;
315     ULONG           bDescriptorType;
316     ULONG           bDescriptorSubtype;
317     ULONG           bTerminalLink;
318     ULONG           bDelay;
319     ULONG           wFormatTag;
320 } UX_DEVICE_CLASS_AUDIO10_AS_INTERFACE_DESCRIPTOR;
321 
322 
323 /* Define Audio Class type I format type descriptor.  */
324 
325 typedef struct UX_DEVICE_CLASS_AUDIO10_AS_TYPE_I_FORMAT_TYPE_DESCRIPTOR_STRUCT
326 {
327 
328     ULONG           bLength;
329     ULONG           bDescriptorType;
330     ULONG           bDescriptorSubtype;
331     ULONG           bFormatType;
332     ULONG           bNrChannels;
333     ULONG           bSubframeSize;
334     ULONG           bBitResolution;
335     ULONG           bSamFreqType;
336     ULONG           SamplingFrequency;
337 } UX_DEVICE_CLASS_AUDIO10_AS_TYPE_I_FORMAT_TYPE_DESCRIPTOR;
338 
339 #define UX_DEVICE_CLASS_AUDIO_AS_TYPE_I_FORMAT_TYPE_DESCRIPTOR_FORMAT_TYPE    3
340 #define UX_DEVICE_CLASS_AUDIO_AS_TYPE_I_FORMAT_TYPE_DESCRIPTOR_NR_CHANNELS    4
341 #define UX_DEVICE_CLASS_AUDIO_AS_TYPE_I_FORMAT_TYPE_DESCRIPTOR_SUBFRAME_SIZE  5
342 #define UX_DEVICE_CLASS_AUDIO_AS_TYPE_I_FORMAT_TYPE_DESCRIPTOR_BIT_RESOLUTION 6
343 #define UX_DEVICE_CLASS_AUDIO_AS_TYPE_I_FORMAT_TYPE_DESCRIPTOR_SAM_FREQ_TYPE  7
344 #define UX_DEVICE_CLASS_AUDIO_AS_TYPE_I_FORMAT_TYPE_DESCRIPTOR_SAM_FREQ_TABLE 8
345 
346 
347 /* Define Audio Class specific streaming endpoint descriptor.  */
348 
349 typedef struct UX_DEVICE_CLASS_AUDIO10_AS_ENDPOINT_DESCRIPTOR_STRUCT
350 {
351 
352     ULONG           bLength;
353     ULONG           bDescriptorType;
354     ULONG           bDescriptorSubtype;
355     ULONG           bmAttributes;
356     ULONG           wMaxPacketSize;
357     ULONG           bInterval;
358     ULONG           bRefresh;
359     ULONG           bSynchAddress;
360 } UX_DEVICE_CLASS_AUDIO10_AS_ENDPOINT_DESCRIPTOR;
361 
362 typedef struct UX_DEVICE_CLASS_AUDIO10_AS_DATA_ENDPOINT_DESCRIPTOR_STRUCT
363 {
364 
365     ULONG           bLength;
366     ULONG           bDescriptorType;
367     ULONG           bDescriptorSubtype;
368     ULONG           bmAttributes;
369     ULONG           bLockDelayUnits;
370     ULONG           wLockDelay;
371 } UX_DEVICE_CLASS_AUDIO10_AS_DATA_ENDPOINT_DESCRIPTOR;
372 
373 typedef struct UX_DEVICE_CLASS_AUDIO10_CONTROL_STRUCT
374 {
375     ULONG           ux_device_class_audio10_control_changed;
376 
377     ULONG           ux_device_class_audio10_control_ep_addr;        /* Endpoint address for sampling frequencies control.  */
378     UCHAR           *ux_device_class_audio10_control_sam_freq_types;/* Format Type I Descriptor - bSamFreqType and followings.  */
379     ULONG           ux_device_class_audio10_control_sam_freq;       /* Current sampling frequency.  */
380 
381     ULONG           ux_device_class_audio10_control_fu_id;
382     USHORT          ux_device_class_audio10_control_mute[1];
383     SHORT           ux_device_class_audio10_control_volume_min[1];
384     SHORT           ux_device_class_audio10_control_volume_max[1];
385     USHORT          ux_device_class_audio10_control_volume_res[1];
386     SHORT           ux_device_class_audio10_control_volume[1];
387 } UX_DEVICE_CLASS_AUDIO10_CONTROL;
388 
389 #define UX_DEVICE_CLASS_AUDIO10_CONTROL_MUTE_CHANGED                1u
390 #define UX_DEVICE_CLASS_AUDIO10_CONTROL_VOLUME_CHANGED              2u
391 #define UX_DEVICE_CLASS_AUDIO10_CONTROL_FREQUENCY_CHANGED           4u
392 
393 typedef struct UX_DEVICE_CLASS_AUDIO10_CONTROL_GROUP_STRUCT
394 {
395     ULONG                            ux_device_class_audio10_control_group_controls_nb;
396     UX_DEVICE_CLASS_AUDIO10_CONTROL *ux_device_class_audio10_control_group_controls;
397 } UX_DEVICE_CLASS_AUDIO10_CONTROL_GROUP;
398 
399 UINT _ux_device_class_audio10_control_process(UX_DEVICE_CLASS_AUDIO *audio,
400                                               UX_SLAVE_TRANSFER *transfer_request,
401                                               UX_DEVICE_CLASS_AUDIO10_CONTROL_GROUP *group);
402 
403 UINT _uxe_device_class_audio10_control_process(UX_DEVICE_CLASS_AUDIO *audio,
404                                               UX_SLAVE_TRANSFER *transfer_request,
405                                               UX_DEVICE_CLASS_AUDIO10_CONTROL_GROUP *group);
406 
407 #if defined(UX_DEVICE_CLASS_AUDIO_ENABLE_ERROR_CHECKING)
408 
409 #define ux_device_class_audio10_control_process _uxe_device_class_audio10_control_process
410 
411 #else
412 
413 #define ux_device_class_audio10_control_process _ux_device_class_audio10_control_process
414 
415 #endif
416 
417 /* Determine if a C++ compiler is being used.  If so, complete the standard
418    C conditional started above.  */
419 #ifdef __cplusplus
420 }
421 #endif
422 
423 #endif /* ifndef UX_DEVICE_CLASS_AUDIO10_H */
424