Added new USB_DeviceState variable to keep track of the current Device mode USB state.
[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
5 while (Length)
6 {
7 if (Endpoint_IsOUTReceived())
8 {
9 while (Length && Endpoint_BytesInEndpoint())
10 {
11 TEMPLATE_TRANSFER_BYTE(DataStream);
12 Length--;
13 }
14
15 Endpoint_ClearOUT();
16 }
17
18 if (USB_DeviceState == DEVICE_STATE_Unattached)
19 return ENDPOINT_RWCSTREAM_DeviceDisconnected;
20 }
21
22 while (!(Endpoint_IsINReady()))
23 {
24 if (USB_DeviceState == DEVICE_STATE_Unattached)
25 return ENDPOINT_RWCSTREAM_DeviceDisconnected;
26 }
27
28 return ENDPOINT_RWCSTREAM_NoError;
29 }
30
31
32 #undef TEMPLATE_BUFFER_OFFSET
33 #undef TEMPLATE_FUNC_NAME
34 #undef TEMPLATE_TRANSFER_BYTE