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 /** USBX Component */ 15 /** */ 16 /** Device Audio Class */ 17 /** */ 18 /**************************************************************************/ 19 /**************************************************************************/ 20 21 #define UX_SOURCE_CODE 22 23 24 /* Include necessary system files. */ 25 26 #include "ux_api.h" 27 #include "ux_device_class_audio.h" 28 #include "ux_device_stack.h" 29 30 31 /**************************************************************************/ 32 /* */ 33 /* FUNCTION RELEASE */ 34 /* */ 35 /* _ux_device_class_audio_feedback_get PORTABLE C */ 36 /* 6.1.10 */ 37 /* AUTHOR */ 38 /* */ 39 /* Chaoqiong Xiao, Microsoft Corporation */ 40 /* */ 41 /* DESCRIPTION */ 42 /* */ 43 /* This function obtain encoded feedback from the Audio Stream. */ 44 /* */ 45 /* INPUT */ 46 /* */ 47 /* stream Address of audio stream */ 48 /* instance */ 49 /* encoded_feedback Feedback data (3 or 4 bytes) */ 50 /* */ 51 /* OUTPUT */ 52 /* */ 53 /* None */ 54 /* */ 55 /* CALLS */ 56 /* */ 57 /* */ 58 /* CALLED BY */ 59 /* */ 60 /* Application */ 61 /* */ 62 /* RELEASE HISTORY */ 63 /* */ 64 /* DATE NAME DESCRIPTION */ 65 /* */ 66 /* 01-31-2022 Chaoqiong Xiao Initial Version 6.1.10 */ 67 /* */ 68 /**************************************************************************/ _ux_device_class_audio_feedback_get(UX_DEVICE_CLASS_AUDIO_STREAM * stream,UCHAR * encoded_feedback)69UINT _ux_device_class_audio_feedback_get(UX_DEVICE_CLASS_AUDIO_STREAM *stream, 70 UCHAR *encoded_feedback) 71 { 72 #if !defined(UX_DEVICE_CLASS_AUDIO_FEEDBACK_SUPPORT) 73 UX_PARAMETER_NOT_USED(stream); 74 UX_PARAMETER_NOT_USED(encoded_feedback); 75 return(UX_FUNCTION_NOT_SUPPORTED); 76 #else 77 78 UX_SLAVE_DEVICE *device; 79 UX_SLAVE_ENDPOINT *endpoint; 80 UX_SLAVE_TRANSFER *transfer; 81 UCHAR *buffer; 82 83 84 /* Get the pointer to the device. */ 85 device = &_ux_system_slave -> ux_system_slave_device; 86 87 /* As long as the device is in the CONFIGURED state. */ 88 if (device -> ux_slave_device_state != UX_DEVICE_CONFIGURED) 89 { 90 91 /* Cannot proceed with command, the interface is down. */ 92 return(UX_CONFIGURATION_HANDLE_UNKNOWN); 93 } 94 95 /* Check if endpoint is available. */ 96 endpoint = stream -> ux_device_class_audio_stream_feedback; 97 if (endpoint == UX_NULL) 98 return(UX_ERROR); 99 100 /* Check if endpoint direction is OK. */ 101 if ((endpoint -> ux_slave_endpoint_descriptor.bEndpointAddress & UX_ENDPOINT_DIRECTION) != UX_ENDPOINT_OUT) 102 return(UX_ERROR); 103 104 /* Get transfer buffer. */ 105 transfer = &endpoint -> ux_slave_endpoint_transfer_request; 106 buffer = transfer -> ux_slave_transfer_request_data_pointer; 107 108 /* Get packed data. */ 109 *encoded_feedback ++ = *buffer ++; 110 *encoded_feedback ++ = *buffer ++; 111 *encoded_feedback ++ = *buffer ++; 112 if (_ux_system_slave -> ux_system_slave_speed == UX_HIGH_SPEED_DEVICE) 113 *encoded_feedback = *buffer; 114 return(UX_SUCCESS); 115 #endif 116 } 117 118 /**************************************************************************/ 119 /* */ 120 /* FUNCTION RELEASE */ 121 /* */ 122 /* _uxe_device_class_audio_feedback_get PORTABLE C */ 123 /* 6.2.1 */ 124 /* AUTHOR */ 125 /* */ 126 /* Chaoqiong Xiao, Microsoft Corporation */ 127 /* */ 128 /* DESCRIPTION */ 129 /* */ 130 /* This function checks errors in encoded feedback getting function */ 131 /* call. */ 132 /* */ 133 /* INPUT */ 134 /* */ 135 /* stream Address of audio stream */ 136 /* instance */ 137 /* encoded_feedback Feedback data (3 or 4 bytes) */ 138 /* */ 139 /* OUTPUT */ 140 /* */ 141 /* None */ 142 /* */ 143 /* CALLS */ 144 /* */ 145 /* _ux_device_class_audio_feedback_get Get encoded feedback */ 146 /* */ 147 /* CALLED BY */ 148 /* */ 149 /* Application */ 150 /* */ 151 /* RELEASE HISTORY */ 152 /* */ 153 /* DATE NAME DESCRIPTION */ 154 /* */ 155 /* 03-08-2023 Chaoqiong Xiao Initial Version 6.2.1 */ 156 /* */ 157 /**************************************************************************/ _uxe_device_class_audio_feedback_get(UX_DEVICE_CLASS_AUDIO_STREAM * stream,UCHAR * encoded_feedback)158UINT _uxe_device_class_audio_feedback_get(UX_DEVICE_CLASS_AUDIO_STREAM *stream, 159 UCHAR *encoded_feedback) 160 { 161 162 /* Sanity check on input parameters. */ 163 if (stream == UX_NULL || encoded_feedback == UX_NULL) 164 return(UX_INVALID_PARAMETER); 165 166 /* Get feedback. */ 167 return(_ux_device_class_audio_feedback_get(stream, encoded_feedback)); 168 } 169