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 /** USBX Component                                                        */
16 /**                                                                       */
17 /**   Device Audio Class                                                  */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 #define UX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "ux_api.h"
28 #include "ux_device_class_audio.h"
29 #include "ux_device_stack.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _ux_device_class_audio_stream_get                   PORTABLE C      */
37 /*                                                           6.2.1        */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Chaoqiong Xiao, Microsoft Corporation                               */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function get the stream instance of Audio class.               */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    audio                                 Address of audio class        */
49 /*                                            instance                    */
50 /*    stream_index                          Stream instance index 0 based */
51 /*    stream                                Pointer to buffer to fill     */
52 /*                                            pointer to stream instance  */
53 /*                                                                        */
54 /*  OUTPUT                                                                */
55 /*                                                                        */
56 /*    Completion Status                                                   */
57 /*                                                                        */
58 /*  CALLS                                                                 */
59 /*                                                                        */
60 /*                                                                        */
61 /*  CALLED BY                                                             */
62 /*                                                                        */
63 /*    Application                                                         */
64 /*                                                                        */
65 /*  RELEASE HISTORY                                                       */
66 /*                                                                        */
67 /*    DATE              NAME                      DESCRIPTION             */
68 /*                                                                        */
69 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
70 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
71 /*                                            resulting in version 6.1    */
72 /*  01-31-2022     Chaoqiong Xiao           Modified comment(s),          */
73 /*                                            resulting in version 6.1.10 */
74 /*  03-08-2023     Chaoqiong Xiao           Modified comment(s),          */
75 /*                                            added error checks support, */
76 /*                                            resulting in version 6.2.1  */
77 /*                                                                        */
78 /**************************************************************************/
_ux_device_class_audio_stream_get(UX_DEVICE_CLASS_AUDIO * audio,ULONG stream_index,UX_DEVICE_CLASS_AUDIO_STREAM ** stream)79 UINT    _ux_device_class_audio_stream_get(UX_DEVICE_CLASS_AUDIO *audio,
80         ULONG stream_index, UX_DEVICE_CLASS_AUDIO_STREAM **stream)
81 {
82 
83     /* Store the stream instance found.  */
84     *stream = audio -> ux_device_class_audio_streams + stream_index;
85 
86     /* Return completion status.  */
87     return(UX_SUCCESS);
88 }
89 
90 /**************************************************************************/
91 /*                                                                        */
92 /*  FUNCTION                                               RELEASE        */
93 /*                                                                        */
94 /*    _uxe_device_class_audio_stream_get                  PORTABLE C      */
95 /*                                                           6.2.1        */
96 /*  AUTHOR                                                                */
97 /*                                                                        */
98 /*    Chaoqiong Xiao, Microsoft Corporation                               */
99 /*                                                                        */
100 /*  DESCRIPTION                                                           */
101 /*                                                                        */
102 /*    This function checks errors in stream instance getting function.    */
103 /*                                                                        */
104 /*  INPUT                                                                 */
105 /*                                                                        */
106 /*    audio                                 Address of audio class        */
107 /*                                            instance                    */
108 /*    stream_index                          Stream instance index 0 based */
109 /*    stream                                Pointer to buffer to fill     */
110 /*                                            pointer to stream instance  */
111 /*                                                                        */
112 /*  OUTPUT                                                                */
113 /*                                                                        */
114 /*    Completion Status                                                   */
115 /*                                                                        */
116 /*  CALLS                                                                 */
117 /*                                                                        */
118 /*    _ux_device_class_audio_stream_get     Get stream instance           */
119 /*                                                                        */
120 /*  CALLED BY                                                             */
121 /*                                                                        */
122 /*    Application                                                         */
123 /*                                                                        */
124 /*  RELEASE HISTORY                                                       */
125 /*                                                                        */
126 /*    DATE              NAME                      DESCRIPTION             */
127 /*                                                                        */
128 /*  03-08-2023     Chaoqiong Xiao           Initial Version 6.2.1         */
129 /*                                                                        */
130 /**************************************************************************/
_uxe_device_class_audio_stream_get(UX_DEVICE_CLASS_AUDIO * audio,ULONG stream_index,UX_DEVICE_CLASS_AUDIO_STREAM ** stream)131 UINT    _uxe_device_class_audio_stream_get(UX_DEVICE_CLASS_AUDIO *audio,
132         ULONG stream_index, UX_DEVICE_CLASS_AUDIO_STREAM **stream)
133 {
134 
135     /* Sanity check.  */
136     if (audio == UX_NULL)
137         return(UX_INVALID_PARAMETER);
138 
139     /* Index validation.  */
140     if (stream_index >= audio -> ux_device_class_audio_streams_nb)
141         return(UX_INVALID_PARAMETER);
142 
143     /* Store the stream instance found.  */
144     if (stream == UX_NULL)
145         return(UX_INVALID_PARAMETER);
146 
147     /* Get audio stream instance.  */
148     return(_ux_device_class_audio_stream_get(audio, stream_index, stream));
149 }
150