Change Host mode class driver Pipe configuration routines -- better to let the applic...
[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_ProcessControlPacket(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 != 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 if (AudioInterfaceInfo->Config.DataINEndpointNumber)
63 {
64 if (!(Endpoint_ConfigureEndpoint(AudioInterfaceInfo->Config.DataINEndpointNumber, EP_TYPE_ISOCHRONOUS,
65 ENDPOINT_DIR_IN, AudioInterfaceInfo->Config.DataINEndpointSize,
66 ENDPOINT_BANK_DOUBLE)))
67 {
68 return false;
69 }
70 }
71
72 if (AudioInterfaceInfo->Config.DataOUTEndpointNumber)
73 {
74 if (!(Endpoint_ConfigureEndpoint(AudioInterfaceInfo->Config.DataOUTEndpointNumber, EP_TYPE_ISOCHRONOUS,
75 ENDPOINT_DIR_OUT, AudioInterfaceInfo->Config.DataOUTEndpointSize,
76 ENDPOINT_BANK_DOUBLE)))
77 {
78 return false;
79 }
80 }
81
82 return true;
83 }
84
85 void Audio_Device_USBTask(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo)
86 {
87
88 }
89
90 int8_t Audio_Device_ReadSample8(void)
91 {
92 int8_t Sample;
93
94 Sample = Endpoint_Read_Byte();
95
96 if (!(Endpoint_IsReadWriteAllowed()))
97 Endpoint_ClearOUT();
98
99 return Sample;
100 }
101
102 int16_t Audio_Device_ReadSample16(void)
103 {
104 int16_t Sample;
105
106 Sample = (int16_t)Endpoint_Read_Word_LE();
107
108 if (!(Endpoint_IsReadWriteAllowed()))
109 Endpoint_ClearOUT();
110
111 return Sample;
112 }
113
114 int32_t Audio_Device_ReadSample24(void)
115 {
116 int32_t Sample;
117
118 Sample = (((uint32_t)Endpoint_Read_Byte() << 16) | Endpoint_Read_Word_LE());
119
120 if (!(Endpoint_IsReadWriteAllowed()))
121 Endpoint_ClearOUT();
122
123 return Sample;
124 }
125
126 void Audio_Device_WriteSample8(const int8_t Sample)
127 {
128 Endpoint_Write_Byte(Sample);
129
130 if (!(Endpoint_IsReadWriteAllowed()))
131 Endpoint_ClearIN();
132 }
133
134 void Audio_Device_WriteSample16(const int16_t Sample)
135 {
136 Endpoint_Write_Word_LE(Sample);
137
138 if (!(Endpoint_IsReadWriteAllowed()))
139 Endpoint_ClearIN();
140 }
141
142 void Audio_Device_WriteSample24(const int32_t Sample)
143 {
144 Endpoint_Write_Byte(Sample >> 16);
145 Endpoint_Write_Word_LE(Sample);
146
147 if (!(Endpoint_IsReadWriteAllowed()))
148 Endpoint_ClearIN();
149 }
150
151 bool Audio_Device_IsSampleReceived(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo)
152 {
153 Endpoint_SelectEndpoint(AudioInterfaceInfo->Config.DataOUTEndpointNumber);
154 return Endpoint_IsOUTReceived();
155 }
156
157 bool Audio_Device_IsReadyForNextSample(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo)
158 {
159 Endpoint_SelectEndpoint(AudioInterfaceInfo->Config.DataINEndpointNumber);
160 return Endpoint_IsINReady();
161 }
162
163 #endif