c2bb3922cac5fa097087a077282e3de600f81a1c
[pub/USBasp.git] / LUFA / Drivers / USB / HighLevel / EndpointStream.c
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2011.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 */
8
9 /*
10 Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
20
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
28 this software.
29 */
30
31 #define __INCLUDE_FROM_USB_DRIVER
32 #include "USBMode.h"
33
34 #if defined(USB_CAN_BE_DEVICE)
35
36 #include "EndpointStream.h"
37
38 #if !defined(CONTROL_ONLY_DEVICE)
39 uint8_t Endpoint_Discard_Stream(uint16_t Length
40 __CALLBACK_PARAM)
41 {
42 uint8_t ErrorCode;
43
44 if ((ErrorCode = Endpoint_WaitUntilReady()))
45 return ErrorCode;
46
47 while (Length)
48 {
49 if (!(Endpoint_IsReadWriteAllowed()))
50 {
51 Endpoint_ClearOUT();
52
53 #if !defined(NO_STREAM_CALLBACKS)
54 if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))
55 return ENDPOINT_RWSTREAM_CallbackAborted;
56 #endif
57
58 if ((ErrorCode = Endpoint_WaitUntilReady()))
59 return ErrorCode;
60 }
61 else
62 {
63 Endpoint_Discard_Byte();
64 Length--;
65 }
66 }
67
68 return ENDPOINT_RWSTREAM_NoError;
69 }
70
71 #define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_LE
72 #define TEMPLATE_BUFFER_TYPE const void*
73 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
74 #define TEMPLATE_BUFFER_OFFSET(Length) 0
75 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*((uint8_t*)BufferPtr++))
76 #include "Template/Template_Endpoint_RW.c"
77
78 #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_LE
79 #define TEMPLATE_BUFFER_TYPE const void*
80 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
81 #define TEMPLATE_BUFFER_OFFSET(Length) 0
82 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr++))
83 #include "Template/Template_Endpoint_RW.c"
84
85 #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_LE
86 #define TEMPLATE_BUFFER_TYPE const void*
87 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
88 #define TEMPLATE_BUFFER_OFFSET(Length) 0
89 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr++))
90 #include "Template/Template_Endpoint_RW.c"
91
92 #define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_BE
93 #define TEMPLATE_BUFFER_TYPE const void*
94 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
95 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
96 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*((uint8_t*)BufferPtr--))
97 #include "Template/Template_Endpoint_RW.c"
98
99 #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_BE
100 #define TEMPLATE_BUFFER_TYPE const void*
101 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
102 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
103 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr--))
104 #include "Template/Template_Endpoint_RW.c"
105
106 #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_BE
107 #define TEMPLATE_BUFFER_TYPE const void*
108 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
109 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
110 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr--))
111 #include "Template/Template_Endpoint_RW.c"
112
113 #define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_LE
114 #define TEMPLATE_BUFFER_TYPE void*
115 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
116 #define TEMPLATE_BUFFER_OFFSET(Length) 0
117 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) *((uint8_t*)BufferPtr++) = Endpoint_Read_Byte()
118 #include "Template/Template_Endpoint_RW.c"
119
120 #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_LE
121 #define TEMPLATE_BUFFER_TYPE void*
122 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
123 #define TEMPLATE_BUFFER_OFFSET(Length) 0
124 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte((uint8_t*)BufferPtr++, Endpoint_Read_Byte())
125 #include "Template/Template_Endpoint_RW.c"
126
127 #define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_BE
128 #define TEMPLATE_BUFFER_TYPE void*
129 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
130 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
131 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) *((uint8_t*)BufferPtr--) = Endpoint_Read_Byte()
132 #include "Template/Template_Endpoint_RW.c"
133
134 #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_BE
135 #define TEMPLATE_BUFFER_TYPE void*
136 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
137 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
138 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte((uint8_t*)BufferPtr--, Endpoint_Read_Byte())
139 #include "Template/Template_Endpoint_RW.c"
140
141 #endif
142
143 #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_LE
144 #define TEMPLATE_BUFFER_OFFSET(Length) 0
145 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*((uint8_t*)BufferPtr++))
146 #include "Template/Template_Endpoint_Control_W.c"
147
148 #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_LE
149 #define TEMPLATE_BUFFER_OFFSET(Length) 0
150 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr++))
151 #include "Template/Template_Endpoint_Control_W.c"
152
153 #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_LE
154 #define TEMPLATE_BUFFER_OFFSET(Length) 0
155 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr++))
156 #include "Template/Template_Endpoint_Control_W.c"
157
158 #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_BE
159 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
160 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*((uint8_t*)BufferPtr--))
161 #include "Template/Template_Endpoint_Control_W.c"
162
163 #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_BE
164 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
165 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr--))
166 #include "Template/Template_Endpoint_Control_W.c"
167
168 #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_BE
169 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
170 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr--))
171 #include "Template/Template_Endpoint_Control_W.c"
172
173 #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_LE
174 #define TEMPLATE_BUFFER_OFFSET(Length) 0
175 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) *((uint8_t*)BufferPtr++) = Endpoint_Read_Byte()
176 #include "Template/Template_Endpoint_Control_R.c"
177
178 #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_LE
179 #define TEMPLATE_BUFFER_OFFSET(Length) 0
180 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte((uint8_t*)BufferPtr++, Endpoint_Read_Byte())
181 #include "Template/Template_Endpoint_Control_R.c"
182
183 #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_BE
184 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
185 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) *((uint8_t*)BufferPtr--) = Endpoint_Read_Byte()
186 #include "Template/Template_Endpoint_Control_R.c"
187
188 #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_BE
189 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
190 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte((uint8_t*)BufferPtr--, Endpoint_Read_Byte())
191 #include "Template/Template_Endpoint_Control_R.c"
192
193 #endif