Don't cast the line encoding baud rate to a uint16_t before performing the baud rate...
[pub/USBasp.git] / LUFA / Drivers / USB / LowLevel / Endpoint.h
index b9122e4..93412f5 100644 (file)
@@ -1,21 +1,21 @@
 /*\r
              LUFA Library\r
-     Copyright (C) Dean Camera, 2009.\r
+     Copyright (C) Dean Camera, 2010.\r
               \r
   dean [at] fourwalledcubicle [dot] com\r
       www.fourwalledcubicle.com\r
 */\r
 \r
 /*\r
-  Copyright 2009  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
-  Permission to use, copy, modify, and distribute this software\r
-  and its documentation for any purpose and without fee is hereby\r
-  granted, provided that the above copyright notice appear in all\r
-  copies and that both that the copyright notice and this\r
-  permission notice and warranty disclaimer appear in supporting\r
-  documentation, and that the name of the author not be used in\r
-  advertising or publicity pertaining to distribution of the\r
+  Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
+\r
+  Permission to use, copy, modify, distribute, and sell this \r
+  software and its documentation for any purpose is hereby granted\r
+  without fee, provided that the above copyright notice appear in \r
+  all copies and that both that the copyright notice and this\r
+  permission notice and warranty disclaimer appear in supporting \r
+  documentation, and that the name of the author not be used in \r
+  advertising or publicity pertaining to distribution of the \r
   software without specific, written prior permission.\r
 \r
   The author disclaim all warranties with regard to this\r
   this software.\r
 */\r
 \r
+/** \file\r
+ *  \brief USB device endpoint management definitions.\r
+ *\r
+ *  This file contains structures, function prototypes and macros related to the management of the device's\r
+ *  data endpoints when the library is initialized in USB device mode.\r
+ *\r
+ *  \note This file should not be included directly. It is automatically included as needed by the USB driver\r
+ *        dispatch header located in LUFA/Drivers/USB/USB.h.\r
+ */\r
+\r
 /** \ingroup Group_USB\r
  *  @defgroup Group_EndpointManagement Endpoint Management\r
  *\r
                        extern "C" {\r
                #endif\r
 \r
+       /* Preprocessor Checks: */\r
+               #if !defined(__INCLUDE_FROM_USB_DRIVER)\r
+                       #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.\r
+               #endif\r
+               \r
        /* Public Interface - May be used in end-application: */\r
                /* Macros: */\r
                        /** Endpoint data direction mask for \ref Endpoint_ConfigureEndpoint(). This indicates that the endpoint\r
                         */\r
                        #define ENDPOINT_EPNUM_MASK                   0x07\r
 \r
+                       /** Endpoint direction mask, for masking against endpoint addresses to retrieve the endpoint's\r
+                        *  direction for comparing with the ENDPOINT_DESCRIPTOR_DIR_* masks.\r
+                        */\r
+                       #define ENDPOINT_EPDIR_MASK                   0x80\r
+\r
                        /** Endpoint bank size mask, for masking against endpoint addresses to retrieve the endpoint's\r
                         *  bank size in the device.\r
                         */\r
                                 */\r
                                static inline void Endpoint_SetEndpointDirection(uint8_t DirectionMask);\r
                        #else\r
-                               #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) || defined(__DOXYGEN__)\r
+                               #if defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)\r
                                        #define Endpoint_BytesInEndpoint()        UEBCX\r
-                               #else\r
+                               #elif defined(USB_SERIES_4_AVR)\r
+                                       #define Endpoint_BytesInEndpoint()        (((uint16_t)UEBCHX << 8) | UEBCLX)                            \r
+                               #elif defined(USB_SERIES_2_AVR)\r
                                        #define Endpoint_BytesInEndpoint()        UEBCLX\r
                                #endif\r
                                \r
                                #if !defined(CONTROL_ONLY_DEVICE)\r
                                        #define Endpoint_SelectEndpoint(epnum)    MACROS{ UENUM = (epnum); }MACROE\r
                                #else\r
