From 9d2613d90868b59ac48ccce8b652819d5cd388d5 Mon Sep 17 00:00:00 2001
From: Dean Camera <dean@fourwalledcubicle.com>
Date: Sun, 19 Jul 2009 09:04:25 +0000
Subject: [PATCH] Fixed incorrect PIPE_EPNUM_MASK mask causing pipe failures on
 devices with endpoint addresses of 8 and above (thanks to John Andrews).

---
 .../Host/Incomplete/PrinterHost/Lib/PrinterCommands.c  |  1 +
 Demos/Host/Incomplete/PrinterHost/PrinterHost.c        | 10 +++++-----
 LUFA/Drivers/USB/LowLevel/Pipe.h                       |  2 +-
 LUFA/ManPages/ChangeLog.txt                            |  1 +
 4 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/Demos/Host/Incomplete/PrinterHost/Lib/PrinterCommands.c b/Demos/Host/Incomplete/PrinterHost/Lib/PrinterCommands.c
index 46e534d4b..9324a141c 100644
--- a/Demos/Host/Incomplete/PrinterHost/Lib/PrinterCommands.c
+++ b/Demos/Host/Incomplete/PrinterHost/Lib/PrinterCommands.c
@@ -90,3 +90,4 @@ uint8_t Printer_SoftReset(void)
 
 	return USB_Host_SendControlRequest(NULL);
 }
+
diff --git a/Demos/Host/Incomplete/PrinterHost/PrinterHost.c b/Demos/Host/Incomplete/PrinterHost/PrinterHost.c
index 5cdd063fb..80fca259c 100644
--- a/Demos/Host/Incomplete/PrinterHost/PrinterHost.c
+++ b/Demos/Host/Incomplete/PrinterHost/PrinterHost.c
@@ -184,6 +184,8 @@ void USB_Printer_Host(void)
 		
             //--------------------------------------------------------------
 			#define TEST_TEXT_PAGE "\033%-12345X\033E LUFA PCL Test Page \033E\033%-12345X"
+//			#define TEST_TEXT_PAGE "\033@\033i\001\033X\001\060\000\r\nLUFA ESCP/2 Test Page\r\n"
+			#define PAGE_SIZE      (sizeof(TEST_TEXT_PAGE) - 1)
 
 			Pipe_SelectPipe(PRINTER_DATA_OUT_PIPE);
             Pipe_Unfreeze();
@@ -192,14 +194,12 @@ void USB_Printer_Host(void)
 			
 			while (!(Pipe_IsReadWriteAllowed()));
 
-			uint8_t strSize = sizeof(TEST_TEXT_PAGE)-1;
-
-			printf_P(PSTR("Printer Write Allowed, sending complete page (%d bytes)...\r\n"), strSize);
+			printf_P(PSTR("Printer Write Allowed, Sending Page (%d bytes)...\r\n"), PAGE_SIZE);
 				
-			Pipe_Write_Stream_LE(TEST_TEXT_PAGE, strSize);
+			Pipe_Write_Stream_LE(TEST_TEXT_PAGE, PAGE_SIZE);
             Pipe_ClearOUT();
 
-			puts_P(PSTR("Page sent to printer.\r\n"));
+			puts_P(PSTR("Page Sent, Waiting for Pipe...\r\n"));
 
 			while (!(Pipe_IsReadWriteAllowed()));
             Pipe_Freeze();				
diff --git a/LUFA/Drivers/USB/LowLevel/Pipe.h b/LUFA/Drivers/USB/LowLevel/Pipe.h
index 58cfb1f23..f03ea09c2 100644
--- a/LUFA/Drivers/USB/LowLevel/Pipe.h
+++ b/LUFA/Drivers/USB/LowLevel/Pipe.h
@@ -173,7 +173,7 @@
 			/** Endpoint number mask, for masking against endpoint addresses to retrieve the endpoint's
 			 *  numerical address in the attached device.
 			 */
-			#define PIPE_EPNUM_MASK                 0x07
+			#define PIPE_EPNUM_MASK                 0x0F
 
 			/** Endpoint bank size mask, for masking against endpoint addresses to retrieve the endpoint's
 			 *  bank size in the attached device.
diff --git a/LUFA/ManPages/ChangeLog.txt b/LUFA/ManPages/ChangeLog.txt
index c2b7d5edb..62997d73d 100644
--- a/LUFA/ManPages/ChangeLog.txt
+++ b/LUFA/ManPages/ChangeLog.txt
@@ -61,6 +61,7 @@
   *  - Fixed Host mode to Device mode UID change not causing a USB Disconnect event when a device was connected
   *  - Fixed Mouse/Keyboard demos not performing the correct arithmetic on the Idle period at the right times (thanks to Brian Dickman)
   *  - Fixed GenericHID failing HID class tests due to incorrect Logical Minimum and Logical Maximum values (thanks to S�ren Greiner)
+  *  - Fixed incorrect PIPE_EPNUM_MASK mask causing pipe failures on devices with endpoint addresses of 8 and above (thanks to John Andrews)
   *
   *
   *  \section Sec_ChangeLog090605 Version 090605
-- 
GitLab