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 /** USBX Component */
16 /** */
17 /** Device Video Class */
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_class_video.h"
29 #include "ux_device_stack.h"
30
31
32 /**************************************************************************/
33 /* */
34 /* FUNCTION RELEASE */
35 /* */
36 /* _ux_device_class_video_control_request PORTABLE C */
37 /* 6.1.11 */
38 /* AUTHOR */
39 /* */
40 /* Chaoqiong Xiao, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function manages the based sent by the host on the control */
45 /* endpoints with a CLASS or VENDOR SPECIFIC type. */
46 /* */
47 /* INPUT */
48 /* */
49 /* command Pointer to class command */
50 /* */
51 /* OUTPUT */
52 /* */
53 /* Completion Status */
54 /* */
55 /* CALLS */
56 /* */
57 /* _ux_device_stack_endpoint_stall Endpoint stall */
58 /* */
59 /* CALLED BY */
60 /* */
61 /* Device Video Class */
62 /* */
63 /* RELEASE HISTORY */
64 /* */
65 /* DATE NAME DESCRIPTION */
66 /* */
67 /* 04-25-2022 Chaoqiong Xiao Initial Version 6.1.11 */
68 /* */
69 /**************************************************************************/
_ux_device_class_video_control_request(UX_SLAVE_CLASS_COMMAND * command)70 UINT _ux_device_class_video_control_request(UX_SLAVE_CLASS_COMMAND *command)
71 {
72
73 UX_SLAVE_TRANSFER *transfer_request;
74 UX_SLAVE_DEVICE *device;
75 UX_SLAVE_CLASS *class_inst;
76 UX_DEVICE_CLASS_VIDEO *video;
77 UX_DEVICE_CLASS_VIDEO_STREAM *stream;
78 ULONG stream_index;
79 UCHAR request_type;
80 UCHAR request;
81 UCHAR index_low;
82 ULONG value_cs;
83 UCHAR *buffer;
84 UINT status;
85
86
87 /* Get the class container. */
88 class_inst = command -> ux_slave_class_command_class_ptr;
89
90 /* Get the video instance from this class container. */
91 video = (UX_DEVICE_CLASS_VIDEO *) class_inst -> ux_slave_class_instance;
92
93 /* Get the pointer to the device. */
94 device = &_ux_system_slave -> ux_system_slave_device;
95
96 /* Get the pointer to the transfer request associated with the control endpoint. */
97 transfer_request = &device -> ux_slave_device_control_endpoint.ux_slave_endpoint_transfer_request;
98
99 /* Get bmRequestType, wValue and wIndex low byte. */
100 request_type = transfer_request -> ux_slave_transfer_request_setup[UX_SETUP_REQUEST_TYPE];
101 request = transfer_request -> ux_slave_transfer_request_setup[UX_SETUP_REQUEST];
102 value_cs = transfer_request -> ux_slave_transfer_request_setup[UX_SETUP_VALUE + 1];
103 index_low = transfer_request -> ux_slave_transfer_request_setup[UX_SETUP_INDEX];
104 buffer = transfer_request -> ux_slave_transfer_request_data_pointer;
105
106 /* Check request target (only target interface is supported now). */
107 if ((request_type & UX_REQUEST_TARGET) != UX_REQUEST_TARGET_INTERFACE)
108 return(UX_ERROR);
109
110 /* Check request interface (wIndex low) of control. */
111 if (index_low == video -> ux_device_class_video_interface -> ux_slave_interface_descriptor.bInterfaceNumber)
112 {
113
114 /* Check control selector. */
115 switch(value_cs)
116 {
117 case UX_DEVICE_CLASS_VIDEO_VC_REQUEST_ERROR_CODE_CONTROL:
118
119 /* Must have at least 1 byte buffer. */
120 if (transfer_request->ux_slave_transfer_request_requested_length < 1)
121 return(UX_ERROR);
122
123 /* GET_CUR. */
124 if (request == UX_DEVICE_CLASS_VIDEO_GET_CUR)
125 {
126
127 /* Fill bRequestErrorCode. */
128 *buffer = (UCHAR)video -> ux_device_class_video_error;
129
130 /* Send data. */
131 status = _ux_device_stack_transfer_request(transfer_request, 1, 1);
132 return(status);
133 }
134
135 /* GET_INFO. */
136 if (request == UX_DEVICE_CLASS_VIDEO_GET_INFO)
137 {
138
139 /* Support GET_CUR | GET_INFO. */
140 *buffer = UX_DEVICE_CLASS_VIDEO_INFO_GET_REQUEST_SUPPORT;
141
142 /* Send data. */
143 status = _ux_device_stack_transfer_request(transfer_request, 1, 1);
144 return(status);
145 }
146
147 /* Request not expected. */
148 return(UX_ERROR);
149
150 default:
151 break;
152 }
153
154 /* By default it's not handled. */
155 status = UX_ERROR;
156
157 /* Invoke callback. */
158 if (video -> ux_device_class_video_callbacks.ux_device_class_video_request != UX_NULL)
159 {
160
161 /* Handled by callback. */
162 status = video -> ux_device_class_video_callbacks.ux_device_class_video_request(video, transfer_request);
163 }
164 return(status);
165 }
166
167 /* Check request index of stream. */
168 stream = video -> ux_device_class_video_streams;
169 for (stream_index = 0; stream_index < video -> ux_device_class_video_streams_nb; stream_index ++)
170 {
171
172 /* No stream. */
173 if (stream -> ux_device_class_video_stream_interface == UX_NULL)
174 break;
175
176 /* Check interface number. */
177 if (index_low == stream -> ux_device_class_video_stream_interface ->
178 ux_slave_interface_descriptor.bInterfaceNumber)
179 {
180
181 /* Check control selector. */
182 switch(value_cs)
183 {
184 case UX_DEVICE_CLASS_VIDEO_VS_STREAM_ERROR_CODE_CONTROL:
185
186 /* Must have at least 1 byte buffer. */
187 if (transfer_request->ux_slave_transfer_request_requested_length < 1)
188 return(UX_ERROR);
189
190 /* GET_CUR. */
191 if (request == UX_DEVICE_CLASS_VIDEO_GET_CUR)
192 {
193
194 /* Fill bRequestErrorCode. */
195 *buffer = (UCHAR)stream -> ux_device_class_video_stream_error;
196
197 /* Send data. */
198 status = _ux_device_stack_transfer_request(transfer_request, 1, 1);
199 return(status);
200 }
201
202 /* GET_INFO. */
203 if (request == UX_DEVICE_CLASS_VIDEO_GET_INFO)
204 {
205
206 /* Support GET_CUR | GET_INFO. */
207 *buffer = UX_DEVICE_CLASS_VIDEO_INFO_GET_REQUEST_SUPPORT;
208
209 /* Send data. */
210 status = _ux_device_stack_transfer_request(transfer_request, 1, 1);
211 return(status);
212 }
213
214 /* Request not expected. */
215 return(UX_ERROR);
216
217 default:
218 break;
219 }
220
221 /* By default it's not handled. */
222 status = UX_ERROR;
223
224 /* Invoke callback. */
225 if (stream -> ux_device_class_video_stream_callbacks.ux_device_class_video_stream_request != UX_NULL)
226 {
227
228 /* Handled by callback. */
229 status = stream -> ux_device_class_video_stream_callbacks.ux_device_class_video_stream_request(stream, transfer_request);
230 }
231 return(status);
232 }
233
234 /* Next stream. */
235 stream ++;
236 }
237
238 /* Not handled. */
239 return(UX_ERROR);
240 }
241