blob: df0d26d825d94b8c8d4c09b177cdd79a19da47f1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
/***************************************************************************
* Copyright (c) 2024 Microsoft Corporation
* Copyright (c) 2026-present Eclipse ThreadX contributors
*
* This program and the accompanying materials are made available under the
* terms of the MIT License which is available at
* https://opensource.org/licenses/MIT.
*
* SPDX-License-Identifier: MIT
**************************************************************************/
/**************************************************************************/
/**************************************************************************/
/** */
/** USBX Component */
/** */
/** Video Class */
/** */
/**************************************************************************/
/**************************************************************************/
/* Include necessary system files. */
#define UX_SOURCE_CODE
#include "ux_api.h"
#include "ux_host_class_video.h"
#include "ux_host_stack.h"
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _ux_host_class_video_alternate_setting_locate PORTABLE C */
/* 6.1.12 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function finds the alternate setting for the specific format. */
/* */
/* INPUT */
/* */
/* video Pointer to video class */
/* alternate_setting Pointer to located alternate */
/* setting */
/* */
/* OUTPUT */
/* */
/* Completion Status */
/* */
/* CALLS */
/* */
/* _ux_system_error_handler Log system error */
/* */
/* CALLED BY */
/* */
/* Video Class */
/* */
/**************************************************************************/
UINT _ux_host_class_video_alternate_setting_locate(UX_HOST_CLASS_VIDEO *video, UINT max_payload_size, UINT *alternate_setting)
{
UX_CONFIGURATION *configuration;
UX_INTERFACE *interface_ptr;
UX_ENDPOINT *endpoint;
UINT streaming_interface;
UINT payload_size;
UINT current_payload_size = 0;
UINT alternate_setting_found;
configuration = video -> ux_host_class_video_streaming_interface -> ux_interface_configuration;
interface_ptr = configuration -> ux_configuration_first_interface;
streaming_interface = video -> ux_host_class_video_streaming_interface -> ux_interface_descriptor.bInterfaceNumber;
alternate_setting_found = UX_FALSE;
/* Scan all interfaces. */
while (interface_ptr != UX_NULL)
{
/* Search for the streaming interface with a endpoint. */
if ((interface_ptr -> ux_interface_descriptor.bInterfaceNumber == streaming_interface) &&
(interface_ptr -> ux_interface_first_endpoint != 0))
{
/* Get the max packet size of the endpoint. */
endpoint = interface_ptr -> ux_interface_first_endpoint;
payload_size = endpoint -> ux_endpoint_transfer_request.ux_transfer_request_packet_length;
/* Check if the payload size is equal or greater than the required payload size. */
if (payload_size >= max_payload_size)
{
/* Check if we have found any alternate settings yet. */
if(alternate_setting_found == UX_FALSE)
{
/* Save the current payload size and mark the found flag. */
alternate_setting_found = UX_TRUE;
current_payload_size = payload_size;
/* Save the found alternate setting number. */
*alternate_setting = interface_ptr -> ux_interface_descriptor.bAlternateSetting;
}
else
{
/* Check if the payload size is smaller. */
if (payload_size < current_payload_size)
{
/* Smaller payload size found, select the current setting. */
current_payload_size = payload_size;
/* Save the found alternate setting number. */
*alternate_setting = interface_ptr -> ux_interface_descriptor.bAlternateSetting;
}
}
}
}
/* Move to next interface. */
interface_ptr = interface_ptr -> ux_interface_next_interface;
}
/* Check if we found the alternate setting. */
if (alternate_setting_found)
{
/* Return successful completion. */
return(UX_SUCCESS);
}
/* Error trap. */
_ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_VIDEO_WRONG_TYPE);
/* We get here when either the report descriptor has a problem or we could
not find the right video device. */
return(UX_HOST_CLASS_VIDEO_WRONG_TYPE);
}
|