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()))
68 Endpoint_Discard_Byte();
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()))
107 Endpoint_Write_Byte(0);
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_Byte(*BufferPtr)
123 #include "Template/Template_Endpoint_RW.c"
125 #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_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_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
130 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte(BufferPtr))
131 #include "Template/Template_Endpoint_RW.c"
133 #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_LE
134 #define TEMPLATE_BUFFER_TYPE const void*
135 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
136 #define TEMPLATE_BUFFER_OFFSET(Length) 0
137 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
138 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte(BufferPtr))
139 #include "Template/Template_Endpoint_RW.c"
141 #define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_BE
142 #define TEMPLATE_BUFFER_TYPE const void*
143 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
144 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
145 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
146 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*BufferPtr)
147 #include "Template/Template_Endpoint_RW.c"
149 #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_BE
150 #define TEMPLATE_BUFFER_TYPE const void*
151 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
152 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
153 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
154 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte(BufferPtr))
155 #include "Template/Template_Endpoint_RW.c"
157 #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_BE
158 #define TEMPLATE_BUFFER_TYPE const void*
159 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
160 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
161 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
162 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte(BufferPtr))
163 #include "Template/Template_Endpoint_RW.c"
165 #define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_LE
166 #define TEMPLATE_BUFFER_TYPE void*
167 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
168 #define TEMPLATE_BUFFER_OFFSET(Length) 0
169 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
170 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_Byte()
171 #include "Template/Template_Endpoint_RW.c"
173 #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_LE
174 #define TEMPLATE_BUFFER_TYPE void*
175 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
176 #define TEMPLATE_BUFFER_OFFSET(Length) 0
177 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
178 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_Byte())
179 #include "Template/Template_Endpoint_RW.c"
181 #define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_BE
182 #define TEMPLATE_BUFFER_TYPE void*
183 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
184 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
185 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
186 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_Byte()
187 #include "Template/Template_Endpoint_RW.c"
189 #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_BE
190 #define TEMPLATE_BUFFER_TYPE void*
191 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
192 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
193 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
194 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_Byte())
195 #include "Template/Template_Endpoint_RW.c"
199 #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_LE
200 #define TEMPLATE_BUFFER_OFFSET(Length) 0
201 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
202 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*BufferPtr)
203 #include "Template/Template_Endpoint_Control_W.c"
205 #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_LE
206 #define TEMPLATE_BUFFER_OFFSET(Length) 0
207 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
208 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte(BufferPtr))
209 #include "Template/Template_Endpoint_Control_W.c"
211 #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_LE
212 #define TEMPLATE_BUFFER_OFFSET(Length) 0
213 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
214 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte(BufferPtr))
215 #include "Template/Template_Endpoint_Control_W.c"
217 #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_BE
218 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
219 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
220 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*BufferPtr)
221 #include "Template/Template_Endpoint_Control_W.c"
223 #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_BE
224 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
225 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
226 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte(BufferPtr))
227 #include "Template/Template_Endpoint_Control_W.c"
229 #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_BE
230 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
231 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
232 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte(BufferPtr))
233 #include "Template/Template_Endpoint_Control_W.c"
235 #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_LE
236 #define TEMPLATE_BUFFER_OFFSET(Length) 0
237 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
238 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_Byte()
239 #include "Template/Template_Endpoint_Control_R.c"
241 #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_LE
242 #define TEMPLATE_BUFFER_OFFSET(Length) 0
243 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
244 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_Byte())
245 #include "Template/Template_Endpoint_Control_R.c"
247 #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_BE
248 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
249 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
250 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_Byte()
251 #include "Template/Template_Endpoint_Control_R.c"
253 #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_BE
254 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
255 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
256 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_Byte())
257 #include "Template/Template_Endpoint_Control_R.c"