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 /**   Video 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_video.h"
29 #include "ux_host_stack.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _ux_host_class_video_entry                          PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Chaoqiong Xiao, Microsoft Corporation                               */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function is the entry point of the Video class. It will be     */
45 /*    called by the USBX stack enumeration module when there is a new     */
46 /*    video device (speaker, microphone ...) on the bus or when the video */
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_video_activate         Activate video class          */
60 /*    _ux_host_class_video_deactivate       Deactivate video class        */
61 /*    _ux_system_error_handler              Log system error              */
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 /*                                                                        */
75 /**************************************************************************/
_ux_host_class_video_entry(UX_HOST_CLASS_COMMAND * command)76 UINT  _ux_host_class_video_entry(UX_HOST_CLASS_COMMAND *command)
77 {
78 
79 UINT        status = UX_SUCCESS;
80 
81 
82     /* The command request will tell us we need to do here, either a enumeration
83        query, an activation or a deactivation.  */
84     switch (command -> ux_host_class_command_request)
85     {
86 
87 
88     case UX_HOST_CLASS_COMMAND_QUERY:
89 
90         /* The query command is used to let the stack enumeration process know if we want to own
91            this device or not.  */
92         if ((command -> ux_host_class_command_usage == UX_HOST_CLASS_COMMAND_USAGE_CSP) &&
93             (command -> ux_host_class_command_class == UX_HOST_CLASS_VIDEO_CLASS))
94             status = UX_SUCCESS;
95         else
96             status = UX_NO_CLASS_MATCH;
97         break;
98 
99     case UX_HOST_CLASS_COMMAND_ACTIVATE:
100 
101         /* The activate command is used when the device inserted has found a parent and
102            is ready to complete the enumeration.   */
103         status =  _ux_host_class_video_activate(command);
104 
105         break;
106 
107 
108     case UX_HOST_CLASS_COMMAND_DEACTIVATE:
109 
110         /* The deactivate command is used when the device has been extracted either
111            directly or when its parents has been extracted.  */
112         status =  _ux_host_class_video_deactivate(command);
113 
114         break;
115 
116 
117     default:
118 
119         /* Error trap. */
120         _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_FUNCTION_NOT_SUPPORTED);
121 
122         /* If trace is enabled, insert this event into the trace buffer.  */
123         //UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_FUNCTION_NOT_SUPPORTED, 0, 0, 0, UX_TRACE_ERRORS, 0, 0)
124 
125         status = UX_FUNCTION_NOT_SUPPORTED;
126     }
127 
128     return(status);
129 }
130 
131