From 2e040d03dffac181def5a6962ec5826e6e0b6aee Mon Sep 17 00:00:00 2001
From: Vert <45634861+Vertabreak@users.noreply.github.com>
Date: Tue, 16 Feb 2021 21:29:55 -0500
Subject: [PATCH] GT2560 v4.1B, YHCB2004 SPI character LCD (#21091)

Co-authored-by: Scott Lahteine <github@thinkyhead.com>
---
 Marlin/Configuration.h                        |  8 +++
 Marlin/src/inc/Conditionals_LCD.h             |  4 ++
 Marlin/src/inc/SanityCheck.h                  |  5 +-
 Marlin/src/lcd/HD44780/marlinui_HD44780.cpp   |  4 ++
 Marlin/src/lcd/HD44780/marlinui_HD44780.h     |  5 ++
 Marlin/src/pins/mega/pins_GT2560_V3.h         | 69 +++++++++++++------
 Marlin/src/pins/mega/pins_GT2560_V3_A20.h     |  4 +-
 Marlin/src/pins/mega/pins_GT2560_V3_MC2.h     |  6 +-
 Marlin/src/pins/mega/pins_HJC2560C_REV2.h     |  2 +-
 Marlin/src/pins/stm32f1/pins_GTM32_MINI.h     |  3 +-
 Marlin/src/pins/stm32f1/pins_GTM32_MINI_A30.h |  3 +-
 Marlin/src/pins/stm32f1/pins_GTM32_PRO_VB.h   |  6 +-
 Marlin/src/pins/stm32f1/pins_GTM32_REV_B.h    |  5 +-
 platformio.ini                                |  1 +
 14 files changed, 85 insertions(+), 40 deletions(-)

diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h
index 428e899b330..3234a73eda0 100644
--- a/Marlin/Configuration.h
+++ b/Marlin/Configuration.h
@@ -1953,6 +1953,14 @@
 //
 //#define REPRAP_DISCOUNT_SMART_CONTROLLER
 
+//
+// GT2560 (YHCB2004) LCD Display
+//
+// Requires Testato, Koepel softwarewire library and
+// Andriy Golovnya's LiquidCrystal_AIP31068 library.
+//
+//#define YHCB2004
+
 //
 // Original RADDS LCD Display+Encoder+SDCardReader
 // http://doku.radds.org/dokumentation/lcd-display/
diff --git a/Marlin/src/inc/Conditionals_LCD.h b/Marlin/src/inc/Conditionals_LCD.h
index 17f427a8dd3..7ac4fe4c310 100644
--- a/Marlin/src/inc/Conditionals_LCD.h
+++ b/Marlin/src/inc/Conditionals_LCD.h
@@ -50,6 +50,10 @@
 
   #define MINIPANEL
 
+#elif ENABLED(YHCB2004)
+
+  #define IS_ULTIPANEL 1
+
 #elif ENABLED(CARTESIO_UI)
 
   #define DOGLCD
diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h
index d5d94b178ee..c1b0290ac1f 100644
--- a/Marlin/src/inc/SanityCheck.h
+++ b/Marlin/src/inc/SanityCheck.h
@@ -2296,8 +2296,6 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal
 #if 1 < 0 \
   + ENABLED(REPRAP_DISCOUNT_SMART_CONTROLLER) \
   + ENABLED(REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER) \
-  + ENABLED(ULTIPANEL) \
-  + ENABLED(ULTRA_LCD) \
   + (ENABLED(U8GLIB_SSD1306) && DISABLED(IS_U8GLIB_SSD1306)) \
   + (ENABLED(MINIPANEL) && NONE(MKS_MINI_12864, ENDER2_STOCKDISPLAY)) \
   + (ENABLED(MKS_MINI_12864) && DISABLED(MKS_LCD12864)) \
@@ -2346,6 +2344,9 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal
   + ENABLED(U8GLIB_SH1106_EINSTART) \
   + ENABLED(ULTI_CONTROLLER) \
   + ENABLED(ULTIMAKERCONTROLLER) \
+  + ENABLED(ULTIPANEL) \
+  + ENABLED(ULTRA_LCD) \
+  + ENABLED(YHCB2004) \
   + ENABLED(ZONESTAR_LCD)
   #error "Please select only one LCD controller option."
 #endif
diff --git a/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp b/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp
index 635751b3f5c..15b3d8bfb32 100644
--- a/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp
+++ b/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp
@@ -93,6 +93,10 @@
 
   LCD_CLASS lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
 
+#elif ENABLED(YHCB2004)
+
+  LCD_CLASS lcd(YHCB2004_CLK, 20, 4, YHCB2004_MOSI, YHCB2004_MISO); // CLK, cols, rows, MOSI, MISO
+
 #else
 
   // Standard direct-connected LCD implementations
diff --git a/Marlin/src/lcd/HD44780/marlinui_HD44780.h b/Marlin/src/lcd/HD44780/marlinui_HD44780.h
index 604d26a029b..62c0c762022 100644
--- a/Marlin/src/lcd/HD44780/marlinui_HD44780.h
+++ b/Marlin/src/lcd/HD44780/marlinui_HD44780.h
@@ -90,6 +90,11 @@
   #include <LiquidCrystal_I2C.h>
   #define LCD_CLASS LiquidCrystal_I2C
 
+#elif ENABLED(YHCB2004)
+
+  #include <LiquidCrystal_AIP31068_SPI.h>
+  #define LCD_CLASS LiquidCrystal_AIP31068_SPI
+
 #else
 
   // Standard directly connected LCD implementations
diff --git a/Marlin/src/pins/mega/pins_GT2560_V3.h b/Marlin/src/pins/mega/pins_GT2560_V3.h
index 606debd1b06..586b3b12ec9 100644
--- a/Marlin/src/pins/mega/pins_GT2560_V3.h
+++ b/Marlin/src/pins/mega/pins_GT2560_V3.h
@@ -22,7 +22,7 @@
 #pragma once
 
 /**
- * GT2560 RevB + GT2560 V3.0 + GT2560 V3.1 + GT2560 V4.0 pin assignment
+ * Geeetech GT2560 RevB + GT2560 3.0/3.1 + GT2560 4.0/4.1 pin assignments
  */
 
 #if NOT_TARGET(__AVR_ATmega1280__, __AVR_ATmega2560__)
@@ -30,13 +30,13 @@
 #endif
 
 #ifndef BOARD_INFO_NAME
-  #define BOARD_INFO_NAME "GT2560 V3.0"
+  #define BOARD_INFO_NAME "GT2560 RevB/3.x/4.x"
 #endif
 
 //
 // Servos
 //
-#define SERVO0_PIN                            11  //13 untested  3Dtouch
+#define SERVO0_PIN                            11  // 13 untested  3Dtouch
 
 //
 // Limit Switches
@@ -142,7 +142,10 @@
 #define SDSS                                  53
 #define LED_PIN                               13  // Use 6 (case light) for external LED. 13 is internal (yellow) LED.
 #define PS_ON_PIN                             12
-#define SUICIDE_PIN                           54  // This pin must be enabled at boot to keep power flowing
+
+#if NUM_RUNOUT_SENSORS < 3
+  #define SUICIDE_PIN                         54  // This pin must be enabled at boot to keep power flowing
+#endif
 
 #ifndef CASE_LIGHT_PIN
   #define CASE_LIGHT_PIN                       6  // 21
@@ -153,26 +156,48 @@
 //
 #define BEEPER_PIN                            18
 
-#ifndef LCD_PINS_RS
-  #define LCD_PINS_RS                         20
-#endif
-#ifndef LCD_PINS_ENABLE
-  #define LCD_PINS_ENABLE                     17
-#endif
-#ifndef LCD_PINS_D4
-  #define LCD_PINS_D4                         16
-#endif
-#ifndef LCD_PINS_D5
-  #define LCD_PINS_D5                         21
-#endif
-#ifndef LCD_PINS_D6
-  #define LCD_PINS_D6                          5
-#endif
-#ifndef LCD_PINS_D7
-  #define LCD_PINS_D7                         36
+#if ENABLED(YHCB2004)
+  #ifndef YHCB2004_SCK
+    #define YHCB2004_SCK                      5
+  #endif
+  #ifndef YHCB2004_MOSI
+    #define YHCB2004_MOSI                     21
+  #endif
+  #ifndef YHCB2004_MISO
+    #define YHCB2004_MISO                     36
+  #endif
+#elif HAS_WIRED_LCD
+  #ifndef LCD_PINS_RS
+    #define LCD_PINS_RS                       20
+  #endif
+  #ifndef LCD_PINS_ENABLE
+    #define LCD_PINS_ENABLE                   17
+  #endif
+  #ifndef LCD_PINS_D4
+    #define LCD_PINS_D4                       16
+  #endif
+  #ifndef LCD_PINS_D5
+    #define LCD_PINS_D5                       21
+  #endif
+  #ifndef LCD_PINS_D6
+    #define LCD_PINS_D6                        5
+  #endif
+  #ifndef LCD_PINS_D7
+    #define LCD_PINS_D7                       36
+  #endif
 #endif
 
-#if IS_NEWPANEL
+#if ENABLED(YHCB2004)
+  #ifndef BTN_EN1
+    #define BTN_EN1                           16
+  #endif
+  #ifndef BTN_EN2
+    #define BTN_EN2                           17
+  #endif
+  #ifndef BTN_ENC
+    #define BTN_ENC                           19
+  #endif
+#elif IS_NEWPANEL
   #ifndef BTN_EN1
     #define BTN_EN1                           42
   #endif
diff --git a/Marlin/src/pins/mega/pins_GT2560_V3_A20.h b/Marlin/src/pins/mega/pins_GT2560_V3_A20.h
index c445f5b2418..986dd1cb04b 100644
--- a/Marlin/src/pins/mega/pins_GT2560_V3_A20.h
+++ b/Marlin/src/pins/mega/pins_GT2560_V3_A20.h
@@ -22,7 +22,7 @@
 #pragma once
 
 /**
- * Geeetech A20M pin assignment
+ * Geeetech A20M board pin assignments
  */
 
 #define LCD_PINS_RS                            5
@@ -30,7 +30,7 @@
 #define LCD_PINS_D4                           21
 #define LCD_PINS_D7                            6
 
-#define SPEAKER  // The speaker can produce tones
+#define SPEAKER                                  // The speaker can produce tones
 
 #if IS_NEWPANEL
   #define BTN_EN1                             16
diff --git a/Marlin/src/pins/mega/pins_GT2560_V3_MC2.h b/Marlin/src/pins/mega/pins_GT2560_V3_MC2.h
index 26721df3641..6b22b4139b6 100644
--- a/Marlin/src/pins/mega/pins_GT2560_V3_MC2.h
+++ b/Marlin/src/pins/mega/pins_GT2560_V3_MC2.h
@@ -21,9 +21,9 @@
  */
 #pragma once
 
-/*****************************************************************
- * GT2560 V3.0 pin assignment (for Mecreator 2)
- *****************************************************************/
+/**
+ * Geeetech GT2560 V 3.0 board pin assignments (for Mecreator 2)
+ */
 
 #define BOARD_INFO_NAME "GT2560 V3.0 (MC2)"
 
diff --git a/Marlin/src/pins/mega/pins_HJC2560C_REV2.h b/Marlin/src/pins/mega/pins_HJC2560C_REV2.h
index d507d20ca7a..dc4b78d9c10 100644
--- a/Marlin/src/pins/mega/pins_HJC2560C_REV2.h
+++ b/Marlin/src/pins/mega/pins_HJC2560C_REV2.h
@@ -22,7 +22,7 @@
 #pragma once
 
 /**
- * HJC2560-C Rev2.x pin assignments
+ * Geeetech HJC2560-C Rev 2.x board pin assignments
  */
 
 #if NOT_TARGET(__AVR_ATmega2560__)
diff --git a/Marlin/src/pins/stm32f1/pins_GTM32_MINI.h b/Marlin/src/pins/stm32f1/pins_GTM32_MINI.h
index 5b97e7f202d..f67dc85b40f 100644
--- a/Marlin/src/pins/stm32f1/pins_GTM32_MINI.h
+++ b/Marlin/src/pins/stm32f1/pins_GTM32_MINI.h
@@ -22,8 +22,7 @@
 #pragma once
 
 /**
- * 24 May 2018 - @chepo for STM32F103VET6
- * Schematic: https://github.com/chepo92/Smartto/blob/master/circuit_diagram/Rostock301/Hardware_GTM32_PRO_VB.pdf
+ * Geeetech GTM32 Mini board pin assignments
  */
 
 #if NOT_TARGET(__STM32F1__)
diff --git a/Marlin/src/pins/stm32f1/pins_GTM32_MINI_A30.h b/Marlin/src/pins/stm32f1/pins_GTM32_MINI_A30.h
index 173eb67f0d0..27b0362758a 100644
--- a/Marlin/src/pins/stm32f1/pins_GTM32_MINI_A30.h
+++ b/Marlin/src/pins/stm32f1/pins_GTM32_MINI_A30.h
@@ -22,8 +22,7 @@
 #pragma once
 
 /**
- * 24 May 2018 - @chepo for STM32F103VET6
- * Schematic: https://github.com/chepo92/Smartto/blob/master/circuit_diagram/Rostock301/Hardware_GTM32_PRO_VB.pdf
+ * Geeetech GTM32 Mini A30 board pin assignments
  */
 
 #if NOT_TARGET(__STM32F1__)
diff --git a/Marlin/src/pins/stm32f1/pins_GTM32_PRO_VB.h b/Marlin/src/pins/stm32f1/pins_GTM32_PRO_VB.h
index 5b97e7f202d..d4ab2ff3e5f 100644
--- a/Marlin/src/pins/stm32f1/pins_GTM32_PRO_VB.h
+++ b/Marlin/src/pins/stm32f1/pins_GTM32_PRO_VB.h
@@ -22,15 +22,15 @@
 #pragma once
 
 /**
- * 24 May 2018 - @chepo for STM32F103VET6
- * Schematic: https://github.com/chepo92/Smartto/blob/master/circuit_diagram/Rostock301/Hardware_GTM32_PRO_VB.pdf
+ * Geeetech GTM32 Pro VB/VD board pin assignments
+ * http://www.geeetech.com/wiki/index.php/File:Hardware_GTM32_PRO_VB.pdf
  */
 
 #if NOT_TARGET(__STM32F1__)
   #error "Oops! Select an STM32F1 board in 'Tools > Board.'"
 #endif
 
-#define BOARD_INFO_NAME      "GTM32 Pro VB"
+#define BOARD_INFO_NAME      "GTM32 Pro VB/VD"
 #define DEFAULT_MACHINE_NAME "STM32F103VET6"
 
 #define BOARD_NO_NATIVE_USB
diff --git a/Marlin/src/pins/stm32f1/pins_GTM32_REV_B.h b/Marlin/src/pins/stm32f1/pins_GTM32_REV_B.h
index b4a34a4b1e4..8e96327816a 100644
--- a/Marlin/src/pins/stm32f1/pins_GTM32_REV_B.h
+++ b/Marlin/src/pins/stm32f1/pins_GTM32_REV_B.h
@@ -22,15 +22,14 @@
 #pragma once
 
 /**
- * 24 May 2018 - @chepo for STM32F103VET6
- * Schematic: https://github.com/chepo92/Smartto/blob/master/circuit_diagram/Rostock301/Hardware_GTM32_PRO_VB.pdf
+ * Geeetech GTM32 Rev. B board pin assignments
  */
 
 #if NOT_TARGET(__STM32F1__)
   #error "Oops! Select an STM32F1 board in 'Tools > Board.'"
 #endif
 
-#define BOARD_INFO_NAME      "GTM32 Pro VB"
+#define BOARD_INFO_NAME      "GTM32 Rev B"
 #define DEFAULT_MACHINE_NAME "M201"
 
 #define BOARD_NO_NATIVE_USB
diff --git a/platformio.ini b/platformio.ini
index bcf90df0f2f..15fbf220d4e 100644
--- a/platformio.ini
+++ b/platformio.ini
@@ -219,6 +219,7 @@ lib_deps           =
 # Feature Dependencies
 #
 [features]
+YHCB2004                = red-scorp/LiquidCrystal_AIP31068@^1.0.4, red-scorp/SoftSPIB@^1.1.1
 HAS_TFT_LVGL_UI         = lvgl=https://github.com/makerbase-mks/LVGL-6.1.1-MKS/archive/master.zip
                           src_filter=+<src/lcd/extui/lib/mks_ui>
                           extra_scripts=download_mks_assets.py