From a789619fbe2cd07347816cc5c168e8f904acca86 Mon Sep 17 00:00:00 2001
From: Dean Camera <dean@fourwalledcubicle.com>
Date: Fri, 31 Jul 2009 00:35:19 +0000
Subject: [PATCH] Renamed USB_Device_SetHighSpeed() to
 USB_Device_SetFullSpeed() so that the correct terminology is used (thanks to
 Brian Dickman).

Fix USB_PLL_Off() call in the series 4, 6 and 7 microcontroller disconnect interrupt handler code, which wasn't guarded by a test of USB_Options to check if the user has specified manual PLL control (thanks to Brian Dickman).
---
 Bootloaders/TeensyHID/TeensyHID.c         | 1 -
 LUFA/Drivers/USB/HighLevel/USBInterrupt.c | 5 ++++-
 LUFA/Drivers/USB/LowLevel/Device.h        | 2 +-
 LUFA/Drivers/USB/LowLevel/LowLevel.c      | 6 ++++--
 LUFA/ManPages/ChangeLog.txt               | 1 +
 5 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/Bootloaders/TeensyHID/TeensyHID.c b/Bootloaders/TeensyHID/TeensyHID.c
index 67dded545..52526689a 100644
--- a/Bootloaders/TeensyHID/TeensyHID.c
+++ b/Bootloaders/TeensyHID/TeensyHID.c
@@ -33,7 +33,6 @@
  *  Main source file for the TeensyHID bootloader. This file contains the complete bootloader logic.
  */
  
-#define  INCLUDE_FROM_TEENSYHID_C
 #include "TeensyHID.h"
 
 /* Global Variables: */
diff --git a/LUFA/Drivers/USB/HighLevel/USBInterrupt.c b/LUFA/Drivers/USB/HighLevel/USBInterrupt.c
index 20545a40e..f0a59edb7 100644
--- a/LUFA/Drivers/USB/HighLevel/USBInterrupt.c
+++ b/LUFA/Drivers/USB/HighLevel/USBInterrupt.c
@@ -93,7 +93,10 @@ ISR(USB_GEN_vect, ISR_BLOCK)
 		
 			USB_Detach();
 			USB_CLK_Freeze();
-			USB_PLL_Off();
+
+			if (!(USB_Options & USB_OPT_MANUAL_PLL))
+			  USB_PLL_Off();
+
 			USB_REG_Off();
 
 			EVENT_USB_VBUSDisconnect();
diff --git a/LUFA/Drivers/USB/LowLevel/Device.h b/LUFA/Drivers/USB/LowLevel/Device.h
index e162a5980..d66def438 100644
--- a/LUFA/Drivers/USB/LowLevel/Device.h
+++ b/LUFA/Drivers/USB/LowLevel/Device.h
@@ -185,7 +185,7 @@
 	#if !defined(__DOXYGEN__)
 		/* Macros: */		
 			#define USB_Device_SetLowSpeed()        MACROS{ UDCON |=  (1 << LSM);   }MACROE
-			#define USB_Device_SetHighSpeed()       MACROS{ UDCON &= ~(1 << LSM);   }MACROE
+			#define USB_Device_SetFullSpeed()       MACROS{ UDCON &= ~(1 << LSM);   }MACROE
 	#endif
 
 #endif
diff --git a/LUFA/Drivers/USB/LowLevel/LowLevel.c b/LUFA/Drivers/USB/LowLevel/LowLevel.c
index 41d9e10cc..3ad1e9830 100644
--- a/LUFA/Drivers/USB/LowLevel/LowLevel.c
+++ b/LUFA/Drivers/USB/LowLevel/LowLevel.c
@@ -121,7 +121,9 @@ void USB_ShutDown(void)
 	USB_ResetInterface();
 	USB_Detach();
 	USB_Controller_Disable();
-	USB_PLL_Off();
+	
+	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();
@@ -188,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);
 	}
diff --git a/LUFA/ManPages/ChangeLog.txt b/LUFA/ManPages/ChangeLog.txt
index 813a5b45d..7adb95fe0 100644
--- a/LUFA/ManPages/ChangeLog.txt
+++ b/LUFA/ManPages/ChangeLog.txt
@@ -64,6 +64,7 @@
   *    to only unfreeze and check one data pipe at a time) to prevent incorrect device enumerations and freezes while trasferring data
   *  - Make Pipe_ConfigurePipe() mask the given endpoint number against PIPE_EPNUM_MASK to ensure the endpoint IN direction bit is
   *    cleared to prevent endpoint type corruption
+  *  - Fixed USB_OPT_MANUAL_PLL option being ignored during device disconnects on some models (thanks to Brian Dickman)
   *  - Fixed documentation mentioning Pipe_GetCurrentToken() function when correct function name is Pipe_GetPipeToken()
   *  - Fixed ADC driver for the ATMEGA32U4 and ATMEGA16U4 (thanks to Opendous Inc.)
   *  - Fixed CDCHost demo unfreezing the pipes at the point of configuration, rather than use
-- 
GitLab