f53d73e7a5802bf77042c5a872f023913d2b650e
3 Copyright (C) Dean Camera, 2009.
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
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.
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
33 void Audio_Device_ProcessControlPacket(USB_ClassInfo_Audio_t
* AudioInterfaceInfo
)
35 if (!(Endpoint_IsSETUPReceived()))
38 if (USB_ControlRequest
.wIndex
!= AudioInterfaceInfo
->StreamingInterfaceNumber
)
41 switch (USB_ControlRequest
.bRequest
)
43 case REQ_SetInterface
:
44 if (USB_ControlRequest
.bmRequestType
== (REQDIR_HOSTTODEVICE
| REQTYPE_STANDARD
| REQREC_INTERFACE
))
46 Endpoint_ClearSETUP();
48 AudioInterfaceInfo
->InterfaceEnabled
= (USB_ControlRequest
.wValue
!= 0);
50 while (!(Endpoint_IsINReady()));
58 bool Audio_Device_ConfigureEndpoints(USB_ClassInfo_Audio_t
* AudioInterfaceInfo
)
60 if (AudioInterfaceInfo
->DataINEndpointNumber
)
62 if (!(Endpoint_ConfigureEndpoint(AudioInterfaceInfo
->DataINEndpointNumber
, EP_TYPE_ISOCHRONOUS
,
63 ENDPOINT_DIR_IN
, AudioInterfaceInfo
->DataINEndpointSize
,
64 ENDPOINT_BANK_DOUBLE
)))
70 if (AudioInterfaceInfo
->DataOUTEndpointNumber
)
72 if (!(Endpoint_ConfigureEndpoint(AudioInterfaceInfo
->DataOUTEndpointNumber
, EP_TYPE_ISOCHRONOUS
,
73 ENDPOINT_DIR_OUT
, AudioInterfaceInfo
->DataOUTEndpointSize
,
74 ENDPOINT_BANK_DOUBLE
)))
83 void Audio_Device_USBTask(USB_ClassInfo_Audio_t
* AudioInterfaceInfo
)
88 int8_t Audio_Device_ReadSample8(void)
92 Sample
= Endpoint_Read_Byte();
94 if (!(Endpoint_IsReadWriteAllowed()))
100 int16_t Audio_Device_ReadSample16(void)
104 Sample
= (int16_t)Endpoint_Read_Word_LE();
106 if (!(Endpoint_IsReadWriteAllowed()))
112 int32_t Audio_Device_ReadSample24(void)
116 Sample
= (((uint32_t)Endpoint_Read_Byte() << 16) | Endpoint_Read_Word_LE());
118 if (!(Endpoint_IsReadWriteAllowed()))
124 void Audio_Device_WriteSample8(int8_t Sample
)
126 Endpoint_Write_Byte(Sample
);
128 if (!(Endpoint_IsReadWriteAllowed()))
132 void Audio_Device_WriteSample16(int16_t Sample
)
134 Endpoint_Write_Word_LE(Sample
);
136 if (!(Endpoint_IsReadWriteAllowed()))
140 void Audio_Device_WriteSample24(int32_t Sample
)
142 Endpoint_Write_Byte(Sample
>> 16);
143 Endpoint_Write_Word_LE(Sample
);
145 if (!(Endpoint_IsReadWriteAllowed()))
149 bool Audio_Device_IsSampleReceived(USB_ClassInfo_Audio_t
* AudioInterfaceInfo
)
151 Endpoint_SelectEndpoint(AudioInterfaceInfo
->DataOUTEndpointNumber
);
152 return Endpoint_IsOUTReceived();
155 bool Audio_Device_IsReadyForNextSample(USB_ClassInfo_Audio_t
* AudioInterfaceInfo
)
157 Endpoint_SelectEndpoint(AudioInterfaceInfo
->DataINEndpointNumber
);
158 return Endpoint_IsINReady();