]> git.donarmstrong.com Git - qmk_firmware.git/blob - protocol/lufa/LUFA-120730/LUFA/Drivers/USB/Core/UC3/Pipe_UC3.h
Squashed 'tmk_core/' content from commit 05caacc
[qmk_firmware.git] / protocol / lufa / LUFA-120730 / LUFA / Drivers / USB / Core / UC3 / Pipe_UC3.h
1 /*\r
2              LUFA Library\r
3      Copyright (C) Dean Camera, 2012.\r
4 \r
5   dean [at] fourwalledcubicle [dot] com\r
6            www.lufa-lib.org\r
7 */\r
8 \r
9 /*\r
10   Copyright 2012  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
11 \r
12   Permission to use, copy, modify, distribute, and sell this\r
13   software and its documentation for any purpose is hereby granted\r
14   without fee, provided that the above copyright notice appear in\r
15   all copies and that both that the copyright notice and this\r
16   permission notice and warranty disclaimer appear in supporting\r
17   documentation, and that the name of the author not be used in\r
18   advertising or publicity pertaining to distribution of the\r
19   software without specific, written prior permission.\r
20 \r
21   The author disclaim all warranties with regard to this\r
22   software, including all implied warranties of merchantability\r
23   and fitness.  In no event shall the author be liable for any\r
24   special, indirect or consequential damages or any damages\r
25   whatsoever resulting from loss of use, data or profits, whether\r
26   in an action of contract, negligence or other tortious action,\r
27   arising out of or in connection with the use or performance of\r
28   this software.\r
29 */\r
30 \r
31 /** \file\r
32  *  \brief USB Pipe definitions for the AVR32 UC3 microcontrollers.\r
33  *  \copydetails Group_PipeManagement_UC3\r
34  *\r
35  *  \note This file should not be included directly. It is automatically included as needed by the USB driver\r
36  *        dispatch header located in LUFA/Drivers/USB/USB.h.\r
37  */\r
38 \r
39 /** \ingroup Group_PipeRW\r
40  *  \defgroup Group_PipeRW_UC3 Pipe Data Reading and Writing (UC3)\r
41  *  \brief Pipe data read/write definitions for the Atmel AVR32 UC3 architecture.\r
42  *\r
43  *  Functions, macros, variables, enums and types related to data reading and writing from and to pipes.\r
44  */\r
45 \r
46 /** \ingroup Group_PipePrimitiveRW\r
47  *  \defgroup Group_PipePrimitiveRW_UC3 Read/Write of Primitive Data Types (UC3)\r
48  *  \brief Pipe primitive data read/write definitions for the Atmel AVR32 UC3 architecture.\r
49  *\r
50  *  Functions, macros, variables, enums and types related to data reading and writing of primitive data types\r
51  *  from and to pipes.\r
52  */\r
53 \r
54 /** \ingroup Group_PipePacketManagement\r
55  *  \defgroup Group_PipePacketManagement_UC3 Pipe Packet Management (UC3)\r
56  *  \brief Pipe packet management definitions for the Atmel AVR32 UC3 architecture.\r
57  *\r
58  *  Functions, macros, variables, enums and types related to packet management of pipes.\r
59  */\r
60 \r
61 /** \ingroup Group_PipeControlReq\r
62  *  \defgroup Group_PipeControlReq_UC3 Pipe Control Request Management (UC3)\r
63  *  \brief Pipe control request management definitions for the Atmel AVR32 UC3 architecture.\r
64  *\r
65  *  Module for host mode request processing. This module allows for the transmission of standard, class and\r
66  *  vendor control requests to the default control endpoint of an attached device while in host mode.\r
67  *\r
68  *  \see Chapter 9 of the USB 2.0 specification.\r
69  */\r
70 \r
71 /** \ingroup Group_PipeManagement\r
72  *  \defgroup Group_PipeManagement_UC3 Pipe Management (UC3)\r
73  *  \brief Pipe management definitions for the Atmel AVR32 UC3 architecture.\r
74  *\r
75  *  This module contains functions, macros and enums related to pipe management when in USB Host mode. This\r
76  *  module contains the pipe management macros, as well as pipe interrupt and data send/receive functions\r
77  *  for various data types.\r
78  *\r
79  *  @{\r
80  */\r
81 \r
82 #ifndef __PIPE_UC3_H__\r
83 #define __PIPE_UC3_H__\r
84 \r
85         /* Includes: */\r
86                 #include "../../../../Common/Common.h"\r
87                 #include "../USBTask.h"\r
88 \r
89         /* Enable C linkage for C++ Compilers: */\r
90                 #if defined(__cplusplus)\r
91                         extern "C" {\r
92                 #endif\r
93 \r
94         /* Preprocessor Checks: */\r
95                 #if !defined(__INCLUDE_FROM_USB_DRIVER)\r
96                         #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.\r
97                 #endif\r
98 \r
99         /* Private Interface - For use in library only: */\r
100         #if !defined(__DOXYGEN__)\r
101                 /* Macros: */\r
102                         #define PIPE_HSB_ADDRESS_SPACE_SIZE     (64 * 1024UL)\r
103 \r
104                 /* External Variables: */\r
105                         extern volatile uint32_t USB_Pipe_SelectedPipe;\r
106                         extern volatile uint8_t* USB_Pipe_FIFOPos[];\r
107         #endif\r
108 \r
109         /* Public Interface - May be used in end-application: */\r
110                 /* Macros: */\r
111                         /** \name Pipe Error Flag Masks */\r
112                         //@{\r
113                         /** Mask for \ref Pipe_GetErrorFlags(), indicating that an overflow error occurred in the pipe on the received data. */\r
114                         #define PIPE_ERRORFLAG_OVERFLOW         (AVR32_USBB_UPSTA0_OVERFI_MASK << 8)\r
115 \r
116                         /** Mask for \ref Pipe_GetErrorFlags(), indicating that a CRC error occurred in the pipe on the received data. */\r
117                         #define PIPE_ERRORFLAG_CRC16            AVR32_USBB_UPERR0_CRC16_MASK\r
118 \r
119                         /** Mask for \ref Pipe_GetErrorFlags(), indicating that a hardware timeout error occurred in the pipe. */\r
120                         #define PIPE_ERRORFLAG_TIMEOUT          AVR32_USBB_UPERR0_TIMEOUT_MASK\r
121 \r
122                         /** Mask for \ref Pipe_GetErrorFlags(), indicating that a hardware PID error occurred in the pipe. */\r
123                         #define PIPE_ERRORFLAG_PID              AVR32_USBB_UPERR0_PID_MASK\r
124 \r
125                         /** Mask for \ref Pipe_GetErrorFlags(), indicating that a hardware data PID error occurred in the pipe. */\r
126                         #define PIPE_ERRORFLAG_DATAPID          AVR32_USBB_UPERR0_DATAPID_MASK\r
127 \r
128                         /** Mask for \ref Pipe_GetErrorFlags(), indicating that a hardware data toggle error occurred in the pipe. */\r
129                         #define PIPE_ERRORFLAG_DATATGL          AVR32_USBB_UPERR0_DATATGL_MASK\r
130                         //@}\r
131 \r
132                         /** \name Pipe Token Masks */\r
133                         //@{\r
134                         /** Token mask for \ref Pipe_SetPipeToken() and \ref Pipe_GetPipeToken(). This sets the pipe as a SETUP token (for CONTROL type pipes),\r
135                          *  which will trigger a control request on the attached device when data is written to the pipe.\r
136                          */\r
137                         #define PIPE_TOKEN_SETUP                AVR32_USBB_UPCFG0_PTOKEN_SETUP\r
138 \r
139                         /** Token mask for \ref Pipe_SetPipeToken() and \ref Pipe_GetPipeToken(). This sets the pipe as a IN token (for non-CONTROL type pipes),\r
140                          *  indicating that the pipe data will flow from device to host.\r
141                          */\r
142                         #define PIPE_TOKEN_IN                   AVR32_USBB_UPCFG0_PTOKEN_IN\r
143 \r
144                         /** Token mask for \ref Pipe_SetPipeToken() and \ref Pipe_GetPipeToken(). This sets the pipe as a OUT token (for non-CONTROL type pipes),\r
145                          *  indicating that the pipe data will flow from host to device.\r
146                          */\r
147                         #define PIPE_TOKEN_OUT                  AVR32_USBB_UPCFG0_PTOKEN_OUT\r
148                         //@}\r
149 \r
150                         /** Default size of the default control pipe's bank, until altered by the Endpoint0Size value\r
151                          *  in the device descriptor of the attached device.\r
152                          */\r
153                         #define PIPE_CONTROLPIPE_DEFAULT_SIZE   64\r
154 \r
155                         #if defined(USB_SERIES_UC3A3_AVR32) || defined(USB_SERIES_UC3A4_AVR32) || defined(__DOXYGEN__)\r
156                                 /** Total number of pipes (including the default control pipe at address 0) which may be used in\r
157                                  *  the device.\r
158                                  */\r
159                                 #define PIPE_TOTAL_PIPES            8\r
160                         #else\r
161                                 #define PIPE_TOTAL_PIPES            7\r
162                         #endif\r
163 \r
164                         /** Size in bytes of the largest pipe bank size possible in the device. Not all banks on each AVR\r
165                          *  model supports the largest bank size possible on the device; different pipe numbers support\r
166                          *  different maximum bank sizes. This value reflects the largest possible bank of any pipe on the\r
167                          *  currently selected UC3 AVR model.\r
168                          */\r
169                         #define PIPE_MAX_SIZE                   256\r
170 \r
171                 /* Enums: */\r
172                         /** Enum for the possible error return codes of the \ref Pipe_WaitUntilReady() function.\r
173                          *\r
174                          *  \ingroup Group_PipeRW_UC3\r
175                          */\r
176                         enum Pipe_WaitUntilReady_ErrorCodes_t\r
177                         {\r
178                                 PIPE_READYWAIT_NoError                 = 0, /**< Pipe ready for next packet, no error. */\r
179                                 PIPE_READYWAIT_PipeStalled             = 1,     /**< The device stalled the pipe while waiting. */\r
180                                 PIPE_READYWAIT_DeviceDisconnected      = 2,     /**< Device was disconnected from the host while waiting. */\r
181                                 PIPE_READYWAIT_Timeout                 = 3, /**< The device failed to accept or send the next packet\r
182                                                                              *   within the software timeout period set by the\r
183                                                                              *   \ref USB_STREAM_TIMEOUT_MS macro.\r
184                                                                              */\r
185                         };\r
186 \r
187                 /* Inline Functions: */\r
188                         /** Indicates the number of bytes currently stored in the current pipes's selected bank.\r
189                          *\r
190                          *  \ingroup Group_PipeRW_UC3\r
191                          *\r
192                          *  \return Total number of bytes in the currently selected pipe's FIFO buffer.\r
193                          */\r
194                         static inline uint16_t Pipe_BytesInPipe(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
195                         static inline uint16_t Pipe_BytesInPipe(void)\r
196                         {\r
197                                 return (&AVR32_USBB.UPSTA0)[USB_Pipe_SelectedPipe].pbyct;\r
198                         }\r
199 \r
200                         /** Determines the currently selected pipe's direction.\r
201                          *\r
202                          *  \return The currently selected pipe's direction, as a \c PIPE_DIR_* mask.\r
203                          */\r
204                         static inline uint8_t Pipe_GetPipeDirection(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
205                         static inline uint8_t Pipe_GetPipeDirection(void)\r
206                         {\r
207                                 return (((&AVR32_USBB.UPCFG0)[USB_Pipe_SelectedPipe].ptoken == PIPE_TOKEN_OUT) ? PIPE_DIR_OUT : PIPE_DIR_IN);\r
208                         }\r
209                         \r
210                         /** Returns the pipe address of the currently selected pipe. This is typically used to save the\r
211                          *  currently selected pipe number so that it can be restored after another pipe has been manipulated.\r
212                          *\r
213                          *  \return Index of the currently selected pipe.\r
214                          */\r
215                         static inline uint8_t Pipe_GetCurrentPipe(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
216                         static inline uint8_t Pipe_GetCurrentPipe(void)\r
217                         {\r
218                                 return (USB_Pipe_SelectedPipe | Pipe_GetPipeDirection());\r
219                         }\r
220 \r
221                         /** Selects the given pipe address. Any pipe operations which do not require the pipe address to be\r
222                          *  indicated will operate on the currently selected pipe.\r
223                          *\r
224                          *  \param[in] Address  Address of the pipe to select.\r
225                          */\r
226                         static inline void Pipe_SelectPipe(const uint8_t Address) ATTR_ALWAYS_INLINE;\r
227                         static inline void Pipe_SelectPipe(const uint8_t Address)\r
228                         {\r
229                                 USB_Pipe_SelectedPipe = (Address & PIPE_EPNUM_MASK);\r
230                         }\r
231 \r
232                         /** Resets the desired pipe, including the pipe banks and flags.\r
233                          *\r
234                          *  \param[in] Address  Index of the pipe to reset.\r
235                          */\r
236                         static inline void Pipe_ResetPipe(const uint8_t Address) ATTR_ALWAYS_INLINE;\r
237                         static inline void Pipe_ResetPipe(const uint8_t Address)\r
238                         {\r
239                                 uint32_t PipeNumber = (Address & PIPE_EPNUM_MASK);\r
240 \r
241                                 AVR32_USBB.uprst |=  (AVR32_USBB_PRST0_MASK << PipeNumber);\r
242                                 AVR32_USBB.uprst &= ~(AVR32_USBB_PRST0_MASK << PipeNumber);\r
243                                 USB_Pipe_FIFOPos[PipeNumber] = &AVR32_USBB_SLAVE[PipeNumber * PIPE_HSB_ADDRESS_SPACE_SIZE];\r
244                         }\r
245 \r
246                         /** Enables the currently selected pipe so that data can be sent and received through it to and from\r
247                          *  an attached device.\r
248                          *\r
249                          *  \pre The currently selected pipe must first be configured properly via \ref Pipe_ConfigurePipe().\r
250                          */\r
251                         static inline void Pipe_EnablePipe(void) ATTR_ALWAYS_INLINE;\r
252                         static inline void Pipe_EnablePipe(void)\r
253                         {\r
254                                 AVR32_USBB.uprst |=  (AVR32_USBB_PEN0_MASK << USB_Pipe_SelectedPipe);\r
255                         }\r
256 \r
257                         /** Disables the currently selected pipe so that data cannot be sent and received through it to and\r
258                          *  from an attached device.\r
259                          */\r
260                         static inline void Pipe_DisablePipe(void) ATTR_ALWAYS_INLINE;\r
261                         static inline void Pipe_DisablePipe(void)\r
262                         {\r
263                                 AVR32_USBB.uprst &= ~(AVR32_USBB_PEN0_MASK << USB_Pipe_SelectedPipe);\r
264                         }\r
265 \r
266                         /** Determines if the currently selected pipe is enabled, but not necessarily configured.\r
267                          *\r
268                          * \return Boolean \c true if the currently selected pipe is enabled, \c false otherwise.\r
269                          */\r
270                         static inline bool Pipe_IsEnabled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
271                         static inline bool Pipe_IsEnabled(void)\r
272                         {\r
273                                 return ((AVR32_USBB.uprst & (AVR32_USBB_PEN0_MASK << USB_Pipe_SelectedPipe)) ? true : false);\r
274                         }\r
275 \r
276                         /** Gets the current pipe token, indicating the pipe's data direction and type.\r
277                          *\r
278                          *  \return The current pipe token, as a \c PIPE_TOKEN_* mask.\r
279                          */\r
280                         static inline uint8_t Pipe_GetPipeToken(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
281                         static inline uint8_t Pipe_GetPipeToken(void)\r
282                         {\r
283                                 return (&AVR32_USBB.UPCFG0)[USB_Pipe_SelectedPipe].ptoken;\r
284                         }\r
285 \r
286                         /** Sets the token for the currently selected pipe to one of the tokens specified by the \c PIPE_TOKEN_*\r
287                          *  masks. This can be used on CONTROL type pipes, to allow for bidirectional transfer of data during\r
288                          *  control requests, or on regular pipes to allow for half-duplex bidirectional data transfer to devices\r
289                          *  which have two endpoints of opposite direction sharing the same endpoint address within the device.\r
290                          *\r
291                          *  \param[in] Token  New pipe token to set the selected pipe to, as a \c PIPE_TOKEN_* mask.\r
292                          */\r
293                         static inline void Pipe_SetPipeToken(const uint8_t Token) ATTR_ALWAYS_INLINE;\r
294                         static inline void Pipe_SetPipeToken(const uint8_t Token)\r
295                         {\r
296                                 (&AVR32_USBB.UPCFG0)[USB_Pipe_SelectedPipe].ptoken = Token;\r
297                         }\r
298 \r
299                         /** Configures the currently selected pipe to allow for an unlimited number of IN requests. */\r
300                         static inline void Pipe_SetInfiniteINRequests(void) ATTR_ALWAYS_INLINE;\r
301                         static inline void Pipe_SetInfiniteINRequests(void)\r
302                         {\r
303                                 (&AVR32_USBB.UPINRQ0)[USB_Pipe_SelectedPipe].inmode = true;\r
304                         }\r
305 \r
306                         /** Configures the currently selected pipe to only allow the specified number of IN requests to be\r
307                          *  accepted by the pipe before it is automatically frozen.\r
308                          *\r
309                          *  \param[in] TotalINRequests  Total number of IN requests that the pipe may receive before freezing.\r
310                          */\r
311                         static inline void Pipe_SetFiniteINRequests(const uint8_t TotalINRequests) ATTR_ALWAYS_INLINE;\r
312                         static inline void Pipe_SetFiniteINRequests(const uint8_t TotalINRequests)\r
313                         {\r
314                                 (&AVR32_USBB.UPINRQ0)[USB_Pipe_SelectedPipe].inmode = false;\r
315                                 (&AVR32_USBB.UPINRQ0)[USB_Pipe_SelectedPipe].inrq   = TotalINRequests;\r
316                         }\r
317 \r
318                         /** Determines if the currently selected pipe is configured.\r
319                          *\r
320                          *  \return Boolean \c true if the selected pipe is configured, \c false otherwise.\r
321                          */\r
322                         static inline bool Pipe_IsConfigured(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
323                         static inline bool Pipe_IsConfigured(void)\r
324                         {\r
325                                 return (&AVR32_USBB.UPSTA0)[USB_Pipe_SelectedPipe].cfgok;\r
326                         }\r
327 \r
328                         /** Retrieves the endpoint address of the endpoint within the attached device that the currently selected\r
329                          *  pipe is bound to.\r
330                          *\r
331                          *  \return Endpoint address the currently selected pipe is bound to.\r
332                          */\r
333                         static inline uint8_t Pipe_GetBoundEndpointAddress(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
334                         static inline uint8_t Pipe_GetBoundEndpointAddress(void)\r
335                         {\r
336                                 return ((&AVR32_USBB.UPCFG0)[USB_Pipe_SelectedPipe].pepnum |\r
337                                         ((Pipe_GetPipeToken() == PIPE_TOKEN_IN) ? PIPE_DIR_IN : PIPE_DIR_OUT));\r
338                         }\r
339 \r
340                         /** Sets the period between interrupts for an INTERRUPT type pipe to a specified number of milliseconds.\r
341                          *\r
342                          *  \param[in] Milliseconds  Number of milliseconds between each pipe poll.\r
343                          */\r
344                         static inline void Pipe_SetInterruptPeriod(const uint8_t Milliseconds) ATTR_ALWAYS_INLINE;\r
345                         static inline void Pipe_SetInterruptPeriod(const uint8_t Milliseconds)\r
346                         {\r
347                                 (&AVR32_USBB.UPCFG0)[USB_Pipe_SelectedPipe].intfrq = Milliseconds;\r
348                         }\r
349 \r
350                         /** Returns a mask indicating which pipe's interrupt periods have elapsed, indicating that the pipe should\r
351                          *  be serviced.\r
352                          *\r
353                          *  \return Mask whose bits indicate which pipes have interrupted.\r
354                          */\r
355                         static inline uint8_t Pipe_GetPipeInterrupts(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
356                         static inline uint8_t Pipe_GetPipeInterrupts(void)\r
357                         {\r
358                                 return ((AVR32_USBB.uhint & (AVR32_USBB_P6INT_MASK | AVR32_USBB_P5INT_MASK |\r
359                                                              AVR32_USBB_P4INT_MASK | AVR32_USBB_P3INT_MASK |\r
360                                                              AVR32_USBB_P2INT_MASK | AVR32_USBB_P1INT_MASK |\r
361                                                              AVR32_USBB_P0INT_MASK)) >> AVR32_USBB_P0INT_OFFSET);\r
362                         }\r
363 \r
364                         /** Determines if the specified pipe address has interrupted (valid only for INTERRUPT type\r
365                          *  pipes).\r
366                          *\r
367                          *  \param[in] Address  Address of the pipe whose interrupt flag should be tested.\r
368                          *\r
369                          *  \return Boolean \c true if the specified pipe has interrupted, \c false otherwise.\r
370                          */\r
371                         static inline bool Pipe_HasPipeInterrupted(const uint8_t Address) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
372                         static inline bool Pipe_HasPipeInterrupted(const uint8_t Address)\r
373                         {\r
374                                 return ((AVR32_USBB.uhint & (AVR32_USBB_P0INTES_MASK << (Address & PIPE_EPNUM_MASK))) ? true : false);\r
375                         }\r
376 \r
377                         /** Unfreezes the selected pipe, allowing it to communicate with an attached device. */\r
378                         static inline void Pipe_Unfreeze(void) ATTR_ALWAYS_INLINE;\r
379                         static inline void Pipe_Unfreeze(void)\r
380                         {\r
381                                 (&AVR32_USBB.UPCON0CLR)[USB_Pipe_SelectedPipe].pfreezec = true;\r
382                         }\r
383 \r
384                         /** Freezes the selected pipe, preventing it from communicating with an attached device. */\r
385                         static inline void Pipe_Freeze(void) ATTR_ALWAYS_INLINE;\r
386                         static inline void Pipe_Freeze(void)\r
387                         {\r
388                                 (&AVR32_USBB.UPCON0SET)[USB_Pipe_SelectedPipe].pfreezes = true;\r
389                         }\r
390 \r
391                         /** Determines if the currently selected pipe is frozen, and not able to accept data.\r
392                          *\r
393                          *  \return Boolean \c true if the currently selected pipe is frozen, \c false otherwise.\r
394                          */\r
395                         static inline bool Pipe_IsFrozen(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
396                         static inline bool Pipe_IsFrozen(void)\r
397                         {\r
398                                 return (((&AVR32_USBB.UPCON0)[USB_Pipe_SelectedPipe].pfreeze) ? true : false);\r
399                         }\r
400 \r
401                         /** Clears the error flags for the currently selected pipe. */\r
402                         static inline void Pipe_ClearError(void) ATTR_ALWAYS_INLINE;\r
403                         static inline void Pipe_ClearError(void)\r
404                         {\r
405                                 (&AVR32_USBB.uperr0)[USB_Pipe_SelectedPipe] = 0;\r
406                                 (&AVR32_USBB.UPSTA0CLR)[USB_Pipe_SelectedPipe].overfic  = true;\r
407                         }\r
408 \r
409                         /** Determines if the master pipe error flag is set for the currently selected pipe, indicating that\r
410                          *  some sort of hardware error has occurred on the pipe.\r
411                          *\r
412                          *  \see \ref Pipe_GetErrorFlags() macro for information on retrieving the exact error flag.\r
413                          *\r
414                          *  \return Boolean \c true if an error has occurred on the selected pipe, \c false otherwise.\r
415                          */\r
416                         static inline bool Pipe_IsError(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
417                         static inline bool Pipe_IsError(void)\r
418                         {\r
419                                 return (((&AVR32_USBB.upsta0)[USB_Pipe_SelectedPipe] &\r
420                                         (AVR32_USBB_PERRI_MASK | AVR32_USBB_OVERFI_MASK)) ? true : false);\r
421                         }\r
422 \r
423                         /** Gets a mask of the hardware error flags which have occurred on the currently selected pipe. This\r
424                          *  value can then be masked against the \c PIPE_ERRORFLAG_* masks to determine what error has occurred.\r
425                          *\r
426                          *  \return  Mask comprising of \c PIPE_ERRORFLAG_* bits indicating what error has occurred on the selected pipe.\r
427                          */\r
428                         static inline uint8_t Pipe_GetErrorFlags(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
429                         static inline uint8_t Pipe_GetErrorFlags(void)\r
430                         {\r
431 \r
432                                 return (((&AVR32_USBB.uperr0)[USB_Pipe_SelectedPipe] &\r
433                                         (PIPE_ERRORFLAG_CRC16 | PIPE_ERRORFLAG_TIMEOUT |\r
434                                          PIPE_ERRORFLAG_PID   | PIPE_ERRORFLAG_DATAPID |\r
435                                          PIPE_ERRORFLAG_DATATGL)) |\r
436                                         (((&AVR32_USBB.upsta0)[USB_Pipe_SelectedPipe] << 8) &\r
437                                                  PIPE_ERRORFLAG_OVERFLOW));\r
438                         }\r
439 \r
440                         /** Retrieves the number of busy banks in the currently selected pipe, which have been queued for\r
441                          *  transmission via the \ref Pipe_ClearOUT() command, or are awaiting acknowledgement via the\r
442                          *  \ref Pipe_ClearIN() command.\r
443                          *\r
444                          *  \ingroup Group_PipePacketManagement_UC3\r
445                          *\r
446                          *  \return Total number of busy banks in the selected pipe.\r
447                          */\r
448                         static inline uint8_t Pipe_GetBusyBanks(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
449                         static inline uint8_t Pipe_GetBusyBanks(void)\r
450                         {\r
451                                 return (&AVR32_USBB.UPSTA0)[USB_Pipe_SelectedPipe].nbusybk;\r
452                         }\r
453 \r
454                         /** Determines if the currently selected pipe may be read from (if data is waiting in the pipe\r
455                          *  bank and the pipe is an IN direction, or if the bank is not yet full if the pipe is an OUT\r
456                          *  direction). This function will return false if an error has occurred in the pipe, or if the pipe\r
457                          *  is an IN direction and no packet (or an empty packet) has been received, or if the pipe is an OUT\r
458                          *  direction and the pipe bank is full.\r
459                          *\r
460                          *  \note This function is not valid on CONTROL type pipes.\r
461                          *\r
462                          *  \ingroup Group_PipePacketManagement_UC3\r
463                          *\r
464                          *  \return Boolean \c true if the currently selected pipe may be read from or written to, depending\r
465                          *          on its direction.\r
466                          */\r
467                         static inline bool Pipe_IsReadWriteAllowed(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
468                         static inline bool Pipe_IsReadWriteAllowed(void)\r
469                         {\r
470                                 return (&AVR32_USBB.UPSTA0)[USB_Pipe_SelectedPipe].rwall;\r
471                         }\r
472 \r
473                         /** Determines if a packet has been received on the currently selected IN pipe from the attached device.\r
474                          *\r
475                          *  \ingroup Group_PipePacketManagement_UC3\r
476                          *\r
477                          *  \return Boolean \c true if the current pipe has received an IN packet, \c false otherwise.\r
478                          */\r
479                         static inline bool Pipe_IsINReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
480                         static inline bool Pipe_IsINReceived(void)\r
481                         {\r
482                                 return (&AVR32_USBB.UPSTA0)[USB_Pipe_SelectedPipe].rxini;\r
483                         }\r
484 \r
485                         /** Determines if the currently selected OUT pipe is ready to send an OUT packet to the attached device.\r
486                          *\r
487                          *  \ingroup Group_PipePacketManagement_UC3\r
488                          *\r
489                          *  \return Boolean \c true if the current pipe is ready for an OUT packet, \c false otherwise.\r
490                          */\r
491                         static inline bool Pipe_IsOUTReady(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
492                         static inline bool Pipe_IsOUTReady(void)\r
493                         {\r
494                                 return (&AVR32_USBB.UPSTA0)[USB_Pipe_SelectedPipe].txouti;\r
495                         }\r
496 \r
497                         /** Determines if no SETUP request is currently being sent to the attached device on the selected\r
498                          *  CONTROL type pipe.\r
499                          *\r
500                          *  \ingroup Group_PipePacketManagement_UC3\r
501                          *\r
502                          *  \return Boolean \c true if the current pipe is ready for a SETUP packet, \c false otherwise.\r
503                          */\r
504                         static inline bool Pipe_IsSETUPSent(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
505                         static inline bool Pipe_IsSETUPSent(void)\r
506                         {\r
507                                 return (&AVR32_USBB.UPSTA0)[USB_Pipe_SelectedPipe].txstpi;\r
508                         }\r
509 \r
510                         /** Sends the currently selected CONTROL type pipe's contents to the device as a SETUP packet.\r
511                          *\r
512                          *  \ingroup Group_PipePacketManagement_UC3\r
513                          */\r
514                         static inline void Pipe_ClearSETUP(void) ATTR_ALWAYS_INLINE;\r
515                         static inline void Pipe_ClearSETUP(void)\r
516                         {\r
517                                 (&AVR32_USBB.UPSTA0CLR)[USB_Pipe_SelectedPipe].txstpic = true;\r
518                                 (&AVR32_USBB.UPCON0CLR)[USB_Pipe_SelectedPipe].fifoconc = true;\r
519                                 USB_Pipe_FIFOPos[USB_Pipe_SelectedPipe] = &AVR32_USBB_SLAVE[USB_Pipe_SelectedPipe * PIPE_HSB_ADDRESS_SPACE_SIZE];\r
520                         }\r
521 \r
522                         /** Acknowledges the reception of a setup IN request from the attached device on the currently selected\r
523                          *  pipe, freeing the bank ready for the next packet.\r
524                          *\r
525                          *  \ingroup Group_PipePacketManagement_UC3\r
526                          */\r
527                         static inline void Pipe_ClearIN(void) ATTR_ALWAYS_INLINE;\r
528                         static inline void Pipe_ClearIN(void)\r
529                         {\r
530                                 (&AVR32_USBB.UPSTA0CLR)[USB_Pipe_SelectedPipe].rxinic   = true;\r
531                                 (&AVR32_USBB.UPCON0CLR)[USB_Pipe_SelectedPipe].fifoconc = true;\r
532                                 USB_Pipe_FIFOPos[USB_Pipe_SelectedPipe] = &AVR32_USBB_SLAVE[USB_Pipe_SelectedPipe * PIPE_HSB_ADDRESS_SPACE_SIZE];\r
533                         }\r
534 \r
535                         /** Sends the currently selected pipe's contents to the device as an OUT packet on the selected pipe, freeing\r
536                          *  the bank ready for the next packet.\r
537                          *\r
538                          *  \ingroup Group_PipePacketManagement_UC3\r
539                          */\r
540                         static inline void Pipe_ClearOUT(void) ATTR_ALWAYS_INLINE;\r
541                         static inline void Pipe_ClearOUT(void)\r
542                         {\r
543                                 (&AVR32_USBB.UPSTA0CLR)[USB_Pipe_SelectedPipe].txoutic  = true;\r
544                                 (&AVR32_USBB.UPCON0CLR)[USB_Pipe_SelectedPipe].fifoconc = true;\r
545                                 USB_Pipe_FIFOPos[USB_Pipe_SelectedPipe] = &AVR32_USBB_SLAVE[USB_Pipe_SelectedPipe * PIPE_HSB_ADDRESS_SPACE_SIZE];\r
546                         }\r
547 \r
548                         /** Determines if the device sent a NAK (Negative Acknowledge) in response to the last sent packet on\r
549                          *  the currently selected pipe. This occurs when the host sends a packet to the device, but the device\r
550                          *  is not currently ready to handle the packet (i.e. its endpoint banks are full). Once a NAK has been\r
551                          *  received, it must be cleared using \ref Pipe_ClearNAKReceived() before the previous (or any other) packet\r
552                          *  can be re-sent.\r
553                          *\r
554                          *  \ingroup Group_PipePacketManagement_UC3\r
555                          *\r
556                          *  \return Boolean \c true if an NAK has been received on the current pipe, \c false otherwise.\r
557                          */\r
558                         static inline bool Pipe_IsNAKReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
559                         static inline bool Pipe_IsNAKReceived(void)\r
560                         {\r
561                                 return (&AVR32_USBB.UPSTA0)[USB_Pipe_SelectedPipe].nakedi;\r
562                         }\r
563 \r
564                         /** Clears the NAK condition on the currently selected pipe.\r
565                          *\r
566                          *  \ingroup Group_PipePacketManagement_UC3\r
567                          *\r
568                          *  \see \ref Pipe_IsNAKReceived() for more details.\r
569                          */\r
570                         static inline void Pipe_ClearNAKReceived(void) ATTR_ALWAYS_INLINE;\r
571                         static inline void Pipe_ClearNAKReceived(void)\r
572                         {\r
573                                 (&AVR32_USBB.UPSTA0CLR)[USB_Pipe_SelectedPipe].nakedic = true;\r
574                         }\r
575 \r
576                         /** Determines if the currently selected pipe has had the STALL condition set by the attached device.\r
577                          *\r
578                          *  \ingroup Group_PipePacketManagement_UC3\r
579                          *\r
580                          *  \return Boolean \c true if the current pipe has been stalled by the attached device, \c false otherwise.\r
581                          */\r
582                         static inline bool Pipe_IsStalled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
583                         static inline bool Pipe_IsStalled(void)\r
584                         {\r
585                                 return (&AVR32_USBB.UPSTA0)[USB_Pipe_SelectedPipe].rxstalldi;\r
586                         }\r
587 \r
588                         /** Clears the STALL condition detection flag on the currently selected pipe, but does not clear the\r
589                          *  STALL condition itself (this must be done via a ClearFeature control request to the device).\r
590                          *\r
591                          *  \ingroup Group_PipePacketManagement_UC3\r
592                          */\r
593                         static inline void Pipe_ClearStall(void) ATTR_ALWAYS_INLINE;\r
594                         static inline void Pipe_ClearStall(void)\r
595                         {\r
596                                 (&AVR32_USBB.UPSTA0CLR)[USB_Pipe_SelectedPipe].rxstalldic = true;\r
597                                 USB_Pipe_FIFOPos[USB_Pipe_SelectedPipe] = &AVR32_USBB_SLAVE[USB_Pipe_SelectedPipe * PIPE_HSB_ADDRESS_SPACE_SIZE];\r
598                         }\r
599 \r
600                         /** Reads one byte from the currently selected pipe's bank, for OUT direction pipes.\r
601                          *\r
602                          *  \ingroup Group_PipePrimitiveRW_UC3\r
603                          *\r
604                          *  \return Next byte in the currently selected pipe's FIFO buffer.\r
605                          */\r
606                         static inline uint8_t Pipe_Read_8(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
607                         static inline uint8_t Pipe_Read_8(void)\r
608                         {\r
609                                 return *(USB_Pipe_FIFOPos[USB_Pipe_SelectedPipe]++);\r
610                         }\r
611 \r
612                         /** Writes one byte to the currently selected pipe's bank, for IN direction pipes.\r
613                          *\r
614                          *  \ingroup Group_PipePrimitiveRW_UC3\r
615                          *\r
616                          *  \param[in] Data  Data to write into the the currently selected pipe's FIFO buffer.\r
617                          */\r
618                         static inline void Pipe_Write_8(const uint8_t Data) ATTR_ALWAYS_INLINE;\r
619                         static inline void Pipe_Write_8(const uint8_t Data)\r
620                         {\r
621                                 *(USB_Pipe_FIFOPos[USB_Pipe_SelectedPipe]++) = Data;\r
622                         }\r
623 \r
624                         /** Discards one byte from the currently selected pipe's bank, for OUT direction pipes.\r
625                          *\r
626                          *  \ingroup Group_PipePrimitiveRW_UC3\r
627                          */\r
628                         static inline void Pipe_Discard_8(void) ATTR_ALWAYS_INLINE;\r
629                         static inline void Pipe_Discard_8(void)\r
630                         {\r
631                                 uint8_t Dummy;\r
632 \r
633                                 Dummy = *(USB_Pipe_FIFOPos[USB_Pipe_SelectedPipe]++);\r
634 \r
635                                 (void)Dummy;\r
636                         }\r
637 \r
638                         /** Reads two bytes from the currently selected pipe's bank in little endian format, for OUT\r
639                          *  direction pipes.\r
640                          *\r
641                          *  \ingroup Group_PipePrimitiveRW_UC3\r
642                          *\r
643                          *  \return Next two bytes in the currently selected pipe's FIFO buffer.\r
644                          */\r
645                         static inline uint16_t Pipe_Read_16_LE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
646                         static inline uint16_t Pipe_Read_16_LE(void)\r
647                         {\r
648                                 uint16_t Byte0 = *(USB_Pipe_FIFOPos[USB_Pipe_SelectedPipe]++);\r
649                                 uint16_t Byte1 = *(USB_Pipe_FIFOPos[USB_Pipe_SelectedPipe]++);\r
650 \r
651                                 return ((Byte1 << 8) | Byte0);\r
652                         }\r
653 \r
654                         /** Reads two bytes from the currently selected pipe's bank in big endian format, for OUT\r
655                          *  direction pipes.\r
656                          *\r
657                          *  \ingroup Group_PipePrimitiveRW_UC3\r
658                          *\r
659                          *  \return Next two bytes in the currently selected pipe's FIFO buffer.\r
660                          */\r
661                         static inline uint16_t Pipe_Read_16_BE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
662                         static inline uint16_t Pipe_Read_16_BE(void)\r
663                         {\r
664                                 uint16_t Byte0 = *(USB_Pipe_FIFOPos[USB_Pipe_SelectedPipe]++);\r
665                                 uint16_t Byte1 = *(USB_Pipe_FIFOPos[USB_Pipe_SelectedPipe]++);\r
666 \r
667                                 return ((Byte0 << 8) | Byte1);\r
668                         }\r
669 \r
670                         /** Writes two bytes to the currently selected pipe's bank in little endian format, for IN\r
671                          *  direction pipes.\r
672                          *\r
673                          *  \ingroup Group_PipePrimitiveRW_UC3\r
674                          *\r
675                          *  \param[in] Data  Data to write to the currently selected pipe's FIFO buffer.\r
676                          */\r
677                         static inline void Pipe_Write_16_LE(const uint16_t Data) ATTR_ALWAYS_INLINE;\r
678                         static inline void Pipe_Write_16_LE(const uint16_t Data)\r
679                         {\r
680                                 *(USB_Pipe_FIFOPos[USB_Pipe_SelectedPipe]++) = (Data & 0xFF);\r
681                                 *(USB_Pipe_FIFOPos[USB_Pipe_SelectedPipe]++) = (Data >> 8);\r
682                         }\r
683 \r
684                         /** Writes two bytes to the currently selected pipe's bank in big endian format, for IN\r
685                          *  direction pipes.\r
686                          *\r
687                          *  \ingroup Group_PipePrimitiveRW_UC3\r
688                          *\r
689                          *  \param[in] Data  Data to write to the currently selected pipe's FIFO buffer.\r
690                          */\r
691                         static inline void Pipe_Write_16_BE(const uint16_t Data) ATTR_ALWAYS_INLINE;\r
692                         static inline void Pipe_Write_16_BE(const uint16_t Data)\r
693                         {\r
694                                 *(USB_Pipe_FIFOPos[USB_Pipe_SelectedPipe]++) = (Data >> 8);\r
695                                 *(USB_Pipe_FIFOPos[USB_Pipe_SelectedPipe]++) = (Data & 0xFF);\r
696                         }\r
697 \r
698                         /** Discards two bytes from the currently selected pipe's bank, for OUT direction pipes.\r
699                          *\r
700                          *  \ingroup Group_PipePrimitiveRW_UC3\r
701                          */\r
702                         static inline void Pipe_Discard_16(void) ATTR_ALWAYS_INLINE;\r
703                         static inline void Pipe_Discard_16(void)\r
704                         {\r
705                                 uint8_t Dummy;\r
706 \r
707                                 Dummy = *(USB_Pipe_FIFOPos[USB_Pipe_SelectedPipe]++);\r
708                                 Dummy = *(USB_Pipe_FIFOPos[USB_Pipe_SelectedPipe]++);\r
709 \r
710                                 (void)Dummy;\r
711                         }\r
712 \r
713                         /** Reads four bytes from the currently selected pipe's bank in little endian format, for OUT\r
714                          *  direction pipes.\r
715                          *\r
716                          *  \ingroup Group_PipePrimitiveRW_UC3\r
717                          *\r
718                          *  \return Next four bytes in the currently selected pipe's FIFO buffer.\r
719                          */\r
720                         static inline uint32_t Pipe_Read_32_LE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
721                         static inline uint32_t Pipe_Read_32_LE(void)\r
722                         {\r
723                                 uint32_t Byte0 = *(USB_Pipe_FIFOPos[USB_Pipe_SelectedPipe]++);\r
724                                 uint32_t Byte1 = *(USB_Pipe_FIFOPos[USB_Pipe_SelectedPipe]++);\r
725                                 uint32_t Byte2 = *(USB_Pipe_FIFOPos[USB_Pipe_SelectedPipe]++);\r
726                                 uint32_t Byte3 = *(USB_Pipe_FIFOPos[USB_Pipe_SelectedPipe]++);\r
727 \r
728                                 return ((Byte3 << 24) | (Byte2 << 16) | (Byte1 << 8) | Byte0);\r
729                         }\r
730 \r
731                         /** Reads four bytes from the currently selected pipe's bank in big endian format, for OUT\r
732                          *  direction pipes.\r
733                          *\r
734                          *  \ingroup Group_PipePrimitiveRW_UC3\r
735                          *\r
736                          *  \return Next four bytes in the currently selected pipe's FIFO buffer.\r
737                          */\r
738                         static inline uint32_t Pipe_Read_32_BE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
739                         static inline uint32_t Pipe_Read_32_BE(void)\r
740                         {\r
741                                 uint32_t Byte0 = *(USB_Pipe_FIFOPos[USB_Pipe_SelectedPipe]++);\r
742                                 uint32_t Byte1 = *(USB_Pipe_FIFOPos[USB_Pipe_SelectedPipe]++);\r
743                                 uint32_t Byte2 = *(USB_Pipe_FIFOPos[USB_Pipe_SelectedPipe]++);\r
744                                 uint32_t Byte3 = *(USB_Pipe_FIFOPos[USB_Pipe_SelectedPipe]++);\r
745 \r
746                                 return ((Byte0 << 24) | (Byte1 << 16) | (Byte2 << 8) | Byte3);\r
747                         }\r
748 \r
749                         /** Writes four bytes to the currently selected pipe's bank in little endian format, for IN\r
750                          *  direction pipes.\r
751                          *\r
752                          *  \ingroup Group_PipePrimitiveRW_UC3\r
753                          *\r
754                          *  \param[in] Data  Data to write to the currently selected pipe's FIFO buffer.\r
755                          */\r
756                         static inline void Pipe_Write_32_LE(const uint32_t Data) ATTR_ALWAYS_INLINE;\r
757                         static inline void Pipe_Write_32_LE(const uint32_t Data)\r
758                         {\r
759                                 *(USB_Pipe_FIFOPos[USB_Pipe_SelectedPipe]++) = (Data &  0xFF);\r
760                                 *(USB_Pipe_FIFOPos[USB_Pipe_SelectedPipe]++) = (Data >> 8);\r
761                                 *(USB_Pipe_FIFOPos[USB_Pipe_SelectedPipe]++) = (Data >> 16);\r
762                                 *(USB_Pipe_FIFOPos[USB_Pipe_SelectedPipe]++) = (Data >> 24);\r
763                         }\r
764 \r
765                         /** Writes four bytes to the currently selected pipe's bank in big endian format, for IN\r
766                          *  direction pipes.\r
767                          *\r
768                          *  \ingroup Group_PipePrimitiveRW_UC3\r
769                          *\r
770                          *  \param[in] Data  Data to write to the currently selected pipe's FIFO buffer.\r
771                          */\r
772                         static inline void Pipe_Write_32_BE(const uint32_t Data) ATTR_ALWAYS_INLINE;\r
773                         static inline void Pipe_Write_32_BE(const uint32_t Data)\r
774                         {\r
775                                 *(USB_Pipe_FIFOPos[USB_Pipe_SelectedPipe]++) = (Data >> 24);\r
776                                 *(USB_Pipe_FIFOPos[USB_Pipe_SelectedPipe]++) = (Data >> 16);\r
777                                 *(USB_Pipe_FIFOPos[USB_Pipe_SelectedPipe]++) = (Data >> 8);\r
778                                 *(USB_Pipe_FIFOPos[USB_Pipe_SelectedPipe]++) = (Data &  0xFF);\r
779                         }\r
780 \r
781                         /** Discards four bytes from the currently selected pipe's bank, for OUT direction pipes.\r
782                          *\r
783                          *  \ingroup Group_PipePrimitiveRW_UC3\r
784                          */\r
785                         static inline void Pipe_Discard_32(void) ATTR_ALWAYS_INLINE;\r
786                         static inline void Pipe_Discard_32(void)\r
787                         {\r
788                                 uint8_t Dummy;\r
789 \r
790                                 Dummy = *(USB_Pipe_FIFOPos[USB_Pipe_SelectedPipe]++);\r
791                                 Dummy = *(USB_Pipe_FIFOPos[USB_Pipe_SelectedPipe]++);\r
792                                 Dummy = *(USB_Pipe_FIFOPos[USB_Pipe_SelectedPipe]++);\r
793                                 Dummy = *(USB_Pipe_FIFOPos[USB_Pipe_SelectedPipe]++);\r
794 \r
795                                 (void)Dummy;\r
796                         }\r
797 \r
798                 /* External Variables: */\r
799                         /** Global indicating the maximum packet size of the default control pipe located at address\r
800                          *  0 in the device. This value is set to the value indicated in the attached device's device\r
801                      *  descriptor once the USB interface is initialized into host mode and a device is attached\r
802                          *  to the USB bus.\r
803                          *\r
804                          *  \attention This variable should be treated as read-only in the user application, and never manually\r
805                          *             changed in value.\r
806                          */\r
807                         extern uint8_t USB_Host_ControlPipeSize;\r
808 \r
809                 /* Function Prototypes: */\r
810                         /** Configures a table of pipe descriptions, in sequence. This function can be used to configure multiple\r
811                          *  pipes at the same time.\r
812                          *\r
813                          *  \note Pipe with a zero address will be ignored, thus this function cannot be used to configure the\r
814                          *        control pipe.\r
815                          *\r
816                          *  \param[in] Table    Pointer to a table of pipe descriptions.\r
817                          *  \param[in] Entries  Number of entries in the pipe table to configure.\r
818                          *\r
819                          *  \return Boolean \c true if all pipes configured successfully, \c false otherwise.\r
820                          */                     \r
821                         bool Pipe_ConfigurePipeTable(const USB_Pipe_Table_t* const Table,\r
822                                                      const uint8_t Entries);\r
823 \r
824                         /** Configures the specified pipe address with the given pipe type, endpoint address within the attached device, bank size\r
825                          *  and number of hardware banks.\r
826                          *\r
827                          *  A newly configured pipe is frozen by default, and must be unfrozen before use via the \ref Pipe_Unfreeze()\r
828                          *  before being used. Pipes should be kept frozen unless waiting for data from a device while in IN mode, or\r
829                          *  sending data to the device in OUT mode. IN type pipes are also automatically configured to accept infinite\r
830                          *  numbers of IN requests without automatic freezing - this can be overridden by a call to\r
831                          *  \ref Pipe_SetFiniteINRequests().\r
832                          *\r
833                          *  \param[in] Address          Pipe address to configure.\r
834                          *\r
835                          *  \param[in] Type             Type of pipe to configure, an \c EP_TYPE_* mask. Not all pipe types are available on Low\r
836                          *                              Speed USB devices - refer to the USB 2.0 specification.\r
837                          *\r
838                          *  \param[in] EndpointAddress  Endpoint address within the attached device that the pipe should interface to.\r
839                          *\r
840                          *  \param[in] Size             Size of the pipe's bank, where packets are stored before they are transmitted to\r
841                          *                              the USB device, or after they have been received from the USB device (depending on\r
842                          *                              the pipe's data direction). The bank size must indicate the maximum packet size that\r
843                          *                              the pipe can handle.\r
844                          *\r
845                          *  \param[in] Banks            Number of banks to use for the pipe being configured.\r
846                          *\r
847                          *  \note When the \c ORDERED_EP_CONFIG compile time option is used, Pipes <b>must</b> be configured in ascending order,\r
848                          *        or bank corruption will occur.\r
849                          *        \n\n\r
850                          *\r
851                          *  \note Certain microcontroller model's pipes may have different maximum packet sizes based on the pipe's\r
852                          *        index - refer to the chosen microcontroller's datasheet to determine the maximum bank size for each pipe.\r
853                          *        \n\n\r
854                          *\r
855                          *  \note The default control pipe should not be manually configured by the user application, as it is\r
856                          *        automatically configured by the library internally.\r
857                          *        \n\n\r
858                          *\r
859                          *  \note This routine will automatically select the specified pipe upon success. Upon failure, the pipe which\r
860                          *        failed to reconfigure correctly will be selected.\r
861                          *\r
862                          *  \return Boolean \c true if the configuration succeeded, \c false otherwise.\r
863                          */\r
864                         bool Pipe_ConfigurePipe(const uint8_t Address,\r
865                                                 const uint8_t Type,\r
866                                                 const uint8_t EndpointAddress,\r
867                                                 const uint16_t Size,\r
868                                                 const uint8_t Banks);\r
869 \r
870                         /** Spin-loops until the currently selected non-control pipe is ready for the next packet of data to be read\r
871                          *  or written to it, aborting in the case of an error condition (such as a timeout or device disconnect).\r
872                          *\r
873                          *  \ingroup Group_PipeRW_UC3\r
874                          *\r
875                          *  \return A value from the \ref Pipe_WaitUntilReady_ErrorCodes_t enum.\r
876                          */\r
877                         uint8_t Pipe_WaitUntilReady(void);\r
878 \r
879                         /** Determines if a pipe has been bound to the given device endpoint address. If a pipe which is bound to the given\r
880                          *  endpoint is found, it is automatically selected.\r
881                          *\r
882                          *  \param[in] EndpointAddress Address and direction mask of the endpoint within the attached device to check.\r
883                          *\r
884                          *  \return Boolean \c true if a pipe bound to the given endpoint address of the specified direction is found,\r
885                          *          \c false otherwise.\r
886                          */\r
887                         bool Pipe_IsEndpointBound(const uint8_t EndpointAddress) ATTR_WARN_UNUSED_RESULT;\r
888 \r
889         /* Private Interface - For use in library only: */\r
890         #if !defined(__DOXYGEN__)\r
891                 /* Macros: */\r
892                         #if !defined(ENDPOINT_CONTROLEP)\r
893                                 #define ENDPOINT_CONTROLEP          0\r
894                         #endif\r
895 \r
896                 /* Inline Functions: */\r
897                         static inline uint8_t Pipe_BytesToEPSizeMask(const uint16_t Bytes) ATTR_WARN_UNUSED_RESULT ATTR_CONST ATTR_ALWAYS_INLINE;\r
898                         static inline uint8_t Pipe_BytesToEPSizeMask(const uint16_t Bytes)\r
899                         {\r
900                                 uint8_t  MaskVal    = 0;\r
901                                 uint16_t CheckBytes = 8;\r
902 \r
903                                 while ((CheckBytes < Bytes) && (CheckBytes < PIPE_MAX_SIZE))\r
904                                 {\r
905                                         MaskVal++;\r
906                                         CheckBytes <<= 1;\r
907                                 }\r
908 \r
909                                 return (MaskVal << AVR32_USBB_PSIZE_OFFSET);\r
910                         }\r
911 \r
912                 /* Function Prototypes: */\r
913                         void Pipe_ClearPipes(void);\r
914         #endif\r
915 \r
916         /* Disable C linkage for C++ Compilers: */\r
917                 #if defined(__cplusplus)\r
918                         }\r
919                 #endif\r
920 \r
921 #endif\r
922 \r
923 /** @} */\r
924 \r