Remove USB_MODE_* macros, replace with a semantically linked USB_Modes_t enum.

Moved the USB device selection logic for ENDPOINT_TOTAL_ENDPOINTS further up in Endpoint.h to where the endpoint bank capabilities are determined, to reduce the total number of device-specific logic.

Change USB_Host_WaitMS() to test and disable the HSOFI interrupt before resuming the bus, so that it does not fire before the delay loop has run.

Add missing const qualifier to the parameter of USB_Host_ClearPipeStall().
pull/1469/head
Dean Camera 14 years ago
parent c1cfffd8eb
commit 7aaced1e8b

@ -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);
}

@ -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
}

@ -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
@ -195,26 +199,22 @@
/** 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)
#define ENDPOINT_DOUBLEBANK_SUPPORTED(EPIndex) _ENDPOINT_GET_DOUBLEBANK(EPIndex)
#if !defined(CONTROL_ONLY_DEVICE)
#if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) || defined(__DOXYGEN__)
#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 7
#else
#define ENDPOINT_TOTAL_ENDPOINTS 5
#endif
#define ENDPOINT_TOTAL_ENDPOINTS ENDPOINT_DETAILS_MAXEP
#else
#define ENDPOINT_TOTAL_ENDPOINTS 1
#endif

@ -196,14 +196,13 @@ uint8_t USB_Host_WaitMS(uint8_t MS)
{
bool BusSuspended = USB_Host_IsBusSuspended();
uint8_t ErrorCode = HOST_WAITERROR_Successful;
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)
{

@ -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__)

@ -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);

@ -123,31 +123,6 @@
/* 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
/** 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

@ -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

@ -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

Loading…
Cancel
Save