3 Copyright (C) Dean Camera, 2012.
5 dean [at] fourwalledcubicle [dot] com
10 Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)
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.
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
31 #define __INCLUDE_FROM_USB_DRIVER
32 #include "../../Core/USBMode.h"
34 #if defined(USB_CAN_BE_DEVICE)
36 #define __INCLUDE_FROM_AUDIO_DRIVER
37 #define __INCLUDE_FROM_AUDIO_DEVICE_C
38 #include "AudioClassDevice.h"
40 void Audio_Device_ProcessControlRequest(USB_ClassInfo_Audio_Device_t
* const AudioInterfaceInfo
)
42 if (!(Endpoint_IsSETUPReceived()))
45 if ((USB_ControlRequest
.bmRequestType
& CONTROL_REQTYPE_RECIPIENT
) == REQREC_INTERFACE
)
47 uint8_t InterfaceIndex
= (USB_ControlRequest
.wIndex
& 0xFF);
49 if ((InterfaceIndex
!= AudioInterfaceInfo
->Config
.ControlInterfaceNumber
) &&
50 (InterfaceIndex
!= AudioInterfaceInfo
->Config
.StreamingInterfaceNumber
))
54 else if ((USB_ControlRequest
.bmRequestType
& CONTROL_REQTYPE_RECIPIENT
) == REQREC_ENDPOINT
)
56 uint8_t EndpointIndex
= (USB_ControlRequest
.wIndex
& 0xFF);
58 if ((EndpointIndex
!= (ENDPOINT_DIR_IN
| AudioInterfaceInfo
->Config
.DataINEndpointNumber
)) &&
59 (EndpointIndex
!= (ENDPOINT_DIR_OUT
| AudioInterfaceInfo
->Config
.DataOUTEndpointNumber
)))
65 switch (USB_ControlRequest
.bRequest
)
67 case REQ_SetInterface
:
68 if (USB_ControlRequest
.bmRequestType
== (REQDIR_HOSTTODEVICE
| REQTYPE_STANDARD
| REQREC_INTERFACE
))
70 Endpoint_ClearSETUP();
71 Endpoint_ClearStatusStage();
73 AudioInterfaceInfo
->State
.InterfaceEnabled
= ((USB_ControlRequest
.wValue
& 0xFF) != 0);
74 EVENT_Audio_Device_StreamStartStop(AudioInterfaceInfo
);
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
)))
82 Endpoint_ClearSETUP();
83 Endpoint_ClearStatusStage();
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
))
93 uint8_t EndpointProperty
= USB_ControlRequest
.bRequest
;
94 uint8_t EndpointAddress
= (uint8_t)USB_ControlRequest
.wIndex
;
95 uint8_t EndpointControl
= (USB_ControlRequest
.wValue
>> 8);
97 if (CALLBACK_Audio_Device_GetSetEndpointProperty(AudioInterfaceInfo
, EndpointProperty
, EndpointAddress
,
98 EndpointControl
, NULL
, NULL
))
100 uint16_t ValueLength
= USB_ControlRequest
.wLength
;
101 uint8_t Value
[ValueLength
];
103 Endpoint_ClearSETUP();
104 Endpoint_Read_Control_Stream_LE(Value
, ValueLength
);
107 CALLBACK_Audio_Device_GetSetEndpointProperty(AudioInterfaceInfo
, EndpointProperty
, EndpointAddress
,
108 EndpointControl
, &ValueLength
, Value
);
111 else if (USB_ControlRequest
.bmRequestType
== (REQDIR_HOSTTODEVICE
| REQTYPE_CLASS
| REQREC_INTERFACE
))
113 uint8_t Property
= USB_ControlRequest
.bRequest
;
114 uint8_t Entity
= (USB_ControlRequest
.wIndex
>> 8);
115 uint16_t Parameter
= USB_ControlRequest
.wValue
;
117 if (CALLBACK_Audio_Device_GetSetInterfaceProperty(AudioInterfaceInfo
, Property
, Entity
,
118 Parameter
, NULL
, NULL
))
120 uint16_t ValueLength
= USB_ControlRequest
.wLength
;
121 uint8_t Value
[ValueLength
];
123 Endpoint_ClearSETUP();
124 Endpoint_Read_Control_Stream_LE(Value
, ValueLength
);
127 CALLBACK_Audio_Device_GetSetInterfaceProperty(AudioInterfaceInfo
, Property
, Entity
,
128 Parameter
, &ValueLength
, Value
);
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
))
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
];
145 if (CALLBACK_Audio_Device_GetSetEndpointProperty(AudioInterfaceInfo
, EndpointProperty
, EndpointAddress
,
146 EndpointControl
, &ValueLength
, Value
))
148 Endpoint_ClearSETUP();
149 Endpoint_Write_Control_Stream_LE(Value
, ValueLength
);
153 else if (USB_ControlRequest
.bmRequestType
== (REQDIR_DEVICETOHOST
| REQTYPE_CLASS
| REQREC_INTERFACE
))
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
];
161 if (CALLBACK_Audio_Device_GetSetInterfaceProperty(AudioInterfaceInfo
, Property
, Entity
,
162 Parameter
, &ValueLength
, Value
))
164 Endpoint_ClearSETUP();
165 Endpoint_Write_Control_Stream_LE(Value
, ValueLength
);
174 bool Audio_Device_ConfigureEndpoints(USB_ClassInfo_Audio_Device_t
* const AudioInterfaceInfo
)
176 memset(&AudioInterfaceInfo
->State
, 0x00, sizeof(AudioInterfaceInfo
->State
));
178 for (uint8_t EndpointNum
= 1; EndpointNum
< ENDPOINT_TOTAL_ENDPOINTS
; EndpointNum
++)
185 if (EndpointNum
== AudioInterfaceInfo
->Config
.DataINEndpointNumber
)
187 Size
= AudioInterfaceInfo
->Config
.DataINEndpointSize
;
188 Direction
= ENDPOINT_DIR_IN
;
189 Type
= EP_TYPE_ISOCHRONOUS
;
192 else if (EndpointNum
== AudioInterfaceInfo
->Config
.DataOUTEndpointNumber
)
194 Size
= AudioInterfaceInfo
->Config
.DataOUTEndpointSize
;
195 Direction
= ENDPOINT_DIR_OUT
;
196 Type
= EP_TYPE_ISOCHRONOUS
;
204 if (!(Endpoint_ConfigureEndpoint(EndpointNum
, Type
, Direction
, Size
,
205 DoubleBanked ? ENDPOINT_BANK_DOUBLE
: ENDPOINT_BANK_SINGLE
)))
214 // cppcheck-suppress unusedFunction
215 void Audio_Device_Event_Stub(void)