From 2603a237f9553fe55262e4612a7a78fb98f030a4 Mon Sep 17 00:00:00 2001
From: thisiskeithb <13375512+thisiskeithb@users.noreply.github.com>
Date: Tue, 16 Jun 2020 00:43:09 -0700
Subject: [PATCH] Add MKS LCD12864 A/B Controller Support (#18120)

---
 Marlin/Configuration.h                         |  6 ++++++
 Marlin/src/inc/Conditionals_LCD.h              | 14 +++++++++-----
 Marlin/src/inc/Conditionals_post.h             |  2 +-
 Marlin/src/inc/SanityCheck.h                   |  3 ++-
 Marlin/src/lcd/dogm/ultralcd_DOGM.cpp          |  4 ++--
 Marlin/src/pins/ramps/pins_RAMPS.h             |  2 +-
 Marlin/src/pins/samd/pins_RAMPS_144.h          |  2 +-
 Marlin/src/pins/stm32f1/pins_BTT_SKR_E3_DIP.h  |  2 +-
 Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3.h    |  8 +++-----
 Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3D.h   |  4 +---
 Marlin/src/pins/stm32f1/pins_MKS_ROBIN_LITE3.h |  2 --
 11 files changed, 27 insertions(+), 22 deletions(-)

diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h
index f3ed3cb91f..6352f9e6ef 100644
--- a/Marlin/Configuration.h
+++ b/Marlin/Configuration.h
@@ -1995,6 +1995,12 @@
 //
 //#define MKS_MINI_12864
 
+//
+// MKS LCD12864A/B with graphic controller and SD support. Follows MKS_MINI_12864 pinout.
+// https://www.aliexpress.com/item/33018110072.html
+//
+//#define MKS_LCD12864
+
 //
 // FYSETC variant of the MINI12864 graphic controller with SD support
 // https://wiki.fysetc.com/Mini12864_Panel/
diff --git a/Marlin/src/inc/Conditionals_LCD.h b/Marlin/src/inc/Conditionals_LCD.h
index df4c5aade0..c54687a2d5 100644
--- a/Marlin/src/inc/Conditionals_LCD.h
+++ b/Marlin/src/inc/Conditionals_LCD.h
@@ -35,7 +35,15 @@
   #define IS_CARTESIAN 1
 #endif
 
-#if ENABLED(CARTESIO_UI)
+#if ENABLED(MKS_LCD12864)
+  #define MKS_MINI_12864
+#endif
+
+#if EITHER(MKS_MINI_12864, ENDER2_STOCKDISPLAY)
+
+  #define MINIPANEL
+
+#elif ENABLED(CARTESIO_UI)
 
   #define DOGLCD
   #define IS_ULTIPANEL
@@ -118,10 +126,6 @@
   #define IS_RRD_SC
   #define IS_U8GLIB_SSD1306
 
-#elif EITHER(MKS_MINI_12864, ENDER2_STOCKDISPLAY)
-
-  #define MINIPANEL
-
 #elif ANY(FYSETC_MINI_12864_X_X, FYSETC_MINI_12864_1_2, FYSETC_MINI_12864_2_0, FYSETC_MINI_12864_2_1, FYSETC_GENERIC_12864_1_1)
 
   #define FYSETC_MINI_12864
diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h
index 9fe25e8778..73d878de22 100644
--- a/Marlin/src/inc/Conditionals_post.h
+++ b/Marlin/src/inc/Conditionals_post.h
@@ -287,7 +287,7 @@
 #elif ENABLED(AZSMZ_12864)
   #define _LCD_CONTRAST_MIN  120
   #define _LCD_CONTRAST_INIT 190
-#elif ENABLED(MKS_LCD12864B)
+#elif ENABLED(MKS_LCD12864)
   #define _LCD_CONTRAST_MIN  120
   #define _LCD_CONTRAST_INIT 205
 #elif EITHER(MKS_MINI_12864, ENDER2_STOCKDISPLAY)
diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h
index 074ef9ec9b..4c42c7f179 100644
--- a/Marlin/src/inc/SanityCheck.h
+++ b/Marlin/src/inc/SanityCheck.h
@@ -2117,6 +2117,7 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal
   + (ENABLED(ULTRA_LCD) && DISABLED(IS_ULTRA_LCD)) \
   + (ENABLED(U8GLIB_SSD1306) && DISABLED(IS_U8GLIB_SSD1306)) \
   + (ENABLED(MINIPANEL) && DISABLED(MKS_MINI_12864, ENDER2_STOCKDISPLAY)) \
+  + (ENABLED(MKS_MINI_12864) && DISABLED(MKS_LCD12864)) \
   + (ENABLED(EXTENSIBLE_UI) && DISABLED(IS_EXTUI)) \
   + (ENABLED(ULTIPANEL) && DISABLED(IS_ULTIPANEL)) \
   + ENABLED(RADDS_DISPLAY) \
@@ -2143,7 +2144,7 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal
   + ENABLED(CARTESIO_UI) \
   + ENABLED(LCD_FOR_MELZI) \
   + ENABLED(ULTI_CONTROLLER) \
-  + ENABLED(MKS_MINI_12864) \
+  + ENABLED(MKS_LCD12864) \
   + ENABLED(ENDER2_STOCKDISPLAY) \
   + ENABLED(FYSETC_MINI_12864_X_X) \
   + ENABLED(FYSETC_MINI_12864_1_2) \
diff --git a/Marlin/src/lcd/dogm/ultralcd_DOGM.cpp b/Marlin/src/lcd/dogm/ultralcd_DOGM.cpp
index afeeebc660..60c7cc2c30 100644
--- a/Marlin/src/lcd/dogm/ultralcd_DOGM.cpp
+++ b/Marlin/src/lcd/dogm/ultralcd_DOGM.cpp
@@ -240,7 +240,7 @@ bool MarlinUI::detected() { return true; }
 
 // Initialize or re-initialize the LCD
 void MarlinUI::init_lcd() {
-  #if DISABLED(MKS_LCD12864B)
+  #if DISABLED(MKS_LCD12864)
 
     #if PIN_EXISTS(LCD_BACKLIGHT)
       OUT_WRITE(LCD_BACKLIGHT_PIN, DISABLED(DELAYED_BACKLIGHT_INIT)); // Illuminate after reset or right away
@@ -272,7 +272,7 @@ void MarlinUI::init_lcd() {
     TERN_(LCD_SCREEN_ROT_180, u8g.setRot180());
     TERN_(LCD_SCREEN_ROT_270, u8g.setRot270());
 
-  #endif // !MKS_LCD12864B
+  #endif // !MKS_LCD12864
 
   uxg_SetUtf8Fonts(g_fontinfo, COUNT(g_fontinfo));
 }
diff --git a/Marlin/src/pins/ramps/pins_RAMPS.h b/Marlin/src/pins/ramps/pins_RAMPS.h
index 8f7b745e66..0c36b19b66 100644
--- a/Marlin/src/pins/ramps/pins_RAMPS.h
+++ b/Marlin/src/pins/ramps/pins_RAMPS.h
@@ -603,7 +603,7 @@
         #define KILL_PIN                      41
       #endif
 
-      #if ENABLED(MKS_MINI_12864)                 // Added in Marlin 1.1.6
+      #if ENABLED(MKS_MINI_12864)
 
         #define DOGLCD_A0                     27
         #define DOGLCD_CS                     25
diff --git a/Marlin/src/pins/samd/pins_RAMPS_144.h b/Marlin/src/pins/samd/pins_RAMPS_144.h
index 566a726559..d95e86907f 100644
--- a/Marlin/src/pins/samd/pins_RAMPS_144.h
+++ b/Marlin/src/pins/samd/pins_RAMPS_144.h
@@ -473,7 +473,7 @@
       //  #define KILL_PIN         41
       //#endif
 
-      #if ENABLED(MKS_MINI_12864)                 // Added in Marlin 1.1.6
+      #if ENABLED(MKS_MINI_12864)
 
         // TO TEST
         //#define DOGLCD_A0                   27
diff --git a/Marlin/src/pins/stm32f1/pins_BTT_SKR_E3_DIP.h b/Marlin/src/pins/stm32f1/pins_BTT_SKR_E3_DIP.h
index 7fb1c48bec..b0c5673579 100644
--- a/Marlin/src/pins/stm32f1/pins_BTT_SKR_E3_DIP.h
+++ b/Marlin/src/pins/stm32f1/pins_BTT_SKR_E3_DIP.h
@@ -222,7 +222,7 @@
     #define LCD_BACKLIGHT_PIN               -1
 
   #else
-    #error "Only CR10_STOCKDISPLAY, ZONESTAR_LCD, ENDER2_STOCKDISPLAY, and MKS_MINI_12864 are currently supported on the BIGTREE_SKR_E3_DIP."
+    #error "Only CR10_STOCKDISPLAY, ZONESTAR_LCD, ENDER2_STOCKDISPLAY, MKS_MINI_12864, and MKS_LCD12864 are currently supported on the BIGTREE_SKR_E3_DIP."
   #endif
 
 #endif // HAS_SPI_LCD
diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3.h
index c441efaf74..abb6d26c09 100644
--- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3.h
+++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3.h
@@ -123,8 +123,8 @@
 //
 // Temperature Sensors
 //
-#define TEMP_BED_PIN                        PA1   //TB
-#define TEMP_0_PIN                          PA0   //TH1
+#define TEMP_BED_PIN                        PA1   // TB
+#define TEMP_0_PIN                          PA0   // TH1
 
 #define FIL_RUNOUT_PIN                      PB10  // MT_DET
 
@@ -157,11 +157,9 @@
     #define DOGLCD_SCK                      PB13
     #define DOGLCD_MOSI                     PB15
 
-    // Required for MKS_MINI_12864 with this board
-    #define MKS_LCD12864B
     #undef SHOW_BOOTSCREEN
 
-  #else                                           // !MKS_MINI_12864
+  #else
 
     #define LCD_PINS_D4                     PA6
     #if ENABLED(ULTIPANEL)
diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3D.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3D.h
index 6111bef8f7..8f0ecd09f5 100644
--- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3D.h
+++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3D.h
@@ -184,11 +184,9 @@
     #define DOGLCD_SCK                      PB13
     #define DOGLCD_MOSI                     PB15
 
-    // Required for MKS_MINI_12864 with this board
-    #define MKS_LCD12864B
     #undef SHOW_BOOTSCREEN
 
-  #else                                           // !MKS_MINI_12864
+  #else
 
     #define LCD_PINS_D4                     PA6
     #if ENABLED(ULTIPANEL)
diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_LITE3.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_LITE3.h
index 466bdecc81..5f94a15099 100644
--- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_LITE3.h
+++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_LITE3.h
@@ -115,8 +115,6 @@
     #define DOGLCD_SCK                      PB13
     #define DOGLCD_MOSI                     PB15
 
-    // Required for MKS_MINI_12864 with this board
-    #define MKS_LCD12864B
     #undef SHOW_BOOTSCREEN
 
   #else                                           // !MKS_MINI_12864