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 /**   Device Stack                                                        */
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_stack.h"
29 
30 
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _ux_device_stack_configuration_get                  PORTABLE C      */
36 /*                                                           6.1          */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Chaoqiong Xiao, Microsoft Corporation                               */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function gets the current configuration for the device.        */
44 /*                                                                        */
45 /*  INPUT                                                                 */
46 /*                                                                        */
47 /*    None                                                                */
48 /*                                                                        */
49 /*  OUTPUT                                                                */
50 /*                                                                        */
51 /*    Completion Status                                                   */
52 /*                                                                        */
53 /*  CALLS                                                                 */
54 /*                                                                        */
55 /*    _ux_device_stack_transfer_request     Transfer request              */
56 /*                                                                        */
57 /*  CALLED BY                                                             */
58 /*                                                                        */
59 /*    Application                                                         */
60 /*    Device Stack                                                        */
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 /*                                                                        */
70 /**************************************************************************/
_ux_device_stack_configuration_get(VOID)71 UINT  _ux_device_stack_configuration_get(VOID)
72 {
73 
74 UX_SLAVE_TRANSFER       *transfer_request;
75 UX_SLAVE_DEVICE         *device;
76 UX_SLAVE_ENDPOINT       *endpoint;
77 UINT                    status;
78 
79     /* Get the pointer to the device.  */
80     device =  &_ux_system_slave -> ux_system_slave_device;
81 
82     /* Get the control endpoint for the device.  */
83     endpoint =  &device -> ux_slave_device_control_endpoint;
84 
85     /* Get the pointer to the transfer request associated with the endpoint.  */
86     transfer_request =  &endpoint -> ux_slave_endpoint_transfer_request;
87 
88     /* Set the value of the configuration in the buffer.  */
89     *transfer_request -> ux_slave_transfer_request_data_pointer =
90                 (UCHAR) device -> ux_slave_device_configuration_selected;
91 
92     /* If trace is enabled, insert this event into the trace buffer.  */
93     UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_STACK_CONFIGURATION_GET, device -> ux_slave_device_configuration_selected, 0, 0, 0, UX_TRACE_DEVICE_STACK_EVENTS, 0, 0)
94 
95     /* Set the phase of the transfer to data out.  */
96     transfer_request -> ux_slave_transfer_request_phase =  UX_TRANSFER_PHASE_DATA_OUT;
97 
98     /* Send the descriptor with the appropriate length to the host.  */
99     status =  _ux_device_stack_transfer_request(transfer_request, 1, 1);
100 
101     /* Return the function status.  */
102     return(status);
103 }
104 
105