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_descriptor_get PORTABLE C */ 38 /* 6.1.12 */ 39 /* AUTHOR */ 40 /* */ 41 /* Chaoqiong Xiao, Microsoft Corporation */ 42 /* */ 43 /* DESCRIPTION */ 44 /* */ 45 /* This function obtains the entire video configuration descriptors. */ 46 /* This is needed because the video class has many class specific */ 47 /* descriptors which describe the alternate settings that can be used. */ 48 /* */ 49 /* INPUT */ 50 /* */ 51 /* video Pointer to video class */ 52 /* */ 53 /* OUTPUT */ 54 /* */ 55 /* Completion Status */ 56 /* */ 57 /* CALLS */ 58 /* */ 59 /* _ux_host_stack_transfer_request Process transfer request */ 60 /* _ux_utility_descriptor_parse Parse descriptor */ 61 /* _ux_utility_memory_allocate Allocate memory block */ 62 /* _ux_utility_memory_free Release memory block */ 63 /* */ 64 /* CALLED BY */ 65 /* */ 66 /* Video Class */ 67 /* */ 68 /* RELEASE HISTORY */ 69 /* */ 70 /* DATE NAME DESCRIPTION */ 71 /* */ 72 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ 73 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ 74 /* resulting in version 6.1 */ 75 /* 07-29-2022 Chaoqiong Xiao Modified comment(s), */ 76 /* used shared device config */ 77 /* descriptor for enum scan, */ 78 /* resulting in version 6.1.12 */ 79 /* */ 80 /**************************************************************************/ _ux_host_class_video_descriptor_get(UX_HOST_CLASS_VIDEO * video)81UINT _ux_host_class_video_descriptor_get(UX_HOST_CLASS_VIDEO *video) 82 { 83 84 UX_DEVICE *device; 85 UX_CONFIGURATION *configuration; 86 UCHAR * descriptor; 87 UX_ENDPOINT *control_endpoint; 88 UX_TRANSFER *transfer_request; 89 UINT status; 90 ULONG total_configuration_length; 91 92 /* Get device, current configuration. */ 93 device = video -> ux_host_class_video_device; 94 configuration = device -> ux_device_current_configuration; 95 96 /* Check if descriptor is previously saved. */ 97 if (device -> ux_device_packed_configuration != UX_NULL) 98 { 99 video -> ux_host_class_video_configuration_descriptor = 100 device -> ux_device_packed_configuration; 101 video -> ux_host_class_video_configuration_descriptor_length = 102 configuration -> ux_configuration_descriptor.wTotalLength; 103 104 /* Descriptor must be kept after enum. */ 105 device -> ux_device_packed_configuration_keep_count ++; 106 return(UX_SUCCESS); 107 } 108 109 /* Get total length of configuration descriptors. */ 110 total_configuration_length = configuration -> ux_configuration_descriptor.wTotalLength; 111 112 /* We need to get the default control endpoint transfer request pointer. */ 113 control_endpoint = &device -> ux_device_control_endpoint; 114 transfer_request = &control_endpoint -> ux_endpoint_transfer_request; 115 116 /* Need to allocate memory for the descriptor. */ 117 descriptor = _ux_utility_memory_allocate(UX_SAFE_ALIGN, UX_CACHE_SAFE_MEMORY, total_configuration_length); 118 if (descriptor == UX_NULL) 119 return(UX_MEMORY_INSUFFICIENT); 120 121 /* Create a transfer request for the GET_DESCRIPTOR request. */ 122 transfer_request -> ux_transfer_request_data_pointer = descriptor; 123 transfer_request -> ux_transfer_request_requested_length = total_configuration_length; 124 transfer_request -> ux_transfer_request_function = UX_GET_DESCRIPTOR; 125 transfer_request -> ux_transfer_request_type = UX_REQUEST_IN | UX_REQUEST_TYPE_STANDARD | UX_REQUEST_TARGET_DEVICE; 126 transfer_request -> ux_transfer_request_value = UX_CONFIGURATION_DESCRIPTOR_ITEM << 8; 127 transfer_request -> ux_transfer_request_index = 0; 128 129 /* Send request to HCD layer. */ 130 status = _ux_host_stack_transfer_request(transfer_request); 131 132 /* Check for correct transfer and entire descriptor returned. */ 133 if ((status == UX_SUCCESS) && (transfer_request -> ux_transfer_request_actual_length == total_configuration_length)) 134 { 135 136 /* Save the address of the entire configuration descriptor of the video device. */ 137 video -> ux_host_class_video_configuration_descriptor = descriptor; 138 139 /* Save the length of the entire descriptor too. */ 140 video -> ux_host_class_video_configuration_descriptor_length = total_configuration_length; 141 142 /* Keep descriptor to be shared for this device. */ 143 device -> ux_device_packed_configuration = descriptor; 144 device -> ux_device_packed_configuration_keep_count ++; 145 146 /* We do not free the resource for the descriptor until the device is 147 plugged out. */ 148 return(UX_SUCCESS); 149 } 150 151 /* Free all used resources. */ 152 _ux_utility_memory_free(descriptor); 153 154 /* Return completion status. */ 155 return(status); 156 } 157