Oops - typos in alterations to HID_DESCRIPTOR_JOYSTICK().
[pub/USBasp.git] / LUFA / Drivers / USB / Class / Device / AudioClassDevice.c
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2012.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 */
8
9 /*
10 Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
20
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
28 this software.
29 */
30
31 #define __INCLUDE_FROM_USB_DRIVER
32 #include "../../Core/USBMode.h"
33
34 #if defined(USB_CAN_BE_DEVICE)
35
36 #define __INCLUDE_FROM_AUDIO_DRIVER
37 #define __INCLUDE_FROM_AUDIO_DEVICE_C
38 #include "AudioClassDevice.h"
39
40 void Audio_Device_ProcessControlRequest(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo)
41 {
42 if (!(Endpoint_IsSETUPReceived()))
43 return;
44
45 if ((USB_ControlRequest.bmRequestType & CONTROL_REQTYPE_RECIPIENT) == REQREC_INTERFACE)
46 {
47 uint8_t InterfaceIndex = (USB_ControlRequest.wIndex & 0xFF);
48
49 if ((InterfaceIndex != AudioInterfaceInfo->Config.ControlInterfaceNumber) &&
50 (InterfaceIndex != AudioInterfaceInfo->Config.StreamingInterfaceNumber))
51
52 return;
53 }
54 else if ((USB_ControlRequest.bmRequestType & CONTROL_REQTYPE_RECIPIENT) == REQREC_ENDPOINT)
55 {
56 uint8_t EndpointIndex = (USB_ControlRequest.wIndex & 0xFF);
57
58 if ((EndpointIndex != (ENDPOINT_DIR_IN | AudioInterfaceInfo->Config.DataINEndpointNumber)) &&
59 (EndpointIndex != (ENDPOINT_DIR_OUT | AudioInterfaceInfo->Config.DataOUTEndpointNumber)))
60 {
61 return;
62 }
63 }
64
65 switch (USB_ControlRequest.bRequest)
66 {
67 case REQ_SetInterface:
68 if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_INTERFACE))
69 {
70 Endpoint_ClearSETUP();
71 Endpoint_ClearStatusStage();
72
73 AudioInterfaceInfo->State.InterfaceEnabled = ((USB_ControlRequest.wValue & 0xFF) != 0);
74 EVENT_Audio_Device_StreamStartStop(AudioInterfaceInfo);
75 }
76
77 break;
78 case AUDIO_REQ_GetStatus:
79 if ((USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) ||
80 (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_ENDPOINT)))
81 {
82 Endpoint_ClearSETUP();
83 Endpoint_ClearStatusStage();
84 }
85
86 break;
87 case AUDIO_REQ_SetCurrent:
88 case AUDIO_REQ_SetMinimum:
89 case AUDIO_REQ_SetMaximum:
90 case AUDIO_REQ_SetResolution:
91 if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_ENDPOINT))
92 {
93 uint8_t EndpointProperty = USB_ControlRequest.bRequest;
94 uint8_t EndpointAddress = (uint8_t)USB_ControlRequest.wIndex;
95 uint8_t EndpointControl = (USB_ControlRequest.wValue >> 8);
96
97 if (CALLBACK_Audio_Device_GetSetEndpointProperty(AudioInterfaceInfo, EndpointProperty, EndpointAddress,
98 EndpointControl, NULL, NULL))
99 {
100 uint16_t ValueLength = USB_ControlRequest.wLength;
101 uint8_t Value[ValueLength];
102
103 Endpoint_ClearSETUP();
104 Endpoint_Read_Control_Stream_LE(Value, ValueLength);
105 Endpoint_ClearIN();
106
107 CALLBACK_Audio_Device_GetSetEndpointProperty(AudioInterfaceInfo, EndpointProperty, EndpointAddress,
108 EndpointControl, &ValueLength, Value);
109 }
110 }
111 else if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
112 {
113 uint8_t Property = USB_ControlRequest.bRequest;
114 uint8_t Entity = (USB_ControlRequest.wIndex >> 8);
115 uint16_t Parameter = USB_ControlRequest.wValue;
116
117 if (CALLBACK_Audio_Device_GetSetInterfaceProperty(AudioInterfaceInfo, Property, Entity,
118 Parameter, NULL, NULL))
119 {
120 uint16_t ValueLength = USB_ControlRequest.wLength;
121 uint8_t Value[ValueLength];
122
123 Endpoint_ClearSETUP();
124 Endpoint_Read_Control_Stream_LE(Value, ValueLength);
125 Endpoint_ClearIN();
126
127 CALLBACK_Audio_Device_GetSetInterfaceProperty(AudioInterfaceInfo, Property, Entity,
128 Parameter, &ValueLength, Value);
129 }
130 }
131
132 break;
133 case AUDIO_REQ_GetCurrent:
134 case AUDIO_REQ_GetMinimum:
135 case AUDIO_REQ_GetMaximum:
136 case AUDIO_REQ_GetResolution:
137 if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_ENDPOINT))
138 {
139 uint8_t EndpointProperty = USB_ControlRequest.bRequest;
140 uint8_t EndpointAddress = (uint8_t)USB_ControlRequest.wIndex;
141 uint8_t EndpointControl = (USB_ControlRequest.wValue >> 8);
142 uint16_t ValueLength = USB_ControlRequest.wLength;
143 uint8_t Value[ValueLength];
144
145 if (CALLBACK_Audio_Device_GetSetEndpointProperty(AudioInterfaceInfo, EndpointProperty, EndpointAddress,
146 EndpointControl, &ValueLength, Value))
147 {
148 Endpoint_ClearSETUP();
149 Endpoint_Write_Control_Stream_LE(Value, ValueLength);
150 Endpoint_ClearOUT();
151 }
152 }
153 else if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
154 {
155 uint8_t Property = USB_ControlRequest.bRequest;
156 uint8_t Entity = (USB_ControlRequest.wIndex >> 8);
157 uint16_t Parameter = USB_ControlRequest.wValue;
158 uint16_t ValueLength = USB_ControlRequest.wLength;
159 uint8_t Value[ValueLength];
160
161 if (CALLBACK_Audio_Device_GetSetInterfaceProperty(AudioInterfaceInfo, Property, Entity,
162 Parameter, &ValueLength, Value))
163 {
164 Endpoint_ClearSETUP();
165 Endpoint_Write_Control_Stream_LE(Value, ValueLength);
166 Endpoint_ClearOUT();
167 }
168 }
169
170 break;
171 }
172 }
173
174 bool Audio_Device_ConfigureEndpoints(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo)
175 {
176 memset(&AudioInterfaceInfo->State, 0x00, sizeof(AudioInterfaceInfo->State));
177
178 for (uint8_t EndpointNum = 1; EndpointNum < ENDPOINT_TOTAL_ENDPOINTS; EndpointNum++)
179 {
180 uint16_t Size;
181 uint8_t Type;
182 uint8_t Direction;
183 bool DoubleBanked;
184
185 if (EndpointNum == AudioInterfaceInfo->Config.DataINEndpointNumber)
186 {
187 Size = AudioInterfaceInfo->Config.DataINEndpointSize;
188 Direction = ENDPOINT_DIR_IN;
189 Type = EP_TYPE_ISOCHRONOUS;
190 DoubleBanked = true;
191 }
192 else if (EndpointNum == AudioInterfaceInfo->Config.DataOUTEndpointNumber)
193 {
194 Size = AudioInterfaceInfo->Config.DataOUTEndpointSize;
195 Direction = ENDPOINT_DIR_OUT;
196 Type = EP_TYPE_ISOCHRONOUS;
197 DoubleBanked = true;
198 }
199 else
200 {
201 continue;
202 }
203
204 if (!(Endpoint_ConfigureEndpoint(EndpointNum, Type, Direction, Size,
205 DoubleBanked ? ENDPOINT_BANK_DOUBLE : ENDPOINT_BANK_SINGLE)))
206 {
207 return false;
208 }
209 }
210
211 return true;
212 }
213
214 // cppcheck-suppress unusedFunction
215 void Audio_Device_Event_Stub(void)
216 {
217
218 }
219
220 #endif
221