- #define PIPE_INT_IN UPIENX, (1 << RXINE) , UPINTX, (1 << RXINI)\r
-\r
- /** Interrupt definition for the pipe OUT interrupt (for INTERRUPT type pipes). Should be used with\r
- * the USB_INT_* macros located in USBInterrupt.h.\r
- *\r
- * This interrupt will fire if enabled on an INTERRUPT type endpoint if a the pipe interrupt period\r
- * has elapsed and the pipe is ready for a packet to be written to the pipe's FIFO buffer and sent\r
- * to the attached device (if required).\r
- * \r
- * This interrupt must be enabled on *each* pipe which requires it (after the pipe is selected), and\r
- * will fire the common pipe interrupt vector.\r
- *\r
- * \see ENDPOINT_PIPE_vect for more information on the common pipe and endpoint interrupt vector. */\r
- #define PIPE_INT_OUT UPIENX, (1 << TXOUTE), UPINTX, (1 << TXOUTI)\r
-\r
- /** Interrupt definition for the pipe SETUP bank ready interrupt (for CONTROL type pipes). Should be\r
- * used with the USB_INT_* macros located in USBInterrupt.h.\r
- *\r
- * This interrupt will fire if enabled on an CONTROL type pipe when the pipe is ready for a new\r
- * control request.\r
- *\r
- * This interrupt must be enabled on *each* pipe which requires it (after the pipe is selected), and\r
- * will fire the common pipe interrupt vector.\r
- *\r
- * \see ENDPOINT_PIPE_vect for more information on the common pipe and endpoint interrupt vector.\r
- */\r
- #define PIPE_INT_SETUP UPIENX, (1 << TXSTPE) , UPINTX, (1 << TXSTPI)\r
-\r
- /** Interrupt definition for the pipe error interrupt. Should be used with the USB_INT_* macros\r
- * located in USBInterrupt.h.\r
- *\r
- * This interrupt will fire if enabled on a particular pipe if an error occurs on that pipe, such\r
- * as a CRC mismatch error.\r
- *\r
- * This interrupt must be enabled on *each* pipe which requires it (after the pipe is selected), and\r
- * will fire the common pipe interrupt vector.\r
- *\r
- * \see ENDPOINT_PIPE_vect for more information on the common pipe and endpoint interrupt vector.\r
- *\r
- * \see Pipe_GetErrorFlags() for more information on the pipe errors.\r
- */\r
- #define PIPE_INT_ERROR UPIENX, (1 << PERRE), UPINTX, (1 << PERRI)\r
-\r
- /** Interrupt definition for the pipe NAK received interrupt. Should be used with the USB_INT_* macros\r
- * located in USBInterrupt.h.\r
- *\r
- * This interrupt will fire if enabled on a particular pipe if an attached device returns a NAK in\r
- * response to a sent packet.\r
- *\r
- * This interrupt must be enabled on *each* pipe which requires it (after the pipe is selected), and\r
- * will fire the common pipe interrupt vector.\r
- *\r
- * \see ENDPOINT_PIPE_vect for more information on the common pipe and endpoint interrupt vector.\r
- *\r
- * \see Pipe_IsNAKReceived() for more information on pipe NAKs.\r
- */\r
- #define PIPE_INT_NAK UPIENX, (1 << NAKEDE), UPINTX, (1 << NAKEDI)\r
-\r
- /** Interrupt definition for the pipe STALL received interrupt. Should be used with the USB_INT_* macros\r
- * located in USBInterrupt.h.\r
- *\r
- * This interrupt will fire if enabled on a particular pipe if an attached device returns a STALL on the\r
- * currently selected pipe. This will also fire if the pipe is an isochronous pipe and a CRC error occurs.\r
- *\r
- * This interrupt must be enabled on *each* pipe which requires it (after the pipe is selected), and\r
- * will fire the common pipe interrupt vector.\r
- *\r
- * \see ENDPOINT_PIPE_vect for more information on the common pipe and endpoint interrupt vector.\r
- */\r
- #define PIPE_INT_STALL UPIENX, (1 << RXSTALLE), UPINTX, (1 << RXSTALLI)\r
-\r
- /** Indicates the number of bytes currently stored in the current pipe's selected bank. */\r
- #define Pipe_BytesInPipe() UPBCX\r
+ #define PIPE_EPDIR_MASK 0x80\r
+\r
+ /* Pseudo-Function Macros: */\r
+ #if defined(__DOXYGEN__)\r
+ /** Indicates the number of bytes currently stored in the current pipes's selected bank.\r
+ *\r
+ * \note The return width of this function may differ, depending on the maximum pipe bank size\r
+ * of the selected AVR model.\r
+ *\r
+ * \ingroup Group_PipeRW\r
+ *\r
+ * \return Total number of bytes in the currently selected Pipe's FIFO buffer\r
+ */\r
+ static inline uint16_t Pipe_BytesInPipe(void);\r
+ \r
+ /** Returns the pipe address of the currently selected pipe. This is typically used to save the\r
+ * currently selected pipe number so that it can be restored after another pipe has been manipulated.\r
+ *\r
+ * \return Index of the currently selected pipe\r
+ */\r
+ static inline uint8_t Pipe_GetCurrentPipe(void);\r
+\r
+ /** Selects the given pipe number. Any pipe operations which do not require the pipe number to be\r
+ * indicated will operate on the currently selected pipe.\r
+ *\r
+ * \param[in] PipeNumber Index of the pipe to select\r
+ */\r
+ static inline void Pipe_SelectPipe(uint8_t PipeNumber);\r
+ \r
+ /** Resets the desired pipe, including the pipe banks and flags.\r
+ *\r
+ * \param[in] PipeNumber Index of the pipe to reset\r
+ */\r
+ static inline void Pipe_ResetPipe(uint8_t PipeNumber);\r
+ \r
+ /** Enables the currently selected pipe so that data can be sent and received through it to and from\r
+ * an attached device.\r
+ *\r
+ * \note Pipes must first be configured properly via \ref Pipe_ConfigurePipe().\r
+ */\r
+ static inline void Pipe_EnablePipe(void);\r
+\r
+ /** Disables the currently selected pipe so that data cannot be sent and received through it to and\r
+ * from an attached device.\r
+ */\r
+ static inline void Pipe_DisablePipe(void);\r
+\r
+ /** Determines if the currently selected pipe is enabled, but not necessarily configured.\r
+ *\r
+ * \return Boolean True if the currently selected pipe is enabled, false otherwise\r
+ */\r
+ static inline bool Pipe_IsEnabled(void);\r
+ \r
+ /** Gets the current pipe token, indicating the pipe's data direction and type.\r
+ *\r
+ * \return The current pipe token, as a PIPE_TOKEN_* mask\r
+ */\r
+ static inline uint8_t Pipe_GetPipeToken(void);\r
+ \r
+ /** Sets the token for the currently selected pipe to one of the tokens specified by the PIPE_TOKEN_*\r
+ * masks. This can be used on CONTROL type pipes, to allow for bidirectional transfer of data during\r
+ * control requests, or on regular pipes to allow for half-duplex bidirectional data transfer to devices\r
+ * which have two endpoints of opposite direction sharing the same endpoint address within the device.\r
+ *\r
+ * \param[in] Token New pipe token to set the selected pipe to, as a PIPE_TOKEN_* mask\r
+ */\r
+ static inline void Pipe_SetPipeToken(uint8_t Token);\r
+ \r
+ /** Configures the currently selected pipe to allow for an unlimited number of IN requests. */\r
+ static inline void Pipe_SetInfiniteINRequests(void);\r
+ \r
+ /** Configures the currently selected pipe to only allow the specified number of IN requests to be\r
+ * accepted by the pipe before it is automatically frozen.\r
+ *\r
+ * \param[in] TotalINRequests Total number of IN requests that the pipe may receive before freezing\r
+ */\r
+ static inline void Pipe_SetFiniteINRequests(uint8_t TotalINRequests);\r
+\r
+ /** Determines if the currently selected pipe is configured.\r
+ *\r
+ * \return Boolean true if the selected pipe is configured, false otherwise\r
+ */\r
+ static inline bool Pipe_IsConfigured(void);\r
+ \r
+ /** Retrieves the endpoint number of the endpoint within the attached device that the currently selected\r
+ * pipe is bound to.\r
+ *\r
+ * \return Endpoint number the currently selected pipe is bound to\r
+ */\r
+ static inline uint8_t Pipe_BoundEndpointNumber(void);\r
+\r
+ /** Sets the period between interrupts for an INTERRUPT type pipe to a specified number of milliseconds.\r
+ *\r
+ * \param[in] Milliseconds Number of milliseconds between each pipe poll\r
+ */\r
+ static inline void Pipe_SetInterruptPeriod(uint8_t Milliseconds);\r
+ \r
+ /** Returns a mask indicating which pipe's interrupt periods have elapsed, indicating that the pipe should\r
+ * be serviced.\r
+ *\r
+ * \return Mask whose bits indicate which pipes have interrupted\r
+ */\r
+ static inline uint8_t Pipe_GetPipeInterrupts(void);\r
+ \r
+ /** Determines if the specified pipe number has interrupted (valid only for INTERRUPT type\r
+ * pipes).\r
+ *\r
+ * \param[in] PipeNumber Index of the pipe whose interrupt flag should be tested\r
+ *\r
+ * \return Boolean true if the specified pipe has interrupted, false otherwise\r
+ */\r
+ static inline bool Pipe_HasPipeInterrupted(uint8_t PipeNumber);\r
+ \r
+ /** Unfreezes the selected pipe, allowing it to communicate with an attached device. */\r
+ static inline void Pipe_Unfreeze(void);\r
+ \r
+ /** Freezes the selected pipe, preventing it from communicating with an attached device. */\r
+ static inline void Pipe_Freeze(void);\r
+\r
+ /** Determines if the currently selected pipe is frozen, and not able to accept data.\r
+ *\r
+ * \return Boolean true if the currently selected pipe is frozen, false otherwise\r
+ */\r
+ static inline bool Pipe_IsFrozen(void);\r
+ \r
+ /** Clears the master pipe error flag. */\r
+ static inline void Pipe_ClearError(void);\r
+ \r
+ /** Determines if the master pipe error flag is set for the currently selected pipe, indicating that\r
+ * some sort of hardware error has occurred on the pipe.\r
+ *\r
+ * \see \ref Pipe_GetErrorFlags() macro for information on retrieving the exact error flag.\r
+ *\r
+ * \return Boolean true if an error has occurred on the selected pipe, false otherwise\r
+ */\r
+ static inline bool Pipe_IsError(void);\r
+ \r
+ /** Clears all the currently selected pipe's hardware error flags, but does not clear the master error\r
+ * flag for the pipe.\r
+ */\r
+ static inline void Pipe_ClearErrorFlags(void);\r
+ \r
+ /** Gets a mask of the hardware error flags which have occurred on the currently selected pipe. This\r
+ * value can then be masked against the PIPE_ERRORFLAG_* masks to determine what error has occurred.\r
+ *\r
+ * \return Mask comprising of PIPE_ERRORFLAG_* bits indicating what error has occurred on the selected pipe\r
+ */\r
+ static inline uint8_t Pipe_GetErrorFlags(void);\r
+ \r
+ /** Determines if the currently selected pipe may be read from (if data is waiting in the pipe\r
+ * bank and the pipe is an IN direction, or if the bank is not yet full if the pipe is an OUT\r
+ * direction). This function will return false if an error has occurred in the pipe, or if the pipe\r
+ * is an IN direction and no packet (or an empty packet) has been received, or if the pipe is an OUT\r
+ * direction and the pipe bank is full.\r
+ *\r
+ * \note This function is not valid on CONTROL type pipes.\r
+ *\r
+ * \ingroup Group_PipePacketManagement\r
+ * \r
+ * \return Boolean true if the currently selected pipe may be read from or written to, depending on its direction\r
+ */\r
+ static inline bool Pipe_IsReadWriteAllowed(void);\r
+ \r
+ /** Determines if an IN request has been received on the currently selected pipe.\r
+ *\r
+ * \ingroup Group_PipePacketManagement\r
+ *\r
+ * \return Boolean true if the current pipe has received an IN packet, false otherwise.\r
+ */\r
+ static inline bool Pipe_IsINReceived(void);\r
+ \r
+ /** Determines if the currently selected pipe is ready to send an OUT request.\r
+ *\r
+ * \ingroup Group_PipePacketManagement\r
+ *\r
+ * \return Boolean true if the current pipe is ready for an OUT packet, false otherwise.\r
+ */\r
+ static inline bool Pipe_IsOUTReady(void);\r
+\r
+ /** Determines if no SETUP request is currently being sent to the attached device on the selected\r
+ * CONTROL type pipe.\r
+ *\r
+ * \ingroup Group_PipePacketManagement\r
+ *\r
+ * \return Boolean true if the current pipe is ready for a SETUP packet, false otherwise.\r
+ */\r
+ static inline bool Pipe_IsSETUPSent(void);\r
+ \r
+ /** Sends the currently selected CONTROL type pipe's contents to the device as a SETUP packet.\r
+ *\r
+ * \ingroup Group_PipePacketManagement \r
+ */\r
+ static inline void Pipe_ClearSETUP(void);\r
+\r
+ /** Acknowledges the reception of a setup IN request from the attached device on the currently selected\r
+ * pipe, freeing the bank ready for the next packet.\r
+ *\r
+ * \ingroup Group_PipePacketManagement\r
+ */\r
+ static inline void Pipe_ClearIN(void);\r
+\r
+ /** Sends the currently selected pipe's contents to the device as an OUT packet on the selected pipe, freeing\r
+ * the bank ready for the next packet.\r
+ *\r
+ * \ingroup Group_PipePacketManagement\r
+ */\r
+ static inline void Pipe_ClearOUT(void);\r
+\r
+ /** Determines if the device sent a NAK (Negative Acknowledge) in response to the last sent packet on\r
+ * the currently selected pipe. This occurs when the host sends a packet to the device, but the device\r
+ * is not currently ready to handle the packet (i.e. its endpoint banks are full). Once a NAK has been\r
+ * received, it must be cleared using \ref Pipe_ClearNAKReceived() before the previous (or any other) packet\r
+ * can be re-sent.\r
+ *\r
+ * \ingroup Group_PipePacketManagement\r
+ *\r
+ * \return Boolean true if an NAK has been received on the current pipe, false otherwise\r
+ */\r
+ static inline bool Pipe_IsNAKReceived(void);\r
+\r
+ /** Clears the NAK condition on the currently selected pipe.\r
+ *\r
+ * \ingroup Group_PipePacketManagement\r
+ *\r
+ * \see \ref Pipe_IsNAKReceived() for more details.\r
+ */\r
+ static inline void Pipe_ClearNAKReceived(void);\r
+ \r
+ /** Determines if the currently selected pipe has had the STALL condition set by the attached device.\r
+ *\r
+ * \ingroup Group_PipePacketManagement\r
+ *\r
+ * \return Boolean true if the current pipe has been stalled by the attached device, false otherwise\r
+ */\r
+ static inline bool Pipe_IsStalled(void);\r
+ \r
+ /** Clears the STALL condition detection flag on the currently selected pipe, but does not clear the\r
+ * STALL condition itself (this must be done via a ClearFeature control request to the device).\r
+ *\r
+ * \ingroup Group_PipePacketManagement\r
+ */\r
+ static inline void Pipe_ClearStall(void);\r
+ #else\r
+ #define Pipe_BytesInPipe() UPBCX\r