Make Benito ping-pong LED code more explicit, using masks of the TX and RX LED masks...
[pub/USBasp.git] / LUFA / Drivers / USB / LowLevel / Template / Template_Endpoint_Control_R.c
1 uint8_t TEMPLATE_FUNC_NAME (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
9 while (Length || LastPacketFull)
10 {
11 if (Endpoint_IsSETUPReceived())
12 return ENDPOINT_RWCSTREAM_HostAborted;
13
14 if (USB_DeviceState == DEVICE_STATE_Unattached)
15 return ENDPOINT_RWCSTREAM_DeviceDisconnected;
16
17 if (Endpoint_IsOUTReceived())
18 {
19 LastPacketFull = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);
20
21 while (Length && Endpoint_BytesInEndpoint())
22 {
23 TEMPLATE_TRANSFER_BYTE(DataStream);
24 Length--;
25 }
26
27 Endpoint_ClearOUT();
28
29 if (!(LastPacketFull))
30 Length = 0;
31 }
32 }
33
34 while (!(Endpoint_IsINReady()))
35 {
36 if (USB_DeviceState == DEVICE_STATE_Unattached)
37 return ENDPOINT_RWCSTREAM_DeviceDisconnected;
38 }
39
40 return ENDPOINT_RWCSTREAM_NoError;
41 }
42
43
44 #undef TEMPLATE_BUFFER_OFFSET
45 #undef TEMPLATE_FUNC_NAME
46 #undef TEMPLATE_TRANSFER_BYTE