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_audio.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.                                                   */
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 /*  01-31-2022     Chaoqiong Xiao           Modified comment(s),          */
54 /*                                            added feedback support,     */
55 /*                                            resulting in version 6.1.10 */
56 /*  04-25-2022     Chaoqiong Xiao           Modified comment(s),          */
57 /*                                            fixed standalone compile,   */
58 /*                                            resulting in version 6.1.11 */
59 /*  07-29-2022     Chaoqiong Xiao           Modified comment(s),          */
60 /*                                            added interrupt support,    */
61 /*                                            resulting in version 6.1.12 */
62 /*  10-31-2022     Yajun Xia                Modified comment(s),          */
63 /*                                            added standalone support,   */
64 /*                                            resulting in version 6.2.0  */
65 /*  03-08-2023     Chaoqiong Xiao           Modified comment(s),          */
66 /*                                            added error checks support, */
67 /*                                            resulting in version 6.2.1  */
68 /*                                                                        */
69 /**************************************************************************/
70 
71 #ifndef UX_DEVICE_CLASS_AUDIO_H
72 #define UX_DEVICE_CLASS_AUDIO_H
73 
74 /* Determine if a C++ compiler is being used.  If so, ensure that standard
75    C is used to process the API information.  */
76 
77 #ifdef   __cplusplus
78 
79 /* Yes, C++ compiler is present.  Use standard C.  */
80 extern   "C" {
81 
82 #endif
83 
84 
85 /* Compile option: if defined, audio feedback endpoint is supported.  */
86 /* #define UX_DEVICE_CLASS_AUDIO_FEEDBACK_SUPPORT  */
87 
88 /* Compile option: if defined, audio interrupt endpoint is supported.  */
89 /* #define UX_DEVICE_CLASS_AUDIO_INTERRUPT_SUPPORT  */
90 
91 /* Internal option: enable the basic USBX error checking. This define is typically used
92    while debugging application.  */
93 #if defined(UX_ENABLE_ERROR_CHECKING) && !defined(UX_DEVICE_CLASS_AUDIO_ENABLE_ERROR_CHECKING)
94 #define UX_DEVICE_CLASS_AUDIO_ENABLE_ERROR_CHECKING
95 #endif
96 
97 
98 
99 /* Define Audio Class OS related constants.  */
100 #define UX_DEVICE_CLASS_AUDIO_FEEDBACK_THREAD_STACK_SIZE            UX_THREAD_STACK_SIZE
101 #define UX_DEVICE_CLASS_AUDIO_INTERRUPT_THREAD_STACK_SIZE           UX_THREAD_STACK_SIZE
102 
103 /* Define Audio Class function (AF) constants.  */
104 
105 #define UX_DEVICE_CLASS_AUDIO_FUNCTION_CLASS                        1
106 #define UX_DEVICE_CLASS_AUDIO_FUNCTION_SUBCLASS_UNDEFINED           0
107 #define UX_DEVICE_CLASS_AUDIO_FUNCTION_PROTOCOL_UNDEFINED           0
108 #define UX_DEVICE_CLASS_AUDIO_FUNCTION_PROTOCOL_VERSION_02_00       0x20
109 
110 /* Define Audio Class interface constants.  */
111 
112 #define UX_DEVICE_CLASS_AUDIO_CLASS                                 1
113 
114 #define UX_DEVICE_CLASS_AUDIO_SUBCLASS_UNDEFINED                    0
115 #define UX_DEVICE_CLASS_AUDIO_SUBCLASS_CONTROL                      1
116 #define UX_DEVICE_CLASS_AUDIO_SUBCLASS_AUDIOSTREAMING               2
117 #define UX_DEVICE_CLASS_AUDIO_SUBCLASS_MIDISTREAMING                3
118 
119 #define UX_DEVICE_CLASS_AUDIO_PROTOCOL_UNDEFINED                    0
120 #define UX_DEVICE_CLASS_AUTIO_PROTOCOL_VERSION_02_00                0x20
121 
122 
123 /* Define Audio Class-specific (CS) descriptor types.  */
124 
125 #define UX_DEVICE_CLASS_AUDIO_CS_UNDEFINED                          0x20
126 #define UX_DEVICE_CLASS_AUDIO_CS_DEVICE                             0x21
127 #define UX_DEVICE_CLASS_AUDIO_CS_CONFIGURATION                      0x22
128 #define UX_DEVICE_CLASS_AUDIO_CS_STRING                             0x23
129 #define UX_DEVICE_CLASS_AUDIO_CS_INTERFACE                          0x24
130 #define UX_DEVICE_CLASS_AUDIO_CS_ENDPOINT                           0x25
131 
132 
133 /* Define Audio Class specific AC interface descriptor subclasses.  */
134 
135 #define UX_DEVICE_CLASS_AUDIO_AC_UNDEFINED                          0x00
136 #define UX_DEVICE_CLASS_AUDIO_AC_HEADER                             0x01
137 #define UX_DEVICE_CLASS_AUDIO_AC_INPUT_TERMINAL                     0x02
138 #define UX_DEVICE_CLASS_AUDIO_AC_OUTPUT_TERMINAL                    0x03
139 #define UX_DEVICE_CLASS_AUDIO_AC_FEATURE_UNIT                       0x06
140 
141 
142 /* Define Audio Class specific AS interface descriptor subclasses.  */
143 
144 #define UX_DEVICE_CLASS_AUDIO_AS_UNDEFINED                          0x00
145 #define UX_DEVICE_CLASS_AUDIO_AS_GENERAL                            0x01
146 #define UX_DEVICE_CLASS_AUDIO_AS_FORMAT_TYPE                        0x02
147 
148 
149 /* Define Audio Class data endpoint descriptor attributes.  */
150 
151 #define UX_DEVICE_CLASS_AUDIO_EP_TRANSFER_TYPE_MASK                 (0x3u<<0)
152 #define UX_DEVICE_CLASS_AUDIO_EP_TRANSFER_TYPE_ISOCHRONOUS          (0x1u<<0)
153 
154 #define UX_DEVICE_CLASS_AUDIO_EP_SYNCHRONIZATION_TYPE_MASK          (0x3u<<2)
155 #define UX_DEVICE_CLASS_AUDIO_EP_SYNCHRONIZATION_TYPE_ASYNCHRONOUS  (0x1u<<2)
156 #define UX_DEVICE_CLASS_AUDIO_EP_SYNCHRONIZATION_TYPE_ADAPTIVE      (0x2u<<2)
157 #define UX_DEVICE_CLASS_AUDIO_EP_SYNCHRONIZATION_TYPE_SYNCHRONOUS   (0x3u<<2)
158 
159 #define UX_DEVICE_CLASS_AUDIO_EP_USAGE_TYPE_MASK                    (0x3u<<4)
160 #define UX_DEVICE_CLASS_AUDIO_EP_USAGE_TYPE_DATA                    (0x0u<<4)
161 #define UX_DEVICE_CLASS_AUDIO_EP_USAGE_TYPE_FEEDBACK                (0x1u<<4)
162 #define UX_DEVICE_CLASS_AUDIO_EP_USAGE_TYPE_IMPLICIT_FEEDBACK       (0x2u<<4)
163 
164 
165 /* Define Audio Class specific endpoint descriptor subtypes.  */
166 
167 #define UX_DEVICE_CLASS_AUDIO_EP_UNDEFINED                          0x00
168 #define UX_DEVICE_CLASS_AUDIO_EP_GENERAL                            0x01
169 
170 
171 /* Define Audio Class specific request codes.  */
172 
173 #define UX_DEVICE_CLASS_AUDIO_REQUEST_CODE_UNDEFINED                0x00
174 
175 #define UX_DEVICE_CLASS_AUDIO_bmRequestType_GET_INTERFACE           0xA1
176 #define UX_DEVICE_CLASS_AUDIO_bmRequestType_SET_INTERFACE           0x21
177 #define UX_DEVICE_CLASS_AUDIO_bmRequestType_GET_ENDPOINT            0xA2
178 #define UX_DEVICE_CLASS_AUDIO_bmRequestType_SET_ENDPOINT            0x22
179 
180 #define UX_DEVICE_CLASS_AUDIO_REQUEST_REQUEST_TYPE                  0
181 #define UX_DEVICE_CLASS_AUDIO_REQUEST_REQUEST                       1
182 
183 #define UX_DEVICE_CLASS_AUDIO_REQUEST_VALUE_LOW                     2
184 #define UX_DEVICE_CLASS_AUDIO_REQUEST_CHANNEL_NUMBER                2
185 #define UX_DEVICE_CLASS_AUDIO_REQUEST_CN                            2
186 #define UX_DEVICE_CLASS_AUDIO_REQUEST_MIXER_CONTROL_NUMBER          2
187 #define UX_DEVICE_CLASS_AUDIO_REQUEST_MCN                           2
188 
189 #define UX_DEVICE_CLASS_AUDIO_REQUEST_VALUE_HIGH                    3
190 #define UX_DEVICE_CLASS_AUDIO_REQUEST_CONTROL_SELECTOR              3
191 #define UX_DEVICE_CLASS_AUDIO_REQUEST_CS                            3
192 
193 #define UX_DEVICE_CLASS_AUDIO_REQUEST_INDEX_LOW                     4
194 #define UX_DEVICE_CLASS_AUDIO_REQUEST_ENDPOINT                      4
195 #define UX_DEVICE_CLASS_AUDIO_REQUEST_INTERFACE                     4
196 
197 #define UX_DEVICE_CLASS_AUDIO_REQUEST_INDEX_HIGH                    5
198 #define UX_DEVICE_CLASS_AUDIO_REQUEST_ENEITY_ID                     5
199 
200 #define UX_DEVICE_CLASS_AUDIO_REQUEST_LENGTH                        6
201 
202 
203 /* Define Audio Class terminal types.  */
204 
205 #define UX_DEVICE_CLASS_AUDIO_UNDEFINED                             0x0100
206 #define UX_DEVICE_CLASS_AUDIO_USB_STREAMING                         0x0101
207 #define UX_DEVICE_CLASS_AUDIO_USB_VENDOR_SPECIFIC                   0x01FF
208 
209 
210 /* Define Audio Class input terminal types.  */
211 
212 #define UX_DEVICE_CLASS_AUDIO_INPUT                                 0x0200
213 #define UX_DEVICE_CLASS_AUDIO_MICROPHONE                            0x0201
214 #define UX_DEVICE_CLASS_AUDIO_DESKTOP_MICROPHONE                    0x0202
215 #define UX_DEVICE_CLASS_AUDIO_PERSONAL_MICROPHONE                   0x0203
216 #define UX_DEVICE_CLASS_AUDIO_OMNI_DIRECTIONAL_MICROPHONE           0x0204
217 #define UX_DEVICE_CLASS_AUDIO_MICROPHONE_ARRAY                      0x0205
218 #define UX_DEVICE_CLASS_AUDIO_PROCESSING_MICROPHONE_ARRAY           0x0206
219 
220 
221 /* Define Audio Class output terminal types.  */
222 
223 #define UX_DEVICE_CLASS_AUDIO_OUTPUT                                0x0300
224 #define UX_DEVICE_CLASS_AUDIO_SPEAKER                               0x0301
225 #define UX_DEVICE_CLASS_AUDIO_HEADPHONES                            0x0302
226 #define UX_DEVICE_CLASS_AUDIO_HEAD_MOUNTED_DISPLAY                  0x0303
227 #define UX_DEVICE_CLASS_AUDIO_DESKTOP_SPEAKER                       0x0304
228 #define UX_DEVICE_CLASS_AUDIO_ROOM_SPEAKER                          0x0305
229 #define UX_DEVICE_CLASS_AUDIO_COMMUNICATION_SPEAKER                 0x0306
230 #define UX_DEVICE_CLASS_AUDIO_LOW_FREQUENCY_SPEAKER                 0x0307
231 
232 
233 /* Define Audio Class bidirectional terminal types.  */
234 
235 #define UX_DEVICE_CLASS_AUDIO_BIDIRECTIONAL_UNDEFINED               0x0400
236 #define UX_DEVICE_CLASS_AUDIO_HANDSET                               0x0401
237 #define UX_DEVICE_CLASS_AUDIO_HEADSET                               0x0402
238 #define UX_DEVICE_CLASS_AUDIO_SPEAKERPHONE                          0x0403
239 #define UX_DEVICE_CLASS_AUDIO_ECHO_SUPRESS_SPEAKERPHONE             0x0404
240 #define UX_DEVICE_CLASS_AUDIO_ECHO_CANCEL_SPEAKERPHONE              0x0405
241 
242 
243 /* Define Audio Class telephony terminal types.  */
244 
245 #define UX_DEVICE_CLASS_AUDIO_TELEPHONTY_UNDEFINED                  0x0500
246 #define UX_DEVICE_CLASS_AUDIO_PHONE_LINE                            0x0501
247 #define UX_DEVICE_CLASS_AUDIO_TELEPHONE                             0x0502
248 #define UX_DEVICE_CLASS_AUDIO_DOWN_LINE_PHONE                       0x0503
249 
250 
251 /* Define Audio Class external terminal types.  */
252 
253 #define UX_DEVICE_CLASS_AUDIO_EXTERNAL_UNDEFINED                    0x0600
254 #define UX_DEVICE_CLASS_AUDIO_ANALOG_CONNECTOR                      0x0601
255 #define UX_DEVICE_CLASS_AUDIO_DIGITAL_AUDIO_INTERFACE               0x0602
256 #define UX_DEVICE_CLASS_AUDIO_LINE_CONNECTOR                        0x0603
257 #define UX_DEVICE_CLASS_AUDIO_LEGACY_AUDIO_CONNECTOR                0x0604
258 #define UX_DEVICE_CLASS_AUDIO_S_PDIF_INTERFACE                      0x0605
259 #define UX_DEVICE_CLASS_AUDIO_1394_DA_STREAM                        0x0606
260 #define UX_DEVICE_CLASS_AUDIO_1394_DV_STREAM_SOUNDTRACK             0x0607
261 #define UX_DEVICE_CLASS_AUDIO_ADAT_LIGHTPIPE                        0x0608
262 #define UX_DEVICE_CLASS_AUDIO_TDIF                                  0x0609
263 #define UX_DEVICE_CLASS_AUDIO_MADI                                  0x060A
264 
265 
266 /* Define Audio Class embedded function terminal types.  */
267 
268 #define UX_DEVICE_CLASS_AUDIO_EMBEDDED_UNDEFINED                    0x0700
269 #define UX_DEVICE_CLASS_AUDIO_EMBEDDED_LEVEL_CALIB_NOISE_SRC        0x0701
270 #define UX_DEVICE_CLASS_AUDIO_EMBEDDED_EQUALIZATION_NOISE           0x0702
271 #define UX_DEVICE_CLASS_AUDIO_EMBEDDED_CD_PLAYER                    0x0703
272 #define UX_DEVICE_CLASS_AUDIO_EMBEDDED_DAT                          0x0704
273 #define UX_DEVICE_CLASS_AUDIO_EMBEDDED_DCC                          0x0705
274 #define UX_DEVICE_CLASS_AUDIO_EMBEDDED_MINIDISK                     0x0706
275 #define UX_DEVICE_CLASS_AUDIO_EMBEDDED_ANALOG_TAPE                  0x0707
276 #define UX_DEVICE_CLASS_AUDIO_EMBEDDED_PHONOGRAPH                   0x0708
277 #define UX_DEVICE_CLASS_AUDIO_EMBEDDED_VCR_AUDIO                    0x0709
278 #define UX_DEVICE_CLASS_AUDIO_EMBEDDED_VIDEO_DISC_AUDIO             0x070A
279 #define UX_DEVICE_CLASS_AUDIO_EMBEDDED_DVD_AUDIO                    0x070B
280 #define UX_DEVICE_CLASS_AUDIO_EMBEDDED_TV_TUNER_AUDIO               0x070C
281 #define UX_DEVICE_CLASS_AUDIO_EMBEDDED_SATELLITE_RECEIVER_AUDIO     0x070D
282 #define UX_DEVICE_CLASS_AUDIO_EMBEDDED_CABLE_TUNER_AUDIO            0x070E
283 #define UX_DEVICE_CLASS_AUDIO_EMBEDDED_DSS_AUDIO                    0x070F
284 #define UX_DEVICE_CLASS_AUDIO_EMBEDDED_RADIO_RECEIVER               0x0710
285 #define UX_DEVICE_CLASS_AUDIO_EMBEDDED_RADIO_TRANSMITTER            0x0711
286 #define UX_DEVICE_CLASS_AUDIO_EMBEDDED_MULTI_TRACK_RECORDER         0x0712
287 #define UX_DEVICE_CLASS_AUDIO_EMBEDDED_SYNTHESIZER                  0x0713
288 #define UX_DEVICE_CLASS_AUDIO_EMBEDDED_PIANO                        0x0714
289 #define UX_DEVICE_CLASS_AUDIO_EMBEDDED_GUITAR                       0x0715
290 #define UX_DEVICE_CLASS_AUDIO_EMBEDDED_DRUMS_RHYTHM                 0x0716
291 #define UX_DEVICE_CLASS_AUDIO_EMBEDDED_OTHER                        0x0717
292 
293 
294 /* Define Audio Class encoding format types.  */
295 
296 #define UX_DEVICE_CLASS_AUDIO_FORMAT_TYPE_UNDEFINED                 0
297 #define UX_DEVICE_CLASS_AUDIO_FORMAT_TYPE_I                         1
298 #define UX_DEVICE_CLASS_AUDIO_FORMAT_TYPE_II                        2
299 #define UX_DEVICE_CLASS_AUDIO_FORMAT_TYPE_III                       3
300 #define UX_DEVICE_CLASS_AUDIO_FORMAT_TYPE_IV                        4
301 #define UX_DEVICE_CLASS_AUDIO_EXT_FORMAT_TYPE_I                     0x81
302 #define UX_DEVICE_CLASS_AUDIO_EXT_FORMAT_TYPE_II                    0x82
303 #define UX_DEVICE_CLASS_AUDIO_EXT_FORMAT_TYPE_III                   0x83
304 
305 
306 /* Define channels.  */
307 
308 #define UX_DEVICE_CLASS_AUDIO_MASTER_CHANNEL                        0
309 #define UX_DEVICE_CLASS_AUDIO_CHANNEL_1                             1
310 #define UX_DEVICE_CLASS_AUDIO_CHANNEL_2                             2
311 #define UX_DEVICE_CLASS_AUDIO_CHANNEL_3                             3
312 #define UX_DEVICE_CLASS_AUDIO_CHANNEL_4                             4
313 #define UX_DEVICE_CLASS_AUDIO_CHANNEL_5                             5
314 #define UX_DEVICE_CLASS_AUDIO_CHANNEL_6                             6
315 #define UX_DEVICE_CLASS_AUDIO_CHANNEL_7                             7
316 #define UX_DEVICE_CLASS_AUDIO_CHANNEL_8                             8
317 #define UX_DEVICE_CLASS_AUDIO_CHANNEL_9                             9
318 
319 
320 /* Define IOCTL code.
321      ux_device_class_audio_ioctl(audio, IOCTL_CODE, parameter).
322  */
323 
324 #define UX_DEVICE_CLASS_AUDIO_IOCTL_GET_ARG                         1
325 
326 /* Define Audio Class Task states.  */
327 #define UX_DEVICE_CLASS_AUDIO_INTERRUPT_STOP            (UX_STATE_RESET)
328 #define UX_DEVICE_CLASS_AUDIO_INTERRUPT_START           (UX_STATE_STEP + 1)
329 #define UX_DEVICE_CLASS_AUDIO_INTERRUPT_WAIT            (UX_STATE_STEP + 2)
330 
331 #define UX_DEVICE_CLASS_AUDIO_STREAM_RW_STOP            (UX_STATE_RESET)
332 #define UX_DEVICE_CLASS_AUDIO_STREAM_RW_START           (UX_STATE_STEP + 1)
333 #define UX_DEVICE_CLASS_AUDIO_STREAM_RW_WAIT            (UX_STATE_STEP + 2)
334 
335 #define UX_DEVICE_CLASS_AUDIO_STREAM_FEEDBACK_RW_STOP   (UX_STATE_RESET)
336 #define UX_DEVICE_CLASS_AUDIO_STREAM_FEEDBACK_RW_WAIT   (UX_STATE_STEP + 1)
337 
338 /* Define Audio Class callback structure.  */
339 
340 struct UX_DEVICE_CLASS_AUDIO_STREAM_STRUCT;
341 struct UX_DEVICE_CLASS_AUDIO_STRUCT;
342 
343 typedef struct UX_DEVICE_CLASS_AUDIO_CALLBACKS_STRUCT
344 {
345 
346     VOID        (*ux_slave_class_audio_instance_activate)(VOID *);
347     VOID        (*ux_slave_class_audio_instance_deactivate)(VOID *);
348     UINT        (*ux_device_class_audio_control_process)(struct UX_DEVICE_CLASS_AUDIO_STRUCT *, UX_SLAVE_TRANSFER *);
349     VOID         *ux_device_class_audio_arg;
350 } UX_DEVICE_CLASS_AUDIO_CALLBACKS;
351 
352 typedef struct UX_DEVICE_CLASS_AUDIO_STREAM_CALLBACKS_STRUCT
353 {
354     VOID        (*ux_device_class_audio_stream_change)(struct UX_DEVICE_CLASS_AUDIO_STREAM_STRUCT *, ULONG);
355     VOID        (*ux_device_class_audio_stream_frame_done)(struct UX_DEVICE_CLASS_AUDIO_STREAM_STRUCT *, ULONG);
356 } UX_DEVICE_CLASS_AUDIO_STREAM_CALLBACKS;
357 
358 
359 /* Define Audio Class Calling Parameter structure */
360 
361 typedef struct UX_DEVICE_CLASS_AUDIO_STREAM_PARAMETER_STRUCT
362 {
363 #if !defined(UX_DEVICE_STANDALONE)
364     ULONG                                         ux_device_class_audio_stream_parameter_thread_stack_size;
365     VOID                                        (*ux_device_class_audio_stream_parameter_thread_entry)(ULONG id);
366 #else
367     UINT                                        (*ux_device_class_audio_stream_parameter_task_function)(struct UX_DEVICE_CLASS_AUDIO_STREAM_STRUCT*);
368 #endif
369 
370 #if defined(UX_DEVICE_CLASS_AUDIO_FEEDBACK_SUPPORT)
371 #if !defined(UX_DEVICE_STANDALONE)
372     ULONG                                         ux_device_class_audio_stream_parameter_feedback_thread_stack_size;
373     VOID                                        (*ux_device_class_audio_stream_parameter_feedback_thread_entry)(ULONG id);
374 #else
375     UINT                                        (*ux_device_class_audio_stream_parameter_feedback_task_function)(struct UX_DEVICE_CLASS_AUDIO_STREAM_STRUCT*);
376 #endif
377 #endif
378     UX_DEVICE_CLASS_AUDIO_STREAM_CALLBACKS        ux_device_class_audio_stream_parameter_callbacks;
379 
380     ULONG                                         ux_device_class_audio_stream_parameter_max_frame_buffer_size;
381     ULONG                                         ux_device_class_audio_stream_parameter_max_frame_buffer_nb;
382 } UX_DEVICE_CLASS_AUDIO_STREAM_PARAMETER;
383 
384 typedef struct UX_DEVICE_CLASS_AUDIO_PARAMETER_STRUCT
385 {
386     ULONG                                         ux_device_class_audio_parameter_master_interface;
387     UX_DEVICE_CLASS_AUDIO_CALLBACKS               ux_device_class_audio_parameter_callbacks;
388 
389     ULONG                                         ux_device_class_audio_parameter_streams_nb;
390     UX_DEVICE_CLASS_AUDIO_STREAM_PARAMETER       *ux_device_class_audio_parameter_streams;
391 
392 #if defined(UX_DEVICE_CLASS_AUDIO_INTERRUPT_SUPPORT)
393     ULONG                                         ux_device_class_audio_parameter_status_size;
394     ULONG                                         ux_device_class_audio_parameter_status_queue_size;
395 #endif
396 } UX_DEVICE_CLASS_AUDIO_PARAMETER;
397 
398 
399 /* Define Audio Class instance structure.  */
400 
401 typedef struct UX_DEVICE_CLASS_AUDIO_FRAME_STRUCT
402 {
403 
404     ULONG                                   ux_device_class_audio_frame_length;
405     ULONG                                   ux_device_class_audio_frame_pos;
406     UCHAR                                   ux_device_class_audio_frame_data[4];
407 } UX_DEVICE_CLASS_AUDIO_FRAME;
408 
409 typedef struct UX_DEVICE_CLASS_AUDIO_STREAM_STRUCT
410 {
411 
412     struct UX_DEVICE_CLASS_AUDIO_STRUCT     *ux_device_class_audio_stream_audio;
413     UX_SLAVE_INTERFACE                      *ux_device_class_audio_stream_interface;
414     UX_SLAVE_ENDPOINT                       *ux_device_class_audio_stream_endpoint;
415 
416 #if defined(UX_DEVICE_CLASS_AUDIO_FEEDBACK_SUPPORT)
417     UX_SLAVE_ENDPOINT                       *ux_device_class_audio_stream_feedback;
418 
419 #if !defined(UX_DEVICE_STANDALONE)
420     UCHAR                                   *ux_device_class_audio_stream_feedback_thread_stack;
421     UX_THREAD                                ux_device_class_audio_stream_feedback_thread;
422 #else
423     UINT                                   (*ux_device_class_audio_stream_feedback_task_function)(struct UX_DEVICE_CLASS_AUDIO_STREAM_STRUCT*);
424     UINT                                     ux_device_class_audio_stream_feedback_task_state;
425     UINT                                     ux_device_class_audio_stream_feedback_task_status;
426 #endif
427 #endif
428 
429     UX_DEVICE_CLASS_AUDIO_STREAM_CALLBACKS   ux_device_class_audio_stream_callbacks;
430 
431 #if !defined(UX_DEVICE_STANDALONE)
432     UCHAR                                   *ux_device_class_audio_stream_thread_stack;
433     UX_THREAD                                ux_device_class_audio_stream_thread;
434 #else
435     UINT                                   (*ux_device_class_audio_stream_task_function)(struct UX_DEVICE_CLASS_AUDIO_STREAM_STRUCT*);
436     UINT                                     ux_device_class_audio_stream_task_state;
437     UINT                                     ux_device_class_audio_stream_task_status;
438 #endif
439 
440     UCHAR                                   *ux_device_class_audio_stream_buffer;
441     ULONG                                    ux_device_class_audio_stream_buffer_size;
442     ULONG                                    ux_device_class_audio_stream_frame_buffer_size;
443     ULONG                                    ux_device_class_audio_stream_buffer_error_count;
444 
445     UX_DEVICE_CLASS_AUDIO_FRAME             *ux_device_class_audio_stream_transfer_pos;
446     UX_DEVICE_CLASS_AUDIO_FRAME             *ux_device_class_audio_stream_access_pos;
447 } UX_DEVICE_CLASS_AUDIO_STREAM;
448 
449 typedef struct UX_DEVICE_CLASS_AUDIO_STRUCT
450 {
451 
452     UX_SLAVE_CLASS                          *ux_device_class_audio_class;
453     UX_SLAVE_DEVICE                         *ux_device_class_audio_device;
454     UX_SLAVE_INTERFACE                      *ux_device_class_audio_interface;
455 
456     UX_DEVICE_CLASS_AUDIO_CALLBACKS          ux_device_class_audio_callbacks;
457 
458     ULONG                                    ux_device_class_audio_streams_nb;
459     UX_DEVICE_CLASS_AUDIO_STREAM            *ux_device_class_audio_streams;
460 
461 #if defined(UX_DEVICE_CLASS_AUDIO_INTERRUPT_SUPPORT)
462     UX_SLAVE_ENDPOINT                       *ux_device_class_audio_interrupt;
463 
464     ULONG                                   ux_device_class_audio_status_size;       /* in Bytes.  */
465     ULONG                                   ux_device_class_audio_status_queue_bytes;/* in Bytes.  */
466     ULONG                                   ux_device_class_audio_status_queued;     /* in Bytes.  */
467     UCHAR                                   *ux_device_class_audio_status_queue;     /* in Bytes.  */
468     UCHAR                                   *ux_device_class_audio_status_head;
469     UCHAR                                   *ux_device_class_audio_status_tail;
470 
471 #if !defined(UX_DEVICE_STANDALONE)
472     UX_SEMAPHORE                            ux_device_class_audio_status_semaphore;
473     UX_MUTEX                                ux_device_class_audio_status_mutex;
474 #else
475     UINT                                    ux_device_class_audio_interrupt_task_state;
476     UINT                                    ux_device_class_audio_interrupt_task_status;
477 #endif
478 #endif
479 } UX_DEVICE_CLASS_AUDIO;
480 
481 
482 /* Define Audio Class function prototypes.  */
483 
484 UINT    _ux_device_class_audio_initialize(UX_SLAVE_CLASS_COMMAND *command);
485 UINT    _ux_device_class_audio_uninitialize(UX_SLAVE_CLASS_COMMAND *command);
486 UINT    _ux_device_class_audio_activate(UX_SLAVE_CLASS_COMMAND *command);
487 UINT    _ux_device_class_audio_change(UX_SLAVE_CLASS_COMMAND *command);
488 UINT    _ux_device_class_audio_deactivate(UX_SLAVE_CLASS_COMMAND *command);
489 UINT    _ux_device_class_audio_control_request(UX_SLAVE_CLASS_COMMAND *command);
490 
491 UINT    _ux_device_class_audio_entry(UX_SLAVE_CLASS_COMMAND *command);
492 
493 UINT    _ux_device_class_audio_ioctl(UX_DEVICE_CLASS_AUDIO *audio, ULONG ioctl_function,
494                                      VOID *parameter);
495 
496 UINT    _ux_device_class_audio_stream_get(UX_DEVICE_CLASS_AUDIO *audio, ULONG stream_index, UX_DEVICE_CLASS_AUDIO_STREAM **stream);
497 
498 VOID    _ux_device_class_audio_write_thread_entry(ULONG audio_stream);
499 VOID    _ux_device_class_audio_read_thread_entry(ULONG audio_stream);
500 UINT    _ux_device_class_audio_write_task_function(UX_DEVICE_CLASS_AUDIO_STREAM *stream);
501 UINT    _ux_device_class_audio_read_task_function(UX_DEVICE_CLASS_AUDIO_STREAM *stream);
502 UINT    _ux_device_class_audio_reception_start(UX_DEVICE_CLASS_AUDIO_STREAM *audio);
503 UINT    _ux_device_class_audio_sample_read8(UX_DEVICE_CLASS_AUDIO_STREAM *audio, UCHAR *sample);
504 UINT    _ux_device_class_audio_sample_read16(UX_DEVICE_CLASS_AUDIO_STREAM *audio, USHORT *sample);
505 UINT    _ux_device_class_audio_sample_read24(UX_DEVICE_CLASS_AUDIO_STREAM *audio, ULONG *sample);
506 UINT    _ux_device_class_audio_sample_read32(UX_DEVICE_CLASS_AUDIO_STREAM *audio, ULONG *sample);
507 
508 UINT    _ux_device_class_audio_read_frame_get(UX_DEVICE_CLASS_AUDIO_STREAM *audio, UCHAR **frame_data, ULONG *frame_length);
509 UINT    _ux_device_class_audio_read_frame_free(UX_DEVICE_CLASS_AUDIO_STREAM *audio);
510 
511 UINT    _ux_device_class_audio_transmission_start(UX_DEVICE_CLASS_AUDIO_STREAM *audio);
512 UINT    _ux_device_class_audio_frame_write(UX_DEVICE_CLASS_AUDIO_STREAM *audio, UCHAR *frame, ULONG length);
513 
514 UINT    _ux_device_class_audio_write_frame_get(UX_DEVICE_CLASS_AUDIO_STREAM *audio, UCHAR **buffer, ULONG *max_length);
515 UINT    _ux_device_class_audio_write_frame_commit(UX_DEVICE_CLASS_AUDIO_STREAM *audio, ULONG length);
516 
517 VOID    _ux_device_class_audio_feedback_thread_entry(ULONG audio_stream);
518 UINT    _ux_device_class_audio_feedback_task_function(UX_DEVICE_CLASS_AUDIO_STREAM *stream);
519 UINT    _ux_device_class_audio_feedback_set(UX_DEVICE_CLASS_AUDIO_STREAM *audio, UCHAR *encoded_feedback);
520 UINT    _ux_device_class_audio_feedback_get(UX_DEVICE_CLASS_AUDIO_STREAM *audio, UCHAR *encoded_feedback);
521 ULONG   _ux_device_class_audio_speed_get(UX_DEVICE_CLASS_AUDIO_STREAM *audio);
522 
523 VOID    _ux_device_class_audio_interrupt_thread_entry(ULONG audio_inst);
524 UINT    _ux_device_class_audio_interrupt_task_function(UX_DEVICE_CLASS_AUDIO *audio);
525 UINT    _ux_device_class_audio_interrupt_send(UX_DEVICE_CLASS_AUDIO *audio, UCHAR *int_data);
526 
527 UINT    _ux_device_class_audio_tasks_run(VOID *instance);
528 
529 
530 UINT    _uxe_device_class_audio_initialize(UX_SLAVE_CLASS_COMMAND *command);
531 
532 UINT    _uxe_device_class_audio_ioctl(UX_DEVICE_CLASS_AUDIO *audio, ULONG ioctl_function,
533                                      VOID *parameter);
534 
535 UINT    _uxe_device_class_audio_stream_get(UX_DEVICE_CLASS_AUDIO *audio, ULONG stream_index, UX_DEVICE_CLASS_AUDIO_STREAM **stream);
536 
537 VOID    _uxe_device_class_audio_write_thread_entry(ULONG audio_stream);
538 VOID    _uxe_device_class_audio_read_thread_entry(ULONG audio_stream);
539 UINT    _uxe_device_class_audio_write_task_function(UX_DEVICE_CLASS_AUDIO_STREAM *stream);
540 UINT    _uxe_device_class_audio_read_task_function(UX_DEVICE_CLASS_AUDIO_STREAM *stream);
541 UINT    _uxe_device_class_audio_reception_start(UX_DEVICE_CLASS_AUDIO_STREAM *audio);
542 UINT    _uxe_device_class_audio_sample_read8(UX_DEVICE_CLASS_AUDIO_STREAM *audio, UCHAR *sample);
543 UINT    _uxe_device_class_audio_sample_read16(UX_DEVICE_CLASS_AUDIO_STREAM *audio, USHORT *sample);
544 UINT    _uxe_device_class_audio_sample_read24(UX_DEVICE_CLASS_AUDIO_STREAM *audio, ULONG *sample);
545 UINT    _uxe_device_class_audio_sample_read32(UX_DEVICE_CLASS_AUDIO_STREAM *audio, ULONG *sample);
546 
547 UINT    _uxe_device_class_audio_read_frame_get(UX_DEVICE_CLASS_AUDIO_STREAM *audio, UCHAR **frame_data, ULONG *frame_length);
548 UINT    _uxe_device_class_audio_read_frame_free(UX_DEVICE_CLASS_AUDIO_STREAM *audio);
549 
550 UINT    _uxe_device_class_audio_transmission_start(UX_DEVICE_CLASS_AUDIO_STREAM *audio);
551 UINT    _uxe_device_class_audio_frame_write(UX_DEVICE_CLASS_AUDIO_STREAM *audio, UCHAR *frame, ULONG length);
552 
553 UINT    _uxe_device_class_audio_write_frame_get(UX_DEVICE_CLASS_AUDIO_STREAM *audio, UCHAR **buffer, ULONG *max_length);
554 UINT    _uxe_device_class_audio_write_frame_commit(UX_DEVICE_CLASS_AUDIO_STREAM *audio, ULONG length);
555 
556 UINT    _uxe_device_class_audio_feedback_set(UX_DEVICE_CLASS_AUDIO_STREAM *audio, UCHAR *encoded_feedback);
557 UINT    _uxe_device_class_audio_feedback_get(UX_DEVICE_CLASS_AUDIO_STREAM *audio, UCHAR *encoded_feedback);
558 ULONG   _uxe_device_class_audio_speed_get(UX_DEVICE_CLASS_AUDIO_STREAM *audio);
559 
560 VOID    _uxe_device_class_audio_interrupt_thread_entry(ULONG audio_inst);
561 UINT    _uxe_device_class_audio_interrupt_task_function(UX_DEVICE_CLASS_AUDIO *audio);
562 UINT    _uxe_device_class_audio_interrupt_send(UX_DEVICE_CLASS_AUDIO *audio, UCHAR *int_data);
563 
564 
565 /* Define Device Class Audio API prototypes.  */
566 
567 #if defined(UX_DEVICE_CLASS_AUDIO_ENABLE_ERROR_CHECKING)
568 
569 #define ux_device_class_audio_entry                   _ux_device_class_audio_entry
570 
571 #define ux_device_class_audio_read_thread_entry       _ux_device_class_audio_read_thread_entry
572 #define ux_device_class_audio_write_thread_entry      _ux_device_class_audio_write_thread_entry
573 
574 #define ux_device_class_audio_read_task_function      _ux_device_class_audio_read_task_function
575 #define ux_device_class_audio_write_task_function     _ux_device_class_audio_write_task_function
576 
577 #define ux_device_class_audio_stream_get              _uxe_device_class_audio_stream_get
578 
579 #define ux_device_class_audio_reception_start         _uxe_device_class_audio_reception_start
580 #define ux_device_class_audio_sample_read8            _uxe_device_class_audio_sample_read8
581 #define ux_device_class_audio_sample_read16           _uxe_device_class_audio_sample_read16
582 #define ux_device_class_audio_sample_read24           _uxe_device_class_audio_sample_read24
583 #define ux_device_class_audio_sample_read32           _uxe_device_class_audio_sample_read32
584 
585 #define ux_device_class_audio_read_frame_get          _uxe_device_class_audio_read_frame_get
586 #define ux_device_class_audio_read_frame_free         _uxe_device_class_audio_read_frame_free
587 
588 #define ux_device_class_audio_transmission_start      _uxe_device_class_audio_transmission_start
589 #define ux_device_class_audio_frame_write             _uxe_device_class_audio_frame_write
590 
591 #define ux_device_class_audio_write_frame_get         _uxe_device_class_audio_write_frame_get
592 #define ux_device_class_audio_write_frame_commit      _uxe_device_class_audio_write_frame_commit
593 
594 #define ux_device_class_audio_ioctl                   _uxe_device_class_audio_ioctl
595 
596 #define ux_device_class_audio_speed_get               _ux_device_class_audio_speed_get
597 #define ux_device_class_audio_feedback_thread_entry   _ux_device_class_audio_feedback_thread_entry
598 #define ux_device_class_audio_feedback_task_function  _ux_device_class_audio_feedback_task_function
599 #define ux_device_class_audio_feedback_get            _uxe_device_class_audio_feedback_get
600 #define ux_device_class_audio_feedback_set            _uxe_device_class_audio_feedback_set
601 
602 #define ux_device_class_audio_interrupt_send          _uxe_device_class_audio_interrupt_send
603 
604 #else
605 
606 #define ux_device_class_audio_entry                   _ux_device_class_audio_entry
607 
608 #define ux_device_class_audio_read_thread_entry       _ux_device_class_audio_read_thread_entry
609 #define ux_device_class_audio_write_thread_entry      _ux_device_class_audio_write_thread_entry
610 
611 #define ux_device_class_audio_read_task_function      _ux_device_class_audio_read_task_function
612 #define ux_device_class_audio_write_task_function     _ux_device_class_audio_write_task_function
613 
614 #define ux_device_class_audio_stream_get              _ux_device_class_audio_stream_get
615 
616 #define ux_device_class_audio_reception_start         _ux_device_class_audio_reception_start
617 #define ux_device_class_audio_sample_read8            _ux_device_class_audio_sample_read8
618 #define ux_device_class_audio_sample_read16           _ux_device_class_audio_sample_read16
619 #define ux_device_class_audio_sample_read24           _ux_device_class_audio_sample_read24
620 #define ux_device_class_audio_sample_read32           _ux_device_class_audio_sample_read32
621 
622 #define ux_device_class_audio_read_frame_get          _ux_device_class_audio_read_frame_get
623 #define ux_device_class_audio_read_frame_free         _ux_device_class_audio_read_frame_free
624 
625 #define ux_device_class_audio_transmission_start      _ux_device_class_audio_transmission_start
626 #define ux_device_class_audio_frame_write             _ux_device_class_audio_frame_write
627 
628 #define ux_device_class_audio_write_frame_get         _ux_device_class_audio_write_frame_get
629 #define ux_device_class_audio_write_frame_commit      _ux_device_class_audio_write_frame_commit
630 
631 #define ux_device_class_audio_ioctl                   _ux_device_class_audio_ioctl
632 
633 #define ux_device_class_audio_speed_get               _ux_device_class_audio_speed_get
634 #define ux_device_class_audio_feedback_thread_entry   _ux_device_class_audio_feedback_thread_entry
635 #define ux_device_class_audio_feedback_task_function  _ux_device_class_audio_feedback_task_function
636 #define ux_device_class_audio_feedback_get            _ux_device_class_audio_feedback_get
637 #define ux_device_class_audio_feedback_set            _ux_device_class_audio_feedback_set
638 
639 #define ux_device_class_audio_interrupt_send          _ux_device_class_audio_interrupt_send
640 
641 #endif
642 
643 /* Determine if a C++ compiler is being used.  If so, complete the standard
644    C conditional started above.  */
645 #ifdef __cplusplus
646 }
647 #endif
648 
649 #endif /* ifndef UX_DEVICE_CLASS_AUDIO_H */
650