aboutsummaryrefslogtreecommitdiffstats
path: root/LUFA/Drivers/USB/HighLevel
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2009-07-21 13:31:21 +0000
committerDean Camera <dean@fourwalledcubicle.com>2009-07-21 13:31:21 +0000
commite071f3897a0946c6be1e1b5e1f78eda8dcbf6fc7 (patch)
tree51ac5c80564fd76c93a357ee4d52a347384ac84b /LUFA/Drivers/USB/HighLevel
parent44179abcf85acb14fb3aff72ce50ae84281c0f2e (diff)
downloadlufa-e071f3897a0946c6be1e1b5e1f78eda8dcbf6fc7.tar.gz
lufa-e071f3897a0946c6be1e1b5e1f78eda8dcbf6fc7.tar.bz2
lufa-e071f3897a0946c6be1e1b5e1f78eda8dcbf6fc7.zip
Added new USB_DeviceState variable to keep track of the current Device mode USB state.
Added new Endpoint_ClearStatusStage() convenience function to assist with the status stages of control transfers. Removed vague USB_IsConnected global - test USB_DeviceState or USB_HostState explicitly to gain previous functionality. Removed USB_IsSuspended global - test USB_DeviceState against DEVICE_STATE_Suspended instead. Fixed possible enumeration errors from spinloops which may fail to exit if the USB connection is severed before the exit condition becomes true.
Diffstat (limited to 'LUFA/Drivers/USB/HighLevel')
-rw-r--r--LUFA/Drivers/USB/HighLevel/Events.h4
-rw-r--r--LUFA/Drivers/USB/HighLevel/USBInterrupt.c52
-rw-r--r--LUFA/Drivers/USB/HighLevel/USBTask.c8
-rw-r--r--LUFA/Drivers/USB/HighLevel/USBTask.h61
4 files changed, 54 insertions, 71 deletions
diff --git a/LUFA/Drivers/USB/HighLevel/Events.h b/LUFA/Drivers/USB/HighLevel/Events.h
index 2df0dda08..4042d4670 100644
--- a/LUFA/Drivers/USB/HighLevel/Events.h
+++ b/LUFA/Drivers/USB/HighLevel/Events.h
@@ -98,7 +98,7 @@
* which is not always accurate (host may suspend the bus while still connected). If the actual connection state
* needs to be determined, VBUS should be routed to an external pin, and the auto-detect behaviour turned off by
* passing the NO_LIMITED_CONTROLLER_CONNECT token to the compiler via the -D switch at compile time. The connection
- * and disconnection events may be manually fired, and the \ref USB_IsConnected global changed manually.
+ * and disconnection events may be manually fired, and the \ref USB_DeviceState global changed manually.
*
* \see USBTask.h for more information on the USB management task and reducing CPU usage.
*/
@@ -116,7 +116,7 @@
* which is not always accurate (host may suspend the bus while still connected). If the actual connection state
* needs to be determined, VBUS should be routed to an external pin, and the auto-detect behaviour turned off by
* passing the NO_LIMITED_CONTROLLER_CONNECT token to the compiler via the -D switch at compile time. The connection
- * and disconnection events may be manually fired, and the \ref USB_IsConnected global changed manually.
+ * and disconnection events may be manually fired, and the \ref USB_DeviceState global changed manually.
*
* \see USBTask.h for more information on the USB management task and reducing CPU usage.
*/
diff --git a/LUFA/Drivers/USB/HighLevel/USBInterrupt.c b/LUFA/Drivers/USB/HighLevel/USBInterrupt.c
index c240bef6e..5edefa996 100644
--- a/LUFA/Drivers/USB/HighLevel/USBInterrupt.c
+++ b/LUFA/Drivers/USB/HighLevel/USBInterrupt.c
@@ -78,19 +78,17 @@ ISR(USB_GEN_vect, ISR_BLOCK)
{
EVENT_USB_VBUSConnect();
- if (USB_IsConnected)
+ if (USB_DeviceState != DEVICE_STATE_Unattached)
EVENT_USB_Disconnect();
USB_ResetInterface();
-
- USB_IsConnected = true;
+ USB_DeviceState = DEVICE_STATE_Powered;
EVENT_USB_Connect();
}
else
{
- USB_IsConnected = false;
-
+ USB_DeviceState = DEVICE_STATE_Unattached;
EVENT_USB_Disconnect();
USB_Detach();
@@ -117,16 +115,12 @@ ISR(USB_GEN_vect, ISR_BLOCK)
if (!(USB_Options & USB_OPT_MANUAL_PLL))
USB_PLL_Off();
- USB_IsSuspended = true;
-
- EVENT_USB_Suspend();
-
#if defined(USB_SERIES_2_AVR) && !defined(NO_LIMITED_CONTROLLER_CONNECT)
- if (USB_IsConnected)
- {
- USB_IsConnected = false;
- EVENT_USB_Disconnect();
- }
+ USB_DeviceState = DEVICE_STATE_Unattached;
+ EVENT_USB_Disconnect();
+ #else
+ USB_DeviceState = DEVICE_STATE_Suspended;
+ EVENT_USB_Suspend();
#endif
}
@@ -146,22 +140,19 @@ ISR(USB_GEN_vect, ISR_BLOCK)
USB_INT_Enable(USB_INT_SUSPEND);
#if defined(USB_SERIES_2_AVR) && !defined(NO_LIMITED_CONTROLLER_CONNECT)
- if (!(USB_IsConnected))
- {
- USB_IsConnected = true;
- EVENT_USB_Connect();
- }
+ USB_DeviceState = DEVICE_STATE_Powered;
+ EVENT_USB_Connect();
+ #else
+ USB_DeviceState = DEVICE_STATE_Configured;
+ EVENT_USB_WakeUp();
#endif
-
- USB_IsSuspended = false;
-
- EVENT_USB_WakeUp();
}
if (USB_INT_HasOccurred(USB_INT_EORSTI) && USB_INT_IsEnabled(USB_INT_EORSTI))
{
USB_INT_Clear(USB_INT_EORSTI);
+ USB_DeviceState = DEVICE_STATE_Default;
USB_ConfigurationNumber = 0;
USB_INT_Clear(USB_INT_SUSPEND);
@@ -217,7 +208,7 @@ ISR(USB_GEN_vect, ISR_BLOCK)
USB_INT_Enable(USB_INT_DDISCI);
- USB_HostState = HOST_STATE_Attached;
+ USB_HostState = HOST_STATE_Powered;
}
if (USB_INT_HasOccurred(USB_INT_BCERRI) && USB_INT_IsEnabled(USB_INT_BCERRI))
@@ -227,7 +218,7 @@ ISR(USB_GEN_vect, ISR_BLOCK)
EVENT_USB_DeviceEnumerationFailed(HOST_ENUMERROR_NoDeviceDetected, 0);
EVENT_USB_DeviceUnattached();
- if (USB_IsConnected)
+ if (USB_HostState != HOST_STATE_Unattached)
EVENT_USB_Disconnect();
USB_ResetInterface();
@@ -239,13 +230,16 @@ ISR(USB_GEN_vect, ISR_BLOCK)
{
USB_INT_Clear(USB_INT_IDTI);
- if (USB_IsConnected)
- {
- if (USB_CurrentMode == USB_MODE_HOST)
- EVENT_USB_DeviceUnattached();
+ if (USB_DeviceState != DEVICE_STATE_Unattached)
+ EVENT_USB_Disconnect();
+ if (USB_HostState != HOST_STATE_Unattached)
+ {
EVENT_USB_Disconnect();
+ EVENT_USB_DeviceUnattached();
}
+
+ EVENT_USB_Disconnect();
EVENT_USB_UIDChange();
diff --git a/LUFA/Drivers/USB/HighLevel/USBTask.c b/LUFA/Drivers/USB/HighLevel/USBTask.c
index 894171f24..500a697bc 100644
--- a/LUFA/Drivers/USB/HighLevel/USBTask.c
+++ b/LUFA/Drivers/USB/HighLevel/USBTask.c
@@ -33,8 +33,6 @@
#define INCLUDE_FROM_USBTASK_C
#include "USBTask.h"
-volatile bool USB_IsSuspended;
-volatile bool USB_IsConnected;
volatile bool USB_IsInitialized;
USB_Request_Header_t USB_ControlRequest;
@@ -42,6 +40,10 @@ USB_Request_Header_t USB_ControlRequest;
volatile uint8_t USB_HostState;
#endif
+#if defined(USB_CAN_BE_DEVICE)
+volatile uint8_t USB_DeviceState;
+#endif
+
void USB_USBTask(void)
{
#if defined(USB_HOST_ONLY)
@@ -59,7 +61,7 @@ void USB_USBTask(void)
#if defined(USB_CAN_BE_DEVICE)
static void USB_DeviceTask(void)
{
- if (USB_IsConnected)
+ if (USB_DeviceState != DEVICE_STATE_Unattached)
{
uint8_t PrevEndpoint = Endpoint_GetCurrentEndpoint();
diff --git a/LUFA/Drivers/USB/HighLevel/USBTask.h b/LUFA/Drivers/USB/HighLevel/USBTask.h
index 2a9bf1953..12acb1195 100644
--- a/LUFA/Drivers/USB/HighLevel/USBTask.h
+++ b/LUFA/Drivers/USB/HighLevel/USBTask.h
@@ -55,23 +55,6 @@
/* Public Interface - May be used in end-application: */
/* Global Variables: */
- /** Indicates if the USB interface is currently connected to a host if in device mode, or to a
- * device while running in host mode.
- *
- * \note This variable should be treated as read-only in the user application, and never manually
- * changed in value.
- *
- * \note For the smaller USB AVRs (AT90USBXX2) with limited USB controllers, VBUS is not available to the USB controller.
- * this means that the current connection state is derived from the bus suspension and wake up events by default,
- * which is not always accurate (host may suspend the bus while still connected). If the actual connection state
- * needs to be determined, VBUS should be routed to an external pin, and the auto-detect behaviour turned off by
- * passing the NO_LIMITED_CONTROLLER_CONNECT token to the compiler via the -D switch at compile time. The connection
- * and disconnection events may be manually fired, and the \ref USB_IsConnected global changed manually.
- *
- * \ingroup Group_USBManagement
- */
- extern volatile bool USB_IsConnected;
-
/** Indicates if the USB interface is currently initialized but not necessarily connected to a host
* or device (i.e. if \ref USB_Init() has been run). If this is false, all other library globals are invalid.
*
@@ -90,39 +73,43 @@
*/
extern USB_Request_Header_t USB_ControlRequest;
- #if defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__)
- /** Indicates if the USB interface is currently suspended by the host when in device mode. When suspended,
- * the device should consume minimal power, and cannot communicate to the host. If Remote Wakeup is
- * supported by the device and \ref USB_RemoteWakeupEnabled is true, suspension can be terminated by the device
- * by issuing a Remote Wakeup request.
- *
- * \note This global is only present if the user application can be a USB device.
- *
- * \note This variable should be treated as read-only in the user application, and never manually
- * changed in value.
- *
- * \ingroup Group_Device
- */
- extern volatile bool USB_IsSuspended;
- #endif
-
#if defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__)
/** Indicates the current host state machine state. When in host mode, this indicates the state
- * via one of the values of the \ref USB_Host_States_t enum values in Host.h.
+ * via one of the values of the \ref USB_Host_States_t enum values.
*
* This value may be altered by the user application to implement the \ref HOST_STATE_Addressed,
- * \ref HOST_STATE_Configured, \ref HOST_STATE_Ready and \ref HOST_STATE_Suspended states which
- * are not implemented by the library.
+ * \ref HOST_STATE_Configured and \ref HOST_STATE_Suspended states which are not implemented by
+ * the library.
*
* \note This global is only present if the user application can be a USB host.
*
- * \see \ref USB_Host_States_t for a list of possible host states
+ * \see \ref USB_Host_States_t for a list of possible device states
*
* \ingroup Group_Host
*/
extern volatile uint8_t USB_HostState;
#endif
+ #if defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__)
+ /** Indicates the current device state machine state. When in device mode, this indicates the state
+ * via one of the values of the \ref USB_Device_States_t enum values.
+ *
+ * This value should not be altered by the user application as it is handled automatically by the
+ * library. The only exception to this rule is if the NO_LIMITED_CONTROLLER_CONNECT token is used
+ * (see \ref EVENT_USB_Connect() and \ref EVENT_USB_Disconnect() events).
+ *
+ * \note This global is only present if the user application can be a USB device.
+ *
+ * \note This variable should be treated as read-only in the user application, and never manually
+ * changed in value except in the circumstances outlined above.
+ *
+ * \see \ref USB_Device_States_t for a list of possible device states
+ *
+ * \ingroup Group_Device
+ */
+ extern volatile uint8_t USB_DeviceState;
+ #endif
+
/* Function Prototypes: */
/** This is the main USB management task. The USB driver requires that this task be executed
* continuously when the USB system is active (device attached in host mode, or attached to a host