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