]> git.gir.st - tmk_keyboard.git/blob - protocol/lufa/LUFA-120730/LUFA/Drivers/USB/Class/Device/AudioClassDevice.c
Change TOP_DIR to TMK_DIR in makefiles
[tmk_keyboard.git] / protocol / lufa / LUFA-120730 / 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 }
55 else if ((USB_ControlRequest.bmRequestType & CONTROL_REQTYPE_RECIPIENT) == REQREC_ENDPOINT)
56 {
57 uint8_t EndpointAddress = (USB_ControlRequest.wIndex & 0xFF);
58
59 if ((EndpointAddress != AudioInterfaceInfo->Config.DataINEndpoint.Address) &&
60 (EndpointAddress != AudioInterfaceInfo->Config.DataOUTEndpoint.Address))
61 {
62 return;
63 }
64 }
65
66 switch (USB_ControlRequest.bRequest)
67 {
68 case REQ_SetInterface:
69 if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_INTERFACE))
70 {
71 Endpoint_ClearSETUP();
72 Endpoint_ClearStatusStage();
73
74 AudioInterfaceInfo->State.InterfaceEnabled = ((USB_ControlRequest.wValue & 0xFF) != 0);
75 EVENT_Audio_Device_StreamStartStop(AudioInterfaceInfo);
76 }
77
78 break;
79 case AUDIO_REQ_GetStatus:
80 if ((USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) ||
81 (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_ENDPOINT)))
82 {
83 Endpoint_ClearSETUP();
84 Endpoint_ClearStatusStage();
85 }
86
87 break;
88 case AUDIO_REQ_SetCurrent:
89 case AUDIO_REQ_SetMinimum:
90 case AUDIO_REQ_SetMaximum:
91 case AUDIO_REQ_SetResolution:
92 if ((USB_ControlRequest.bmRequestType & CONTROL_REQTYPE_RECIPIENT) == REQREC_ENDPOINT)
93 {
94 uint8_t EndpointProperty = USB_ControlRequest.bRequest;
95 uint8_t EndpointAddress = (uint8_t)USB_ControlRequest.wIndex;
96 uint8_t EndpointControl = (USB_ControlRequest.wValue >> 8);
97
98 if (CALLBACK_Audio_Device_GetSetEndpointProperty(AudioInterfaceInfo, EndpointProperty, EndpointAddress,
99 EndpointControl, NULL, NULL))
100 {
101 uint16_t ValueLength = USB_ControlRequest.wLength;
102 uint8_t Value[ValueLength];
103
104 Endpoint_ClearSETUP();
105 Endpoint_Read_Control_Stream_LE(Value, ValueLength);
106 Endpoint_ClearIN();
107
108 CALLBACK_Audio_Device_GetSetEndpointProperty(AudioInterfaceInfo, EndpointProperty, EndpointAddress,
109 EndpointControl, &ValueLength, Value);
110 }
111 }
112 else if ((USB_ControlRequest.bmRequestType & CONTROL_REQTYPE_RECIPIENT) == REQREC_INTERFACE)
113 {
114 uint8_t Property = USB_ControlRequest.bRequest;
115 uint8_t Entity = (USB_ControlRequest.wIndex >> 8);
116 uint16_t Parameter = USB_ControlRequest.wValue;
117
118 if (CALLBACK_Audio_Device_GetSetInterfaceProperty(AudioInterfaceInfo, Property, Entity,
119 Parameter, NULL, NULL))
120 {
121 uint16_t ValueLength = USB_ControlRequest.wLength;
122 uint8_t Value[ValueLength];
123
124 Endpoint_ClearSETUP();
125 Endpoint_Read_Control_Stream_LE(Value, ValueLength);
126 Endpoint_ClearIN();
127
128 CALLBACK_Audio_Device_GetSetInterfaceProperty(AudioInterfaceInfo, Property, Entity,
129 Parameter, &ValueLength, Value);
130 }
131 }
132
133 break;
134 case AUDIO_REQ_GetCurrent:
135 case AUDIO_REQ_GetMinimum:
136 case AUDIO_REQ_GetMaximum:
137 case AUDIO_REQ_GetResolution:
138 if ((USB_ControlRequest.bmRequestType & CONTROL_REQTYPE_RECIPIENT) == REQREC_ENDPOINT)
139 {
140 uint8_t EndpointProperty = USB_ControlRequest.bRequest;
141 uint8_t EndpointAddress = (uint8_t)USB_ControlRequest.wIndex;
142 uint8_t EndpointControl = (USB_ControlRequest.wValue >> 8);
143 uint16_t ValueLength = USB_ControlRequest.wLength;
144 uint8_t Value[ValueLength];
145
146 if (CALLBACK_Audio_Device_GetSetEndpointProperty(AudioInterfaceInfo, EndpointProperty, EndpointAddress,
147 EndpointControl, &ValueLength, Value))
148 {
149 Endpoint_ClearSETUP();
150 Endpoint_Write_Control_Stream_LE(Value, ValueLength);
151 Endpoint_ClearOUT();
152 }
153 }
154 else if ((USB_ControlRequest.bmRequestType & CONTROL_REQTYPE_RECIPIENT) == REQREC_INTERFACE)
155 {
156 uint8_t Property = USB_ControlRequest.bRequest;
157 uint8_t Entity = (USB_ControlRequest.wIndex >> 8);
158 uint16_t Parameter = USB_ControlRequest.wValue;
159 uint16_t ValueLength = USB_ControlRequest.wLength;
160 uint8_t Value[ValueLength];
161
162 if (CALLBACK_Audio_Device_GetSetInterfaceProperty(AudioInterfaceInfo, Property, Entity,
163 Parameter, &ValueLength, Value))
164 {
165 Endpoint_ClearSETUP();
166 Endpoint_Write_Control_Stream_LE(Value, ValueLength);
167 Endpoint_ClearOUT();
168 }
169 }
170
171 break;
172 }
173 }
174
175 bool Audio_Device_ConfigureEndpoints(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo)
176 {
177 memset(&AudioInterfaceInfo->State, 0x00, sizeof(AudioInterfaceInfo->State));
178
179 AudioInterfaceInfo->Config.DataINEndpoint.Type = EP_TYPE_ISOCHRONOUS;
180 AudioInterfaceInfo->Config.DataOUTEndpoint.Type = EP_TYPE_ISOCHRONOUS;
181
182 if (!(Endpoint_ConfigureEndpointTable(&AudioInterfaceInfo->Config.DataINEndpoint, 1)))
183 return false;
184
185 if (!(Endpoint_ConfigureEndpointTable(&AudioInterfaceInfo->Config.DataOUTEndpoint, 1)))
186 return false;
187
188 return true;
189 }
190
191 // cppcheck-suppress unusedFunction
192 void Audio_Device_Event_Stub(void)
193 {
194
195 }
196
197 #endif
198
Imprint / Impressum