3 Copyright (C) Dean Camera, 2012.
\r
5 dean [at] fourwalledcubicle [dot] com
\r
10 Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)
\r
12 Permission to use, copy, modify, distribute, and sell this
\r
13 software and its documentation for any purpose is hereby granted
\r
14 without fee, provided that the above copyright notice appear in
\r
15 all copies and that both that the copyright notice and this
\r
16 permission notice and warranty disclaimer appear in supporting
\r
17 documentation, and that the name of the author not be used in
\r
18 advertising or publicity pertaining to distribution of the
\r
19 software without specific, written prior permission.
\r
21 The author disclaim all warranties with regard to this
\r
22 software, including all implied warranties of merchantability
\r
23 and fitness. In no event shall the author be liable for any
\r
24 special, indirect or consequential damages or any damages
\r
25 whatsoever resulting from loss of use, data or profits, whether
\r
26 in an action of contract, negligence or other tortious action,
\r
27 arising out of or in connection with the use or performance of
\r
31 #define __INCLUDE_FROM_USB_DRIVER
\r
32 #include "../../Core/USBMode.h"
\r
34 #if defined(USB_CAN_BE_DEVICE)
\r
36 #define __INCLUDE_FROM_AUDIO_DRIVER
\r
37 #define __INCLUDE_FROM_AUDIO_DEVICE_C
\r
38 #include "AudioClassDevice.h"
\r
40 void Audio_Device_ProcessControlRequest(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo)
\r
42 if (!(Endpoint_IsSETUPReceived()))
\r
45 if ((USB_ControlRequest.bmRequestType & CONTROL_REQTYPE_RECIPIENT) == REQREC_INTERFACE)
\r
47 uint8_t InterfaceIndex = (USB_ControlRequest.wIndex & 0xFF);
\r
49 if ((InterfaceIndex != AudioInterfaceInfo->Config.ControlInterfaceNumber) &&
\r
50 (InterfaceIndex != AudioInterfaceInfo->Config.StreamingInterfaceNumber))
\r
55 else if ((USB_ControlRequest.bmRequestType & CONTROL_REQTYPE_RECIPIENT) == REQREC_ENDPOINT)
\r
57 uint8_t EndpointAddress = (USB_ControlRequest.wIndex & 0xFF);
\r
59 if ((EndpointAddress != AudioInterfaceInfo->Config.DataINEndpoint.Address) &&
\r
60 (EndpointAddress != AudioInterfaceInfo->Config.DataOUTEndpoint.Address))
\r
66 switch (USB_ControlRequest.bRequest)
\r
68 case REQ_SetInterface:
\r
69 if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_INTERFACE))
\r
71 Endpoint_ClearSETUP();
\r
72 Endpoint_ClearStatusStage();
\r
74 AudioInterfaceInfo->State.InterfaceEnabled = ((USB_ControlRequest.wValue & 0xFF) != 0);
\r
75 EVENT_Audio_Device_StreamStartStop(AudioInterfaceInfo);
\r
79 case AUDIO_REQ_GetStatus:
\r
80 if ((USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) ||
\r
81 (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_ENDPOINT)))
\r
83 Endpoint_ClearSETUP();
\r
84 Endpoint_ClearStatusStage();
\r
88 case AUDIO_REQ_SetCurrent:
\r
89 case AUDIO_REQ_SetMinimum:
\r
90 case AUDIO_REQ_SetMaximum:
\r
91 case AUDIO_REQ_SetResolution:
\r
92 if ((USB_ControlRequest.bmRequestType & CONTROL_REQTYPE_RECIPIENT) == REQREC_ENDPOINT)
\r
94 uint8_t EndpointProperty = USB_ControlRequest.bRequest;
\r
95 uint8_t EndpointAddress = (uint8_t)USB_ControlRequest.wIndex;
\r
96 uint8_t EndpointControl = (USB_ControlRequest.wValue >> 8);
\r
98 if (CALLBACK_Audio_Device_GetSetEndpointProperty(AudioInterfaceInfo, EndpointProperty, EndpointAddress,
\r
99 EndpointControl, NULL, NULL))
\r
101 uint16_t ValueLength = USB_ControlRequest.wLength;
\r
102 uint8_t Value[ValueLength];
\r
104 Endpoint_ClearSETUP();
\r
105 Endpoint_Read_Control_Stream_LE(Value, ValueLength);
\r
106 Endpoint_ClearIN();
\r
108 CALLBACK_Audio_Device_GetSetEndpointProperty(AudioInterfaceInfo, EndpointProperty, EndpointAddress,
\r
109 EndpointControl, &ValueLength, Value);
\r
112 else if ((USB_ControlRequest.bmRequestType & CONTROL_REQTYPE_RECIPIENT) == REQREC_INTERFACE)
\r
114 uint8_t Property = USB_ControlRequest.bRequest;
\r
115 uint8_t Entity = (USB_ControlRequest.wIndex >> 8);
\r
116 uint16_t Parameter = USB_ControlRequest.wValue;
\r
118 if (CALLBACK_Audio_Device_GetSetInterfaceProperty(AudioInterfaceInfo, Property, Entity,
\r
119 Parameter, NULL, NULL))
\r
121 uint16_t ValueLength = USB_ControlRequest.wLength;
\r
122 uint8_t Value[ValueLength];
\r
124 Endpoint_ClearSETUP();
\r
125 Endpoint_Read_Control_Stream_LE(Value, ValueLength);
\r
126 Endpoint_ClearIN();
\r
128 CALLBACK_Audio_Device_GetSetInterfaceProperty(AudioInterfaceInfo, Property, Entity,
\r
129 Parameter, &ValueLength, Value);
\r
134 case AUDIO_REQ_GetCurrent:
\r
135 case AUDIO_REQ_GetMinimum:
\r
136 case AUDIO_REQ_GetMaximum:
\r
137 case AUDIO_REQ_GetResolution:
\r
138 if ((USB_ControlRequest.bmRequestType & CONTROL_REQTYPE_RECIPIENT) == REQREC_ENDPOINT)
\r
140 uint8_t EndpointProperty = USB_ControlRequest.bRequest;
\r
141 uint8_t EndpointAddress = (uint8_t)USB_ControlRequest.wIndex;
\r
142 uint8_t EndpointControl = (USB_ControlRequest.wValue >> 8);
\r
143 uint16_t ValueLength = USB_ControlRequest.wLength;
\r
144 uint8_t Value[ValueLength];
\r
146 if (CALLBACK_Audio_Device_GetSetEndpointProperty(AudioInterfaceInfo, EndpointProperty, EndpointAddress,
\r
147 EndpointControl, &ValueLength, Value))
\r
149 Endpoint_ClearSETUP();
\r
150 Endpoint_Write_Control_Stream_LE(Value, ValueLength);
\r
151 Endpoint_ClearOUT();
\r
154 else if ((USB_ControlRequest.bmRequestType & CONTROL_REQTYPE_RECIPIENT) == REQREC_INTERFACE)
\r
156 uint8_t Property = USB_ControlRequest.bRequest;
\r
157 uint8_t Entity = (USB_ControlRequest.wIndex >> 8);
\r
158 uint16_t Parameter = USB_ControlRequest.wValue;
\r
159 uint16_t ValueLength = USB_ControlRequest.wLength;
\r
160 uint8_t Value[ValueLength];
\r
162 if (CALLBACK_Audio_Device_GetSetInterfaceProperty(AudioInterfaceInfo, Property, Entity,
\r
163 Parameter, &ValueLength, Value))
\r
165 Endpoint_ClearSETUP();
\r
166 Endpoint_Write_Control_Stream_LE(Value, ValueLength);
\r
167 Endpoint_ClearOUT();
\r
175 bool Audio_Device_ConfigureEndpoints(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo)
\r
177 memset(&AudioInterfaceInfo->State, 0x00, sizeof(AudioInterfaceInfo->State));
\r
179 AudioInterfaceInfo->Config.DataINEndpoint.Type = EP_TYPE_ISOCHRONOUS;
\r
180 AudioInterfaceInfo->Config.DataOUTEndpoint.Type = EP_TYPE_ISOCHRONOUS;
\r
182 if (!(Endpoint_ConfigureEndpointTable(&AudioInterfaceInfo->Config.DataINEndpoint, 1)))
\r
185 if (!(Endpoint_ConfigureEndpointTable(&AudioInterfaceInfo->Config.DataOUTEndpoint, 1)))
\r
191 // cppcheck-suppress unusedFunction
\r
192 void Audio_Device_Event_Stub(void)
\r