Changed all Device mode LowLevel demos and Device Class drivers so that the control...
[pub/USBasp.git] / LUFA / Drivers / USB / LowLevel / Endpoint.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2010.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2010 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 /** \file
32 * \brief USB device endpoint management definitions.
33 *
34 * This file contains structures, function prototypes and macros related to the management of the device's
35 * data endpoints when the library is initialized in USB device mode.
36 *
37 * \note This file should not be included directly. It is automatically included as needed by the USB driver
38 * dispatch header located in LUFA/Drivers/USB/USB.h.
39 */
40
41 /** \ingroup Group_USB
42 * @defgroup Group_EndpointManagement Endpoint Management
43 *
44 * Functions, macros and enums related to endpoint management when in USB Device mode. This
45 * module contains the endpoint management macros, as well as endpoint interrupt and data
46 * send/receive functions for various data types.
47 *
48 * @{
49 */
50
51 /** @defgroup Group_EndpointRW Endpoint Data Reading and Writing
52 *
53 * Functions, macros, variables, enums and types related to data reading and writing from and to endpoints.
54 */
55
56 /** \ingroup Group_EndpointRW
57 * @defgroup Group_EndpointPrimitiveRW Read/Write of Primitive Data Types
58 *
59 * Functions, macros, variables, enums and types related to data reading and writing of primitive data types
60 * from and to endpoints.
61 */
62
63 /** \ingroup Group_EndpointRW
64 * @defgroup Group_EndpointStreamRW Read/Write of Multi-Byte Streams
65 *
66 * Functions, macros, variables, enums and types related to data reading and writing of data streams from
67 * and to endpoints.
68 */
69
70 /** @defgroup Group_EndpointPacketManagement Endpoint Packet Management
71 *
72 * Functions, macros, variables, enums and types related to packet management of endpoints.
73 */
74
75 #ifndef __ENDPOINT_H__
76 #define __ENDPOINT_H__
77
78 /* Includes: */
79 #include <avr/io.h>
80 #include <avr/pgmspace.h>
81 #include <avr/eeprom.h>
82 #include <stdbool.h>
83
84 #include "../../../Common/Common.h"
85 #include "../HighLevel/USBTask.h"
86 #include "USBInterrupt.h"
87
88 #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__)
89 #include "../HighLevel/StreamCallbacks.h"
90 #endif
91
92 /* Enable C linkage for C++ Compilers: */
93 #if defined(__cplusplus)
94 extern "C" {
95 #endif
96
97 /* Preprocessor Checks: */
98 #if !defined(__INCLUDE_FROM_USB_DRIVER)
99 #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
100 #endif
101
102 #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__)
103 #define __CALLBACK_PARAM , StreamCallbackPtr_t Callback
104 #else
105 #define __CALLBACK_PARAM
106 #endif
107
108 /* Private Interface - For use in library only: */
109 #if !defined(__DOXYGEN__)
110 /* Macros: */
111 #define _ENDPOINT_GET_MAXSIZE(EPIndex) _ENDPOINT_GET_MAXSIZE2(ENDPOINT_DETAILS_EP ## EPIndex)
112 #define _ENDPOINT_GET_MAXSIZE2(EPDetails) _ENDPOINT_GET_MAXSIZE3(EPDetails)
113 #define _ENDPOINT_GET_MAXSIZE3(MaxSize, DB) (MaxSize)
114
115 #define _ENDPOINT_GET_DOUBLEBANK(EPIndex) _ENDPOINT_GET_DOUBLEBANK2(ENDPOINT_DETAILS_EP ## EPIndex)
116 #define _ENDPOINT_GET_DOUBLEBANK2(EPDetails) _ENDPOINT_GET_DOUBLEBANK3(EPDetails)
117 #define _ENDPOINT_GET_DOUBLEBANK3(MaxSize, DB) (DB)
118
119 #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
120 #define ENDPOINT_DETAILS_EP0 64, true
121 #define ENDPOINT_DETAILS_EP1 256, true
122 #define ENDPOINT_DETAILS_EP2 64, true
123 #define ENDPOINT_DETAILS_EP3 64, true
124 #define ENDPOINT_DETAILS_EP4 64, true
125 #define ENDPOINT_DETAILS_EP5 64, true
126 #define ENDPOINT_DETAILS_EP6 64, true
127 #else
128 #define ENDPOINT_DETAILS_EP0 64, true
129 #define ENDPOINT_DETAILS_EP1 64, false
130 #define ENDPOINT_DETAILS_EP2 64, false
131 #define ENDPOINT_DETAILS_EP3 64, true
132 #define ENDPOINT_DETAILS_EP4 64, true
133 #endif
134
135 /* Inline Functions: */
136 static inline uint8_t Endpoint_BytesToEPSizeMask(const uint16_t Bytes) ATTR_WARN_UNUSED_RESULT ATTR_CONST
137 ATTR_ALWAYS_INLINE;
138 static inline uint8_t Endpoint_BytesToEPSizeMask(const uint16_t Bytes)
139 {
140 uint8_t MaskVal = 0;
141 uint16_t CheckBytes = 8;
142
143 while (CheckBytes < Bytes)
144 {
145 MaskVal++;
146 CheckBytes <<= 1;
147 }
148
149 return (MaskVal << EPSIZE0);
150 }
151
152 /* Function Prototypes: */
153 void Endpoint_ClearEndpoints(void);
154 bool Endpoint_ConfigureEndpoint_Prv(const uint8_t Number,
155 const uint8_t UECFG0XData,
156 const uint8_t UECFG1XData);
157
158 #endif
159
160 /* Public Interface - May be used in end-application: */
161 /* Macros: */
162 /** Endpoint data direction mask for \ref Endpoint_ConfigureEndpoint(). This indicates that the endpoint
163 * should be initialized in the OUT direction - i.e. data flows from host to device.
164 */
165 #define ENDPOINT_DIR_OUT (0 << EPDIR)
166
167 /** Endpoint data direction mask for \ref Endpoint_ConfigureEndpoint(). This indicates that the endpoint
168 * should be initialized in the IN direction - i.e. data flows from device to host.
169 */
170 #define ENDPOINT_DIR_IN (1 << EPDIR)
171
172 /** Mask for the bank mode selection for the \ref Endpoint_ConfigureEndpoint() macro. This indicates
173 * that the endpoint should have one single bank, which requires less USB FIFO memory but results
174 * in slower transfers as only one USB device (the AVR or the host) can access the endpoint's
175 * bank at the one time.
176 */
177 #define ENDPOINT_BANK_SINGLE (0 << EPBK0)
178
179 /** Mask for the bank mode selection for the \ref Endpoint_ConfigureEndpoint() macro. This indicates
180 * that the endpoint should have two banks, which requires more USB FIFO memory but results
181 * in faster transfers as one USB device (the AVR or the host) can access one bank while the other
182 * accesses the second bank.
183 */
184 #define ENDPOINT_BANK_DOUBLE (1 << EPBK0)
185
186 /** Endpoint address for the default control endpoint, which always resides in address 0. This is
187 * defined for convenience to give more readable code when used with the endpoint macros.
188 */
189 #define ENDPOINT_CONTROLEP 0
190
191 #if (!defined(FIXED_CONTROL_ENDPOINT_SIZE) || defined(__DOXYGEN__))
192 /** Default size of the default control endpoint's bank, until altered by the control endpoint bank size
193 * value in the device descriptor. Not available if the FIXED_CONTROL_ENDPOINT_SIZE token is defined.
194 */
195 #define ENDPOINT_CONTROLEP_DEFAULT_SIZE 8
196 #endif
197
198 /** Endpoint number mask, for masking against endpoint addresses to retrieve the endpoint's
199 * numerical address in the device.
200 */
201 #define ENDPOINT_EPNUM_MASK 0x07
202
203 /** Endpoint direction mask, for masking against endpoint addresses to retrieve the endpoint's
204 * direction for comparing with the ENDPOINT_DESCRIPTOR_DIR_* masks.
205 */
206 #define ENDPOINT_EPDIR_MASK 0x80
207
208 /** Endpoint bank size mask, for masking against endpoint addresses to retrieve the endpoint's
209 * bank size in the device.
210 */
211 #define ENDPOINT_EPSIZE_MASK 0x7F
212
213 /** Maximum size in bytes of a given endpoint.
214 *
215 * \param[in] n Endpoint number, a value between 0 and (ENDPOINT_TOTAL_ENDPOINTS - 1)
216 */
217 #define ENDPOINT_MAX_SIZE(n) _ENDPOINT_GET_MAXSIZE(n)
218
219 /** Indicates if the given endpoint supports double banking.
220 *
221 * \param[in] n Endpoint number, a value between 0 and (ENDPOINT_TOTAL_ENDPOINTS - 1)
222 */
223 #define ENDPOINT_DOUBLEBANK_SUPPORTED(n) _ENDPOINT_GET_DOUBLEBANK(n)
224
225 #if !defined(CONTROL_ONLY_DEVICE)
226 #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) || defined(__DOXYGEN__)
227 /** Total number of endpoints (including the default control endpoint at address 0) which may
228 * be used in the device. Different USB AVR models support different amounts of endpoints,
229 * this value reflects the maximum number of endpoints for the currently selected AVR model.
230 */
231 #define ENDPOINT_TOTAL_ENDPOINTS 7
232 #else
233 #define ENDPOINT_TOTAL_ENDPOINTS 5
234 #endif
235 #else
236 #define ENDPOINT_TOTAL_ENDPOINTS 1
237 #endif
238
239 /* Enums: */
240 /** Enum for the possible error return codes of the \ref Endpoint_WaitUntilReady() function.
241 *
242 * \ingroup Group_EndpointRW
243 */
244 enum Endpoint_WaitUntilReady_ErrorCodes_t
245 {
246 ENDPOINT_READYWAIT_NoError = 0, /**< Endpoint is ready for next packet, no error. */
247 ENDPOINT_READYWAIT_EndpointStalled = 1, /**< The endpoint was stalled during the stream
248 * transfer by the host or device.
249 */
250 ENDPOINT_READYWAIT_DeviceDisconnected = 2, /**< Device was disconnected from the host while
251 * waiting for the endpoint to become ready.
252 */
253 ENDPOINT_READYWAIT_BusSuspended = 3, /**< The USB bus has been suspended by the host and
254 * no USB endpoint traffic can occur until the bus
255 * has resumed.
256 */
257 ENDPOINT_READYWAIT_Timeout = 4, /**< The host failed to accept or send the next packet
258 * within the software timeout period set by the
259 * \ref USB_STREAM_TIMEOUT_MS macro.
260 */
261 };
262
263 /** Enum for the possible error return codes of the Endpoint_*_Stream_* functions.
264 *
265 * \ingroup Group_EndpointStreamRW
266 */
267 enum Endpoint_Stream_RW_ErrorCodes_t
268 {
269 ENDPOINT_RWSTREAM_NoError = 0, /**< Command completed successfully, no error. */
270 ENDPOINT_RWSTREAM_EndpointStalled = 1, /**< The endpoint was stalled during the stream
271 * transfer by the host or device.
272 */
273 ENDPOINT_RWSTREAM_DeviceDisconnected = 2, /**< Device was disconnected from the host during
274 * the transfer.
275 */
276 ENDPOINT_RWSTREAM_BusSuspended = 3, /**< The USB bus has been suspended by the host and
277 * no USB endpoint traffic can occur until the bus
278 * has resumed.
279 */
280 ENDPOINT_RWSTREAM_Timeout = 4, /**< The host failed to accept or send the next packet
281 * within the software timeout period set by the
282 * \ref USB_STREAM_TIMEOUT_MS macro.
283 */
284 ENDPOINT_RWSTREAM_CallbackAborted = 5, /**< Indicates that the stream's callback function
285 * aborted the transfer early.
286 */
287 };
288
289 /** Enum for the possible error return codes of the Endpoint_*_Control_Stream_* functions..
290 *
291 * \ingroup Group_EndpointStreamRW
292 */
293 enum Endpoint_ControlStream_RW_ErrorCodes_t
294 {
295 ENDPOINT_RWCSTREAM_NoError = 0, /**< Command completed successfully, no error. */
296 ENDPOINT_RWCSTREAM_HostAborted = 1, /**< The aborted the transfer prematurely. */
297 ENDPOINT_RWCSTREAM_DeviceDisconnected = 2, /**< Device was disconnected from the host during
298 * the transfer.
299 */
300 ENDPOINT_RWCSTREAM_BusSuspended = 3, /**< The USB bus has been suspended by the host and
301 * no USB endpoint traffic can occur until the bus
302 * has resumed.
303 */
304 };
305
306 /* Inline Functions: */
307 /** Configures the specified endpoint number with the given endpoint type, direction, bank size
308 * and banking mode. Endpoints should be allocated in ascending order by their address in the
309 * device (i.e. endpoint 1 should be configured before endpoint 2 and so on) to prevent fragmentation
310 * of the USB FIFO memory.
311 *
312 * The endpoint type may be one of the EP_TYPE_* macros listed in LowLevel.h and the direction
313 * may be either \ref ENDPOINT_DIR_OUT or \ref ENDPOINT_DIR_IN.
314 *
315 * The bank size must indicate the maximum packet size that the endpoint can handle. Different
316 * endpoint numbers can handle different maximum packet sizes - refer to the chosen USB AVR's
317 * datasheet to determine the maximum bank size for each endpoint.
318 *
319 * The banking mode may be either \ref ENDPOINT_BANK_SINGLE or \ref ENDPOINT_BANK_DOUBLE.
320 *
321 * \note The default control endpoint should not be manually configured by the user application, as
322 * it is automatically configured by the library internally.
323 * \n\n
324 *
325 * \note This routine will select the specified endpoint, and the endpoint will remain selected
326 * once the routine completes regardless of if the endpoint configuration succeeds.
327 *
328 * \return Boolean true if the configuration succeeded, false otherwise.
329 */
330 static inline bool Endpoint_ConfigureEndpoint(const uint8_t Number,
331 const uint8_t Type,
332 const uint8_t Direction,
333 const uint16_t Size,
334 const uint8_t Banks) ATTR_ALWAYS_INLINE;
335 static inline bool Endpoint_ConfigureEndpoint(const uint8_t Number,
336 const uint8_t Type,
337 const uint8_t Direction,
338 const uint16_t Size,
339 const uint8_t Banks)
340 {
341 return Endpoint_ConfigureEndpoint_Prv(Number, (((Type) << EPTYPE0) | (Direction)),
342 ((1 << ALLOC) | Banks | Endpoint_BytesToEPSizeMask(Size)));
343 }
344
345 /** Indicates the number of bytes currently stored in the current endpoint's selected bank.
346 *
347 * \note The return width of this function may differ, depending on the maximum endpoint bank size
348 * of the selected AVR model.
349 *
350 * \ingroup Group_EndpointRW
351 *
352 * \return Total number of bytes in the currently selected Endpoint's FIFO buffer.
353 */
354 static inline uint16_t Endpoint_BytesInEndpoint(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
355 static inline uint16_t Endpoint_BytesInEndpoint(void)
356 {
357 #if defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
358 return UEBCX;
359 #elif defined(USB_SERIES_4_AVR)
360 return (((uint16_t)UEBCHX << 8) | UEBCLX);
361 #elif defined(USB_SERIES_2_AVR)
362 return UEBCLX;
363 #endif
364 }
365
366 /** Get the endpoint address of the currently selected endpoint. This is typically used to save
367 * the currently selected endpoint number so that it can be restored after another endpoint has
368 * been manipulated.
369 *
370 * \return Index of the currently selected endpoint.
371 */
372 static inline uint8_t Endpoint_GetCurrentEndpoint(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
373 static inline uint8_t Endpoint_GetCurrentEndpoint(void)
374 {
375 #if !defined(CONTROL_ONLY_DEVICE)
376 return (UENUM & ENDPOINT_EPNUM_MASK);
377 #else
378 return ENDPOINT_CONTROLEP;
379 #endif
380 }
381
382 /** Selects the given endpoint number. If the address from the device descriptors is used, the
383 * value should be masked with the \ref ENDPOINT_EPNUM_MASK constant to extract only the endpoint
384 * number (and discarding the endpoint direction bit).
385 *
386 * Any endpoint operations which do not require the endpoint number to be indicated will operate on
387 * the currently selected endpoint.
388 *
389 * \param[in] EndpointNumber Endpoint number to select.
390 */
391 static inline void Endpoint_SelectEndpoint(const uint8_t EndpointNumber) ATTR_ALWAYS_INLINE;
392 static inline void Endpoint_SelectEndpoint(const uint8_t EndpointNumber)
393 {
394 #if !defined(CONTROL_ONLY_DEVICE)
395 UENUM = EndpointNumber;
396 #endif
397 }
398
399 /** Resets the endpoint bank FIFO. This clears all the endpoint banks and resets the USB controller's
400 * In and Out pointers to the bank's contents.
401 *
402 * \param[in] EndpointNumber Endpoint number whose FIFO buffers are to be reset.
403 */
404 static inline void Endpoint_ResetFIFO(const uint8_t EndpointNumber) ATTR_ALWAYS_INLINE;
405 static inline void Endpoint_ResetFIFO(const uint8_t EndpointNumber)
406 {
407 UERST = (1 << EndpointNumber);
408 UERST = 0;
409 }
410
411 /** Enables the currently selected endpoint so that data can be sent and received through it to
412 * and from a host.
413 *
414 * \note Endpoints must first be configured properly via \ref Endpoint_ConfigureEndpoint().
415 */
416 static inline void Endpoint_EnableEndpoint(void) ATTR_ALWAYS_INLINE;
417 static inline void Endpoint_EnableEndpoint(void)
418 {
419 UECONX |= (1 << EPEN);
420 }
421
422 /** Disables the currently selected endpoint so that data cannot be sent and received through it
423 * to and from a host.
424 */
425 static inline void Endpoint_DisableEndpoint(void) ATTR_ALWAYS_INLINE;
426 static inline void Endpoint_DisableEndpoint(void)
427 {
428 UECONX &= ~(1 << EPEN);
429 }
430
431 /** Determines if the currently selected endpoint is enabled, but not necessarily configured.
432 *
433 * \return Boolean True if the currently selected endpoint is enabled, false otherwise.
434 */
435 static inline bool Endpoint_IsEnabled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
436 static inline bool Endpoint_IsEnabled(void)
437 {
438 return ((UECONX & (1 << EPEN)) ? true : false);
439 }
440
441 /** Determines if the currently selected endpoint may be read from (if data is waiting in the endpoint
442 * bank and the endpoint is an OUT direction, or if the bank is not yet full if the endpoint is an IN
443 * direction). This function will return false if an error has occurred in the endpoint, if the endpoint
444 * is an OUT direction and no packet (or an empty packet) has been received, or if the endpoint is an IN
445 * direction and the endpoint bank is full.
446 *
447 * \ingroup Group_EndpointPacketManagement
448 *
449 * \return Boolean true if the currently selected endpoint may be read from or written to, depending on its direction.
450 */
451 static inline bool Endpoint_IsReadWriteAllowed(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
452 static inline bool Endpoint_IsReadWriteAllowed(void)
453 {
454 return ((UEINTX & (1 << RWAL)) ? true : false);
455 }
456
457 /** Determines if the currently selected endpoint is configured.
458 *
459 * \return Boolean true if the currently selected endpoint has been configured, false otherwise.
460 */
461 static inline bool Endpoint_IsConfigured(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
462 static inline bool Endpoint_IsConfigured(void)
463 {
464 return ((UESTA0X & (1 << CFGOK)) ? true : false);
465 }
466
467 /** Returns a mask indicating which INTERRUPT type endpoints have interrupted - i.e. their
468 * interrupt duration has elapsed. Which endpoints have interrupted can be determined by
469 * masking the return value against (1 << {Endpoint Number}).
470 *
471 * \return Mask whose bits indicate which endpoints have interrupted.
472 */
473 static inline uint8_t Endpoint_GetEndpointInterrupts(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
474 static inline uint8_t Endpoint_GetEndpointInterrupts(void)
475 {
476 return UEINT;
477 }
478
479 /** Determines if the specified endpoint number has interrupted (valid only for INTERRUPT type
480 * endpoints).
481 *
482 * \param[in] EndpointNumber Index of the endpoint whose interrupt flag should be tested.
483 *
484 * \return Boolean true if the specified endpoint has interrupted, false otherwise.
485 */
486 static inline bool Endpoint_HasEndpointInterrupted(const uint8_t EndpointNumber) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
487 static inline bool Endpoint_HasEndpointInterrupted(const uint8_t EndpointNumber)
488 {
489 return ((UEINT & (1 << EndpointNumber)) ? true : false);
490 }
491
492 /** Determines if the selected IN endpoint is ready for a new packet.
493 *
494 * \ingroup Group_EndpointPacketManagement
495 *
496 * \return Boolean true if the current endpoint is ready for an IN packet, false otherwise.
497 */
498 static inline bool Endpoint_IsINReady(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
499 static inline bool Endpoint_IsINReady(void)
500 {
501 return ((UEINTX & (1 << TXINI)) ? true : false);
502 }
503
504 /** Determines if the selected OUT endpoint has received new packet.
505 *
506 * \ingroup Group_EndpointPacketManagement
507 *
508 * \return Boolean true if current endpoint is has received an OUT packet, false otherwise.
509 */
510 static inline bool Endpoint_IsOUTReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
511 static inline bool Endpoint_IsOUTReceived(void)
512 {
513 return ((UEINTX & (1 << RXOUTI)) ? true : false);
514 }
515
516 /** Determines if the current CONTROL type endpoint has received a SETUP packet.
517 *
518 * \ingroup Group_EndpointPacketManagement
519 *
520 * \return Boolean true if the selected endpoint has received a SETUP packet, false otherwise.
521 */
522 static inline bool Endpoint_IsSETUPReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
523 static inline bool Endpoint_IsSETUPReceived(void)
524 {
525 return ((UEINTX & (1 << RXSTPI)) ? true : false);
526 }
527
528 /** Clears a received SETUP packet on the currently selected CONTROL type endpoint, freeing up the
529 * endpoint for the next packet.
530 *
531 * \ingroup Group_EndpointPacketManagement
532 *
533 * \note This is not applicable for non CONTROL type endpoints.
534 */
535 static inline void Endpoint_ClearSETUP(void) ATTR_ALWAYS_INLINE;
536 static inline void Endpoint_ClearSETUP(void)
537 {
538 UEINTX &= ~(1 << RXSTPI);
539 }
540
541 /** Sends an IN packet to the host on the currently selected endpoint, freeing up the endpoint for the
542 * next packet and switching to the alternative endpoint bank if double banked.
543 *
544 * \ingroup Group_EndpointPacketManagement
545 */
546 static inline void Endpoint_ClearIN(void) ATTR_ALWAYS_INLINE;
547 static inline void Endpoint_ClearIN(void)
548 {
549 #if !defined(CONTROL_ONLY_DEVICE)
550 UEINTX &= ~((1 << TXINI) | (1 << FIFOCON));
551 #else
552 UEINTX &= ~(1 << TXINI);
553 #endif
554 }
555
556 /** Acknowledges an OUT packet to the host on the currently selected endpoint, freeing up the endpoint
557 * for the next packet and switching to the alternative endpoint bank if double banked.
558 *
559 * \ingroup Group_EndpointPacketManagement
560 */
561 static inline void Endpoint_ClearOUT(void) ATTR_ALWAYS_INLINE;
562 static inline void Endpoint_ClearOUT(void)
563 {
564 #if !defined(CONTROL_ONLY_DEVICE)
565 UEINTX &= ~((1 << RXOUTI) | (1 << FIFOCON));
566 #else
567 UEINTX &= ~(1 << RXOUTI);
568 #endif
569 }
570
571 /** Stalls the current endpoint, indicating to the host that a logical problem occurred with the
572 * indicated endpoint and that the current transfer sequence should be aborted. This provides a
573 * way for devices to indicate invalid commands to the host so that the current transfer can be
574 * aborted and the host can begin its own recovery sequence.
575 *
576 * The currently selected endpoint remains stalled until either the \ref Endpoint_ClearStall() macro
577 * is called, or the host issues a CLEAR FEATURE request to the device for the currently selected
578 * endpoint.
579 *
580 * \ingroup Group_EndpointPacketManagement
581 */
582 static inline void Endpoint_StallTransaction(void) ATTR_ALWAYS_INLINE;
583 static inline void Endpoint_StallTransaction(void)
584 {
585 UECONX |= (1 << STALLRQ);
586 }
587
588 /** Clears the STALL condition on the currently selected endpoint.
589 *
590 * \ingroup Group_EndpointPacketManagement
591 */
592 static inline void Endpoint_ClearStall(void) ATTR_ALWAYS_INLINE;
593 static inline void Endpoint_ClearStall(void)
594 {
595 UECONX |= (1 << STALLRQC);
596 }
597
598 /** Determines if the currently selected endpoint is stalled, false otherwise.
599 *
600 * \ingroup Group_EndpointPacketManagement
601 *
602 * \return Boolean true if the currently selected endpoint is stalled, false otherwise.
603 */
604 static inline bool Endpoint_IsStalled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
605 static inline bool Endpoint_IsStalled(void)
606 {
607 return ((UECONX & (1 << STALLRQ)) ? true : false);
608 }
609
610 /** Resets the data toggle of the currently selected endpoint. */
611 static inline void Endpoint_ResetDataToggle(void) ATTR_ALWAYS_INLINE;
612 static inline void Endpoint_ResetDataToggle(void)
613 {
614 UECONX |= (1 << RSTDT);
615 }
616
617 /** Determines the currently selected endpoint's direction.
618 *
619 * \return The currently selected endpoint's direction, as a ENDPOINT_DIR_* mask.
620 */
621 static inline uint8_t Endpoint_GetEndpointDirection(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
622 static inline uint8_t Endpoint_GetEndpointDirection(void)
623 {
624 return (UECFG0X & ENDPOINT_DIR_IN);
625 }
626
627 /** Sets the direction of the currently selected endpoint.
628 *
629 * \param[in] DirectionMask New endpoint direction, as a ENDPOINT_DIR_* mask.
630 */
631 static inline void Endpoint_SetEndpointDirection(const uint8_t DirectionMask) ATTR_ALWAYS_INLINE;
632 static inline void Endpoint_SetEndpointDirection(const uint8_t DirectionMask)
633 {
634 UECFG0X = ((UECFG0X & ~ENDPOINT_DIR_IN) | DirectionMask);
635 }
636
637 /** Reads one byte from the currently selected endpoint's bank, for OUT direction endpoints.
638 *
639 * \ingroup Group_EndpointPrimitiveRW
640 *
641 * \return Next byte in the currently selected endpoint's FIFO buffer.
642 */
643 static inline uint8_t Endpoint_Read_Byte(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
644 static inline uint8_t Endpoint_Read_Byte(void)
645 {
646 return UEDATX;
647 }
648
649 /** Writes one byte from the currently selected endpoint's bank, for IN direction endpoints.
650 *
651 * \ingroup Group_EndpointPrimitiveRW
652 *
653 * \param[in] Byte Next byte to write into the the currently selected endpoint's FIFO buffer.
654 */
655 static inline void Endpoint_Write_Byte(const uint8_t Byte) ATTR_ALWAYS_INLINE;
656 static inline void Endpoint_Write_Byte(const uint8_t Byte)
657 {
658 UEDATX = Byte;
659 }
660
661 /** Discards one byte from the currently selected endpoint's bank, for OUT direction endpoints.
662 *
663 * \ingroup Group_EndpointPrimitiveRW
664 */
665 static inline void Endpoint_Discard_Byte(void) ATTR_ALWAYS_INLINE;
666 static inline void Endpoint_Discard_Byte(void)
667 {
668 uint8_t Dummy;
669
670 Dummy = UEDATX;
671 }
672
673 /** Reads two bytes from the currently selected endpoint's bank in little endian format, for OUT
674 * direction endpoints.
675 *
676 * \ingroup Group_EndpointPrimitiveRW
677 *
678 * \return Next word in the currently selected endpoint's FIFO buffer.
679 */
680 static inline uint16_t Endpoint_Read_Word_LE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
681 static inline uint16_t Endpoint_Read_Word_LE(void)
682 {
683 union
684 {
685 uint16_t Word;
686 uint8_t Bytes[2];
687 } Data;
688
689 Data.Bytes[0] = UEDATX;
690 Data.Bytes[1] = UEDATX;
691
692 return Data.Word;
693 }
694
695 /** Reads two bytes from the currently selected endpoint's bank in big endian format, for OUT
696 * direction endpoints.
697 *
698 * \ingroup Group_EndpointPrimitiveRW
699 *
700 * \return Next word in the currently selected endpoint's FIFO buffer.
701 */
702 static inline uint16_t Endpoint_Read_Word_BE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
703 static inline uint16_t Endpoint_Read_Word_BE(void)
704 {
705 union
706 {
707 uint16_t Word;
708 uint8_t Bytes[2];
709 } Data;
710
711 Data.Bytes[1] = UEDATX;
712 Data.Bytes[0] = UEDATX;
713
714 return Data.Word;
715 }
716
717 /** Writes two bytes to the currently selected endpoint's bank in little endian format, for IN
718 * direction endpoints.
719 *
720 * \ingroup Group_EndpointPrimitiveRW
721 *
722 * \param[in] Word Next word to write to the currently selected endpoint's FIFO buffer.
723 */
724 static inline void Endpoint_Write_Word_LE(const uint16_t Word) ATTR_ALWAYS_INLINE;
725 static inline void Endpoint_Write_Word_LE(const uint16_t Word)
726 {
727 UEDATX = (Word & 0xFF);
728 UEDATX = (Word >> 8);
729 }
730
731 /** Writes two bytes to the currently selected endpoint's bank in big endian format, for IN
732 * direction endpoints.
733 *
734 * \ingroup Group_EndpointPrimitiveRW
735 *
736 * \param[in] Word Next word to write to the currently selected endpoint's FIFO buffer.
737 */
738 static inline void Endpoint_Write_Word_BE(const uint16_t Word) ATTR_ALWAYS_INLINE;
739 static inline void Endpoint_Write_Word_BE(const uint16_t Word)
740 {
741 UEDATX = (Word >> 8);
742 UEDATX = (Word & 0xFF);
743 }
744
745 /** Discards two bytes from the currently selected endpoint's bank, for OUT direction endpoints.
746 *
747 * \ingroup Group_EndpointPrimitiveRW
748 */
749 static inline void Endpoint_Discard_Word(void) ATTR_ALWAYS_INLINE;
750 static inline void Endpoint_Discard_Word(void)
751 {
752 uint8_t Dummy;
753
754 Dummy = UEDATX;
755 Dummy = UEDATX;
756 }
757
758 /** Reads four bytes from the currently selected endpoint's bank in little endian format, for OUT
759 * direction endpoints.
760 *
761 * \ingroup Group_EndpointPrimitiveRW
762 *
763 * \return Next double word in the currently selected endpoint's FIFO buffer.
764 */
765 static inline uint32_t Endpoint_Read_DWord_LE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
766 static inline uint32_t Endpoint_Read_DWord_LE(void)
767 {
768 union
769 {
770 uint32_t DWord;
771 uint8_t Bytes[4];
772 } Data;
773
774 Data.Bytes[0] = UEDATX;
775 Data.Bytes[1] = UEDATX;
776 Data.Bytes[2] = UEDATX;
777 Data.Bytes[3] = UEDATX;
778
779 return Data.DWord;
780 }
781
782 /** Reads four bytes from the currently selected endpoint's bank in big endian format, for OUT
783 * direction endpoints.
784 *
785 * \ingroup Group_EndpointPrimitiveRW
786 *
787 * \return Next double word in the currently selected endpoint's FIFO buffer.
788 */
789 static inline uint32_t Endpoint_Read_DWord_BE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
790 static inline uint32_t Endpoint_Read_DWord_BE(void)
791 {
792 union
793 {
794 uint32_t DWord;
795 uint8_t Bytes[4];
796 } Data;
797
798 Data.Bytes[3] = UEDATX;
799 Data.Bytes[2] = UEDATX;
800 Data.Bytes[1] = UEDATX;
801 Data.Bytes[0] = UEDATX;
802
803 return Data.DWord;
804 }
805
806 /** Writes four bytes to the currently selected endpoint's bank in little endian format, for IN
807 * direction endpoints.
808 *
809 * \ingroup Group_EndpointPrimitiveRW
810 *
811 * \param[in] DWord Next double word to write to the currently selected endpoint's FIFO buffer.
812 */
813 static inline void Endpoint_Write_DWord_LE(const uint32_t DWord) ATTR_ALWAYS_INLINE;
814 static inline void Endpoint_Write_DWord_LE(const uint32_t DWord)
815 {
816 UEDATX = (DWord & 0xFF);
817 UEDATX = (DWord >> 8);
818 UEDATX = (DWord >> 16);
819 UEDATX = (DWord >> 24);
820 }
821
822 /** Writes four bytes to the currently selected endpoint's bank in big endian format, for IN
823 * direction endpoints.
824 *
825 * \ingroup Group_EndpointPrimitiveRW
826 *
827 * \param[in] DWord Next double word to write to the currently selected endpoint's FIFO buffer.
828 */
829 static inline void Endpoint_Write_DWord_BE(const uint32_t DWord) ATTR_ALWAYS_INLINE;
830 static inline void Endpoint_Write_DWord_BE(const uint32_t DWord)
831 {
832 UEDATX = (DWord >> 24);
833 UEDATX = (DWord >> 16);
834 UEDATX = (DWord >> 8);
835 UEDATX = (DWord & 0xFF);
836 }
837
838 /** Discards four bytes from the currently selected endpoint's bank, for OUT direction endpoints.
839 *
840 * \ingroup Group_EndpointPrimitiveRW
841 */
842 static inline void Endpoint_Discard_DWord(void) ATTR_ALWAYS_INLINE;
843 static inline void Endpoint_Discard_DWord(void)
844 {
845 uint8_t Dummy;
846
847 Dummy = UEDATX;
848 Dummy = UEDATX;
849 Dummy = UEDATX;
850 Dummy = UEDATX;
851 }
852
853 /* External Variables: */
854 /** Global indicating the maximum packet size of the default control endpoint located at address
855 * 0 in the device. This value is set to the value indicated in the device descriptor in the user
856 * project once the USB interface is initialized into device mode.
857 *
858 * If space is an issue, it is possible to fix this to a static value by defining the control
859 * endpoint size in the FIXED_CONTROL_ENDPOINT_SIZE token passed to the compiler in the makefile
860 * via the -D switch. When a fixed control endpoint size is used, the size is no longer dynamically
861 * read from the descriptors at runtime and instead fixed to the given value. When used, it is
862 * important that the descriptor control endpoint size value matches the size given as the
863 * FIXED_CONTROL_ENDPOINT_SIZE token - it is recommended that the FIXED_CONTROL_ENDPOINT_SIZE token
864 * be used in the descriptors to ensure this.
865 *
866 * \note This variable should be treated as read-only in the user application, and never manually
867 * changed in value.
868 */
869 #if (!defined(FIXED_CONTROL_ENDPOINT_SIZE) || defined(__DOXYGEN__))
870 extern uint8_t USB_ControlEndpointSize;
871 #else
872 #define USB_ControlEndpointSize FIXED_CONTROL_ENDPOINT_SIZE
873 #endif
874
875 /* Function Prototypes: */
876 /** Spin-loops until the currently selected non-control endpoint is ready for the next packet of data
877 * to be read or written to it.
878 *
879 * \note This routine should not be called on CONTROL type endpoints.
880 *
881 * \ingroup Group_EndpointRW
882 *
883 * \return A value from the \ref Endpoint_WaitUntilReady_ErrorCodes_t enum.
884 */
885 uint8_t Endpoint_WaitUntilReady(void);
886
887 /** Completes the status stage of a control transfer on a CONTROL type endpoint automatically,
888 * with respect to the data direction. This is a convenience function which can be used to
889 * simplify user control request handling.
890 */
891 void Endpoint_ClearStatusStage(void);
892
893 /** Reads and discards the given number of bytes from the endpoint from the given buffer,
894 * discarding fully read packets from the host as needed. The last packet is not automatically
895 * discarded once the remaining bytes has been read; the user is responsible for manually
896 * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro. Between
897 * each USB packet, the given stream callback function is executed repeatedly until the next
898 * packet is ready, allowing for early aborts of stream transfers.
899 *
900 * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
901 * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
902 * disabled and this function has the Callback parameter omitted.
903 *
904 * \note This routine should not be used on CONTROL type endpoints.
905 *
906 * \ingroup Group_EndpointStreamRW
907 *
908 * \param[in] Length Number of bytes to send via the currently selected endpoint.
909 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback.
910 *
911 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
912 */
913 uint8_t Endpoint_Discard_Stream(uint16_t Length
914 __CALLBACK_PARAM);
915
916 /** Writes the given number of bytes to the endpoint from the given buffer in little endian,
917 * sending full packets to the host as needed. The last packet filled is not automatically sent;
918 * the user is responsible for manually sending the last written packet to the host via the
919 * \ref Endpoint_ClearIN() macro. Between each USB packet, the given stream callback function
920 * is executed repeatedly until the endpoint is ready to accept the next packet, allowing for early
921 * aborts of stream transfers.
922 *
923 * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
924 * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
925 * disabled and this function has the Callback parameter omitted.
926 *
927 * \note This routine should not be used on CONTROL type endpoints.
928 *
929 * \ingroup Group_EndpointStreamRW
930 *
931 * \param[in] Buffer Pointer to the source data buffer to read from.
932 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
933 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback.
934 *
935 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
936 */
937 uint8_t Endpoint_Write_Stream_LE(const void* Buffer,
938 uint16_t Length
939 __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
940
941 /** EEPROM buffer source version of \ref Endpoint_Write_Stream_LE().
942 *
943 * \ingroup Group_EndpointStreamRW
944 *
945 * \param[in] Buffer Pointer to the source data buffer to read from.
946 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
947 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback.
948 *
949 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
950 */
951 uint8_t Endpoint_Write_EStream_LE(const void* Buffer,
952 uint16_t Length
953 __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
954
955 /** FLASH buffer source version of \ref Endpoint_Write_Stream_LE().
956 *
957 * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
958 *
959 * \ingroup Group_EndpointStreamRW
960 *
961 * \param[in] Buffer Pointer to the source data buffer to read from.
962 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
963 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback.
964 *
965 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
966 */
967 uint8_t Endpoint_Write_PStream_LE(const void* Buffer,
968 uint16_t Length
969 __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
970
971 /** Writes the given number of bytes to the endpoint from the given buffer in big endian,
972 * sending full packets to the host as needed. The last packet filled is not automatically sent;
973 * the user is responsible for manually sending the last written packet to the host via the
974 * \ref Endpoint_ClearIN() macro. Between each USB packet, the given stream callback function
975 * is executed repeatedly until the endpoint is ready to accept the next packet, allowing for early
976 * aborts of stream transfers.
977 *
978 * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
979 * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
980 * disabled and this function has the Callback parameter omitted.
981 *
982 * \note This routine should not be used on CONTROL type endpoints.
983 *
984 * \ingroup Group_EndpointStreamRW
985 *
986 * \param[in] Buffer Pointer to the source data buffer to read from.
987 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
988 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback.
989 *
990 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
991 */
992 uint8_t Endpoint_Write_Stream_BE(const void* Buffer,
993 uint16_t Length
994 __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
995
996 /** EEPROM buffer source version of \ref Endpoint_Write_Stream_BE().
997 *
998 * \ingroup Group_EndpointStreamRW
999 *
1000 * \param[in] Buffer Pointer to the source data buffer to read from.
1001 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
1002 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback.
1003 *
1004 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
1005 */
1006 uint8_t Endpoint_Write_EStream_BE(const void* Buffer,
1007 uint16_t Length
1008 __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
1009
1010 /** FLASH buffer source version of \ref Endpoint_Write_Stream_BE().
1011 *
1012 * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
1013 *
1014 * \ingroup Group_EndpointStreamRW
1015 *
1016 * \param[in] Buffer Pointer to the source data buffer to read from.
1017 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
1018 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback.
1019 *
1020 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
1021 */
1022 uint8_t Endpoint_Write_PStream_BE(const void* Buffer,
1023 uint16_t Length
1024 __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
1025
1026 /** Reads the given number of bytes from the endpoint from the given buffer in little endian,
1027 * discarding fully read packets from the host as needed. The last packet is not automatically
1028 * discarded once the remaining bytes has been read; the user is responsible for manually
1029 * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro. Between
1030 * each USB packet, the given stream callback function is executed repeatedly until the endpoint
1031 * is ready to accept the next packet, allowing for early aborts of stream transfers.
1032 *
1033 * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
1034 * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
1035 * disabled and this function has the Callback parameter omitted.
1036 *
1037 * \note This routine should not be used on CONTROL type endpoints.
1038 *
1039 * \ingroup Group_EndpointStreamRW
1040 *
1041 * \param[out] Buffer Pointer to the destination data buffer to write to.
1042 * \param[in] Length Number of bytes to send via the currently selected endpoint.
1043 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback.
1044 *
1045 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
1046 */
1047 uint8_t Endpoint_Read_Stream_LE(void* Buffer,
1048 uint16_t Length
1049 __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
1050
1051 /** EEPROM buffer source version of \ref Endpoint_Read_Stream_LE().
1052 *
1053 * \ingroup Group_EndpointStreamRW
1054 *
1055 * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space.
1056 * \param[in] Length Number of bytes to send via the currently selected endpoint.
1057 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback.
1058 *
1059 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
1060 */
1061 uint8_t Endpoint_Read_EStream_LE(void* Buffer,
1062 uint16_t Length
1063 __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
1064
1065 /** Reads the given number of bytes from the endpoint from the given buffer in big endian,
1066 * discarding fully read packets from the host as needed. The last packet is not automatically
1067 * discarded once the remaining bytes has been read; the user is responsible for manually
1068 * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro. Between
1069 * each USB packet, the given stream callback function is executed repeatedly until the endpoint
1070 * is ready to accept the next packet, allowing for early aborts of stream transfers.
1071 *
1072 * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
1073 * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
1074 * disabled and this function has the Callback parameter omitted.
1075 *
1076 * \note This routine should not be used on CONTROL type endpoints.
1077 *
1078 * \ingroup Group_EndpointStreamRW
1079 *
1080 * \param[out] Buffer Pointer to the destination data buffer to write to.
1081 * \param[in] Length Number of bytes to send via the currently selected endpoint.
1082 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback.
1083 *
1084 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
1085 */
1086 uint8_t Endpoint_Read_Stream_BE(void* Buffer,
1087 uint16_t Length
1088 __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
1089
1090 /** EEPROM buffer source version of \ref Endpoint_Read_Stream_BE().
1091 *
1092 * \ingroup Group_EndpointStreamRW
1093 *
1094 * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space.
1095 * \param[in] Length Number of bytes to send via the currently selected endpoint.
1096 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback.
1097 *
1098 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
1099 */
1100 uint8_t Endpoint_Read_EStream_BE(void* Buffer,
1101 uint16_t Length
1102 __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
1103
1104 /** Writes the given number of bytes to the CONTROL type endpoint from the given buffer in little endian,
1105 * sending full packets to the host as needed. The host OUT acknowledgement is not automatically cleared
1106 * in both failure and success states; the user is responsible for manually clearing the setup OUT to
1107 * finalize the transfer via the \ref Endpoint_ClearOUT() macro.
1108 *
1109 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1110 * to clear the status stage when using this routine in a control transaction.
1111 * \n\n
1112 *
1113 * \note This routine should only be used on CONTROL type endpoints.
1114 *
1115 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1116 * together; i.e. the entire stream data must be read or written at the one time.
1117 *
1118 * \ingroup Group_EndpointStreamRW
1119 *
1120 * \param[in] Buffer Pointer to the source data buffer to read from.
1121 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
1122 *
1123 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1124 */
1125 uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer,
1126 uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
1127
1128 /** EEPROM buffer source version of Endpoint_Write_Control_Stream_LE.
1129 *
1130 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1131 * to clear the status stage when using this routine in a control transaction.
1132 * \n\n
1133 *
1134 * \note This routine should only be used on CONTROL type endpoints.
1135 *
1136 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1137 * together; i.e. the entire stream data must be read or written at the one time.
1138 *
1139 * \ingroup Group_EndpointStreamRW
1140 *
1141 * \param[in] Buffer Pointer to the source data buffer to read from.
1142 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
1143 *
1144 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1145 */
1146 uint8_t Endpoint_Write_Control_EStream_LE(const void* Buffer,
1147 uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
1148
1149 /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_LE().
1150 *
1151 * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
1152 *
1153 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1154 * to clear the status stage when using this routine in a control transaction.
1155 * \n\n
1156 *
1157 * \note This routine should only be used on CONTROL type endpoints.
1158 *
1159 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1160 * together; i.e. the entire stream data must be read or written at the one time.
1161 *
1162 * \ingroup Group_EndpointStreamRW
1163 *
1164 * \param[in] Buffer Pointer to the source data buffer to read from.
1165 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
1166 *
1167 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1168 */
1169 uint8_t Endpoint_Write_Control_PStream_LE(const void* Buffer,
1170 uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
1171
1172 /** Writes the given number of bytes to the CONTROL type endpoint from the given buffer in big endian,
1173 * sending full packets to the host as needed. The host OUT acknowledgement is not automatically cleared
1174 * in both failure and success states; the user is responsible for manually clearing the setup OUT to
1175 * finalize the transfer via the \ref Endpoint_ClearOUT() macro.
1176 *
1177 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1178 * to clear the status stage when using this routine in a control transaction.
1179 * \n\n
1180 *
1181 * \note This routine should only be used on CONTROL type endpoints.
1182 *
1183 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1184 * together; i.e. the entire stream data must be read or written at the one time.
1185 *
1186 * \ingroup Group_EndpointStreamRW
1187 *
1188 * \param[in] Buffer Pointer to the source data buffer to read from.
1189 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
1190 *
1191 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1192 */
1193 uint8_t Endpoint_Write_Control_Stream_BE(const void* Buffer,
1194 uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
1195
1196 /** EEPROM buffer source version of \ref Endpoint_Write_Control_Stream_BE().
1197 *
1198 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1199 * to clear the status stage when using this routine in a control transaction.
1200 * \n\n
1201 *
1202 * \note This routine should only be used on CONTROL type endpoints.
1203 *
1204 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1205 * together; i.e. the entire stream data must be read or written at the one time.
1206 *
1207 * \ingroup Group_EndpointStreamRW
1208 *
1209 * \param[in] Buffer Pointer to the source data buffer to read from.
1210 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
1211 *
1212 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1213 */
1214 uint8_t Endpoint_Write_Control_EStream_BE(const void* Buffer,
1215 uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
1216
1217 /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_BE().
1218 *
1219 * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
1220 *
1221 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1222 * to clear the status stage when using this routine in a control transaction.
1223 * \n\n
1224 *
1225 * \note This routine should only be used on CONTROL type endpoints.
1226 *
1227 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1228 * together; i.e. the entire stream data must be read or written at the one time.
1229 *
1230 * \ingroup Group_EndpointStreamRW
1231 *
1232 * \param[in] Buffer Pointer to the source data buffer to read from.
1233 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
1234 *
1235 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1236 */
1237 uint8_t Endpoint_Write_Control_PStream_BE(const void* Buffer,
1238 uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
1239
1240 /** Reads the given number of bytes from the CONTROL endpoint from the given buffer in little endian,
1241 * discarding fully read packets from the host as needed. The device IN acknowledgement is not
1242 * automatically sent after success or failure states; the user is responsible for manually sending the
1243 * setup IN to finalize the transfer via the \ref Endpoint_ClearIN() macro.
1244 *
1245 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1246 * to clear the status stage when using this routine in a control transaction.
1247 * \n\n
1248 *
1249 * \note This routine should only be used on CONTROL type endpoints.
1250 *
1251 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1252 * together; i.e. the entire stream data must be read or written at the one time.
1253 *
1254 * \ingroup Group_EndpointStreamRW
1255 *
1256 * \param[out] Buffer Pointer to the destination data buffer to write to.
1257 * \param[in] Length Number of bytes to send via the currently selected endpoint.
1258 *
1259 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1260 */
1261 uint8_t Endpoint_Read_Control_Stream_LE(void* Buffer,
1262 uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
1263
1264 /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_LE().
1265 *
1266 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1267 * to clear the status stage when using this routine in a control transaction.
1268 * \n\n
1269 *
1270 * \note This routine should only be used on CONTROL type endpoints.
1271 *
1272 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1273 * together; i.e. the entire stream data must be read or written at the one time.
1274 *
1275 * \ingroup Group_EndpointStreamRW
1276 *
1277 * \param[out] Buffer Pointer to the destination data buffer to write to.
1278 * \param[in] Length Number of bytes to send via the currently selected endpoint.
1279 *
1280 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1281 */
1282 uint8_t Endpoint_Read_Control_EStream_LE(void* Buffer,
1283 uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
1284
1285 /** Reads the given number of bytes from the CONTROL endpoint from the given buffer in big endian,
1286 * discarding fully read packets from the host as needed. The device IN acknowledgement is not
1287 * automatically sent after success or failure states; the user is responsible for manually sending the
1288 * setup IN to finalize the transfer via the \ref Endpoint_ClearIN() macro.
1289 *
1290 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1291 * to clear the status stage when using this routine in a control transaction.
1292 * \n\n
1293 *
1294 * \note This routine should only be used on CONTROL type endpoints.
1295 *
1296 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1297 * together; i.e. the entire stream data must be read or written at the one time.
1298 *
1299 * \ingroup Group_EndpointStreamRW
1300 *
1301 * \param[out] Buffer Pointer to the destination data buffer to write to.
1302 * \param[in] Length Number of bytes to send via the currently selected endpoint.
1303 *
1304 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1305 */
1306 uint8_t Endpoint_Read_Control_Stream_BE(void* Buffer,
1307 uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
1308
1309 /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_BE().
1310 *
1311 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1312 * to clear the status stage when using this routine in a control transaction.
1313 * \n\n
1314 *
1315 * \note This routine should only be used on CONTROL type endpoints.
1316 *
1317 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1318 * together; i.e. the entire stream data must be read or written at the one time.
1319 *
1320 * \ingroup Group_EndpointStreamRW
1321 *
1322 * \param[out] Buffer Pointer to the destination data buffer to write to.
1323 * \param[in] Length Number of bytes to send via the currently selected endpoint.
1324 *
1325 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1326 */
1327 uint8_t Endpoint_Read_Control_EStream_BE(void* Buffer,
1328 uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
1329
1330 /* Disable C linkage for C++ Compilers: */
1331 #if defined(__cplusplus)
1332 }
1333 #endif
1334
1335 #endif
1336
1337 /** @} */