From a60a668f6bff4fbaba2eec75463050819df25bb0 Mon Sep 17 00:00:00 2001
From: brupje <brupje@gmail.com>
Date: Tue, 21 Jun 2016 14:39:10 +0200
Subject: [PATCH 1/2] Support for REPRAPWORLD_GRAPHICAL_LCD

---
 Marlin/Conditionals.h       |  7 +++++
 Marlin/Configuration.h      |  7 +++++
 Marlin/pins_MEGATRONICS_3.h | 52 ++++++++++++++++++++++++++++++-------
 Marlin/pins_MINITRONICS.h   | 21 +++++++++++++++
 Marlin/pins_RAMPS_14.h      | 18 ++++++++++++-
 Marlin/ultralcd_impl_DOGM.h |  4 ++-
 6 files changed, 97 insertions(+), 12 deletions(-)

diff --git a/Marlin/Conditionals.h b/Marlin/Conditionals.h
index e5e072a224..2cc8eac31b 100644
--- a/Marlin/Conditionals.h
+++ b/Marlin/Conditionals.h
@@ -130,6 +130,13 @@
     #define NEWPANEL
   #endif
 
+
+  #if ENABLED(REPRAPWORLD_GRAPHICAL_LCD)
+    #define DOGLCD
+    #define U8GLIB_ST7920
+    #define ULTIPANEL
+  #endif
+
   /**
    * I2C PANELS
    */
diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h
index f810fcd0c1..999e043d99 100644
--- a/Marlin/Configuration.h
+++ b/Marlin/Configuration.h
@@ -1118,6 +1118,13 @@
 //
 //#define MAKRPANEL
 
+//
+// ReprapWorld Graphical LCD
+// https://reprapworld.com/?products_details&products_id/1218
+//
+//#define REPRAPWORLD_GRAPHICAL_LCD
+
+
 //
 // Activate one of these if you have a Panucatt Devices
 // Viki 2.0 or mini Viki with Graphic LCD
diff --git a/Marlin/pins_MEGATRONICS_3.h b/Marlin/pins_MEGATRONICS_3.h
index 47ec17649f..a77232f219 100644
--- a/Marlin/pins_MEGATRONICS_3.h
+++ b/Marlin/pins_MEGATRONICS_3.h
@@ -106,17 +106,49 @@
 
 #define BEEPER_PIN 61
 
-#define LCD_PINS_RS 32
-#define LCD_PINS_ENABLE 31
-#define LCD_PINS_D4 14
-#define LCD_PINS_D5 30
-#define LCD_PINS_D6 39
-#define LCD_PINS_D7 15
 
-#define SHIFT_CLK 43
-#define SHIFT_LD 35
-#define SHIFT_OUT 34
-#define SHIFT_EN 44
+
+
+#if ENABLED(DOGLCD)
+
+    #if ENABLED(U8GLIB_ST7920)
+    
+        #define LCD_PINS_RS     56 //CS chip select /SS chip slave select
+        #define LCD_PINS_ENABLE 51 //SID (MOSI)
+        #define LCD_PINS_D4     52 //SCK (CLK) clock     
+
+        #define BTN_EN1             44
+        #define BTN_EN2             45
+        #define BTN_ENC             33
+
+        
+        #define SD_DETECT_PIN 35
+    #endif
+
+#else
+  #define LCD_PINS_RS 32
+  #define LCD_PINS_ENABLE 31
+  #define LCD_PINS_D4 14
+  #define LCD_PINS_D5 30
+  #define LCD_PINS_D6 39
+  #define LCD_PINS_D7 15
+  
+  #define SHIFT_CLK 43
+  #define SHIFT_LD 35
+  #define SHIFT_OUT 34
+  #define SHIFT_EN 44
+  //buttons are directly attached using keypad
+  #define BTN_EN1 44
+  #define BTN_EN2 45
+  #define BTN_ENC 33 //the click
+
+  #define BLEN_C 2
+  #define BLEN_B 1
+  #define BLEN_A 0
+
+  #define SD_DETECT_PIN 56 // Megatronics v3.1 only
+#endif
+
 
 // Buttons are directly attached using keypad
 #define BTN_EN1 44
