Documentation improvements - put driver example code into its own section, fix incorr...
[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 uint8_t USB_DeviceState_LCL = USB_DeviceState;
12
13 if (USB_DeviceState_LCL == DEVICE_STATE_Unattached)
14 return ENDPOINT_RWCSTREAM_DeviceDisconnected;
15 else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended)
16 return ENDPOINT_RWCSTREAM_BusSuspended;
17 else if (Endpoint_IsSETUPReceived())
18 return ENDPOINT_RWCSTREAM_HostAborted;
19
20 if (Endpoint_IsOUTReceived())
21 {
22 while (Length && Endpoint_BytesInEndpoint())
23 {
24 TEMPLATE_TRANSFER_BYTE(DataStream);
25 Length--;
26 }
27
28 Endpoint_ClearOUT();
29 }
30 }
31
32 while (!(Endpoint_IsINReady()))
33 {
34 uint8_t USB_DeviceState_LCL = USB_DeviceState;
35
36 if (USB_DeviceState_LCL == DEVICE_STATE_Unattached)
37 return ENDPOINT_RWCSTREAM_DeviceDisconnected;
38 else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended)
39 return ENDPOINT_RWCSTREAM_BusSuspended;
40 }
41
42 return ENDPOINT_RWCSTREAM_NoError;
43 }
44
45
46 #undef TEMPLATE_BUFFER_OFFSET
47 #undef TEMPLATE_FUNC_NAME
48 #undef TEMPLATE_TRANSFER_BYTE