-                                       #define Endpoint_SelectEndpoint(epnum)    (void)epnum\r
+                                       #define Endpoint_SelectEndpoint(epnum)    (void)(epnum)\r
                                #endif\r
 \r
                                #define Endpoint_ResetFIFO(epnum)             MACROS{ UERST = (1 << (epnum)); UERST = 0; }MACROE\r
                                #define Endpoint_ClearSETUP()                 MACROS{ UEINTX &= ~(1 << RXSTPI); }MACROE\r
 \r
                                #if !defined(CONTROL_ONLY_DEVICE)\r
-                                       #define Endpoint_ClearIN()                MACROS{ uint8_t Temp = UEINTX; UEINTX = (Temp & ~(1 << TXINI)); \\r
-                                                                                         UEINTX = (Temp & ~(1 << FIFOCON)); }MACROE\r
+                                       #define Endpoint_ClearIN()                MACROS{ UEINTX &= ~((1 << TXINI) | (1 << FIFOCON)); }MACROE\r
                                #else\r
                                        #define Endpoint_ClearIN()                MACROS{ UEINTX &= ~(1 << TXINI); }MACROE\r
                                #endif\r
 \r
                                #if !defined(CONTROL_ONLY_DEVICE)\r
-                                       #define Endpoint_ClearOUT()               MACROS{ uint8_t Temp = UEINTX; UEINTX = (Temp & ~(1 << RXOUTI)); \\r
-                                                                                         UEINTX = (Temp & ~(1 << FIFOCON)); }MACROE\r
+                                       #define Endpoint_ClearOUT()               MACROS{ UEINTX &= ~((1 << RXOUTI) | (1 << FIFOCON)); }MACROE\r
                                #else\r
                                        #define Endpoint_ClearOUT()               MACROS{ UEINTX &= ~(1 << RXOUTI); }MACROE                     \r
                                #endif\r
                                                                                 */\r
                                ENDPOINT_READYWAIT_DeviceDisconnected      = 2, /**< Device was disconnected from the host while\r
                                                                                 *   waiting for the endpoint to become ready.\r
-                                                                                */     \r
-                               ENDPOINT_READYWAIT_Timeout                 = 3, /**< The host failed to accept or send the next packet\r
+                                                                                */\r
+                               ENDPOINT_READYWAIT_BusSuspended            = 3, /**< The USB bus has been suspended by the host and\r
+                                                                                *   no USB endpoint traffic can occur until the bus\r
+                                                                                *   has resumed.\r
+                                                                                */\r
+                               ENDPOINT_READYWAIT_Timeout                 = 4, /**< The host failed to accept or send the next packet\r
                                                                                 *   within the software timeout period set by the\r
                                                                                 *   \ref USB_STREAM_TIMEOUT_MS macro.\r
                                                                                 */\r
                                ENDPOINT_RWSTREAM_DeviceDisconnected = 2, /**< Device was disconnected from the host during\r
                                                                           *   the transfer.\r
                                                                           */\r
-                               ENDPOINT_RWSTREAM_Timeout            = 3, /**< The host failed to accept or send the next packet\r
+                               ENDPOINT_RWSTREAM_BusSuspended       = 3, /**< The USB bus has been suspended by the host and\r
+                                                                          *   no USB endpoint traffic can occur until the bus\r
+                                                                          *   has resumed.\r
+                                                                          */\r
+                               ENDPOINT_RWSTREAM_Timeout            = 4, /**< The host failed to accept or send the next packet\r
                                                                           *   within the software timeout period set by the\r
                                                                           *   \ref USB_STREAM_TIMEOUT_MS macro.\r
                                                                           */\r
-                               ENDPOINT_RWSTREAM_CallbackAborted    = 4, /**< Indicates that the stream's callback function\r
+                               ENDPOINT_RWSTREAM_CallbackAborted    = 5, /**< Indicates that the stream's callback function\r
                                                                       *   aborted the transfer early.\r
                                                                           */\r
                        };\r
                                ENDPOINT_RWCSTREAM_DeviceDisconnected = 2, /**< Device was disconnected from the host during\r
                                                                            *   the transfer.\r
                                                                            */\r
