1 /***************************************************************************
2  * Copyright (c) 2024 Microsoft Corporation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the MIT License which is available at
6  * https://opensource.org/licenses/MIT.
7  *
8  * SPDX-License-Identifier: MIT
9  **************************************************************************/
10 
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /** USBX Component                                                        */
16 /**                                                                       */
17 /**   Audio Class                                                         */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 
23 /* Include necessary system files.  */
24 
25 #define UX_SOURCE_CODE
26 
27 #include "ux_api.h"
28 #include "ux_host_class_audio.h"
29 #include "ux_host_stack.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _ux_host_class_audio_entry                          PORTABLE C      */
37 /*                                                           6.1.12       */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Chaoqiong Xiao, Microsoft Corporation                               */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function is the entry point of the Audio class. It will be     */
45 /*    called by the USBX stack enumeration module when there is a new     */
46 /*    audio device (speaker, microphone ...) on the bus or when the audio */
47 /*    device is removed.                                                  */
48 /*                                                                        */
49 /*  INPUT                                                                 */
50 /*                                                                        */
51 /*    command                               Pointer to command            */
52 /*                                                                        */
53 /*  OUTPUT                                                                */
54 /*                                                                        */
55 /*    Completion Status                                                   */
56 /*                                                                        */
57 /*  CALLS                                                                 */
58 /*                                                                        */
59 /*    _ux_host_class_audio_activate         Activate audio class          */
60 /*    _ux_host_class_audio_deactivate       Deactivate audio class        */
61 /*                                                                        */
62 /*  CALLED BY                                                             */
63 /*                                                                        */
64 /*    Host Stack                                                          */
65 /*                                                                        */
66 /*  RELEASE HISTORY                                                       */
67 /*                                                                        */
68 /*    DATE              NAME                      DESCRIPTION             */
69 /*                                                                        */
70 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
71 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
72 /*                                            resulting in version 6.1    */
73 /*  07-29-2022     Chaoqiong Xiao           Modified comment(s),          */
74 /*                                            added audio 2.0 support,    */
75 /*                                            resulting in version 6.1.12 */
76 /*                                                                        */
77 /**************************************************************************/
_ux_host_class_audio_entry(UX_HOST_CLASS_COMMAND * command)78 UINT  _ux_host_class_audio_entry(UX_HOST_CLASS_COMMAND *command)
79 {
80 
81 UINT        status;
82 
83 
84     /* The command request will tell us we need to do here, either a enumeration
85        query, an activation or a deactivation.  */
86     switch (command -> ux_host_class_command_request)
87     {
88 
89 
90     case UX_HOST_CLASS_COMMAND_QUERY:
91 
92         /* The query command is used to let the stack enumeration process know if we want to own
93            this device or not.  */
94         if ((command -> ux_host_class_command_usage == UX_HOST_CLASS_COMMAND_USAGE_CSP) &&
95             (command -> ux_host_class_command_class == UX_HOST_CLASS_AUDIO_CLASS) &&
96 #if defined(UX_HOST_CLASS_AUDIO_2_SUPPORT)
97             ((command -> ux_host_class_command_protocol == UX_HOST_CLASS_AUDIO_PROTOCOL_IP_VERSION_01_00) ||
98              (command -> ux_host_class_command_protocol == UX_HOST_CLASS_AUDIO_PROTOCOL_IP_VERSION_02_00))
99 #else
100             (command -> ux_host_class_command_protocol == UX_HOST_CLASS_AUDIO_PROTOCOL_IP_VERSION_01_00)
101 #endif
102             )
103             return(UX_SUCCESS);
104         else
105             return(UX_NO_CLASS_MATCH);
106 
107 
108     case UX_HOST_CLASS_COMMAND_ACTIVATE:
109 
110         /* The activate command is used when the device inserted has found a parent and
111            is ready to complete the enumeration.   */
112         status =  _ux_host_class_audio_activate(command);
113 
114         /* Return completion status.  */
115         return(status);
116 
117 
118     case UX_HOST_CLASS_COMMAND_DEACTIVATE:
119 
120         /* The deactivate command is used when the device has been extracted either
121            directly or when its parents has been extracted.  */
122         status =  _ux_host_class_audio_deactivate(command);
123 
124         /* Return completion status.  */
125         return(status);
126 
127 
128     default:
129 
130         /* Error trap. */
131         _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_FUNCTION_NOT_SUPPORTED);
132 
133         /* If trace is enabled, insert this event into the trace buffer.  */
134         UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_FUNCTION_NOT_SUPPORTED, 0, 0, 0, UX_TRACE_ERRORS, 0, 0)
135 
136         return(UX_FUNCTION_NOT_SUPPORTED);
137     }
138 }
139 
140