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_control_value_set PORTABLE C */
37 /* 6.1.11 */
38 /* AUTHOR */
39 /* */
40 /* Chaoqiong Xiao, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function updates the current values for a single video control.*/
45 /* */
46 /* INPUT */
47 /* */
48 /* video Pointer to video class */
49 /* video_control Pointer to video control */
50 /* */
51 /* OUTPUT */
52 /* */
53 /* Completion Status */
54 /* */
55 /* CALLS */
56 /* */
57 /* _ux_host_stack_class_instance_verify Verify instance is valid */
58 /* _ux_host_stack_transfer_request Process transfer request */
59 /* _ux_host_semaphore_get Get semaphore */
60 /* _ux_host_semaphore_put Release semaphore */
61 /* _ux_utility_memory_allocate Allocate memory block */
62 /* _ux_utility_memory_free Release memory block */
63 /* _ux_utility_short_put Put 16-bit value */
64 /* */
65 /* CALLED BY */
66 /* */
67 /* Application */
68 /* Video Class */
69 /* */
70 /* RELEASE HISTORY */
71 /* */
72 /* DATE NAME DESCRIPTION */
73 /* */
74 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
75 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
76 /* resulting in version 6.1 */
77 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
78 /* refined macros names, */
79 /* resulting in version 6.1.10 */
80 /* 04-25-2022 Chaoqiong Xiao Modified comment(s), */
81 /* fixed standalone compile, */
82 /* resulting in version 6.1.11 */
83 /* */
84 /**************************************************************************/
_ux_host_class_video_control_value_set(UX_HOST_CLASS_VIDEO * video,UX_HOST_CLASS_VIDEO_CONTROL * video_control)85 UINT _ux_host_class_video_control_value_set(UX_HOST_CLASS_VIDEO *video, UX_HOST_CLASS_VIDEO_CONTROL *video_control)
86 {
87
88 UX_ENDPOINT *control_endpoint;
89 UX_TRANSFER *transfer_request;
90 UINT status;
91 UCHAR * control_buffer;
92
93
94 /* Ensure the instance is valid. */
95 if (_ux_host_stack_class_instance_verify(_ux_system_host_class_video_name, (VOID *) video) != UX_SUCCESS)
96 {
97
98 /* Error trap. */
99 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_INSTANCE_UNKNOWN);
100
101 /* If trace is enabled, insert this event into the trace buffer. */
102 //UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, video, 0, 0, UX_TRACE_ERRORS, 0, 0)
103
104 return(UX_HOST_CLASS_INSTANCE_UNKNOWN);
105 }
106
107 /* Protect thread reentry to this instance. */
108 status = _ux_host_semaphore_get(&video -> ux_host_class_video_semaphore, UX_WAIT_FOREVER);
109 if (status != UX_SUCCESS)
110 return(status);
111
112 /* We need to get the default control endpoint transfer request pointer. */
113 control_endpoint = &video -> ux_host_class_video_device -> ux_device_control_endpoint;
114 transfer_request = &control_endpoint -> ux_endpoint_transfer_request;
115
116 /* Need to allocate memory for the control buffer. */
117 control_buffer = _ux_utility_memory_allocate(UX_SAFE_ALIGN, UX_CACHE_SAFE_MEMORY, 2);
118 if (control_buffer == UX_NULL)
119 {
120
121 /* Unprotect thread reentry to this instance. */
122 _ux_host_semaphore_put(&video -> ux_host_class_video_semaphore);
123
124 /* Return an error. */
125 return(UX_MEMORY_INSUFFICIENT);
126 }
127
128 /* Update the control buffer with the current control value. */
129 _ux_utility_short_put(control_buffer, (USHORT) video_control -> ux_host_class_video_control_cur);
130
131 /* Protect the control endpoint semaphore here. It will be unprotected in the
132 transfer request function. */
133 status = _ux_host_semaphore_get(&video -> ux_host_class_video_device -> ux_device_protection_semaphore, UX_WAIT_FOREVER);
134
135 /* Check for status. */
136 if (status != UX_SUCCESS)
137
138 /* Something went wrong. */
139 return(status);
140
141 /* Create a transfer request for the GET_MIN request. */
142 transfer_request -> ux_transfer_request_data_pointer = control_buffer;
143 transfer_request -> ux_transfer_request_requested_length = 2;
144 transfer_request -> ux_transfer_request_function = UX_HOST_CLASS_VIDEO_SET_CUR;
145 transfer_request -> ux_transfer_request_type = UX_REQUEST_OUT | UX_REQUEST_TYPE_CLASS | UX_REQUEST_TARGET_INTERFACE;
146 transfer_request -> ux_transfer_request_value = (video_control -> ux_host_class_video_control << 8);
147 transfer_request -> ux_transfer_request_index = video -> ux_host_class_video_control_interface_number | (video -> ux_host_class_video_feature_unit_id << 8);
148
149 /* Send request to HCD layer. */
150 status = _ux_host_stack_transfer_request(transfer_request);
151
152 /* Check for correct transfer. */
153 if (status != UX_SUCCESS)
154 {
155
156 /* Free the previous control buffer. */
157 _ux_utility_memory_free(control_buffer);
158
159 /* Unprotect thread reentry to this instance. */
160 _ux_host_semaphore_put(&video -> ux_host_class_video_semaphore);
161
162 /* Return completion status. */
163 return(UX_TRANSFER_ERROR);
164 }
165
166 /* Free all used resources. */
167 _ux_utility_memory_free(control_buffer);
168
169 /* Unprotect thread reentry to this instance. */
170 _ux_host_semaphore_put(&video -> ux_host_class_video_semaphore);
171
172 /* Return completion status. */
173 return(status);
174 }
175
176 /**************************************************************************/
177 /* */
178 /* FUNCTION RELEASE */
179 /* */
180 /* _uxe_host_class_video_control_value_set PORTABLE C */
181 /* 6.3.0 */
182 /* AUTHOR */
183 /* */
184 /* Yajun Xia, Microsoft Corporation */
185 /* */
186 /* DESCRIPTION */
187 /* */
188 /* This function checks errors in video control value set function */
189 /* call. */
190 /* */
191 /* INPUT */
192 /* */
193 /* video Pointer to video class */
194 /* video_control Pointer to video control */
195 /* */
196 /* OUTPUT */
197 /* */
198 /* Completion Status */
199 /* */
200 /* CALLS */
201 /* */
202 /* _ux_host_class_video_control_value_set */
203 /* Set the video control value */
204 /* */
205 /* CALLED BY */
206 /* */
207 /* Application */
208 /* Video Class */
209 /* */
210 /* RELEASE HISTORY */
211 /* */
212 /* DATE NAME DESCRIPTION */
213 /* */
214 /* 10-31-2023 Yajun xia Initial Version 6.3.0 */
215 /* */
216 /**************************************************************************/
_uxe_host_class_video_control_value_set(UX_HOST_CLASS_VIDEO * video,UX_HOST_CLASS_VIDEO_CONTROL * video_control)217 UINT _uxe_host_class_video_control_value_set(UX_HOST_CLASS_VIDEO *video, UX_HOST_CLASS_VIDEO_CONTROL *video_control)
218 {
219
220 /* Sanity Checks. */
221 if ((video == UX_NULL) || (video_control == UX_NULL))
222 return(UX_INVALID_PARAMETER);
223
224 /* Call the actual video control value set function. */
225 return(_ux_host_class_video_control_value_set(video, video_control));
226 }