Fix documentation glitches from the restructuring changes.
[pub/USBasp.git] / LUFA / Drivers / USB / HighLevel / Template / Template_Endpoint_Control_W.c
1 uint8_t TEMPLATE_FUNC_NAME (const void* const Buffer,
2 uint16_t Length)
3 {
4 uint8_t* DataStream = ((uint8_t*)Buffer + TEMPLATE_BUFFER_OFFSET(Length));
5 bool LastPacketFull = false;
6
7 if (Length > USB_ControlRequest.wLength)
8 Length = USB_ControlRequest.wLength;
9 else if (!(Length))
10 Endpoint_ClearIN();
11
12 while (Length || LastPacketFull)
13 {
14 uint8_t USB_DeviceState_LCL = USB_DeviceState;
15
16 if (USB_DeviceState_LCL == DEVICE_STATE_Unattached)
17 return ENDPOINT_RWCSTREAM_DeviceDisconnected;
18 else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended)
19 return ENDPOINT_RWCSTREAM_BusSuspended;
20 else if (Endpoint_IsSETUPReceived())
21 return ENDPOINT_RWCSTREAM_HostAborted;
22 else if (Endpoint_IsOUTReceived())
23 break;
24
25 if (Endpoint_IsINReady())
26 {
27 uint16_t BytesInEndpoint = Endpoint_BytesInEndpoint();
28
29 while (Length && (BytesInEndpoint < USB_ControlEndpointSize))
30 {
31 TEMPLATE_TRANSFER_BYTE(DataStream);
32 TEMPLATE_BUFFER_MOVE(DataStream, 1);
33 Length--;
34 BytesInEndpoint++;
35 }
36
37 LastPacketFull = (BytesInEndpoint == USB_ControlEndpointSize);
38 Endpoint_ClearIN();
39 }
40 }
41
42 while (!(Endpoint_IsOUTReceived()))
43 {
44 uint8_t USB_DeviceState_LCL = USB_DeviceState;
45
46 if (USB_DeviceState_LCL == DEVICE_STATE_Unattached)
47 return ENDPOINT_RWCSTREAM_DeviceDisconnected;
48 else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended)
49 return ENDPOINT_RWCSTREAM_BusSuspended;
50 }
51
52 return ENDPOINT_RWCSTREAM_NoError;
53 }
54
55 #undef TEMPLATE_BUFFER_OFFSET
56 #undef TEMPLATE_BUFFER_MOVE
57 #undef TEMPLATE_FUNC_NAME
58 #undef TEMPLATE_TRANSFER_BYTE