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 /** USBX Component                                                        */
15 /**                                                                       */
16 /**   Device Audio Class                                                    */
17 /**                                                                       */
18 /**************************************************************************/
19 /**************************************************************************/
20 
21 #define UX_SOURCE_CODE
22 
23 
24 /* Include necessary system files.  */
25 
26 #include "ux_api.h"
27 #include "ux_device_class_audio.h"
28 #include "ux_device_stack.h"
29 
30 
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _ux_device_class_audio_control_request              PORTABLE C      */
36 /*                                                           6.1.12       */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Chaoqiong Xiao, Microsoft Corporation                               */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function manages the based sent by the host on the control     */
44 /*    endpoints with a CLASS or VENDOR SPECIFIC type.                     */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    command                               Pointer to class command      */
49 /*                                                                        */
50 /*  OUTPUT                                                                */
51 /*                                                                        */
52 /*    Completion Status                                                   */
53 /*                                                                        */
54 /*  CALLS                                                                 */
55 /*                                                                        */
56 /*    _ux_device_stack_endpoint_stall       Endpoint stall                */
57 /*                                                                        */
58 /*  CALLED BY                                                             */
59 /*                                                                        */
60 /*    Device Audio Class                                                  */
61 /*                                                                        */
62 /*  RELEASE HISTORY                                                       */
63 /*                                                                        */
64 /*    DATE              NAME                      DESCRIPTION             */
65 /*                                                                        */
66 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
67 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
68 /*                                            resulting in version 6.1    */
69 /*  07-29-2022     Chaoqiong Xiao           Modified comment(s),          */
70 /*                                            fixed parameter/variable    */
71 /*                                            names conflict C++ keyword, */
72 /*                                            resulting in version 6.1.12 */
73 /*                                                                        */
74 /**************************************************************************/
_ux_device_class_audio_control_request(UX_SLAVE_CLASS_COMMAND * command)75 UINT  _ux_device_class_audio_control_request(UX_SLAVE_CLASS_COMMAND *command)
76 {
77 
78 UX_SLAVE_TRANSFER             *transfer_request;
79 UX_SLAVE_DEVICE               *device;
80 UX_SLAVE_CLASS                *class_ptr;
81 UX_DEVICE_CLASS_AUDIO         *audio;
82 
83 
84     /* Get the class container.  */
85     class_ptr =  command -> ux_slave_class_command_class_ptr;
86 
87     /* Get the audio instance from this class container.  */
88     audio =  (UX_DEVICE_CLASS_AUDIO *) class_ptr -> ux_slave_class_instance;
89 
90     /* Get the pointer to the device.  */
91     device =  &_ux_system_slave -> ux_system_slave_device;
92 
93     /* Get the pointer to the transfer request associated with the control endpoint.  */
94     transfer_request =  &device -> ux_slave_device_control_endpoint.ux_slave_endpoint_transfer_request;
95 
96     /* Invoke callback.  */
97     if (audio -> ux_device_class_audio_callbacks.ux_device_class_audio_control_process != UX_NULL)
98     {
99 
100         /* Handled by callback.  */
101         return audio -> ux_device_class_audio_callbacks.ux_device_class_audio_control_process(audio, transfer_request);
102     }
103 
104     /* Not handled.  */
105     return(UX_ERROR);
106 }
107