Changed all Device mode LowLevel demos and Device Class drivers so that the control...
[pub/USBasp.git] / LUFA / Drivers / USB / LowLevel / Pipe.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 host pipe management definitions.
33 *
34 * This file contains structures, function prototypes and macros related to the management of the device's
35 * data pipes when the library is initialized in USB host 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_PipeManagement Pipe Management
43 *
44 * This module contains functions, macros and enums related to pipe management when in USB Host mode. This
45 * module contains the pipe management macros, as well as pipe interrupt and data send/receive functions
46 * for various data types.
47 *
48 * @{
49 */
50
51 /** @defgroup Group_PipeRW Pipe Data Reading and Writing
52 *
53 * Functions, macros, variables, enums and types related to data reading and writing from and to pipes.
54 */
55
56 /** \ingroup Group_PipeRW
57 * @defgroup Group_PipePrimitiveRW 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 pipes.
61 */
62
63 /** \ingroup Group_PipeRW
64 * @defgroup Group_PipeStreamRW 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 pipes.
68 */
69
70 /** @defgroup Group_PipePacketManagement Pipe Packet Management
71 *
72 * Functions, macros, variables, enums and types related to packet management of pipes.
73 */
74
75 /** @defgroup Group_PipeControlReq Pipe Control Request Management
76 *
77 * Module for host mode request processing. This module allows for the transmission of standard, class and
78 * vendor control requests to the default control endpoint of an attached device while in host mode.
79 *
80 * \see Chapter 9 of the USB 2.0 specification.
81 */
82
83 #ifndef __PIPE_H__
84 #define __PIPE_H__
85
86 /* Includes: */
87 #include <avr/io.h>
88 #include <avr/pgmspace.h>
89 #include <avr/eeprom.h>
90 #include <stdbool.h>
91
92 #include "../../../Common/Common.h"
93 #include "../HighLevel/USBTask.h"
94
95 #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__)
96 #include "../HighLevel/StreamCallbacks.h"
97 #endif
98
99 /* Enable C linkage for C++ Compilers: */
100 #if defined(__cplusplus)
101 extern "C" {
102 #endif
103
104 /* Preprocessor Checks: */
105 #if !defined(__INCLUDE_FROM_USB_DRIVER)
106 #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
107 #endif
108
109 #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__)
110 #define __CALLBACK_PARAM , StreamCallbackPtr_t Callback
111 #else
112 #define __CALLBACK_PARAM
113 #endif
114
115 /* Public Interface - May be used in end-application: */
116 /* Macros: */
117 /** Mask for \ref Pipe_GetErrorFlags(), indicating that an overflow error occurred in the pipe on the received data. */
118 #define PIPE_ERRORFLAG_OVERFLOW (1 << 6)
119
120 /** Mask for \ref Pipe_GetErrorFlags(), indicating that an underflow error occurred in the pipe on the received data. */
121 #define PIPE_ERRORFLAG_UNDERFLOW (1 << 5)
122
123 /** Mask for \ref Pipe_GetErrorFlags(), indicating that a CRC error occurred in the pipe on the received data. */
124 #define PIPE_ERRORFLAG_CRC16 (1 << 4)
125
126 /** Mask for \ref Pipe_GetErrorFlags(), indicating that a hardware timeout error occurred in the pipe. */
127 #define PIPE_ERRORFLAG_TIMEOUT (1 << 3)
128
129 /** Mask for \ref Pipe_GetErrorFlags(), indicating that a hardware PID error occurred in the pipe. */
130 #define PIPE_ERRORFLAG_PID (1 << 2)
131
132 /** Mask for \ref Pipe_GetErrorFlags(), indicating that a hardware data PID error occurred in the pipe. */
133 #define PIPE_ERRORFLAG_DATAPID (1 << 1)
134
135 /** Mask for \ref Pipe_GetErrorFlags(), indicating that a hardware data toggle error occurred in the pipe. */
136 #define PIPE_ERRORFLAG_DATATGL (1 << 0)
137
138 /** Token mask for \ref Pipe_ConfigurePipe(). This sets the pipe as a SETUP token (for CONTROL type pipes),
139 * which will trigger a control request on the attached device when data is written to the pipe.
140 */
141 #define PIPE_TOKEN_SETUP (0 << PTOKEN0)
142
143 /** Token mask for \ref Pipe_ConfigurePipe(). This sets the pipe as a IN token (for non-CONTROL type pipes),
144 * indicating that the pipe data will flow from device to host.
145 */
146 #define PIPE_TOKEN_IN (1 << PTOKEN0)
147
148 /** Token mask for \ref Pipe_ConfigurePipe(). This sets the pipe as a OUT token (for non-CONTROL type pipes),
149 * indicating that the pipe data will flow from host to device.
150 */
151 #define PIPE_TOKEN_OUT (2 << PTOKEN0)
152
153 /** Mask for the bank mode selection for the \ref Pipe_ConfigurePipe() macro. This indicates that the pipe
154 * should have one single bank, which requires less USB FIFO memory but results in slower transfers as
155 * only one USB device (the AVR or the attached device) can access the pipe's bank at the one time.
156 */
157 #define PIPE_BANK_SINGLE (0 << EPBK0)
158
159 /** Mask for the bank mode selection for the \ref Pipe_ConfigurePipe() macro. This indicates that the pipe
160 * should have two banks, which requires more USB FIFO memory but results in faster transfers as one
161 * USB device (the AVR or the attached device) can access one bank while the other accesses the second
162 * bank.
163 */
164 #define PIPE_BANK_DOUBLE (1 << EPBK0)
165
166 /** Pipe address for the default control pipe, which always resides in address 0. This is
167 * defined for convenience to give more readable code when used with the pipe macros.
168 */
169 #define PIPE_CONTROLPIPE 0
170
171 /** Default size of the default control pipe's bank, until altered by the Endpoint0Size value
172 * in the device descriptor of the attached device.
173 */
174 #define PIPE_CONTROLPIPE_DEFAULT_SIZE 64
175
176 /** Pipe number mask, for masking against pipe addresses to retrieve the pipe's numerical address
177 * in the device.
178 */
179 #define PIPE_PIPENUM_MASK 0x07
180
181 /** Total number of pipes (including the default control pipe at address 0) which may be used in
182 * the device. Different USB AVR models support different amounts of pipes, this value reflects
183 * the maximum number of pipes for the currently selected AVR model.
184 */
185 #define PIPE_TOTAL_PIPES 7
186
187 /** Size in bytes of the largest pipe bank size possible in the device. Not all banks on each AVR
188 * model supports the largest bank size possible on the device; different pipe numbers support
189 * different maximum bank sizes. This value reflects the largest possible bank of any pipe on the
190 * currently selected USB AVR model.
191 */
192 #define PIPE_MAX_SIZE 256
193
194 /** Endpoint number mask, for masking against endpoint addresses to retrieve the endpoint's
195 * numerical address in the attached device.
196 */
197 #define PIPE_EPNUM_MASK 0x0F
198
199 /** Endpoint direction mask, for masking against endpoint addresses to retrieve the endpoint's
200 * direction for comparing with the ENDPOINT_DESCRIPTOR_DIR_* masks.
201 */
202 #define PIPE_EPDIR_MASK 0x80
203
204 /* Enums: */
205 /** Enum for the possible error return codes of the Pipe_WaitUntilReady function.
206 *
207 * \ingroup Group_PipeRW
208 */
209 enum Pipe_WaitUntilReady_ErrorCodes_t
210 {
211 PIPE_READYWAIT_NoError = 0, /**< Pipe ready for next packet, no error. */
212 PIPE_READYWAIT_PipeStalled = 1, /**< The device stalled the pipe while waiting. */
213 PIPE_READYWAIT_DeviceDisconnected = 2, /**< Device was disconnected from the host while waiting. */
214 PIPE_READYWAIT_Timeout = 3, /**< The device failed to accept or send the next packet
215 * within the software timeout period set by the
216 * \ref USB_STREAM_TIMEOUT_MS macro.
217 */
218 };
219
220 /** Enum for the possible error return codes of the Pipe_*_Stream_* functions.
221 *
222 * \ingroup Group_PipeRW
223 */
224 enum Pipe_Stream_RW_ErrorCodes_t
225 {
226 PIPE_RWSTREAM_NoError = 0, /**< Command completed successfully, no error. */
227 PIPE_RWSTREAM_PipeStalled = 1, /**< The device stalled the pipe during the transfer. */
228 PIPE_RWSTREAM_DeviceDisconnected = 2, /**< Device was disconnected from the host during
229 * the transfer.
230 */
231 PIPE_RWSTREAM_Timeout = 3, /**< The device failed to accept or send the next packet
232 * within the software timeout period set by the
233 * \ref USB_STREAM_TIMEOUT_MS macro.
234 */
235 PIPE_RWSTREAM_CallbackAborted = 4, /**< Indicates that the stream's callback function aborted
236 * the transfer early.
237 */
238 };
239
240 /* Inline Functions: */
241 /** Indicates the number of bytes currently stored in the current pipes's selected bank.
242 *
243 * \note The return width of this function may differ, depending on the maximum pipe bank size
244 * of the selected AVR model.
245 *
246 * \ingroup Group_PipeRW
247 *
248 * \return Total number of bytes in the currently selected Pipe's FIFO buffer.
249 */
250 static inline uint16_t Pipe_BytesInPipe(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
251 static inline uint16_t Pipe_BytesInPipe(void)
252 {
253 return UPBCX;
254 }
255
256 /** Returns the pipe address of the currently selected pipe. This is typically used to save the
257 * currently selected pipe number so that it can be restored after another pipe has been manipulated.
258 *
259 * \return Index of the currently selected pipe.
260 */
261 static inline uint8_t Pipe_GetCurrentPipe(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
262 static inline uint8_t Pipe_GetCurrentPipe(void)
263 {
264 return (UPNUM & PIPE_PIPENUM_MASK);
265 }
266
267 /** Selects the given pipe number. Any pipe operations which do not require the pipe number to be
268 * indicated will operate on the currently selected pipe.
269 *
270 * \param[in] PipeNumber Index of the pipe to select.
271 */
272 static inline void Pipe_SelectPipe(const uint8_t PipeNumber) ATTR_ALWAYS_INLINE;
273 static inline void Pipe_SelectPipe(const uint8_t PipeNumber)
274 {
275 UPNUM = PipeNumber;
276 }
277
278 /** Resets the desired pipe, including the pipe banks and flags.
279 *
280 * \param[in] PipeNumber Index of the pipe to reset.
281 */
282 static inline void Pipe_ResetPipe(const uint8_t PipeNumber) ATTR_ALWAYS_INLINE;
283 static inline void Pipe_ResetPipe(const uint8_t PipeNumber)
284 {
285 UPRST = (1 << PipeNumber);
286 UPRST = 0;
287 }
288
289 /** Enables the currently selected pipe so that data can be sent and received through it to and from
290 * an attached device.
291 *
292 * \pre The currently selected pipe must first be configured properly via \ref Pipe_ConfigurePipe().
293 */
294 static inline void Pipe_EnablePipe(void) ATTR_ALWAYS_INLINE;
295 static inline void Pipe_EnablePipe(void)
296 {
297 UPCONX |= (1 << PEN);
298 }
299
300 /** Disables the currently selected pipe so that data cannot be sent and received through it to and
301 * from an attached device.
302 */
303 static inline void Pipe_DisablePipe(void) ATTR_ALWAYS_INLINE;
304 static inline void Pipe_DisablePipe(void)
305 {
306 UPCONX &= ~(1 << PEN);
307 }
308
309 /** Determines if the currently selected pipe is enabled, but not necessarily configured.
310 *
311 * \return Boolean True if the currently selected pipe is enabled, false otherwise.
312 */
313 static inline bool Pipe_IsEnabled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
314 static inline bool Pipe_IsEnabled(void)
315 {
316 return ((UPCONX & (1 << PEN)) ? true : false);
317 }
318
319 /** Gets the current pipe token, indicating the pipe's data direction and type.
320 *
321 * \return The current pipe token, as a PIPE_TOKEN_* mask.
322 */
323 static inline uint8_t Pipe_GetPipeToken(void) ATTR_ALWAYS_INLINE;
324 static inline uint8_t Pipe_GetPipeToken(void)
325 {
326 return (UPCFG0X & (0x03 << PTOKEN0));
327 }
328
329 /** Sets the token for the currently selected pipe to one of the tokens specified by the PIPE_TOKEN_*
330 * masks. This can be used on CONTROL type pipes, to allow for bidirectional transfer of data during
331 * control requests, or on regular pipes to allow for half-duplex bidirectional data transfer to devices
332 * which have two endpoints of opposite direction sharing the same endpoint address within the device.
333 *
334 * \param[in] Token New pipe token to set the selected pipe to, as a PIPE_TOKEN_* mask.
335 */
336 static inline void Pipe_SetPipeToken(const uint8_t Token) ATTR_ALWAYS_INLINE;
337 static inline void Pipe_SetPipeToken(const uint8_t Token)
338 {
339 UPCFG0X = ((UPCFG0X & ~(0x03 << PTOKEN0)) | Token);
340 }
341
342 /** Configures the currently selected pipe to allow for an unlimited number of IN requests. */
343 static inline void Pipe_SetInfiniteINRequests(void) ATTR_ALWAYS_INLINE;
344 static inline void Pipe_SetInfiniteINRequests(void)
345 {
346 UPCONX |= (1 << INMODE);
347 }
348
349 /** Configures the currently selected pipe to only allow the specified number of IN requests to be
350 * accepted by the pipe before it is automatically frozen.
351 *
352 * \param[in] TotalINRequests Total number of IN requests that the pipe may receive before freezing.
353 */
354 static inline void Pipe_SetFiniteINRequests(const uint8_t TotalINRequests) ATTR_ALWAYS_INLINE;
355 static inline void Pipe_SetFiniteINRequests(const uint8_t TotalINRequests)
356 {
357 UPCONX &= ~(1 << INMODE);
358 UPINRQX = TotalINRequests;
359 }
360
361 /** Determines if the currently selected pipe is configured.
362 *
363 * \return Boolean true if the selected pipe is configured, false otherwise.
364 */
365 static inline bool Pipe_IsConfigured(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
366 static inline bool Pipe_IsConfigured(void)
367 {
368 return ((UPSTAX & (1 << CFGOK)) ? true : false);
369 }
370
371 /** Retrieves the endpoint number of the endpoint within the attached device that the currently selected
372 * pipe is bound to.
373 *
374 * \return Endpoint number the currently selected pipe is bound to.
375 */
376 static inline uint8_t Pipe_BoundEndpointNumber(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
377 static inline uint8_t Pipe_BoundEndpointNumber(void)
378 {
379 return ((UPCFG0X >> PEPNUM0) & PIPE_EPNUM_MASK);
380 }
381
382 /** Sets the period between interrupts for an INTERRUPT type pipe to a specified number of milliseconds.
383 *
384 * \param[in] Milliseconds Number of milliseconds between each pipe poll.
385 */
386 static inline void Pipe_SetInterruptPeriod(const uint8_t Milliseconds) ATTR_ALWAYS_INLINE;
387 static inline void Pipe_SetInterruptPeriod(const uint8_t Milliseconds)
388 {
389 UPCFG2X = Milliseconds;
390 }
391
392 /** Returns a mask indicating which pipe's interrupt periods have elapsed, indicating that the pipe should
393 * be serviced.
394 *
395 * \return Mask whose bits indicate which pipes have interrupted.
396 */
397 static inline uint8_t Pipe_GetPipeInterrupts(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
398 static inline uint8_t Pipe_GetPipeInterrupts(void)
399 {
400 return UPINT;
401 }
402
403 /** Determines if the specified pipe number has interrupted (valid only for INTERRUPT type
404 * pipes).
405 *
406 * \param[in] PipeNumber Index of the pipe whose interrupt flag should be tested.
407 *
408 * \return Boolean true if the specified pipe has interrupted, false otherwise.
409 */
410 static inline bool Pipe_HasPipeInterrupted(const uint8_t PipeNumber) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
411 static inline bool Pipe_HasPipeInterrupted(const uint8_t PipeNumber)
412 {
413 return ((UPINT & (1 << PipeNumber)) ? true : false);
414 }
415
416 /** Unfreezes the selected pipe, allowing it to communicate with an attached device. */
417 static inline void Pipe_Unfreeze(void) ATTR_ALWAYS_INLINE;
418 static inline void Pipe_Unfreeze(void)
419 {
420 UPCONX &= ~(1 << PFREEZE);
421 }
422
423 /** Freezes the selected pipe, preventing it from communicating with an attached device. */
424 static inline void Pipe_Freeze(void) ATTR_ALWAYS_INLINE;
425 static inline void Pipe_Freeze(void)
426 {
427 UPCONX |= (1 << PFREEZE);
428 }
429
430 /** Determines if the currently selected pipe is frozen, and not able to accept data.
431 *
432 * \return Boolean true if the currently selected pipe is frozen, false otherwise.
433 */
434 static inline bool Pipe_IsFrozen(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
435 static inline bool Pipe_IsFrozen(void)
436 {
437 return ((UPCONX & (1 << PFREEZE)) ? true : false);
438 }
439
440 /** Clears the master pipe error flag. */
441 static inline void Pipe_ClearError(void) ATTR_ALWAYS_INLINE;
442 static inline void Pipe_ClearError(void)
443 {
444 UPINTX &= ~(1 << PERRI);
445 }
446
447 /** Determines if the master pipe error flag is set for the currently selected pipe, indicating that
448 * some sort of hardware error has occurred on the pipe.
449 *
450 * \see \ref Pipe_GetErrorFlags() macro for information on retrieving the exact error flag.
451 *
452 * \return Boolean true if an error has occurred on the selected pipe, false otherwise.
453 */
454 static inline bool Pipe_IsError(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
455 static inline bool Pipe_IsError(void)
456 {
457 return ((UPINTX & (1 << PERRI)) ? true : false);
458 }
459
460 /** Clears all the currently selected pipe's hardware error flags, but does not clear the master error
461 * flag for the pipe.
462 */
463 static inline void Pipe_ClearErrorFlags(void) ATTR_ALWAYS_INLINE;
464 static inline void Pipe_ClearErrorFlags(void)
465 {
466 UPERRX = 0;
467 }
468
469 /** Gets a mask of the hardware error flags which have occurred on the currently selected pipe. This
470 * value can then be masked against the PIPE_ERRORFLAG_* masks to determine what error has occurred.
471 *
472 * \return Mask comprising of PIPE_ERRORFLAG_* bits indicating what error has occurred on the selected pipe.
473 */
474 static inline uint8_t Pipe_GetErrorFlags(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
475 static inline uint8_t Pipe_GetErrorFlags(void)
476 {
477 return ((UPERRX & (PIPE_ERRORFLAG_CRC16 | PIPE_ERRORFLAG_TIMEOUT |
478 PIPE_ERRORFLAG_PID | PIPE_ERRORFLAG_DATAPID |
479 PIPE_ERRORFLAG_DATATGL)) |
480 (UPSTAX & (PIPE_ERRORFLAG_OVERFLOW | PIPE_ERRORFLAG_UNDERFLOW)));
481 }
482
483 /** Determines if the currently selected pipe may be read from (if data is waiting in the pipe
484 * bank and the pipe is an IN direction, or if the bank is not yet full if the pipe is an OUT
485 * direction). This function will return false if an error has occurred in the pipe, or if the pipe
486 * is an IN direction and no packet (or an empty packet) has been received, or if the pipe is an OUT
487 * direction and the pipe bank is full.
488 *
489 * \note This function is not valid on CONTROL type pipes.
490 *
491 * \ingroup Group_PipePacketManagement
492 *
493 * \return Boolean true if the currently selected pipe may be read from or written to, depending on its direction.
494 */
495 static inline bool Pipe_IsReadWriteAllowed(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
496 static inline bool Pipe_IsReadWriteAllowed(void)
497 {
498 return ((UPINTX & (1 << RWAL)) ? true : false);
499 }
500
501 /** Determines if an IN request has been received on the currently selected pipe.
502 *
503 * \ingroup Group_PipePacketManagement
504 *
505 * \return Boolean true if the current pipe has received an IN packet, false otherwise.
506 */
507 static inline bool Pipe_IsINReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
508 static inline bool Pipe_IsINReceived(void)
509 {
510 return ((UPINTX & (1 << RXINI)) ? true : false);
511 }
512
513 /** Determines if the currently selected pipe is ready to send an OUT request.
514 *
515 * \ingroup Group_PipePacketManagement
516 *
517 * \return Boolean true if the current pipe is ready for an OUT packet, false otherwise.
518 */
519 static inline bool Pipe_IsOUTReady(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
520 static inline bool Pipe_IsOUTReady(void)
521 {
522 return ((UPINTX & (1 << TXOUTI)) ? true : false);
523 }
524
525 /** Determines if no SETUP request is currently being sent to the attached device on the selected
526 * CONTROL type pipe.
527 *
528 * \ingroup Group_PipePacketManagement
529 *
530 * \return Boolean true if the current pipe is ready for a SETUP packet, false otherwise.
531 */
532 static inline bool Pipe_IsSETUPSent(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
533 static inline bool Pipe_IsSETUPSent(void)
534 {
535 return ((UPINTX & (1 << TXSTPI)) ? true : false);
536 }
537
538 /** Sends the currently selected CONTROL type pipe's contents to the device as a SETUP packet.
539 *
540 * \ingroup Group_PipePacketManagement
541 */
542 static inline void Pipe_ClearSETUP(void) ATTR_ALWAYS_INLINE;
543 static inline void Pipe_ClearSETUP(void)
544 {
545 UPINTX &= ~((1 << TXSTPI) | (1 << FIFOCON));
546 }
547
548 /** Acknowledges the reception of a setup IN request from the attached device on the currently selected
549 * pipe, freeing the bank ready for the next packet.
550 *
551 * \ingroup Group_PipePacketManagement
552 */
553 static inline void Pipe_ClearIN(void) ATTR_ALWAYS_INLINE;
554 static inline void Pipe_ClearIN(void)
555 {
556 UPINTX &= ~((1 << RXINI) | (1 << FIFOCON));
557 }
558
559 /** Sends the currently selected pipe's contents to the device as an OUT packet on the selected pipe, freeing
560 * the bank ready for the next packet.
561 *
562 * \ingroup Group_PipePacketManagement
563 */
564 static inline void Pipe_ClearOUT(void) ATTR_ALWAYS_INLINE;
565 static inline void Pipe_ClearOUT(void)
566 {
567 UPINTX &= ~((1 << TXOUTI) | (1 << FIFOCON));
568 }
569
570 /** Determines if the device sent a NAK (Negative Acknowledge) in response to the last sent packet on
571 * the currently selected pipe. This occurs when the host sends a packet to the device, but the device
572 * is not currently ready to handle the packet (i.e. its endpoint banks are full). Once a NAK has been
573 * received, it must be cleared using \ref Pipe_ClearNAKReceived() before the previous (or any other) packet
574 * can be re-sent.
575 *
576 * \ingroup Group_PipePacketManagement
577 *
578 * \return Boolean true if an NAK has been received on the current pipe, false otherwise.
579 */
580 static inline bool Pipe_IsNAKReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
581 static inline bool Pipe_IsNAKReceived(void)
582 {
583 return ((UPINTX & (1 << NAKEDI)) ? true : false);
584 }
585
586 /** Clears the NAK condition on the currently selected pipe.
587 *
588 * \ingroup Group_PipePacketManagement
589 *
590 * \see \ref Pipe_IsNAKReceived() for more details.
591 */
592 static inline void Pipe_ClearNAKReceived(void) ATTR_ALWAYS_INLINE;
593 static inline void Pipe_ClearNAKReceived(void)
594 {
595 UPINTX &= ~(1 << NAKEDI);
596 }
597
598 /** Determines if the currently selected pipe has had the STALL condition set by the attached device.
599 *
600 * \ingroup Group_PipePacketManagement
601 *
602 * \return Boolean true if the current pipe has been stalled by the attached device, false otherwise.
603 */
604 static inline bool Pipe_IsStalled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
605 static inline bool Pipe_IsStalled(void)
606 {
607 return ((UPINTX & (1 << RXSTALLI)) ? true : false);
608 }
609
610 /** Clears the STALL condition detection flag on the currently selected pipe, but does not clear the
611 * STALL condition itself (this must be done via a ClearFeature control request to the device).
612 *
613 * \ingroup Group_PipePacketManagement
614 */
615 static inline void Pipe_ClearStall(void) ATTR_ALWAYS_INLINE;
616 static inline void Pipe_ClearStall(void)
617 {
618 UPINTX &= ~(1 << RXSTALLI);
619 }
620
621 /** Reads one byte from the currently selected pipe's bank, for OUT direction pipes.
622 *
623 * \ingroup Group_PipePrimitiveRW
624 *
625 * \return Next byte in the currently selected pipe's FIFO buffer.
626 */
627 static inline uint8_t Pipe_Read_Byte(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
628 static inline uint8_t Pipe_Read_Byte(void)
629 {
630 return UPDATX;
631 }
632
633 /** Writes one byte from the currently selected pipe's bank, for IN direction pipes.
634 *
635 * \ingroup Group_PipePrimitiveRW
636 *
637 * \param[in] Byte Next byte to write into the the currently selected pipe's FIFO buffer.
638 */
639 static inline void Pipe_Write_Byte(const uint8_t Byte) ATTR_ALWAYS_INLINE;
640 static inline void Pipe_Write_Byte(const uint8_t Byte)
641 {
642 UPDATX = Byte;
643 }
644
645 /** Discards one byte from the currently selected pipe's bank, for OUT direction pipes.
646 *
647 * \ingroup Group_PipePrimitiveRW
648 */
649 static inline void Pipe_Discard_Byte(void) ATTR_ALWAYS_INLINE;
650 static inline void Pipe_Discard_Byte(void)
651 {
652 uint8_t Dummy;
653
654 Dummy = UPDATX;
655 }
656
657 /** Reads two bytes from the currently selected pipe's bank in little endian format, for OUT
658 * direction pipes.
659 *
660 * \ingroup Group_PipePrimitiveRW
661 *
662 * \return Next word in the currently selected pipe's FIFO buffer.
663 */
664 static inline uint16_t Pipe_Read_Word_LE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
665 static inline uint16_t Pipe_Read_Word_LE(void)
666 {
667 union
668 {
669 uint16_t Word;
670 uint8_t Bytes[2];
671 } Data;
672
673 Data.Bytes[0] = UPDATX;
674 Data.Bytes[1] = UPDATX;
675
676 return Data.Word;
677 }
678
679 /** Reads two bytes from the currently selected pipe's bank in big endian format, for OUT
680 * direction pipes.
681 *
682 * \ingroup Group_PipePrimitiveRW
683 *
684 * \return Next word in the currently selected pipe's FIFO buffer.
685 */
686 static inline uint16_t Pipe_Read_Word_BE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
687 static inline uint16_t Pipe_Read_Word_BE(void)
688 {
689 union
690 {
691 uint16_t Word;
692 uint8_t Bytes[2];
693 } Data;
694
695 Data.Bytes[1] = UPDATX;
696 Data.Bytes[0] = UPDATX;
697
698 return Data.Word;
699 }
700
701 /** Writes two bytes to the currently selected pipe's bank in little endian format, for IN
702 * direction pipes.
703 *
704 * \ingroup Group_PipePrimitiveRW
705 *
706 * \param[in] Word Next word to write to the currently selected pipe's FIFO buffer.
707 */
708 static inline void Pipe_Write_Word_LE(const uint16_t Word) ATTR_ALWAYS_INLINE;
709 static inline void Pipe_Write_Word_LE(const uint16_t Word)
710 {
711 UPDATX = (Word & 0xFF);
712 UPDATX = (Word >> 8);
713 }
714
715 /** Writes two bytes to the currently selected pipe's bank in big endian format, for IN
716 * direction pipes.
717 *
718 * \ingroup Group_PipePrimitiveRW
719 *
720 * \param[in] Word Next word to write to the currently selected pipe's FIFO buffer.
721 */
722 static inline void Pipe_Write_Word_BE(const uint16_t Word) ATTR_ALWAYS_INLINE;
723 static inline void Pipe_Write_Word_BE(const uint16_t Word)
724 {
725 UPDATX = (Word >> 8);
726 UPDATX = (Word & 0xFF);
727 }
728
729 /** Discards two bytes from the currently selected pipe's bank, for OUT direction pipes.
730 *
731 * \ingroup Group_PipePrimitiveRW
732 */
733 static inline void Pipe_Discard_Word(void) ATTR_ALWAYS_INLINE;
734 static inline void Pipe_Discard_Word(void)
735 {
736 uint8_t Dummy;
737
738 Dummy = UPDATX;
739 Dummy = UPDATX;
740 }
741
742 /** Reads four bytes from the currently selected pipe's bank in little endian format, for OUT
743 * direction pipes.
744 *
745 * \ingroup Group_PipePrimitiveRW
746 *
747 * \return Next double word in the currently selected pipe's FIFO buffer.
748 */
749 static inline uint32_t Pipe_Read_DWord_LE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
750 static inline uint32_t Pipe_Read_DWord_LE(void)
751 {
752 union
753 {
754 uint32_t DWord;
755 uint8_t Bytes[4];
756 } Data;
757
758 Data.Bytes[0] = UPDATX;
759 Data.Bytes[1] = UPDATX;
760 Data.Bytes[2] = UPDATX;
761 Data.Bytes[3] = UPDATX;
762
763 return Data.DWord;
764 }
765
766 /** Reads four bytes from the currently selected pipe's bank in big endian format, for OUT
767 * direction pipes.
768 *
769 * \ingroup Group_PipePrimitiveRW
770 *
771 * \return Next double word in the currently selected pipe's FIFO buffer.
772 */
773 static inline uint32_t Pipe_Read_DWord_BE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
774 static inline uint32_t Pipe_Read_DWord_BE(void)
775 {
776 union
777 {
778 uint32_t DWord;
779 uint8_t Bytes[4];
780 } Data;
781
782 Data.Bytes[3] = UPDATX;
783 Data.Bytes[2] = UPDATX;
784 Data.Bytes[1] = UPDATX;
785 Data.Bytes[0] = UPDATX;
786
787 return Data.DWord;
788 }
789
790 /** Writes four bytes to the currently selected pipe's bank in little endian format, for IN
791 * direction pipes.
792 *
793 * \ingroup Group_PipePrimitiveRW
794 *
795 * \param[in] DWord Next double word to write to the currently selected pipe's FIFO buffer.
796 */
797 static inline void Pipe_Write_DWord_LE(const uint32_t DWord) ATTR_ALWAYS_INLINE;
798 static inline void Pipe_Write_DWord_LE(const uint32_t DWord)
799 {
800 UPDATX = (DWord & 0xFF);
801 UPDATX = (DWord >> 8);
802 UPDATX = (DWord >> 16);
803 UPDATX = (DWord >> 24);
804 }
805
806 /** Writes four bytes to the currently selected pipe's bank in big endian format, for IN
807 * direction pipes.
808 *
809 * \ingroup Group_PipePrimitiveRW
810 *
811 * \param[in] DWord Next double word to write to the currently selected pipe's FIFO buffer.
812 */
813 static inline void Pipe_Write_DWord_BE(const uint32_t DWord) ATTR_ALWAYS_INLINE;
814 static inline void Pipe_Write_DWord_BE(const uint32_t DWord)
815 {
816 UPDATX = (DWord >> 24);
817 UPDATX = (DWord >> 16);
818 UPDATX = (DWord >> 8);
819 UPDATX = (DWord & 0xFF);
820 }
821
822 /** Discards four bytes from the currently selected pipe's bank, for OUT direction pipes.
823 *
824 * \ingroup Group_PipePrimitiveRW
825 */
826 static inline void Pipe_Discard_DWord(void) ATTR_ALWAYS_INLINE;
827 static inline void Pipe_Discard_DWord(void)
828 {
829 uint8_t Dummy;
830
831 Dummy = UPDATX;
832 Dummy = UPDATX;
833 Dummy = UPDATX;
834 Dummy = UPDATX;
835 }
836
837 /* External Variables: */
838 /** Global indicating the maximum packet size of the default control pipe located at address
839 * 0 in the device. This value is set to the value indicated in the attached device's device
840 * descriptor once the USB interface is initialized into host mode and a device is attached
841 * to the USB bus.
842 *
843 * \note This variable should be treated as read-only in the user application, and never manually
844 * changed in value.
845 */
846 extern uint8_t USB_ControlPipeSize;
847
848 /* Function Prototypes: */
849 /** Configures the specified pipe number with the given pipe type, token, target endpoint number in the
850 * attached device, bank size and banking mode. Pipes should be allocated in ascending order by their
851 * address in the device (i.e. pipe 1 should be configured before pipe 2 and so on) to prevent fragmentation
852 * of the USB FIFO memory.
853 *
854 * The pipe type may be one of the EP_TYPE_* macros listed in LowLevel.h, the token may be one of the
855 * PIPE_TOKEN_* masks.
856 *
857 * The bank size must indicate the maximum packet size that the pipe can handle. Different pipe
858 * numbers can handle different maximum packet sizes - refer to the chosen USB AVR's datasheet to
859 * determine the maximum bank size for each pipe.
860 *
861 * The banking mode may be either \ref PIPE_BANK_SINGLE or \ref PIPE_BANK_DOUBLE.
862 *
863 * A newly configured pipe is frozen by default, and must be unfrozen before use via the \ref Pipe_Unfreeze()
864 * before being used. Pipes should be kept frozen unless waiting for data from a device while in IN mode, or
865 * sending data to the device in OUT mode. IN type pipes are also automatically configured to accept infinite
866 * numbers of IN requests without automatic freezing - this can be overridden by a call to
867 * \ref Pipe_SetFiniteINRequests().
868 *
869 * \note The default control pipe should not be manually configured by the user application, as it
870 * is automatically configured by the library internally.
871 * \n\n
872 *
873 * \note This routine will select the specified pipe, and the pipe will remain selected once the
874 * routine completes regardless of if the pipe configuration succeeds.
875 *
876 * \return Boolean true if the configuration is successful, false otherwise.
877 */
878 bool Pipe_ConfigurePipe(const uint8_t Number,
879 const uint8_t Type,
880 const uint8_t Token,
881 const uint8_t EndpointNumber,
882 const uint16_t Size,
883 const uint8_t Banks);
884
885 /** Spin-loops until the currently selected non-control pipe is ready for the next packed of data to be read
886 * or written to it, aborting in the case of an error condition (such as a timeout or device disconnect).
887 *
888 * \ingroup Group_PipeRW
889 *
890 * \return A value from the Pipe_WaitUntilReady_ErrorCodes_t enum.
891 */
892 uint8_t Pipe_WaitUntilReady(void);
893
894 /** Determines if a pipe has been bound to the given device endpoint address. If a pipe which is bound to the given
895 * endpoint is found, it is automatically selected.
896 *
897 * \param[in] EndpointAddress Address and direction mask of the endpoint within the attached device to check.
898 *
899 * \return Boolean true if a pipe bound to the given endpoint address of the specified direction is found, false
900 * otherwise.
901 */
902 bool Pipe_IsEndpointBound(const uint8_t EndpointAddress);
903
904 /** Reads and discards the given number of bytes from the pipe, discarding fully read packets from the host
905 * as needed. The last packet is not automatically discarded once the remaining bytes has been read; the
906 * user is responsible for manually discarding the last packet from the device via the \ref Pipe_ClearIN() macro.
907 * Between each USB packet, the given stream callback function is executed repeatedly until the next packet is ready,
908 * allowing for early aborts of stream transfers.
909 *
910 * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
911 * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
912 * disabled and this function has the Callback parameter omitted.
913 *
914 * The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
915 * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
916 *
917 * \ingroup Group_PipeStreamRW
918 *
919 * \param[in] Length Number of bytes to send via the currently selected pipe.
920 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback.
921 *
922 * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
923 */
924 uint8_t Pipe_Discard_Stream(uint16_t Length
925 __CALLBACK_PARAM);
926
927 /** Writes the given number of bytes to the pipe from the given buffer in little endian,
928 * sending full packets to the device as needed. The last packet filled is not automatically sent;
929 * the user is responsible for manually sending the last written packet to the host via the
930 * \ref Pipe_ClearOUT() macro. Between each USB packet, the given stream callback function is
931 * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
932 *
933 * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
934 * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
935 * disabled and this function has the Callback parameter omitted.
936 *
937 * The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
938 * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
939 *
940 * \ingroup Group_PipeStreamRW
941 *
942 * \param[in] Buffer Pointer to the source data buffer to read from.
943 * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
944 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback.
945 *
946 * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
947 */
948 uint8_t Pipe_Write_Stream_LE(const void* Buffer,
949 uint16_t Length
950 __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
951
952 /** EEPROM buffer source version of \ref Pipe_Write_Stream_LE().
953 *
954 * \ingroup Group_PipeStreamRW
955 *
956 * \param[in] Buffer Pointer to the source data buffer to read from.
957 * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
958 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback.
959 *
960 * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
961 */
962 uint8_t Pipe_Write_EStream_LE(const void* Buffer,
963 uint16_t Length
964 __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
965
966 /** FLASH buffer source version of \ref Pipe_Write_Stream_LE().
967 *
968 * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
969 *
970 * \ingroup Group_PipeStreamRW
971 *
972 * \param[in] Buffer Pointer to the source data buffer to read from.
973 * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
974 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback.
975 *
976 * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
977 */
978 uint8_t Pipe_Write_PStream_LE(const void* Buffer,
979 uint16_t Length
980 __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
981
982 /** Writes the given number of bytes to the pipe from the given buffer in big endian,
983 * sending full packets to the device as needed. The last packet filled is not automatically sent;
984 * the user is responsible for manually sending the last written packet to the host via the
985 * \ref Pipe_ClearOUT() macro. Between each USB packet, the given stream callback function is
986 * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
987 *
988 * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
989 * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
990 * disabled and this function has the Callback parameter omitted.
991 *
992 * The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
993 * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
994 *
995 * \ingroup Group_PipeStreamRW
996 *
997 * \param[in] Buffer Pointer to the source data buffer to read from.
998 * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
999 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback.
1000 *
1001 * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
1002 */
1003 uint8_t Pipe_Write_Stream_BE(const void* Buffer,
1004 uint16_t Length
1005 __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
1006
1007 /** EEPROM buffer source version of \ref Pipe_Write_Stream_BE().
1008 *
1009 * \ingroup Group_PipeStreamRW
1010 *
1011 * \param[in] Buffer Pointer to the source data buffer to read from.
1012 * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
1013 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback.
1014 *
1015 * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
1016 */
1017 uint8_t Pipe_Write_EStream_BE(const void* Buffer,
1018 uint16_t Length
1019 __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
1020
1021 /** FLASH buffer source version of \ref Pipe_Write_Stream_BE().
1022 *
1023 * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
1024 *
1025 * \ingroup Group_PipeStreamRW
1026 *
1027 * \param[in] Buffer Pointer to the source data buffer to read from.
1028 * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
1029 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback.
1030 *
1031 * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
1032 */
1033 uint8_t Pipe_Write_PStream_BE(const void* Buffer,
1034 uint16_t Length
1035 __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
1036
1037 /** Reads the given number of bytes from the pipe into the given buffer in little endian,
1038 * sending full packets to the device as needed. The last packet filled is not automatically sent;
1039 * the user is responsible for manually sending the last written packet to the host via the
1040 * \ref Pipe_ClearIN() macro. Between each USB packet, the given stream callback function is
1041 * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
1042 *
1043 * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
1044 * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
1045 * disabled and this function has the Callback parameter omitted.
1046 *
1047 * The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
1048 * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
1049 *
1050 * \ingroup Group_PipeStreamRW
1051 *
1052 * \param[out] Buffer Pointer to the source data buffer to write to.
1053 * \param[in] Length Number of bytes to read for the currently selected pipe to read from.
1054 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback.
1055 *
1056 * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
1057 */
1058 uint8_t Pipe_Read_Stream_LE(void* Buffer,
1059 uint16_t Length
1060 __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
1061
1062 /** EEPROM buffer source version of \ref Pipe_Read_Stream_LE().
1063 *
1064 * \ingroup Group_PipeStreamRW
1065 *
1066 * \param[out] Buffer Pointer to the source data buffer to write to.
1067 * \param[in] Length Number of bytes to read for the currently selected pipe to read from.
1068 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback.
1069 *
1070 * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
1071 */
1072 uint8_t Pipe_Read_EStream_LE(void* Buffer,
1073 uint16_t Length
1074 __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
1075
1076 /** Reads the given number of bytes from the pipe into the given buffer in big endian,
1077 * sending full packets to the device as needed. The last packet filled is not automatically sent;
1078 * the user is responsible for manually sending the last written packet to the host via the
1079 * \ref Pipe_ClearIN() macro. Between each USB packet, the given stream callback function is
1080 * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
1081 *
1082 * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
1083 * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
1084 * disabled and this function has the Callback parameter omitted.
1085 *
1086 * The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
1087 * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
1088 *
1089 * \ingroup Group_PipeStreamRW
1090 *
1091 * \param[out] Buffer Pointer to the source data buffer to write to.
1092 * \param[in] Length Number of bytes to read for the currently selected pipe to read from.
1093 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback.
1094 *
1095 * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
1096 */
1097 uint8_t Pipe_Read_Stream_BE(void* Buffer,
1098 uint16_t Length
1099 __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
1100
1101 /** EEPROM buffer source version of \ref Pipe_Read_Stream_BE().
1102 *
1103 * \ingroup Group_PipeStreamRW
1104 *
1105 * \param[out] Buffer Pointer to the source data buffer to write to.
1106 * \param[in] Length Number of bytes to read for the currently selected pipe to read from.
1107 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback.
1108 *
1109 * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
1110 */
1111 uint8_t Pipe_Read_EStream_BE(void* Buffer,
1112 uint16_t Length
1113 __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
1114
1115 /* Private Interface - For use in library only: */
1116 #if !defined(__DOXYGEN__)
1117 /* Macros: */
1118 #if !defined(ENDPOINT_CONTROLEP)
1119 #define ENDPOINT_CONTROLEP 0
1120 #endif
1121
1122 /* Inline Functions: */
1123 static inline uint8_t Pipe_BytesToEPSizeMask(const uint16_t Bytes) ATTR_WARN_UNUSED_RESULT ATTR_CONST ATTR_ALWAYS_INLINE;
1124 static inline uint8_t Pipe_BytesToEPSizeMask(const uint16_t Bytes)
1125 {
1126 uint8_t MaskVal = 0;
1127 uint16_t CheckBytes = 8;
1128
1129 while ((CheckBytes < Bytes) && (CheckBytes < PIPE_MAX_SIZE))
1130 {
1131 MaskVal++;
1132 CheckBytes <<= 1;
1133 }
1134
1135 return (MaskVal << EPSIZE0);
1136 }
1137
1138 /* Function Prototypes: */
1139 void Pipe_ClearPipes(void);
1140 #endif
1141
1142 /* Disable C linkage for C++ Compilers: */
1143 #if defined(__cplusplus)
1144 }
1145 #endif
1146
1147 #endif
1148
1149 /** @} */