Make board specific and device peripheral specific drivers' file documentation copy...
[pub/USBasp.git] / LUFA / Drivers / USB / LowLevel / LowLevel.c
index 4fcf4fc..b49c5b8 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
@@ -54,8 +54,6 @@ void USB_Init(
                #endif\r
                )\r
 {\r
-       USB_ShutDown();\r
-\r
        #if defined(USB_CAN_BE_BOTH)\r
        USB_CurrentMode = Mode;\r
        #endif\r
@@ -110,31 +108,12 @@ void USB_Init(
 \r
 void USB_ShutDown(void)\r
 {\r
-       if (USB_IsConnected)\r
-         EVENT_USB_Disconnect();\r
-\r
+       USB_ResetInterface();\r
        USB_Detach();\r
-\r
-       USB_INT_DisableAllInterrupts();\r
-       USB_INT_ClearAllInterrupts();\r
-\r
-       USB_IsConnected   = false;\r
-       USB_IsInitialized = false;\r
-\r
-       #if defined(USB_CAN_BE_HOST)\r
-       USB_HostState = HOST_STATE_Unattached;\r
-       #endif\r
-\r
-       #if defined(USB_CAN_BE_DEVICE)\r
-       USB_ConfigurationNumber = 0;\r
-       #endif\r
-\r
-       #if defined(CAN_BE_BOTH)\r
-       USB_CurrentMode = USB_MODE_NONE;\r
-       #endif\r
-\r
-       USB_Interface_Disable();\r
-       USB_PLL_Off();\r
+       USB_Controller_Disable();\r
+       \r
+       if (!(USB_Options & USB_OPT_MANUAL_PLL))\r
+         USB_PLL_Off();\r
        \r
        #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)\r
        USB_OTGPAD_Off();\r
@@ -143,24 +122,34 @@ void USB_ShutDown(void)
        #if defined(USB_CAN_BE_BOTH)\r
        UHWCON &= ~(1 << UIDE);\r
        #endif\r
+\r
+       USB_IsInitialized = false;\r
+\r
+       #if defined(USB_CAN_BE_BOTH)\r
+       USB_CurrentMode = USB_MODE_NONE;\r
+       #endif\r
 }\r
 \r
 void USB_ResetInterface(void)\r
 {\r
        USB_INT_DisableAllInterrupts();\r
        USB_INT_ClearAllInterrupts();\r
-\r
-       USB_IsConnected = false;\r
-\r
+       \r
        #if defined(USB_CAN_BE_HOST)\r
-       USB_HostState = HOST_STATE_Unattached;\r
+       USB_HostState   = HOST_STATE_Unattached;\r
        #endif\r
-\r
+       \r
        #if defined(USB_CAN_BE_DEVICE)\r
+       USB_DeviceState = DEVICE_STATE_Unattached;\r
        USB_ConfigurationNumber  = 0;\r
-       USB_IsSuspended          = false;\r
-       USB_RemoteWakeupEnabled  = false;\r
-       USB_CurrentlySelfPowered = false;\r
+\r
+       #if !defined(NO_DEVICE_REMOTE_WAKEUP)\r
+               USB_RemoteWakeupEnabled  = false;\r
+       #endif\r
+       \r
+       #if !defined(NO_DEVICE_SELF_POWER)\r
+               USB_CurrentlySelfPowered = false;\r
+       #endif\r
        #endif\r
        \r
        if (!(USB_Options & USB_OPT_MANUAL_PLL))\r
@@ -173,7 +162,7 @@ void USB_ResetInterface(void)
                while (!(USB_PLL_IsReady()));\r
        }\r
        \r
-       USB_Interface_Reset();\r
+       USB_Controller_Reset();\r
        \r
        #if defined(USB_CAN_BE_BOTH)\r
        if (UHWCON & (1 << UIDE))\r
@@ -197,9 +186,7 @@ void USB_ResetInterface(void)
                if (USB_Options & USB_DEVICE_OPT_LOWSPEED)\r
                  USB_Device_SetLowSpeed();\r
                else\r
-                 USB_Device_SetHighSpeed();\r
-                 \r
-               USB_INT_Enable(USB_INT_VBUS);\r
+                 USB_Device_SetFullSpeed();\r
        }\r
        #endif\r
        \r
@@ -211,11 +198,11 @@ void USB_ResetInterface(void)
                if (CALLBACK_USB_GetDescriptor((DTYPE_Device << 8), 0, (void*)&DeviceDescriptorPtr) != NO_DESCRIPTOR)\r
                {                 \r
                        #if defined(USE_RAM_DESCRIPTORS)\r
-                               USB_ControlEndpointSize = DeviceDescriptorPtr->Endpoint0Size;\r
+                       USB_ControlEndpointSize = DeviceDescriptorPtr->Endpoint0Size;\r
                        #elif defined(USE_EEPROM_DESCRIPTORS)\r
-                               USB_ControlEndpointSize = eeprom_read_byte(&DeviceDescriptorPtr->Endpoint0Size);\r
+                       USB_ControlEndpointSize = eeprom_read_byte(&DeviceDescriptorPtr->Endpoint0Size);\r
                        #else\r
-                               USB_ControlEndpointSize = pgm_read_byte(&DeviceDescriptorPtr->Endpoint0Size);\r
+                       USB_ControlEndpointSize = pgm_read_byte(&DeviceDescriptorPtr->Endpoint0Size);\r
                        #endif\r
                }\r
        }\r
@@ -223,13 +210,15 @@ void USB_ResetInterface(void)
 \r
        USB_Attach();\r
        \r
-       #if defined(USB_DEVICE_ONLY)    \r
+       #if defined(USB_DEVICE_ONLY)\r
+       USB_INT_Clear(USB_INT_SUSPEND);\r
        USB_INT_Enable(USB_INT_SUSPEND);\r
+       USB_INT_Clear(USB_INT_EORSTI);\r
        USB_INT_Enable(USB_INT_EORSTI);\r
-       #if defined(CONTROL_ONLY_DEVICE)\r
-       UENUM = ENDPOINT_CONTROLEP;\r
-       #endif\r
-               \r
+\r
+               #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)\r
+               USB_INT_Enable(USB_INT_VBUS);\r
+               #endif\r
        #elif defined(USB_HOST_ONLY)\r
        USB_Host_HostMode_On();\r
        \r
@@ -244,9 +233,15 @@ void USB_ResetInterface(void)
        #else\r
        if (USB_CurrentMode == USB_MODE_DEVICE)\r
        {\r
+               USB_INT_Clear(USB_INT_SUSPEND);\r
                USB_INT_Enable(USB_INT_SUSPEND);\r
+               USB_INT_Clear(USB_INT_EORSTI);\r
                USB_INT_Enable(USB_INT_EORSTI);\r
 \r
+               #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)\r
+               USB_INT_Enable(USB_INT_VBUS);\r
+               #endif\r
+\r
                #if defined(CONTROL_ONLY_DEVICE)\r
                UENUM = ENDPOINT_CONTROLEP;\r
                #endif\r