Refactored Host mode Class Driver *_Host_ConfigurePipes() routines to be more space...
[pub/USBasp.git] / LUFA / Drivers / USB / Class / Device / Audio.c
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2010.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 */
8
9 /*
10 Copyright 2010 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 "../../HighLevel/USBMode.h"
33 #if defined(USB_CAN_BE_DEVICE)
34
35 #define __INCLUDE_FROM_AUDIO_DRIVER
36 #define __INCLUDE_FROM_AUDIO_DEVICE_C
37 #include "Audio.h"
38
39 void Audio_Device_ProcessControlRequest(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo)
40 {
41 if (!(Endpoint_IsSETUPReceived()))
42 return;
43
44 if (USB_ControlRequest.wIndex != AudioInterfaceInfo->Config.StreamingInterfaceNumber)
45 return;
46
47 switch (USB_ControlRequest.bRequest)
48 {
49 case REQ_SetInterface:
50 if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_INTERFACE))
51 {
52 Endpoint_ClearSETUP();
53 Endpoint_ClearStatusStage();
54
55 AudioInterfaceInfo->State.InterfaceEnabled = ((USB_ControlRequest.wValue & 0xFF) != 0);
56 }
57
58 break;
59 }
60 }
61
62 bool Audio_Device_ConfigureEndpoints(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo)
63 {
64 memset(&AudioInterfaceInfo->State, 0x00, sizeof(AudioInterfaceInfo->State));
65
66 for (uint8_t EndpointNum = 1; EndpointNum < ENDPOINT_TOTAL_ENDPOINTS; EndpointNum++)
67 {
68 uint16_t Size;
69 uint8_t Type;
70 uint8_t Direction;
71
72 if (EndpointNum == AudioInterfaceInfo->Config.DataINEndpointNumber)
73 {
74 Size = AudioInterfaceInfo->Config.DataINEndpointSize;
75 Direction = ENDPOINT_DIR_IN;
76 Type = EP_TYPE_ISOCHRONOUS;
77 }
78 else if (EndpointNum == AudioInterfaceInfo->Config.DataOUTEndpointNumber)
79 {
80 Size = AudioInterfaceInfo->Config.DataOUTEndpointSize;
81 Direction = ENDPOINT_DIR_OUT;
82 Type = EP_TYPE_ISOCHRONOUS;
83 }
84 else
85 {
86 continue;
87 }
88
89 if (!(Endpoint_ConfigureEndpoint(EndpointNum, Type, Direction, Size, ENDPOINT_BANK_DOUBLE)))
90 {
91 return false;
92 }
93 }
94
95 return true;
96 }
97
98 #endif