Oops - with new changes to the way the device Configuration Descriptor is retrieved...
[pub/USBasp.git] / LUFA / Drivers / USB / LowLevel / Template / Template_Endpoint_RW.c
1 uint8_t TEMPLATE_FUNC_NAME (void* Buffer, uint16_t Length _CALLBACK_PARAM)
2 {
3 uint8_t* DataStream = (uint8_t*)(Buffer + TEMPLATE_BUFFER_OFFSET(Length));
4 uint8_t ErrorCode;
5
6 if ((ErrorCode = Endpoint_WaitUntilReady()))
7 return ErrorCode;
8
9 #if defined(FAST_STREAM_TRANSFERS)
10 uint8_t BytesRemToAlignment = (Endpoint_BytesInEndpoint() & 0x07);
11
12 if (Length >= 8)
13 {
14 Length -= BytesRemToAlignment;
15
16 switch (BytesRemToAlignment)
17 {
18 default:
19 do
20 {
21 if (!(Endpoint_IsReadWriteAllowed()))
22 {
23 TEMPLATE_CLEAR_ENDPOINT();
24
25 #if !defined(NO_STREAM_CALLBACKS)
26 if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))
27 return ENDPOINT_RWSTREAM_CallbackAborted;
28 #endif
29
30 if ((ErrorCode = Endpoint_WaitUntilReady()))
31 return ErrorCode;
32 }
33
34 Length -= 8;
35
36 TEMPLATE_TRANSFER_BYTE(DataStream);
37 case 7: TEMPLATE_TRANSFER_BYTE(DataStream);
38 case 6: TEMPLATE_TRANSFER_BYTE(DataStream);
39 case 5: TEMPLATE_TRANSFER_BYTE(DataStream);
40 case 4: TEMPLATE_TRANSFER_BYTE(DataStream);
41 case 3: TEMPLATE_TRANSFER_BYTE(DataStream);
42 case 2: TEMPLATE_TRANSFER_BYTE(DataStream);
43 case 1: TEMPLATE_TRANSFER_BYTE(DataStream);
44 } while (Length >= 8);
45 }
46 }
47 #endif
48
49 while (Length)
50 {
51 if (!(Endpoint_IsReadWriteAllowed()))
52 {
53 TEMPLATE_CLEAR_ENDPOINT();
54
55 #if !defined(NO_STREAM_CALLBACKS)
56 if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))
57 return ENDPOINT_RWSTREAM_CallbackAborted;
58 #endif
59
60 if ((ErrorCode = Endpoint_WaitUntilReady()))
61 return ErrorCode;
62 }
63 else
64 {
65 TEMPLATE_TRANSFER_BYTE(DataStream);
66 Length--;
67 }
68 }
69
70 return ENDPOINT_RWSTREAM_NoError;
71 }
72
73 #undef TEMPLATE_FUNC_NAME
74 #undef TEMPLATE_TRANSFER_BYTE
75 #undef TEMPLATE_CLEAR_ENDPOINT
76 #undef TEMPLATE_BUFFER_OFFSET