Fix documentation glitches from the restructuring changes.
[pub/USBasp.git] / LUFA / Drivers / USB / HighLevel / Template / Template_Endpoint_RW.c
1 uint8_t TEMPLATE_FUNC_NAME (TEMPLATE_BUFFER_TYPE const Buffer,
2 uint16_t Length,
3 uint16_t* const BytesProcessed)
4 {
5 uint8_t* DataStream = ((uint8_t*)Buffer + TEMPLATE_BUFFER_OFFSET(Length));
6 uint16_t BytesInTransfer = 0;
7 uint8_t ErrorCode;
8
9 if ((ErrorCode = Endpoint_WaitUntilReady()))
10 return ErrorCode;
11
12 if (BytesProcessed != NULL)
13 {
14 Length -= *BytesProcessed;
15 TEMPLATE_BUFFER_MOVE(DataStream, *BytesProcessed);
16 }
17
18 while (Length)
19 {
20 if (!(Endpoint_IsReadWriteAllowed()))
21 {
22 TEMPLATE_CLEAR_ENDPOINT();
23
24 if (BytesProcessed != NULL)
25 {
26 *BytesProcessed += BytesInTransfer;
27 return ENDPOINT_RWSTREAM_IncompleteTransfer;
28 }
29
30 #if !defined(INTERRUPT_CONTROL_ENDPOINT)
31 USB_USBTask();
32 #endif
33
34 if ((ErrorCode = Endpoint_WaitUntilReady()))
35 return ErrorCode;
36 }
37 else
38 {
39 TEMPLATE_TRANSFER_BYTE(DataStream);
40 TEMPLATE_BUFFER_MOVE(DataStream, 1);
41 Length--;
42 BytesInTransfer++;
43 }
44 }
45
46 return ENDPOINT_RWSTREAM_NoError;
47 }
48
49 #undef TEMPLATE_FUNC_NAME
50 #undef TEMPLATE_BUFFER_TYPE
51 #undef TEMPLATE_TRANSFER_BYTE
52 #undef TEMPLATE_CLEAR_ENDPOINT
53 #undef TEMPLATE_BUFFER_OFFSET
54 #undef TEMPLATE_BUFFER_MOVE