Added new EEPROM and FLASH buffer versions of the Endpoint and Pipe stream functions...
[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 && !(Endpoint_IsOUTReceived()))
10 {
11 while (!(Endpoint_IsINReady()));
12
13 while (Length && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize))
14 {
15 TEMPLATE_TRANSFER_BYTE(DataStream);
16 Length--;
17 }
18
19 LastPacketFull = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);
20 Endpoint_ClearIN();
21 }
22
23 if (Endpoint_IsOUTReceived())
24 return ENDPOINT_RWCSTREAM_HostAborted;
25
26 if (LastPacketFull)
27 {
28 while (!(Endpoint_IsINReady()));
29 Endpoint_ClearIN();
30 }
31
32 while (!(Endpoint_IsOUTReceived()));
33
34 return ENDPOINT_RWCSTREAM_NoError;
35 }
36
37 #undef TEMPLATE_BUFFER_OFFSET
38 #undef TEMPLATE_FUNC_NAME
39 #undef TEMPLATE_TRANSFER_BYTE