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