diff options
-rw-r--r-- | Demos/DualRole/ClassDriver/MouseHostDevice/MouseHostDevice.c | 4 | ||||
-rw-r--r-- | LUFA/Drivers/USB/HighLevel/USBTask.c | 4 | ||||
-rw-r--r-- | LUFA/Drivers/USB/LowLevel/Endpoint.h | 50 | ||||
-rw-r--r-- | LUFA/Drivers/USB/LowLevel/Host.c | 17 | ||||
-rw-r--r-- | LUFA/Drivers/USB/LowLevel/Host.h | 2 | ||||
-rw-r--r-- | LUFA/Drivers/USB/LowLevel/OTG.h | 2 | ||||
-rw-r--r-- | LUFA/Drivers/USB/LowLevel/Pipe.h | 2 | ||||
-rw-r--r-- | LUFA/Drivers/USB/LowLevel/USBController.c | 8 | ||||
-rw-r--r-- | LUFA/Drivers/USB/LowLevel/USBController.h | 65 | ||||
-rw-r--r-- | LUFA/ManPages/ChangeLog.txt | 1 | ||||
-rw-r--r-- | LUFA/ManPages/MigrationInformation.txt | 2 |
11 files changed, 78 insertions, 79 deletions
diff --git a/Demos/DualRole/ClassDriver/MouseHostDevice/MouseHostDevice.c b/Demos/DualRole/ClassDriver/MouseHostDevice/MouseHostDevice.c index 1b905b114..38acd8562 100644 --- a/Demos/DualRole/ClassDriver/MouseHostDevice/MouseHostDevice.c +++ b/Demos/DualRole/ClassDriver/MouseHostDevice/MouseHostDevice.c @@ -51,7 +51,7 @@ int main(void) for (;;) { /* Determine which USB mode we are currently in */ - if (USB_CurrentMode == USB_MODE_HOST) + if (USB_CurrentMode == USB_MODE_Host) { MouseHostTask(); HID_Host_USBTask(&Mouse_HID_Host_Interface); @@ -87,7 +87,7 @@ void SetupHardware(void) void EVENT_USB_UIDChange(void) { printf_P(PSTR(ESC_FG_YELLOW "UID Change to %S mode\r\n" ESC_FG_WHITE), - (USB_CurrentMode == USB_MODE_DEVICE) ? PSTR("Device") : PSTR("Host")); + (USB_CurrentMode == USB_MODE_Device) ? PSTR("Device") : PSTR("Host")); LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); } diff --git a/LUFA/Drivers/USB/HighLevel/USBTask.c b/LUFA/Drivers/USB/HighLevel/USBTask.c index 5ec1746fd..a2737f7d0 100644 --- a/LUFA/Drivers/USB/HighLevel/USBTask.c +++ b/LUFA/Drivers/USB/HighLevel/USBTask.c @@ -50,9 +50,9 @@ void USB_USBTask(void) #elif defined(USB_DEVICE_ONLY) USB_DeviceTask(); #else - if (USB_CurrentMode == USB_MODE_DEVICE) + if (USB_CurrentMode == USB_MODE_Device) USB_DeviceTask(); - else if (USB_CurrentMode == USB_MODE_HOST) + else if (USB_CurrentMode == USB_MODE_Host) USB_HostTask(); #endif } diff --git a/LUFA/Drivers/USB/LowLevel/Endpoint.h b/LUFA/Drivers/USB/LowLevel/Endpoint.h index acf0c5195..66f5591f0 100644 --- a/LUFA/Drivers/USB/LowLevel/Endpoint.h +++ b/LUFA/Drivers/USB/LowLevel/Endpoint.h @@ -100,6 +100,8 @@ #define _ENDPOINT_GET_DOUBLEBANK3(MaxSize, DB) (DB) #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) + #define ENDPOINT_DETAILS_MAXEP 7 + #define ENDPOINT_DETAILS_EP0 64, true #define ENDPOINT_DETAILS_EP1 256, true #define ENDPOINT_DETAILS_EP2 64, true @@ -108,6 +110,8 @@ #define ENDPOINT_DETAILS_EP5 64, true #define ENDPOINT_DETAILS_EP6 64, true #else + #define ENDPOINT_DETAILS_MAXEP 5 + #define ENDPOINT_DETAILS_EP0 64, true #define ENDPOINT_DETAILS_EP1 64, false #define ENDPOINT_DETAILS_EP2 64, false @@ -145,78 +149,74 @@ /** Endpoint data direction mask for \ref Endpoint_ConfigureEndpoint(). This indicates that the endpoint * should be initialized in the OUT direction - i.e. data flows from host to device. */ - #define ENDPOINT_DIR_OUT (0 << EPDIR) + #define ENDPOINT_DIR_OUT (0 << EPDIR) /** Endpoint data direction mask for \ref Endpoint_ConfigureEndpoint(). This indicates that the endpoint * should be initialized in the IN direction - i.e. data flows from device to host. */ - #define ENDPOINT_DIR_IN (1 << EPDIR) + #define ENDPOINT_DIR_IN (1 << EPDIR) /** Mask for the bank mode selection for the \ref Endpoint_ConfigureEndpoint() macro. This indicates * that the endpoint should have one single bank, which requires less USB FIFO memory but results * in slower transfers as only one USB device (the AVR or the host) can access the endpoint's * bank at the one time. */ - #define ENDPOINT_BANK_SINGLE (0 << EPBK0) + #define ENDPOINT_BANK_SINGLE (0 << EPBK0) /** Mask for the bank mode selection for the \ref Endpoint_ConfigureEndpoint() macro. This indicates * that the endpoint should have two banks, which requires more USB FIFO memory but results * in faster transfers as one USB device (the AVR or the host) can access one bank while the other * accesses the second bank. */ - #define ENDPOINT_BANK_DOUBLE (1 << EPBK0) + #define ENDPOINT_BANK_DOUBLE (1 << EPBK0) /** Endpoint address for the default control endpoint, which always resides in address 0. This is * defined for convenience to give more readable code when used with the endpoint macros. */ - #define ENDPOINT_CONTROLEP 0 + #define ENDPOINT_CONTROLEP 0 #if (!defined(FIXED_CONTROL_ENDPOINT_SIZE) || defined(__DOXYGEN__)) /** Default size of the default control endpoint's bank, until altered by the control endpoint bank size * value in the device descriptor. Not available if the FIXED_CONTROL_ENDPOINT_SIZE token is defined. */ - #define ENDPOINT_CONTROLEP_DEFAULT_SIZE 8 + #define ENDPOINT_CONTROLEP_DEFAULT_SIZE 8 #endif /** Endpoint number mask, for masking against endpoint addresses to retrieve the endpoint's * numerical address in the device. */ - #define ENDPOINT_EPNUM_MASK 0x07 + #define ENDPOINT_EPNUM_MASK 0x07 /** Endpoint direction mask, for masking against endpoint addresses to retrieve the endpoint's * direction for comparing with the ENDPOINT_DESCRIPTOR_DIR_* masks. */ - #define ENDPOINT_EPDIR_MASK 0x80 + #define ENDPOINT_EPDIR_MASK 0x80 /** Endpoint bank size mask, for masking against endpoint addresses to retrieve the endpoint's * bank size in the device. */ - #define ENDPOINT_EPSIZE_MASK 0x7F + #define ENDPOINT_EPSIZE_MASK 0x7F /** Maximum size in bytes of a given endpoint. * - * \param[in] n Endpoint number, a value between 0 and (ENDPOINT_TOTAL_ENDPOINTS - 1) + * \param[in] EPIndex Endpoint number, a value between 0 and (ENDPOINT_TOTAL_ENDPOINTS - 1) */ - #define ENDPOINT_MAX_SIZE(n) _ENDPOINT_GET_MAXSIZE(n) + #define ENDPOINT_MAX_SIZE(EPIndex) _ENDPOINT_GET_MAXSIZE(EPIndex) /** Indicates if the given endpoint supports double banking. * - * \param[in] n Endpoint number, a value between 0 and (ENDPOINT_TOTAL_ENDPOINTS - 1) + * \param[in] EPIndex Endpoint number, a value between 0 and (ENDPOINT_TOTAL_ENDPOINTS - 1) */ - #define ENDPOINT_DOUBLEBANK_SUPPORTED(n) _ENDPOINT_GET_DOUBLEBANK(n) - - #if !defined(CONTROL_ONLY_DEVICE) - #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) || defined(__DOXYGEN__) - /** Total number of endpoints (including the default control endpoint at address 0) which may - * be used in the device. Different USB AVR models support different amounts of endpoints, - * this value reflects the maximum number of endpoints for the currently selected AVR model. - */ - #define ENDPOINT_TOTAL_ENDPOINTS 7 - #else - #define ENDPOINT_TOTAL_ENDPOINTS 5 - #endif + #define ENDPOINT_DOUBLEBANK_SUPPORTED(EPIndex) _ENDPOINT_GET_DOUBLEBANK(EPIndex) + + #if !defined(CONTROL_ONLY_DEVICE) || defined(__DOXYGEN__) + /** Total number of endpoints (including the default control endpoint at address 0) which may + * be used in the device. Different USB AVR models support different amounts of endpoints, + * this value reflects the maximum number of endpoints for the currently selected AVR model. + */ + #define ENDPOINT_TOTAL_ENDPOINTS ENDPOINT_DETAILS_MAXEP #else - #define ENDPOINT_TOTAL_ENDPOINTS 1 + #define ENDPOINT_TOTAL_ENDPOINTS 1 #endif /* Enums: */ diff --git a/LUFA/Drivers/USB/LowLevel/Host.c b/LUFA/Drivers/USB/LowLevel/Host.c index 1d7faa197..1fa5290fc 100644 --- a/LUFA/Drivers/USB/LowLevel/Host.c +++ b/LUFA/Drivers/USB/LowLevel/Host.c @@ -196,14 +196,13 @@ uint8_t USB_Host_WaitMS(uint8_t MS) { bool BusSuspended = USB_Host_IsBusSuspended(); uint8_t ErrorCode = HOST_WAITERROR_Successful; + bool HSOFIEnabled = USB_INT_IsEnabled(USB_INT_HSOFI); - USB_Host_ResumeBus(); - - bool HSOFIEnabled = USB_INT_IsEnabled(USB_INT_HSOFI); - USB_INT_Disable(USB_INT_HSOFI); USB_INT_Clear(USB_INT_HSOFI); + USB_Host_ResumeBus(); + while (MS) { if (USB_INT_HasOccurred(USB_INT_HSOFI)) @@ -212,7 +211,7 @@ uint8_t USB_Host_WaitMS(uint8_t MS) MS--; } - if ((USB_HostState == HOST_STATE_Unattached) || (USB_CurrentMode == USB_MODE_DEVICE)) + if ((USB_HostState == HOST_STATE_Unattached) || (USB_CurrentMode != USB_MODE_Host)) { ErrorCode = HOST_WAITERROR_DeviceDisconnect; @@ -236,12 +235,12 @@ uint8_t USB_Host_WaitMS(uint8_t MS) } } - if (HSOFIEnabled) - USB_INT_Enable(USB_INT_HSOFI); - if (BusSuspended) USB_Host_SuspendBus(); + if (HSOFIEnabled) + USB_INT_Enable(USB_INT_HSOFI); + return ErrorCode; } @@ -336,7 +335,7 @@ uint8_t USB_Host_GetDeviceStringDescriptor(const uint8_t Index, return USB_Host_SendControlRequest(Buffer); } -uint8_t USB_Host_ClearPipeStall(uint8_t EndpointNum) +uint8_t USB_Host_ClearPipeStall(const uint8_t EndpointNum) { USB_ControlRequest = (USB_Request_Header_t) { diff --git a/LUFA/Drivers/USB/LowLevel/Host.h b/LUFA/Drivers/USB/LowLevel/Host.h index b11883974..1e28b903e 100644 --- a/LUFA/Drivers/USB/LowLevel/Host.h +++ b/LUFA/Drivers/USB/LowLevel/Host.h @@ -435,7 +435,7 @@ * * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result. */ - uint8_t USB_Host_ClearPipeStall(uint8_t EndpointIndex); + uint8_t USB_Host_ClearPipeStall(const uint8_t EndpointIndex); /* Private Interface - For use in library only: */ #if !defined(__DOXYGEN__) diff --git a/LUFA/Drivers/USB/LowLevel/OTG.h b/LUFA/Drivers/USB/LowLevel/OTG.h index deb786642..5afa8b3a2 100644 --- a/LUFA/Drivers/USB/LowLevel/OTG.h +++ b/LUFA/Drivers/USB/LowLevel/OTG.h @@ -118,7 +118,7 @@ static inline void USB_OTG_Device_InitiateSRP(const uint8_t SRPTypeMask) ATTR_ALWAYS_INLINE; static inline void USB_OTG_Device_InitiateSRP(const uint8_t SRPTypeMask) { - OTGCON = ((OTGCON & ~(1 << SRPSEL)) | (SRPTypeMask | (1 << SRPREQ))); + OTGCON = ((OTGCON & ~(1 << SRPSEL)) | (SRPTypeMask | (1 << SRPREQ))); } /** Accepts a HNP from a connected device, indicating that both devices should exchange diff --git a/LUFA/Drivers/USB/LowLevel/Pipe.h b/LUFA/Drivers/USB/LowLevel/Pipe.h index 01f57751c..1a5f62cd5 100644 --- a/LUFA/Drivers/USB/LowLevel/Pipe.h +++ b/LUFA/Drivers/USB/LowLevel/Pipe.h @@ -855,7 +855,7 @@ * * \return Boolean true if the configuration succeeded, false otherwise. */ - bool Pipe_ConfigurePipe(const uint8_t Number, + bool Pipe_ConfigurePipe(const uint8_t Number, const uint8_t Type, const uint8_t Token, const uint8_t EndpointNumber, diff --git a/LUFA/Drivers/USB/LowLevel/USBController.c b/LUFA/Drivers/USB/LowLevel/USBController.c index f6b1b125b..6d4a89dd0 100644 --- a/LUFA/Drivers/USB/LowLevel/USBController.c +++ b/LUFA/Drivers/USB/LowLevel/USBController.c @@ -33,7 +33,7 @@ #include "USBController.h" #if (!defined(USB_HOST_ONLY) && !defined(USB_DEVICE_ONLY)) -volatile uint8_t USB_CurrentMode = USB_MODE_NONE; +volatile uint8_t USB_CurrentMode = USB_MODE_None; #endif #if !defined(USE_STATIC_OPTIONS) @@ -101,7 +101,7 @@ void USB_ShutDown(void) #endif #if defined(USB_CAN_BE_BOTH) - USB_CurrentMode = USB_MODE_NONE; + USB_CurrentMode = USB_MODE_None; #endif USB_IsInitialized = false; @@ -138,7 +138,7 @@ void USB_ResetInterface(void) USB_CLK_Unfreeze(); - if (USB_CurrentMode == USB_MODE_DEVICE) + if (USB_CurrentMode == USB_MODE_Device) { #if defined(USB_CAN_BE_DEVICE) #if (defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)) @@ -148,7 +148,7 @@ void USB_ResetInterface(void) USB_Init_Device(); #endif } - else + else if (USB_CurrentMode == USB_MODE_Host) { #if defined(USB_CAN_BE_HOST) UHWCON &= ~(1 << UIMOD); diff --git a/LUFA/Drivers/USB/LowLevel/USBController.h b/LUFA/Drivers/USB/LowLevel/USBController.h index 298141eef..8a2fec788 100644 --- a/LUFA/Drivers/USB/LowLevel/USBController.h +++ b/LUFA/Drivers/USB/LowLevel/USBController.h @@ -122,32 +122,7 @@ #endif /* Public Interface - May be used in end-application: */ - /* Macros: */ - /** Mode mask for the \ref USB_CurrentMode global. This indicates that the USB interface is currently not - * initialized into any mode. - */ - #define USB_MODE_NONE 0 - - /** Mode mask for the \ref USB_CurrentMode global and the \ref USB_Init() function. This indicates that the - * USB interface is or should be initialized in the USB device mode. - */ - #define USB_MODE_DEVICE 1 - - /** Mode mask for the \ref USB_CurrentMode global and the \ref USB_Init() function. This indicates that the - * USB interface is or should be initialized in the USB host mode. - */ - #define USB_MODE_HOST 2 - - #if defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__) - /** Mode mask for the the \ref USB_Init() function. This indicates that the USB interface should be - * initialized into whatever mode the UID pin of the USB AVR indicates, and that the device - * should swap over its mode when the level of the UID pin changes during operation. - * - * \note This token is not available on AVR models which do not support both host and device modes. - */ - #define USB_MODE_UID 3 - #endif - + /* Macros: */ /** Regulator disable option mask for \ref USB_Init(). This indicates that the internal 3.3V USB data pad * regulator should be enabled to regulate the data pin voltages to within the USB standard. * @@ -262,8 +237,8 @@ * Calling this function when the USB interface is already initialized will cause a complete USB * interface reset and re-enumeration. * - * \param[in] Mode This is a mask indicating what mode the USB interface is to be initialized to. - * Valid mode masks are \ref USB_MODE_DEVICE, \ref USB_MODE_HOST or \ref USB_MODE_UID. + * \param[in] Mode This is a mask indicating what mode the USB interface is to be initialized to, a value + * from the \ref USB_Modes_t enum. * * \param[in] Options Mask indicating the options which should be used when initializing the USB * interface to control the USB interface's behaviour. This should be comprised of @@ -319,17 +294,25 @@ /* Global Variables: */ #if (!defined(USB_HOST_ONLY) && !defined(USB_DEVICE_ONLY)) || defined(__DOXYGEN__) - /** Indicates the mode that the USB interface is currently initialized to. This value will be - * one of the USB_MODE_* masks defined elsewhere in this module. + /** Indicates the mode that the USB interface is currently initialized to, a value from the + * \ref USB_Modes_t enum. * * \note This variable should be treated as read-only in the user application, and never manually * changed in value. + * \n\n + * + * \note When the controller is initialized into UID autodetection mode, this variable will hold the + * currently selected USB mode (i.e. \ref USB_MODE_Device or \ref USB_MODE_Host). If the controller + * is fixed into a specific mode (either through the USB_DEVICE_ONLY or USB_HOST_ONLY compile time + * options, or a limitation of the USB controller in the chosen device model) this will evaluate to + * a constant of the appropriate value and will never evaluate to \ref USB_MODE_None even when the + * USB interface is not initialized. */ extern volatile uint8_t USB_CurrentMode; #elif defined(USB_HOST_ONLY) - #define USB_CurrentMode USB_MODE_HOST + #define USB_CurrentMode USB_MODE_Host #elif defined(USB_DEVICE_ONLY) - #define USB_CurrentMode USB_MODE_DEVICE + #define USB_CurrentMode USB_MODE_Device #endif #if !defined(USE_STATIC_OPTIONS) || defined(__DOXYGEN__) @@ -344,6 +327,20 @@ #define USB_Options USE_STATIC_OPTIONS #endif + /* Enums: */ + /** Enum for the possible USB controller modes, for initialization via \ref USB_Init() and indication back to the + * user application via \ref USB_CurrentMode. + */ + enum USB_Modes_t + { + USB_MODE_None = 0, /**< Indicates that the controller is currently not initialized in any specific USB mode. */ + USB_MODE_Device = 1, /**< Indicates that the controller is currently initialized in USB Device mode. */ + USB_MODE_Host = 2, /**< Indicates that the controller is currently initialized in USB Host mode. */ + USB_MODE_UID = 3, /**< Indicates that the controller should determine the USB mode from the UID pin of the + * USB connector. + */ + }; + /* Private Interface - For use in library only: */ #if !defined(__DOXYGEN__) /* Function Prototypes: */ @@ -449,9 +446,9 @@ static inline uint8_t USB_GetUSBModeFromUID(void) { if (USBSTA & (1 << ID)) - return USB_MODE_DEVICE; + return USB_MODE_Device; else - return USB_MODE_HOST; + return USB_MODE_Host; } #endif diff --git a/LUFA/ManPages/ChangeLog.txt b/LUFA/ManPages/ChangeLog.txt index faf007ad0..787ac709e 100644 --- a/LUFA/ManPages/ChangeLog.txt +++ b/LUFA/ManPages/ChangeLog.txt @@ -47,6 +47,7 @@ * - Renamed and moved class driver common constant definitions to make the naming scheme more uniform * - Changed default value for the reset polarity parameter in the AVRISP-MKII project so that it defaults to active low drive * - Changed configuration descriptor parser for all host mode projects and class drivers to ensure better compatibility with devices + * - Moved the USB mode specifier constants into a new enum, so that they are semantically related to one another * * <b>Fixed:</b> * - Fixed USB_GetHIDReportItemInfo() function modifying the given report item's data when the report item does not exist diff --git a/LUFA/ManPages/MigrationInformation.txt b/LUFA/ManPages/MigrationInformation.txt index 6faa65a9f..6f8c8642a 100644 --- a/LUFA/ManPages/MigrationInformation.txt +++ b/LUFA/ManPages/MigrationInformation.txt @@ -19,6 +19,8 @@ * project makefiles using the USB driver of LUFA, or the makefile should be updated to use the new module source variables. * - The EVENT_USB_InitFailure() event has been removed, as the USB_Init() function will no longer fail; if not USB mode is * specified, the controller will default to UID selection mode. + * - The USB mode specifier constants have been moved into a new enum and renamed. Existing projects should use the equivalent + * value in the new \ref USB_Modes_t enum. * * <b>Device Mode</b> * - Endpoints MUST be allocated in ascending order to ensure that bank corruption does not occur. Ensure that your user application |