Oops - with new changes to the way the device Configuration Descriptor is retrieved...
[pub/USBasp.git] / LUFA / Drivers / USB / LowLevel / Template / Template_Endpoint_Control_W.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 (Endpoint_IsOUTReceived())
15 break;
16
17 if (USB_DeviceState == DEVICE_STATE_Unattached)
18 return ENDPOINT_RWCSTREAM_DeviceDisconnected;
19
20 if (Endpoint_IsINReady())
21 {
22 while (Length && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize))
23 {
24 TEMPLATE_TRANSFER_BYTE(DataStream);
25 Length--;
26 }
27
28 LastPacketFull = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);
29 Endpoint_ClearIN();
30 }
31 }
32
33 while (!(Endpoint_IsOUTReceived()))
34 {
35 if (USB_DeviceState == DEVICE_STATE_Unattached)
36 return ENDPOINT_RWCSTREAM_DeviceDisconnected;
37 }
38
39 return ENDPOINT_RWCSTREAM_NoError;
40 }
41
42 #undef TEMPLATE_BUFFER_OFFSET
43 #undef TEMPLATE_FUNC_NAME
44 #undef TEMPLATE_TRANSFER_BYTE