diff --git a/Marlin/pins_MINITRONICS.h b/Marlin/pins_MINITRONICS.h
index 0c80ceda45..734b39de4d 100644
--- a/Marlin/pins_MINITRONICS.h
+++ b/Marlin/pins_MINITRONICS.h
@@ -76,6 +76,25 @@
 
 #define BEEPER_PIN -1
 
+
+
+#if ENABLED(DOGLCD)
+
+    #if ENABLED(U8GLIB_ST7920)
+    
+        #define LCD_PINS_RS     15 //CS chip select /SS chip slave select
+        #define LCD_PINS_ENABLE 11 //SID (MOSI)
+        #define LCD_PINS_D4     10 //SCK (CLK) clock     
+
+        #define BTN_EN1             18
+        #define BTN_EN2             17
+        #define BTN_ENC             25
+
+        
+        #define SD_DETECT_PIN 30
+    #endif
+
+#else
 #define LCD_PINS_RS -1
 #define LCD_PINS_ENABLE -1
 #define LCD_PINS_D4 -1
@@ -92,3 +111,5 @@
 #define BLEN_B 1
 #define BLEN_A 0
 
+#define SD_DETECT_PIN -1  // Minitronics doesn't use this
+#endif
diff --git a/Marlin/pins_RAMPS_14.h b/Marlin/pins_RAMPS_14.h
index c51a8d02a1..3434e8c904 100644
--- a/Marlin/pins_RAMPS_14.h
+++ b/Marlin/pins_RAMPS_14.h
@@ -139,7 +139,23 @@
   #define SLED_PIN           -1
 #endif
 
-#if ENABLED(ULTRA_LCD)
+
+
+#if ENABLED(REPRAPWORLD_GRAPHICAL_LCD)
+
+
+  #define LCD_PINS_RS     49 //CS chip select /SS chip slave select
+  #define LCD_PINS_ENABLE 51 //SID (MOSI)
+  #define LCD_PINS_D4     52 //SCK (CLK) clock     
+
+  #define BTN_EN1             64
+  #define BTN_EN2             59
+  #define BTN_ENC             63
+
+  
+  #define SD_DETECT_PIN 42
+
+#elif ENABLED(ULTRA_LCD)
 
   #if ENABLED(NEWPANEL) && ENABLED(PANEL_ONE)
     #define LCD_PINS_RS 40
diff --git a/Marlin/ultralcd_impl_DOGM.h b/Marlin/ultralcd_impl_DOGM.h
index f53f9269c5..218f3217bc 100644
--- a/Marlin/ultralcd_impl_DOGM.h
+++ b/Marlin/ultralcd_impl_DOGM.h
@@ -141,7 +141,9 @@
 #define START_COL              0
 
 // LCD selection
-#if ENABLED(U8GLIB_ST7920)
+#if ENABLED(REPRAPWORLD_GRAPHICAL_LCD)
+  U8GLIB_ST7920_128X64_4X u8g(LCD_PINS_RS);
+#elif ENABLED(U8GLIB_ST7920)
   //U8GLIB_ST7920_128X64_RRD u8g(0,0,0);
   U8GLIB_ST7920_128X64_RRD u8g(0);
 #elif defined(CARTESIO_UI)

From 0c0a63322b86a871a825a56ffa9b88616fc97fef Mon Sep 17 00:00:00 2001
From: Scott Lahteine <sourcetree@thinkyhead.com>
Date: Mon, 25 Jul 2016 12:09:24 -0700
Subject: [PATCH 2/2] Patches to prepare REPRAPWORLD_GRAPHICAL_LCD

---
 Marlin/Conditionals.h       |  8 ++++--
 Marlin/Configuration.h      |  1 -
 Marlin/pins_MEGATRONICS_3.h | 36 +++++++------------------
 Marlin/pins_MINITRONICS.h   | 52 ++++++++++++++++++-------------------
 Marlin/pins_RAMPS_14.h      | 29 ++++++++-------------
 5 files changed, 51 insertions(+), 75 deletions(-)

diff --git a/Marlin/Conditionals.h b/Marlin/Conditionals.h
index 2cc8eac31b..3a9ace9198 100644
--- a/Marlin/Conditionals.h
+++ b/Marlin/Conditionals.h
@@ -118,7 +118,11 @@
     #define REPRAP_DISCOUNT_SMART_CONTROLLER
   #endif
 
