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 /** Audio 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_audio.h"
30 #include "ux_host_stack.h"
31
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _ux_host_class_audio_feedback_set PORTABLE C */
38 /* 6.1.12 */
39 /* AUTHOR */
40 /* */
41 /* Chaoqiong Xiao, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function copies packed feedback data from given buffer. */
46 /* Note high speed data size is 4 and full speed data size is 3 bytes. */
47 /* */
48 /* Note if feedback is supported this function can work even there is */
49 /* no interface alternate setting selected. This way the default */
50 /* feedback data can be set before streaming starts. */
51 /* */
52 /* INPUT */
53 /* */
54 /* audio Pointer to audio class */
55 /* feedback Pointer to packed feedback */
56 /* data to copy */
57 /* */
58 /* OUTPUT */
59 /* */
60 /* Completion Status */
61 /* */
62 /* CALLS */
63 /* */
64 /* */
65 /* CALLED BY */
66 /* */
67 /* Application */
68 /* */
69 /* RELEASE HISTORY */
70 /* */
71 /* DATE NAME DESCRIPTION */
72 /* */
73 /* 07-29-2022 Chaoqiong Xiao Initial Version 6.1.12 */
74 /* */
75 /**************************************************************************/
_ux_host_class_audio_feedback_set(UX_HOST_CLASS_AUDIO * audio,UCHAR * feedback)76 UINT _ux_host_class_audio_feedback_set(UX_HOST_CLASS_AUDIO *audio, UCHAR *feedback)
77 {
78 #if !defined(UX_HOST_CLASS_AUDIO_FEEDBACK_SUPPORT)
79 UX_PARAMETER_NOT_USED(audio);
80 UX_PARAMETER_NOT_USED(feedback);
81 return(UX_FUNCTION_NOT_SUPPORTED);
82 #else
83 UX_ENDPOINT *endpoint;
84 UX_TRANSFER *transfer;
85
86 /* Ensure the instance is valid. */
87 if (_ux_host_stack_class_instance_verify(_ux_system_host_class_audio_name, (VOID *) audio) != UX_SUCCESS)
88 {
89
90 /* Error trap. */
91 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_INSTANCE_UNKNOWN);
92
93 /* If trace is enabled, insert this event into the trace buffer. */
94 UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, audio, 0, 0, UX_TRACE_ERRORS, 0, 0)
95
96 return(UX_HOST_CLASS_INSTANCE_UNKNOWN);
97 }
98
99 audio -> ux_host_class_audio_feedback_buffer[0] = feedback[0];
100 audio -> ux_host_class_audio_feedback_buffer[1] = feedback[1];
101 audio -> ux_host_class_audio_feedback_buffer[2] = feedback[2];
102 if (_ux_host_class_audio_speed_get(audio) == UX_HIGH_SPEED_DEVICE)
103 audio -> ux_host_class_audio_feedback_buffer[3] = feedback[3];
104
105 /* Sync with transfer buffer. */
106 endpoint = audio -> ux_host_class_audio_feedback_endpoint;
107 if (endpoint)
108 {
109 transfer = &endpoint -> ux_endpoint_transfer_request;
110 _ux_utility_memory_copy(transfer -> ux_transfer_request_data_pointer,
111 audio -> ux_host_class_audio_feedback_buffer,
112 sizeof(audio -> ux_host_class_audio_feedback_buffer)); /* Use case of memcpy is verified. */
113 }
114
115 return(UX_SUCCESS);
116 #endif
117 }
118