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_entity_control_value_set PORTABLE C */
38 /* 6.1.12 */
39 /* AUTHOR */
40 /* */
41 /* Chaoqiong Xiao, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function updates the dynamic values for a single audio */
46 /* control on either the master channel or a specific channel. */
47 /* */
48 /* Note only control value of BYTE, WORD and DWORD (<4) is supported. */
49 /* E.g., Graphic Equalizer Control is not supported. */
50 /* */
51 /* INPUT */
52 /* */
53 /* audio Pointer to audio class */
54 /* audio_control Pointer to audio control */
55 /* */
56 /* OUTPUT */
57 /* */
58 /* Completion Status */
59 /* */
60 /* CALLS */
61 /* */
62 /* _ux_host_stack_class_instance_verify Verify instance is valid */
63 /* _ux_host_class_audio_control_request Issue audio transfer request */
64 /* _ux_host_mutex_on Get mutex */
65 /* _ux_host_mutex_off Release mutex */
66 /* _ux_utility_memory_allocate Allocate memory block */
67 /* _ux_utility_memory_free Release memory block */
68 /* _ux_utility_long_put Write 32-bit value */
69 /* */
70 /* CALLED BY */
71 /* */
72 /* Application */
73 /* Audio Class */
74 /* */
75 /* RELEASE HISTORY */
76 /* */
77 /* DATE NAME DESCRIPTION */
78 /* */
79 /* 07-29-2022 Chaoqiong Xiao Initial Version 6.1.12 */
80 /* */
81 /**************************************************************************/
_ux_host_class_audio_entity_control_value_set(UX_HOST_CLASS_AUDIO * audio,UX_HOST_CLASS_AUDIO_CONTROL * audio_control)82 UINT _ux_host_class_audio_entity_control_value_set(UX_HOST_CLASS_AUDIO *audio, UX_HOST_CLASS_AUDIO_CONTROL *audio_control)
83 {
84
85 UINT status;
86 UCHAR *control_buffer;
87 ULONG actual_size;
88
89 /* If trace is enabled, insert this event into the trace buffer. */
90 UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_AUDIO_CONTROL_VALUE_SET, audio, audio_control -> ux_host_class_audio_control_entity, audio_control -> ux_host_class_audio_control_cur, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0)
91
92 /* Ensure the instance is valid. */
93 if (_ux_host_stack_class_instance_verify(_ux_system_host_class_audio_name, (VOID *) audio) != UX_SUCCESS)
94 {
95
96 /* If trace is enabled, insert this event into the trace buffer. */
97 UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, audio, 0, 0, UX_TRACE_ERRORS, 0, 0)
98
99 return(UX_HOST_CLASS_INSTANCE_UNKNOWN);
100 }
101
102 /* Protect thread reentry to this instance. */
103 _ux_host_mutex_on(&audio -> ux_host_class_audio_mutex);
104
105 /* Need to allocate memory for the control buffer. */
106 control_buffer = _ux_utility_memory_allocate(UX_SAFE_ALIGN, UX_CACHE_SAFE_MEMORY, 4);
107 if (control_buffer == UX_NULL)
108 {
109
110 /* Unprotect thread reentry to this instance. */
111 _ux_host_mutex_off(&audio -> ux_host_class_audio_mutex);
112
113 /* Return an error. */
114 return(UX_MEMORY_INSUFFICIENT);
115 }
116
117 /* The buffer should be aligned. Returned data is little endian so DWord can be used
118 to copy any returned data of BYTE/WORD/DWORD. */
119 _ux_utility_long_put(control_buffer, audio_control -> ux_host_class_audio_control_cur);
120
121 /* Issue SET CUR request. */
122 status = _ux_host_class_audio_control_request(audio, 0,
123 UX_REQUEST_OUT | UX_REQUEST_TYPE_CLASS | UX_REQUEST_TARGET_INTERFACE,
124 #if defined(UX_HOST_CLASS_AUDIO_2_SUPPORT)
125 (_ux_host_class_audio_protocol_get(audio) == UX_HOST_CLASS_AUDIO_PROTOCOL_IP_VERSION_02_00) ?
126 UX_CLASS_AUDIO20_CUR : UX_HOST_CLASS_AUDIO_SET_CUR,
127 #else
128 UX_HOST_CLASS_AUDIO_SET_CUR,
129 #endif
130 audio_control -> ux_host_class_audio_control_channel |
131 (audio_control -> ux_host_class_audio_control << 8),
132 audio_control -> ux_host_class_audio_control_entity,
133 control_buffer, audio_control -> ux_host_class_audio_control_size, &actual_size);
134
135 /* Free all used resources. */
136 _ux_utility_memory_free(control_buffer);
137
138 /* Unprotect thread reentry to this instance. */
139 _ux_host_mutex_off(&audio -> ux_host_class_audio_mutex);
140
141 /* Return completion status. */
142 return(status);
143 }
144