Added incomplete MIDIToneGenerator project.
[pub/USBasp.git] / LUFA / Drivers / USB / LowLevel / Template / Template_Endpoint_Control_W.c
1 uint8_t TEMPLATE_FUNC_NAME (const void* Buffer, uint16_t Length)
2 {
3 uint8_t* DataStream = ((uint8_t*)Buffer + TEMPLATE_BUFFER_OFFSET(Length));
4 bool LastPacketFull = false;
5
6 if (Length > USB_ControlRequest.wLength)
7 Length = USB_ControlRequest.wLength;
8 else if (!(Length))
9 Endpoint_ClearIN();
10
11 while (Length || LastPacketFull)
12 {
13 if (Endpoint_IsSETUPReceived())
14 return ENDPOINT_RWCSTREAM_HostAborted;
15
16 if (Endpoint_IsOUTReceived())
17 break;
18
19 if (USB_DeviceState == DEVICE_STATE_Unattached)
20 return ENDPOINT_RWCSTREAM_DeviceDisconnected;
21
22 if (Endpoint_IsINReady())
23 {
24 uint16_t BytesInEndpoint = Endpoint_BytesInEndpoint();
25
26 while (Length && (BytesInEndpoint < USB_ControlEndpointSize))
27 {
28 TEMPLATE_TRANSFER_BYTE(DataStream);
29 Length--;
30 BytesInEndpoint++;
31 }
32
33 LastPacketFull = (BytesInEndpoint == USB_ControlEndpointSize);
34 Endpoint_ClearIN();
35 }
36 }
37
38 while (!(Endpoint_IsOUTReceived()))
39 {
40 if (USB_DeviceState == DEVICE_STATE_Unattached)
41 return ENDPOINT_RWCSTREAM_DeviceDisconnected;
42 }
43
44 return ENDPOINT_RWCSTREAM_NoError;
45 }
46
47 #undef TEMPLATE_BUFFER_OFFSET
48 #undef TEMPLATE_FUNC_NAME
49 #undef TEMPLATE_TRANSFER_BYTE