+                               ENDPOINT_RWCSTREAM_BusSuspended       = 3, /**< The USB bus has been suspended by the host and\r
+                                                                           *   no USB endpoint traffic can occur until the bus\r
+                                                                           *   has resumed.\r
+                                                                           */\r
                        };\r
 \r
                /* Inline Functions: */\r
                         *  The banking mode may be either \ref ENDPOINT_BANK_SINGLE or \ref ENDPOINT_BANK_DOUBLE.\r
                         *\r
                         *  \note The default control endpoint does not have to be manually configured, as it is automatically\r
-                        *  configured by the library internally.\r
+                        *        configured by the library internally.\r
+                        *        \n\n\r
                         *\r
                         *  \note This routine will select the specified endpoint, and the endpoint will remain selected\r
                         *        once the routine completes regardless of if the endpoint configuration succeeds.\r
                         *\r
                         *  \note This function automatically clears the control transfer's status stage. Do not manually attempt\r
                         *        to clear the status stage when using this routine in a control transaction.\r
+                        *        \n\n\r
                         *\r
                         *  \note This routine should only be used on CONTROL type endpoints.\r
                         *\r
                         *\r
                         *  \note This function automatically clears the control transfer's status stage. Do not manually attempt\r
                         *        to clear the status stage when using this routine in a control transaction.\r
+                        *        \n\n\r
                         *\r
                         *  \note This routine should only be used on CONTROL type endpoints.\r
                         *\r
                         *\r
                         *  \note This function automatically clears the control transfer's status stage. Do not manually attempt\r
                         *        to clear the status stage when using this routine in a control transaction.\r
+                        *        \n\n\r
                         *\r
                         *  \note The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.\r
+                        *        \n\n\r
                         *\r
                         *  \note This routine should only be used on CONTROL type endpoints.\r
                         *\r
                         *\r
                         *  \note This function automatically clears the control transfer's status stage. Do not manually attempt\r
                         *        to clear the status stage when using this routine in a control transaction.\r
+                        *        \n\n\r
                         *\r
                         *  \note This routine should only be used on CONTROL type endpoints.\r
                         *\r
                         *\r
                         *  \note This function automatically clears the control transfer's status stage. Do not manually attempt\r
                         *        to clear the status stage when using this routine in a control transaction.\r
+                        *        \n\n\r
                         *\r
                         *  \note This routine should only be used on CONTROL type endpoints.\r
                         *\r
                         *\r
                         *  \note This function automatically clears the control transfer's status stage. Do not manually attempt\r
                         *        to clear the status stage when using this routine in a control transaction.\r
+                        *        \n\n\r
                         *\r
                         *  \note The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.\r
+                        *        \n\n\r
                         *\r
                         *  \note This routine should only be used on CONTROL type endpoints.\r
                         *\r
                         *\r
                         *  \note This function automatically clears the control transfer's status stage. Do not manually attempt\r
                         *        to clear the status stage when using this routine in a control transaction.\r
+                        *        \n\n\r
                         *\r
                         *  \note This routine should only be used on CONTROL type endpoints.\r
                         *\r
                         *\r
                         *  \note This function automatically clears the control transfer's status stage. Do not manually attempt\r
                         *        to clear the status stage when using this routine in a control transaction.\r
+                        *        \n\n\r
                         *\r
                         *  \note This routine should only be used on CONTROL type endpoints.\r
                         *\r
                         *\r
                         *  \note This function automatically clears the control transfer's status stage. Do not manually attempt\r
                         *        to clear the status stage when using this routine in a control transaction.\r
+                        *        \n\n\r
                         *\r
                         *  \note This routine should only be used on CONTROL type endpoints.\r
                         *\r
                         *\r
                         *  \note This function automatically clears the control transfer's status stage. Do not manually attempt\r
                         *        to clear the status stage when using this routine in a control transaction.\r
+                        *        \n\n\r
                         *\r
                         *  \note This routine should only be used on CONTROL type endpoints.\r
                         *\r