Added new RNDISHost Host LowLevel demo. Fixed misnamed Pipe_SetPipeToken() macro...
[pub/USBasp.git] / LUFA / Drivers / USB / Class / Device / Audio.c
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2009.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, and distribute this software
13 and its documentation for any purpose and without fee is hereby
14 granted, provided that the above copyright notice appear in all
15 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 #include "../../HighLevel/USBMode.h"
32 #if defined(USB_CAN_BE_DEVICE)
33
34 #include "Audio.h"
35
36 void Audio_Device_ProcessControlRequest(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo)
37 {
38 if (!(Endpoint_IsSETUPReceived()))
39 return;
40
41 if (USB_ControlRequest.wIndex != AudioInterfaceInfo->Config.StreamingInterfaceNumber)
42 return;
43
44 switch (USB_ControlRequest.bRequest)
45 {
46 case REQ_SetInterface:
47 if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_INTERFACE))
48 {
49 Endpoint_ClearSETUP();
50
51 AudioInterfaceInfo->State.InterfaceEnabled = ((USB_ControlRequest.wValue & 0xFF) != 0);
52
53 Endpoint_ClearStatusStage();
54 }
55
56 break;
57 }
58 }
59
60 bool Audio_Device_ConfigureEndpoints(USB_ClassInfo_Audio_Device_t* AudioInterfaceInfo)
61 {
62 memset(&AudioInterfaceInfo->State, 0x00, sizeof(AudioInterfaceInfo->State));
63
64 if (AudioInterfaceInfo->Config.DataINEndpointNumber)
65 {
66 if (!(Endpoint_ConfigureEndpoint(AudioInterfaceInfo->Config.DataINEndpointNumber, EP_TYPE_ISOCHRONOUS,
67 ENDPOINT_DIR_IN, AudioInterfaceInfo->Config.DataINEndpointSize,
68 ENDPOINT_BANK_DOUBLE)))
69 {
70 return false;
71 }
72 }
73
74 if (AudioInterfaceInfo->Config.DataOUTEndpointNumber)
75 {
76 if (!(Endpoint_ConfigureEndpoint(AudioInterfaceInfo->Config.DataOUTEndpointNumber, EP_TYPE_ISOCHRONOUS,
77 ENDPOINT_DIR_OUT, AudioInterfaceInfo->Config.DataOUTEndpointSize,
78 ENDPOINT_BANK_DOUBLE)))
79 {
80 return false;
81 }
82 }
83
84 return true;
85 }
86
87 void Audio_Device_USBTask(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo)
88 {
89
90 }
91
92 bool Audio_Device_IsSampleReceived(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo)
93 {
94 if ((USB_DeviceState != DEVICE_STATE_Configured) || !(AudioInterfaceInfo->State.InterfaceEnabled))
95 return false;
96
97 Endpoint_SelectEndpoint(AudioInterfaceInfo->Config.DataOUTEndpointNumber);
98 return Endpoint_IsOUTReceived();
99 }
100
101 bool Audio_Device_IsReadyForNextSample(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo)
102 {
103 if ((USB_DeviceState != DEVICE_STATE_Configured) || !(AudioInterfaceInfo->State.InterfaceEnabled))
104 return false;
105
106 Endpoint_SelectEndpoint(AudioInterfaceInfo->Config.DataINEndpointNumber);
107 return Endpoint_IsINReady();
108 }
109
110 #endif