3 Copyright (C) Dean Camera, 2010.
5 dean [at] fourwalledcubicle [dot] com
10 Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
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.
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
31 #define __INCLUDE_FROM_USB_DRIVER
34 #if defined(USB_CAN_BE_DEVICE)
36 #include "EndpointStream.h"
38 #if !defined(CONTROL_ONLY_DEVICE)
39 uint8_t Endpoint_Discard_Stream(uint16_t Length
44 if ((ErrorCode
= Endpoint_WaitUntilReady()))
47 #if defined(FAST_STREAM_TRANSFERS)
48 uint8_t BytesRemToAlignment
= (Endpoint_BytesInEndpoint() & 0x07);
52 Length
-= BytesRemToAlignment
;
54 switch (BytesRemToAlignment
)
59 if (!(Endpoint_IsReadWriteAllowed()))
63 #if !defined(NO_STREAM_CALLBACKS)
64 if ((Callback
!= NULL
) && (Callback() == STREAMCALLBACK_Abort
))
65 return ENDPOINT_RWSTREAM_CallbackAborted
;
68 if ((ErrorCode
= Endpoint_WaitUntilReady()))
74 Endpoint_Discard_Byte();
75 case 7: Endpoint_Discard_Byte();
76 case 6: Endpoint_Discard_Byte();
77 case 5: Endpoint_Discard_Byte();
78 case 4: Endpoint_Discard_Byte();
79 case 3: Endpoint_Discard_Byte();
80 case 2: Endpoint_Discard_Byte();
81 case 1: Endpoint_Discard_Byte();
82 } while (Length
>= 8);
89 if (!(Endpoint_IsReadWriteAllowed()))
93 #if !defined(NO_STREAM_CALLBACKS)
94 if ((Callback
!= NULL
) && (Callback() == STREAMCALLBACK_Abort
))
95 return ENDPOINT_RWSTREAM_CallbackAborted
;
98 if ((ErrorCode
= Endpoint_WaitUntilReady()))
103 Endpoint_Discard_Byte();
108 return ENDPOINT_RWSTREAM_NoError
;
111 #define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_LE
112 #define TEMPLATE_BUFFER_TYPE const void*
113 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
114 #define TEMPLATE_BUFFER_OFFSET(Length) 0
115 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*((uint8_t*)BufferPtr++))
116 #include "Template/Template_Endpoint_RW.c"
118 #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_LE
119 #define TEMPLATE_BUFFER_TYPE const void*
120 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
121 #define TEMPLATE_BUFFER_OFFSET(Length) 0
122 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr++))
123 #include "Template/Template_Endpoint_RW.c"
125 #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_LE
126 #define TEMPLATE_BUFFER_TYPE const void*
127 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
128 #define TEMPLATE_BUFFER_OFFSET(Length) 0
129 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr++))
130 #include "Template/Template_Endpoint_RW.c"
132 #define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_BE
133 #define TEMPLATE_BUFFER_TYPE const void*
134 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
135 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
136 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*((uint8_t*)BufferPtr--))
137 #include "Template/Template_Endpoint_RW.c"
139 #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_BE
140 #define TEMPLATE_BUFFER_TYPE const void*
141 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
142 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
143 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr--))
144 #include "Template/Template_Endpoint_RW.c"
146 #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_BE
147 #define TEMPLATE_BUFFER_TYPE const void*
148 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
149 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
150 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr--))
151 #include "Template/Template_Endpoint_RW.c"
153 #define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_LE
154 #define TEMPLATE_BUFFER_TYPE void*
155 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
156 #define TEMPLATE_BUFFER_OFFSET(Length) 0
157 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) *((uint8_t*)BufferPtr++) = Endpoint_Read_Byte()
158 #include "Template/Template_Endpoint_RW.c"
160 #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_LE
161 #define TEMPLATE_BUFFER_TYPE void*
162 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
163 #define TEMPLATE_BUFFER_OFFSET(Length) 0
164 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte((uint8_t*)BufferPtr++, Endpoint_Read_Byte())
165 #include "Template/Template_Endpoint_RW.c"
167 #define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_BE
168 #define TEMPLATE_BUFFER_TYPE void*
169 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
170 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
171 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) *((uint8_t*)BufferPtr--) = Endpoint_Read_Byte()
172 #include "Template/Template_Endpoint_RW.c"
174 #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_BE
175 #define TEMPLATE_BUFFER_TYPE void*
176 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
177 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
178 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte((uint8_t*)BufferPtr--, Endpoint_Read_Byte())
179 #include "Template/Template_Endpoint_RW.c"
183 #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_LE
184 #define TEMPLATE_BUFFER_OFFSET(Length) 0
185 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*((uint8_t*)BufferPtr++))
186 #include "Template/Template_Endpoint_Control_W.c"
188 #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_LE
189 #define TEMPLATE_BUFFER_OFFSET(Length) 0
190 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr++))
191 #include "Template/Template_Endpoint_Control_W.c"
193 #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_LE
194 #define TEMPLATE_BUFFER_OFFSET(Length) 0
195 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr++))
196 #include "Template/Template_Endpoint_Control_W.c"
198 #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_BE
199 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
200 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*((uint8_t*)BufferPtr--))
201 #include "Template/Template_Endpoint_Control_W.c"
203 #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_BE
204 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
205 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr--))
206 #include "Template/Template_Endpoint_Control_W.c"
208 #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_BE
209 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
210 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr--))
211 #include "Template/Template_Endpoint_Control_W.c"
213 #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_LE
214 #define TEMPLATE_BUFFER_OFFSET(Length) 0
215 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) *((uint8_t*)BufferPtr++) = Endpoint_Read_Byte()
216 #include "Template/Template_Endpoint_Control_R.c"
218 #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_LE
219 #define TEMPLATE_BUFFER_OFFSET(Length) 0
220 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte((uint8_t*)BufferPtr++, Endpoint_Read_Byte())
221 #include "Template/Template_Endpoint_Control_R.c"
223 #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_BE
224 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
225 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) *((uint8_t*)BufferPtr--) = Endpoint_Read_Byte()
226 #include "Template/Template_Endpoint_Control_R.c"
228 #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_BE
229 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
230 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte((uint8_t*)BufferPtr--, Endpoint_Read_Byte())
231 #include "Template/Template_Endpoint_Control_R.c"