From b7f6a65c258cafc3111d77502b491f223b886a33 Mon Sep 17 00:00:00 2001
From: Dean Camera <dean@fourwalledcubicle.com>
Date: Sun, 29 Nov 2009 07:41:54 +0000
Subject: [PATCH] Fixed USB driver failing to define the PLL prescaler mask for
 the ATMEGA8U2 and ATMEGA16U2.

Simplified the USB.h master include file's target validity checks.
---
 LUFA/Drivers/USB/HighLevel/StdDescriptors.h | 22 ++++++++++-----------
 LUFA/Drivers/USB/LowLevel/LowLevel.h        |  6 ++++--
 LUFA/Drivers/USB/USB.h                      | 13 +++++-------
 LUFA/ManPages/ChangeLog.txt                 |  1 +
 4 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/LUFA/Drivers/USB/HighLevel/StdDescriptors.h b/LUFA/Drivers/USB/HighLevel/StdDescriptors.h
index 9e5764bce..19ca8aa69 100644
--- a/LUFA/Drivers/USB/HighLevel/StdDescriptors.h
+++ b/LUFA/Drivers/USB/HighLevel/StdDescriptors.h
@@ -544,17 +544,17 @@
 			{
 				USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */
 				
-				int16_t     UnicodeString[]; /**< String data, as unicode characters (alternatively,
-				                              *   string language IDs). If normal ASCII characters are
-				                              *   to be used, they must be added as an array of characters
-				                              *   rather than a normal C string so that they are widened to
-				                              *   Unicode size.
-				                              *
-				                              *   Under GCC, strings prefixed with the "L" character (before
-				                              *   the opening string quotation mark) are considered to be
-				                              *   Unicode strings, and may be used instead of an explicit
-				                              *   array of ASCII characters.
-				                              */
+				wchar_t UnicodeString[];  /**< String data, as unicode characters (alternatively,
+				                           *   string language IDs). If normal ASCII characters are
+				                           *   to be used, they must be added as an array of characters
+				                           *   rather than a normal C string so that they are widened to
+				                           *   Unicode size.
+				                           *
+				                           *   Under GCC, strings prefixed with the "L" character (before
+				                           *   the opening string quotation mark) are considered to be
+				                           *   Unicode strings, and may be used instead of an explicit
+				                           *   array of ASCII characters.
+				                           */
 			} USB_Descriptor_String_t;
 
 			/** Type define for a standard string descriptor. Unlike other standard descriptors, the length
diff --git a/LUFA/Drivers/USB/LowLevel/LowLevel.h b/LUFA/Drivers/USB/LowLevel/LowLevel.h
index 743a318ad..8b441c2e2 100644
--- a/LUFA/Drivers/USB/LowLevel/LowLevel.h
+++ b/LUFA/Drivers/USB/LowLevel/LowLevel.h
@@ -75,7 +75,8 @@
 		#endif
 	
 		#if (F_CLOCK == 8000000)
-			#if (defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__))
+			#if (defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__) || \
+			     defined(__AVR_ATMEGA8U2__) || defined(__AVR_ATMEGA16U2__))
 				#define USB_PLL_PSC                0
 			#elif (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__))
 				#define USB_PLL_PSC                0
@@ -85,7 +86,8 @@
 				#define USB_PLL_PSC                ((1 << PLLP1) | (1 << PLLP0))
 			#endif
 		#elif (F_CLOCK == 16000000)
-			#if (defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__))
+			#if (defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__) || \
+			     defined(__AVR_ATMEGA8U2__) || defined(__AVR_ATMEGA16U2__))
 				#define USB_PLL_PSC                (1 << PLLP0)
 			#elif (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__))
 				#define USB_PLL_PSC                (1 << PINDIV)
diff --git a/LUFA/Drivers/USB/USB.h b/LUFA/Drivers/USB/USB.h
index b40d6ab44..0d0a3f784 100644
--- a/LUFA/Drivers/USB/USB.h
+++ b/LUFA/Drivers/USB/USB.h
@@ -132,19 +132,16 @@
 #ifndef __USB_H__
 #define __USB_H__
 
+	/* Includes: */
+		#include "HighLevel/USBMode.h"
+
 	/* Preprocessor Checks: */		
-		#if (!(defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB647__) ||  \
-		       defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB646__) ||  \
-			   defined(__AVR_AT90USB162__)  || defined(__AVR_AT90USB82__)  ||  \
-			   defined(__AVR_ATmega32U2__)  || defined(__AVR_ATmega16U2__) ||  \
-			   defined(__AVR_ATmega8U2__)   ||                                 \
-			   defined(__AVR_ATmega16U4__)  || defined(__AVR_ATmega32U4__) ||  \
-			   defined(__AVR_ATmega32U6__)))
+		#if (!defined(USB_SERIES_2_AVR) && !defined(USB_SERIES_4_AVR) && \
+		     !defined(USB_SERIES_6_AVR) && !defined(USB_SERIES_7_AVR))
 			#error The currently selected AVR model is not supported under the USB component of the LUFA library.
 		#endif
 		
 	/* Includes: */
-		#include "HighLevel/USBMode.h"
 		#include "HighLevel/USBTask.h"
 		#include "HighLevel/USBInterrupt.h"
 		#include "HighLevel/Events.h"
diff --git a/LUFA/ManPages/ChangeLog.txt b/LUFA/ManPages/ChangeLog.txt
index 8f7a410ff..4b37995af 100644
--- a/LUFA/ManPages/ChangeLog.txt
+++ b/LUFA/ManPages/ChangeLog.txt
@@ -40,6 +40,7 @@
   *  - Fixed host state machine not enabling Auto VBUS mode when HOST_DEVICE_SETTLE_DELAY_MS is set to zero
   *  - Fixed misnamed Pipe_SetPipeToken() macro for setting a pipe's direction
   *  - Fixed CDCHost failing on devices with bidirectional endpoints
+  *  - Fixed USB driver failing to define the PLL prescaler mask for the ATMEGA8U2 and ATMEGA16U2
   *
   *  \section Sec_ChangeLog091122 Version 091122
   *
-- 
GitLab