X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/4d3a594f3e26447ba223ac58292c9a77480ceed3..ab2ae13d81427ddddbd24e8ba6bdfbd2f05ff958:/LUFA/Drivers/USB/LowLevel/LowLevel.c?ds=sidebyside diff --git a/LUFA/Drivers/USB/LowLevel/LowLevel.c b/LUFA/Drivers/USB/LowLevel/LowLevel.c index 865a57d57..3ad1e9830 100644 --- a/LUFA/Drivers/USB/LowLevel/LowLevel.c +++ b/LUFA/Drivers/USB/LowLevel/LowLevel.c @@ -54,8 +54,6 @@ void USB_Init( #endif ) { - USB_ShutDown(); - #if defined(USB_CAN_BE_BOTH) USB_CurrentMode = Mode; #endif @@ -110,31 +108,22 @@ void USB_Init( void USB_ShutDown(void) { - if (USB_IsConnected) - EVENT_USB_Disconnect(); - - USB_Detach(); - - USB_INT_DisableAllInterrupts(); - USB_INT_ClearAllInterrupts(); - - USB_IsConnected = false; - USB_IsInitialized = false; - - #if defined(USB_CAN_BE_HOST) - USB_HostState = HOST_STATE_Unattached; - #endif - #if defined(USB_CAN_BE_DEVICE) - USB_ConfigurationNumber = 0; + if (USB_DeviceState != DEVICE_STATE_Unattached) + EVENT_USB_Disconnect(); #endif - - #if defined(CAN_BE_BOTH) - USB_CurrentMode = USB_MODE_NONE; + + #if defined(USB_CAN_BE_HOST) + if (USB_HostState != HOST_STATE_Unattached) + EVENT_USB_Disconnect(); #endif - USB_Interface_Disable(); - USB_PLL_Off(); + USB_ResetInterface(); + USB_Detach(); + USB_Controller_Disable(); + + if (!(USB_Options & USB_OPT_MANUAL_PLL)) + USB_PLL_Off(); #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) USB_OTGPAD_Off(); @@ -143,29 +132,33 @@ void USB_ShutDown(void) #if defined(USB_CAN_BE_BOTH) UHWCON &= ~(1 << UIDE); #endif + + USB_IsInitialized = false; + + #if defined(CAN_BE_BOTH) + USB_CurrentMode = USB_MODE_NONE; + #endif } void USB_ResetInterface(void) { USB_INT_DisableAllInterrupts(); USB_INT_ClearAllInterrupts(); - - USB_IsConnected = false; - + #if defined(USB_CAN_BE_HOST) - USB_HostState = HOST_STATE_Unattached; + USB_HostState = HOST_STATE_Unattached; #endif - + #if defined(USB_CAN_BE_DEVICE) + USB_DeviceState = DEVICE_STATE_Unattached; USB_ConfigurationNumber = 0; - USB_IsSuspended = false; USB_RemoteWakeupEnabled = false; USB_CurrentlySelfPowered = false; #endif if (!(USB_Options & USB_OPT_MANUAL_PLL)) { - #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) + #if defined(USB_SERIES_4_AVR) PLLFRQ = ((1 << PLLUSB) | (1 << PDIV3) | (1 << PDIV1)); #endif @@ -173,7 +166,7 @@ void USB_ResetInterface(void) while (!(USB_PLL_IsReady())); } - USB_Interface_Reset(); + USB_Controller_Reset(); #if defined(USB_CAN_BE_BOTH) if (UHWCON & (1 << UIDE)) @@ -186,6 +179,8 @@ void USB_ResetInterface(void) if (!(USB_Options & USB_OPT_REG_DISABLED)) USB_REG_On(); + else + USB_REG_Off(); USB_CLK_Unfreeze(); @@ -195,7 +190,7 @@ void USB_ResetInterface(void) if (USB_Options & USB_DEVICE_OPT_LOWSPEED) USB_Device_SetLowSpeed(); else - USB_Device_SetHighSpeed(); + USB_Device_SetFullSpeed(); USB_INT_Enable(USB_INT_VBUS); }