Split out endpoint and pipe stream functions into new EndpointStream.c/.h and PipeStr...
[pub/USBasp.git] / LUFA / Drivers / USB / HighLevel / Template / Template_Endpoint_Control_R.c
1 uint8_t TEMPLATE_FUNC_NAME (void* Buffer,
2 uint16_t Length)
3 {
4 uint8_t* DataStream = ((uint8_t*)Buffer + TEMPLATE_BUFFER_OFFSET(Length));
5
6 if (!(Length))
7 Endpoint_ClearOUT();
8
9 while (Length)
10 {
11 if (Endpoint_IsSETUPReceived())
12 return ENDPOINT_RWCSTREAM_HostAborted;
13
14 if (USB_DeviceState == DEVICE_STATE_Unattached)
15 return ENDPOINT_RWCSTREAM_DeviceDisconnected;
16 else if (USB_DeviceState == DEVICE_STATE_Suspended)
17 return ENDPOINT_RWCSTREAM_BusSuspended;
18
19 if (Endpoint_IsOUTReceived())
20 {
21 while (Length && Endpoint_BytesInEndpoint())
22 {
23 TEMPLATE_TRANSFER_BYTE(DataStream);
24 Length--;
25 }
26
27 Endpoint_ClearOUT();
28 }
29 }
30
31 while (!(Endpoint_IsINReady()))
32 {
33 if (USB_DeviceState == DEVICE_STATE_Unattached)
34 return ENDPOINT_RWCSTREAM_DeviceDisconnected;
35 else if (USB_DeviceState == DEVICE_STATE_Suspended)
36 return ENDPOINT_RWCSTREAM_BusSuspended;
37 }
38
39 return ENDPOINT_RWCSTREAM_NoError;
40 }
41
42
43 #undef TEMPLATE_BUFFER_OFFSET
44 #undef TEMPLATE_FUNC_NAME
45 #undef TEMPLATE_TRANSFER_BYTE