3 Copyright (C) Dean Camera, 2011.
5 dean [at] fourwalledcubicle [dot] com
10 Copyright 2011 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
,
40 uint16_t* const BytesProcessed
)
43 uint16_t BytesInTransfer
= 0;
45 if ((ErrorCode
= Endpoint_WaitUntilReady()))
48 if (BytesProcessed
!= NULL
)
49 Length
-= *BytesProcessed
;
53 if (!(Endpoint_IsReadWriteAllowed()))
57 if (BytesProcessed
!= NULL
)
59 *BytesProcessed
+= BytesInTransfer
;
60 return ENDPOINT_RWSTREAM_IncompleteTransfer
;
63 if ((ErrorCode
= Endpoint_WaitUntilReady()))
75 return ENDPOINT_RWSTREAM_NoError
;
78 uint8_t Endpoint_Null_Stream(uint16_t Length
,
79 uint16_t* const BytesProcessed
)
82 uint16_t BytesInTransfer
= 0;
84 if ((ErrorCode
= Endpoint_WaitUntilReady()))
87 if (BytesProcessed
!= NULL
)
88 Length
-= *BytesProcessed
;
92 if (!(Endpoint_IsReadWriteAllowed()))
96 if (BytesProcessed
!= NULL
)
98 *BytesProcessed
+= BytesInTransfer
;
99 return ENDPOINT_RWSTREAM_IncompleteTransfer
;
102 if ((ErrorCode
= Endpoint_WaitUntilReady()))
114 return ENDPOINT_RWSTREAM_NoError
;
117 #define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_LE
118 #define TEMPLATE_BUFFER_TYPE const void*
119 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
120 #define TEMPLATE_BUFFER_OFFSET(Length) 0
121 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
122 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr)
123 #include "Template/Template_Endpoint_RW.c"
125 #define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_BE
126 #define TEMPLATE_BUFFER_TYPE const void*
127 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
128 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
129 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
130 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr)
131 #include "Template/Template_Endpoint_RW.c"
133 #define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_LE
134 #define TEMPLATE_BUFFER_TYPE void*
135 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
136 #define TEMPLATE_BUFFER_OFFSET(Length) 0
137 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
138 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8()
139 #include "Template/Template_Endpoint_RW.c"
141 #define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_BE
142 #define TEMPLATE_BUFFER_TYPE void*
143 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
144 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
145 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
146 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8()
147 #include "Template/Template_Endpoint_RW.c"
149 #if defined(ARCH_HAS_FLASH_ADDRESS_SPACE)
150 #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_LE
151 #define TEMPLATE_BUFFER_TYPE const void*
152 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
153 #define TEMPLATE_BUFFER_OFFSET(Length) 0
154 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
155 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr))
156 #include "Template/Template_Endpoint_RW.c"
158 #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_BE
159 #define TEMPLATE_BUFFER_TYPE const void*
160 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
161 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
162 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
163 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr))
164 #include "Template/Template_Endpoint_RW.c"
167 #if defined(ARCH_HAS_EEPROM_ADDRESS_SPACE)
168 #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_LE
169 #define TEMPLATE_BUFFER_TYPE const void*
170 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
171 #define TEMPLATE_BUFFER_OFFSET(Length) 0
172 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
173 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr))
174 #include "Template/Template_Endpoint_RW.c"
176 #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_BE
177 #define TEMPLATE_BUFFER_TYPE const void*
178 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
179 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
180 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
181 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr))
182 #include "Template/Template_Endpoint_RW.c"
184 #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_LE
185 #define TEMPLATE_BUFFER_TYPE void*
186 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
187 #define TEMPLATE_BUFFER_OFFSET(Length) 0
188 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
189 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8())
190 #include "Template/Template_Endpoint_RW.c"
192 #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_BE
193 #define TEMPLATE_BUFFER_TYPE void*
194 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
195 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
196 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
197 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8())
198 #include "Template/Template_Endpoint_RW.c"
203 #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_LE
204 #define TEMPLATE_BUFFER_OFFSET(Length) 0
205 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
206 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr)
207 #include "Template/Template_Endpoint_Control_W.c"
209 #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_BE
210 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
211 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
212 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr)
213 #include "Template/Template_Endpoint_Control_W.c"
215 #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_LE
216 #define TEMPLATE_BUFFER_OFFSET(Length) 0
217 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
218 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8()
219 #include "Template/Template_Endpoint_Control_R.c"
221 #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_BE
222 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
223 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
224 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8()
225 #include "Template/Template_Endpoint_Control_R.c"
227 #if defined(ARCH_HAS_FLASH_ADDRESS_SPACE)
228 #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_LE
229 #define TEMPLATE_BUFFER_OFFSET(Length) 0
230 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
231 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr))
232 #include "Template/Template_Endpoint_Control_W.c"
234 #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_BE
235 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
236 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
237 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr))
238 #include "Template/Template_Endpoint_Control_W.c"
241 #if defined(ARCH_HAS_EEPROM_ADDRESS_SPACE)
242 #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_LE
243 #define TEMPLATE_BUFFER_OFFSET(Length) 0
244 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
245 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr))
246 #include "Template/Template_Endpoint_Control_W.c"
248 #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_BE
249 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
250 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
251 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr))
252 #include "Template/Template_Endpoint_Control_W.c"
254 #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_LE
255 #define TEMPLATE_BUFFER_OFFSET(Length) 0
256 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
257 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8())
258 #include "Template/Template_Endpoint_Control_R.c"
260 #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_BE
261 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
262 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
263 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8())
264 #include "Template/Template_Endpoint_Control_R.c"