-  #if ENABLED(ULTIMAKERCONTROLLER) || ENABLED(REPRAP_DISCOUNT_SMART_CONTROLLER) || ENABLED(G3D_PANEL) || ENABLED(RIGIDBOT_PANEL) || ENABLED(REPRAPWORLD_KEYPAD)
+  #if ENABLED(ULTIMAKERCONTROLLER)              \
+   || ENABLED(REPRAP_DISCOUNT_SMART_CONTROLLER) \
+   || ENABLED(G3D_PANEL)                        \
+   || ENABLED(RIGIDBOT_PANEL)                   \
+   || ENABLED(REPRAPWORLD_KEYPAD)
     #define ULTIPANEL
     #define NEWPANEL
   #endif
@@ -130,11 +134,11 @@
     #define NEWPANEL
   #endif
 
-
   #if ENABLED(REPRAPWORLD_GRAPHICAL_LCD)
     #define DOGLCD
     #define U8GLIB_ST7920
     #define ULTIPANEL
+    #define NEWPANEL
   #endif
 
   /**
diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h
index 999e043d99..1ab5eddb14 100644
--- a/Marlin/Configuration.h
+++ b/Marlin/Configuration.h
@@ -1124,7 +1124,6 @@
 //
 //#define REPRAPWORLD_GRAPHICAL_LCD
 
-
 //
 // Activate one of these if you have a Panucatt Devices
 // Viki 2.0 or mini Viki with Graphic LCD
diff --git a/Marlin/pins_MEGATRONICS_3.h b/Marlin/pins_MEGATRONICS_3.h
index a77232f219..93599781bf 100644
--- a/Marlin/pins_MEGATRONICS_3.h
+++ b/Marlin/pins_MEGATRONICS_3.h
@@ -106,26 +106,17 @@
 
 #define BEEPER_PIN 61
 
-
-
-
 #if ENABLED(DOGLCD)
 
-    #if ENABLED(U8GLIB_ST7920)
-    
-        #define LCD_PINS_RS     56 //CS chip select /SS chip slave select
-        #define LCD_PINS_ENABLE 51 //SID (MOSI)
-        #define LCD_PINS_D4     52 //SCK (CLK) clock     
-
-        #define BTN_EN1             44
-        #define BTN_EN2             45
-        #define BTN_ENC             33
-
-        
-        #define SD_DETECT_PIN 35
-    #endif
+  #if ENABLED(U8GLIB_ST7920)
+    #define LCD_PINS_RS     56 //CS chip select /SS chip slave select
+    #define LCD_PINS_ENABLE 51 //SID (MOSI)
+    #define LCD_PINS_D4     52 //SCK (CLK) clock
+    #define SD_DETECT_PIN 35
+  #endif
 
 #else
+
   #define LCD_PINS_RS 32
   #define LCD_PINS_ENABLE 31
   #define LCD_PINS_D4 14
@@ -137,25 +128,16 @@
   #define SHIFT_LD 35
   #define SHIFT_OUT 34
   #define SHIFT_EN 44
-  //buttons are directly attached using keypad
-  #define BTN_EN1 44
-  #define BTN_EN2 45
-  #define BTN_ENC 33 //the click
-
-  #define BLEN_C 2
-  #define BLEN_B 1
-  #define BLEN_A 0
 
   #define SD_DETECT_PIN 56 // Megatronics v3.1 only
-#endif
 
+#endif
 
 // Buttons are directly attached using keypad
 #define BTN_EN1 44
 #define BTN_EN2 45
-#define BTN_ENC 33 // the click
+#define BTN_ENC 33
 
 #define BLEN_C 2
 #define BLEN_B 1
 #define BLEN_A 0
-
diff --git a/Marlin/pins_MINITRONICS.h b/Marlin/pins_MINITRONICS.h
index 734b39de4d..db68c97aec 100644
--- a/Marlin/pins_MINITRONICS.h
+++ b/Marlin/pins_MINITRONICS.h
@@ -76,40 +76,38 @@
 
 #define BEEPER_PIN -1
 
-
-
 #if ENABLED(DOGLCD)
 
-    #if ENABLED(U8GLIB_ST7920)
-    
-        #define LCD_PINS_RS     15 //CS chip select /SS chip slave select
-        #define LCD_PINS_ENABLE 11 //SID (MOSI)
-        #define LCD_PINS_D4     10 //SCK (CLK) clock     
+  #if ENABLED(U8GLIB_ST7920)
+    #define LCD_PINS_RS     15 //CS chip select /SS chip slave select
+    #define LCD_PINS_ENABLE 11 //SID (MOSI)
+    #define LCD_PINS_D4     10 //SCK (CLK) clock     
 
-        #define BTN_EN1             18
-        #define BTN_EN2             17
-        #define BTN_ENC             25
+    #define BTN_EN1 18
+    #define BTN_EN2 17
+    #define BTN_ENC 25
 
-        
-        #define SD_DETECT_PIN 30
-    #endif
+    #define SD_DETECT_PIN 30
+  #endif
 
 #else
-#define LCD_PINS_RS -1
-#define LCD_PINS_ENABLE -1
-#define LCD_PINS_D4 -1
-#define LCD_PINS_D5 -1
-#define LCD_PINS_D6 -1
-#define LCD_PINS_D7 -1
 
-// Buttons are directly attached using keypad
-#define BTN_EN1 -1
-#define BTN_EN2 -1
-#define BTN_ENC -1 // the click
+  #define LCD_PINS_RS -1
+  #define LCD_PINS_ENABLE -1
+  #define LCD_PINS_D4 -1
+  #define LCD_PINS_D5 -1
+  #define LCD_PINS_D6 -1
+  #define LCD_PINS_D7 -1
 
-#define BLEN_C 2
-#define BLEN_B 1
-#define BLEN_A 0
+  // Buttons are directly attached using keypad
+  #define BTN_EN1 -1
+  #define BTN_EN2 -1
+  #define BTN_ENC -1
+
+  #define BLEN_C 2
+  #define BLEN_B 1
+  #define BLEN_A 0
+
+  #define SD_DETECT_PIN -1  // Minitronics doesn't use this
 
-#define SD_DETECT_PIN -1  // Minitronics doesn't use this
 #endif
diff --git a/Marlin/pins_RAMPS_14.h b/Marlin/pins_RAMPS_14.h
index 3434e8c904..ef96f59a60 100644
--- a/Marlin/pins_RAMPS_14.h
+++ b/Marlin/pins_RAMPS_14.h
@@ -139,25 +139,13 @@
   #define SLED_PIN           -1
 #endif
 
+#if ENABLED(ULTRA_LCD)
 
-
-#if ENABLED(REPRAPWORLD_GRAPHICAL_LCD)
-
-
-  #define LCD_PINS_RS     49 //CS chip select /SS chip slave select
-  #define LCD_PINS_ENABLE 51 //SID (MOSI)
-  #define LCD_PINS_D4     52 //SCK (CLK) clock     
-
-  #define BTN_EN1             64
-  #define BTN_EN2             59
-  #define BTN_ENC             63
-
-  
-  #define SD_DETECT_PIN 42
-
-#elif ENABLED(ULTRA_LCD)
-
-  #if ENABLED(NEWPANEL) && ENABLED(PANEL_ONE)
+  #if ENABLED(REPRAPWORLD_GRAPHICAL_LCD)
+    #define LCD_PINS_RS     49 //CS chip select /SS chip slave select
+    #define LCD_PINS_ENABLE 51 //SID (MOSI)
+    #define LCD_PINS_D4     52 //SCK (CLK) clock
+  #elif ENABLED(NEWPANEL) && ENABLED(PANEL_ONE)
     #define LCD_PINS_RS 40
     #define LCD_PINS_ENABLE 42
     #define LCD_PINS_D4 65
@@ -198,6 +186,11 @@
         #define LCD_PIN_BL 39
       #endif
 
+    #elif ENABLED(REPRAPWORLD_GRAPHICAL_LCD)
+      #define BTN_EN1 64
+      #define BTN_EN2 59
+      #define BTN_ENC 63
+      #define SD_DETECT_PIN 42
     #elif ENABLED(LCD_I2C_PANELOLU2)
       #define BTN_EN1 47  // reverse if the encoder turns the wrong way.
       #define BTN_EN2 43