From 650e1dd1d22c2dde6b2e09b38b64769d32be578e Mon Sep 17 00:00:00 2001
From: Scott Lahteine <github@thinkyhead.com>
Date: Wed, 14 Jul 2021 18:51:58 -0500
Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Minor=20cleanup=20of=20TFT/FSMC?=
 =?UTF-8?q?=20pins?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h     |  6 +---
 Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h     |  7 +----
 Marlin/src/pins/stm32f1/pins_FLSUN_HISPEED.h  | 18 ++++++-----
 .../src/pins/stm32f1/pins_JGAURORA_A5S_A1.h   | 24 ++++++++++-----
 Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h    | 30 ++++++++++++-------
 .../pins/stm32f1/pins_MINGDA_MPX_ARM_MINI.h   | 21 ++++++-------
 Marlin/src/pins/stm32f1/pins_MKS_ROBIN.h      | 15 +++++-----
 Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h | 20 +++++++------
 Marlin/src/pins/stm32f1/pins_MKS_ROBIN_PRO.h  | 18 ++++++-----
 Marlin/src/pins/stm32f1/pins_TRIGORILLA_PRO.h | 26 +++++++++-------
 Marlin/src/pins/stm32f4/pins_ANET_ET4.h       | 18 ++++++-----
 Marlin/src/pins/stm32f4/pins_LERDGE_K.h       |  3 +-
 12 files changed, 114 insertions(+), 92 deletions(-)

diff --git a/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h b/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h
index 8f5893e3b9..e892d3e3f8 100644
--- a/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h
+++ b/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h
@@ -117,13 +117,9 @@
 #define W25QXX_SCK_PIN                      PB13
 
 //
-// TronXY TFT Support
+// TFT with FSMC interface
 //
-
 #if HAS_FSMC_TFT
-
-  // Shared FSMC
-
   #define TOUCH_CS_PIN                      PB7   // SPI1_NSS
   #define TOUCH_SCK_PIN                     PA5   // SPI1_SCK
   #define TOUCH_MISO_PIN                    PA6   // SPI1_MISO
diff --git a/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h b/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h
index df49da1095..51bd7294a9 100644
--- a/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h
+++ b/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h
@@ -132,13 +132,9 @@
 #define W25QXX_SCK_PIN                      PB13
 
 //
-// TronXY TFT Support
+// TFT with FSMC interface
 //
-
 #if HAS_FSMC_TFT
-
-  // Shared FSMC
-
   #define TOUCH_CS_PIN                      PB7   // SPI1_NSS
   #define TOUCH_SCK_PIN                     PA5   // SPI1_SCK
   #define TOUCH_MISO_PIN                    PA6   // SPI1_MISO
@@ -152,7 +148,6 @@
   #define FSMC_RS_PIN                       PD11
   #define FSMC_DMA_DEV                      DMA2
   #define FSMC_DMA_CHANNEL               DMA_CH5
-
 #endif
 
 #if ENABLED(TFT_LVGL_UI)
diff --git a/Marlin/src/pins/stm32f1/pins_FLSUN_HISPEED.h b/Marlin/src/pins/stm32f1/pins_FLSUN_HISPEED.h
index c49c31e741..bdf3f48c3a 100644
--- a/Marlin/src/pins/stm32f1/pins_FLSUN_HISPEED.h
+++ b/Marlin/src/pins/stm32f1/pins_FLSUN_HISPEED.h
@@ -271,11 +271,9 @@
   #error "FLSun HiSpeed default BEEPER_PIN is not a SPEAKER."
 #endif
 
-#if HAS_FSMC_TFT || HAS_GRAPHICAL_TFT
-  #define TFT_CS_PIN                        PD7   // NE4
-  #define TFT_RS_PIN                        PD11  // A0
-#endif
-
+//
+// TFT with FSMC interface
+//
 #if HAS_FSMC_TFT
   /**
    * Note: MKS Robin TFT screens use various TFT controllers
@@ -291,12 +289,16 @@
    */
   //#define TFT_RESET_PIN                   PC6   // FSMC_RST
   #define TFT_BACKLIGHT_PIN                 PD13
-  #define FSMC_CS_PIN                 TFT_CS_PIN  // NE4
-  #define FSMC_RS_PIN                 TFT_RS_PIN  // A0
 
   #define LCD_USE_DMA_FSMC                        // Use DMA transfers to send data to the TFT
+  #define FSMC_CS_PIN                       PD7   // NE4
+  #define FSMC_RS_PIN                       PD11  // A0
   #define FSMC_DMA_DEV                      DMA2
   #define FSMC_DMA_CHANNEL               DMA_CH5
+
+  #define TFT_CS_PIN                  TFT_CS_PIN
+  #define TFT_RS_PIN                  TFT_RS_PIN
+
   #ifdef TFT_CLASSIC_UI
     #define TFT_MARLINBG_COLOR            0x3186  // Grey
     #define TFT_MARLINUI_COLOR            0xC7B6  // Green
@@ -307,6 +309,8 @@
 #elif HAS_GRAPHICAL_TFT
   #define TFT_RESET_PIN                     PC6
   #define TFT_BACKLIGHT_PIN                 PD13
+  #define TFT_CS_PIN                        PD7   // NE4
+  #define TFT_RS_PIN                        PD11  // A0
 #endif
 
 #if NEED_TOUCH_PINS
diff --git a/Marlin/src/pins/stm32f1/pins_JGAURORA_A5S_A1.h b/Marlin/src/pins/stm32f1/pins_JGAURORA_A5S_A1.h
index 9f08f18bf7..bded0edd3a 100644
--- a/Marlin/src/pins/stm32f1/pins_JGAURORA_A5S_A1.h
+++ b/Marlin/src/pins/stm32f1/pins_JGAURORA_A5S_A1.h
@@ -26,6 +26,8 @@
   *  ║║ ╦╠═╣│ │├┬┘│ │├┬┘├─┤╠╣ │ │├┬┘│ ││││ │  │ ││││
   * ╚╝╚═╝╩ ╩└─┘┴└─└─┘┴└─┴ ┴╚  └─┘┴└─└─┘┴ ┴o└─┘└─┘┴ ┴
   *   Pin assignments for 32-bit JGAurora A5S & A1
+  *
+  * https://jgaurorawiki.com/_media/jgaurora_a5s_a1_pinout.png
   */
 
 #include "env_validate.h"
@@ -102,15 +104,20 @@
 #define FIL_RUNOUT_PIN                      PC7
 
 //
-// LCD
+// TFT with FSMC interface
 //
-#define LCD_BACKLIGHT_PIN                   PF11
-#define FSMC_CS_PIN                         PD7
-#define FSMC_RS_PIN                         PG0
+#if HAS_FSMC_TFT
+  #define LCD_BACKLIGHT_PIN                 PF11
+  #define FSMC_CS_PIN                       PD7
+  #define FSMC_RS_PIN                       PG0
 
-#define LCD_USE_DMA_FSMC                          // Use DMA transfers to send data to the TFT
-#define FSMC_DMA_DEV                        DMA2
-#define FSMC_DMA_CHANNEL                 DMA_CH5
+  #define LCD_USE_DMA_FSMC                        // Use DMA transfers to send data to the TFT
+  #define FSMC_DMA_DEV                      DMA2
+  #define FSMC_DMA_CHANNEL               DMA_CH5
+
+  #define TFT_CS_PIN                 FSMC_CS_PIN
+  #define TFT_RS_PIN                 FSMC_RS_PIN
+#endif
 
 //
 // SD Card
@@ -129,4 +136,7 @@
 #if NEED_TOUCH_PINS
   #define TOUCH_CS_PIN                      PA4
   #define TOUCH_INT_PIN                     PC4
+  #define TOUCH_MISO_PIN                    PA6
+  #define TOUCH_MOSI_PIN                    PA7
+  #define TOUCH_SCK_PIN                     PA5
 #endif
diff --git a/Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h b/Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h
index fa708b248e..391610522d 100644
--- a/Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h
+++ b/Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h
@@ -117,20 +117,28 @@
   //#undef Z_MAX_PIN                              // Uncomment if using ZMAX connector (PE5)
 #endif
 
-#define TFT_RESET_PIN                       PC4   // pin 33
-#define TFT_BACKLIGHT_PIN                   PD12  // pin 59
-#define FSMC_CS_PIN                         PD7   // pin 88 = FSMC_NE1
-#define FSMC_RS_PIN                         PD11  // pin 58 A16 Register. Only one address needed
+//
+// TFT with FSMC interface
+//
+#if HAS_FSMC_TFT
+  #define LCD_USE_DMA_FSMC                        // Use DMA transfers to send data to the TFT
+  #define FSMC_CS_PIN                       PD7   // pin 88 = FSMC_NE1
+  #define FSMC_RS_PIN                       PD11  // pin 58 A16 Register. Only one address needed
+  #define FSMC_DMA_DEV                      DMA2
+  #define FSMC_DMA_CHANNEL               DMA_CH5
 
-#define LCD_USE_DMA_FSMC                          // Use DMA transfers to send data to the TFT
-#define FSMC_DMA_DEV                        DMA2
-#define FSMC_DMA_CHANNEL                 DMA_CH5
+  #define TFT_CS_PIN                 FSMC_CS_PIN
+  #define TFT_RS_PIN                 FSMC_RS_PIN
 
-#define DOGLCD_MOSI                         -1    // Prevent auto-define by Conditionals_post.h
-#define DOGLCD_SCK                          -1
+  #define TFT_RESET_PIN                     PC4   // pin 33
+  #define TFT_BACKLIGHT_PIN                 PD12  // pin 59
 
-// Buffer for Color UI
-#define TFT_BUFFER_SIZE                     3200
+  #define DOGLCD_MOSI                       -1    // Prevent auto-define by Conditionals_post.h
+  #define DOGLCD_SCK                        -1
+
+  // Buffer for Color UI
+  #define TFT_BUFFER_SIZE                   3200
+#endif
 
 /**
  * Note: Alfawise U20/U30 boards DON'T use SPI2, as the hardware designer
diff --git a/Marlin/src/pins/stm32f1/pins_MINGDA_MPX_ARM_MINI.h b/Marlin/src/pins/stm32f1/pins_MINGDA_MPX_ARM_MINI.h
index 429cf14ac5..d2f77e8727 100644
--- a/Marlin/src/pins/stm32f1/pins_MINGDA_MPX_ARM_MINI.h
+++ b/Marlin/src/pins/stm32f1/pins_MINGDA_MPX_ARM_MINI.h
@@ -133,11 +133,9 @@
 //
 #define BEEPER_PIN                          PE4
 
-/**
- * Note: MKS Robin TFT screens use various TFT controllers.
- * If the screen stays white, disable 'LCD_RESET_PIN'
- * to let the bootloader init the screen.
- */
+//
+// TFT with FSMC interface
+//
 #if HAS_FSMC_TFT
   /**
    * Note: MKS Robin TFT screens use various TFT controllers
@@ -151,18 +149,17 @@
    * Setting an 'TFT_RESET_PIN' may cause a flicker when entering the LCD menu
    * because Marlin uses the reset as a failsafe to revive a glitchy LCD.
    */
-  #define TFT_CS_PIN                        PD7   // NE4
-  #define TFT_RS_PIN                        PG0   // A0
-
-  #define FSMC_CS_PIN                 TFT_CS_PIN
-  #define FSMC_RS_PIN                 TFT_RS_PIN
+  #define TFT_RESET_PIN                     PF15
+  #define TFT_BACKLIGHT_PIN                 PF11
 
   #define LCD_USE_DMA_FSMC                        // Use DMA transfers to send data to the TFT
+  #define FSMC_CS_PIN                       PD7   // NE4
+  #define FSMC_RS_PIN                       PG0   // A0
   #define FSMC_DMA_DEV                      DMA2
   #define FSMC_DMA_CHANNEL               DMA_CH5
 
-  #define TFT_RESET_PIN                     PF15
-  #define TFT_BACKLIGHT_PIN                 PF11
+  #define TFT_CS_PIN                 FSMC_CS_PIN
+  #define TFT_RS_PIN                 FSMC_RS_PIN
 
   #define TOUCH_BUTTONS_HW_SPI
   #define TOUCH_BUTTONS_HW_SPI_DEVICE          1
diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN.h
index b9f1074c7a..39638599e3 100644
--- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN.h
+++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN.h
@@ -155,7 +155,7 @@
 #define WIFI_IO0_PIN                        PG1
 
 //
-// LCD screen
+// TFT with FSMC interface
 //
 #if HAS_FSMC_TFT
   /**
@@ -170,18 +170,17 @@
    * Setting an 'TFT_RESET_PIN' may cause a flicker when entering the LCD menu
    * because Marlin uses the reset as a failsafe to revive a glitchy LCD.
    */
-  #define TFT_CS_PIN                        PG12  // NE4
-  #define TFT_RS_PIN                        PF0   // A0
-
-  #define FSMC_CS_PIN                 TFT_CS_PIN
-  #define FSMC_RS_PIN                 TFT_RS_PIN
+  #define TFT_RESET_PIN                     PF6
+  #define TFT_BACKLIGHT_PIN                 PG11
 
   #define LCD_USE_DMA_FSMC                        // Use DMA transfers to send data to the TFT
+  #define FSMC_CS_PIN                       PG12  // NE4
+  #define FSMC_RS_PIN                       PF0   // A0
   #define FSMC_DMA_DEV                      DMA2
   #define FSMC_DMA_CHANNEL               DMA_CH5
 
-  #define TFT_RESET_PIN                     PF6
-  #define TFT_BACKLIGHT_PIN                 PG11
+  #define TFT_CS_PIN                 FSMC_CS_PIN
+  #define TFT_RS_PIN                 FSMC_RS_PIN
 
   #define TOUCH_BUTTONS_HW_SPI
   #define TOUCH_BUTTONS_HW_SPI_DEVICE          2
diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h
index ea3a7a1eea..a07af0e692 100644
--- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h
+++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h
@@ -172,13 +172,18 @@
 //
 #define BEEPER_PIN                          PC5
 
-/**
- * Note: MKS Robin TFT screens use various TFT controllers.
- * If the screen stays white, disable 'TFT_RESET_PIN'
- * to let the bootloader init the screen.
- */
-// Shared FSMC Configs
+//
+// TFT with FSMC interface
+//
 #if HAS_FSMC_TFT
+  /**
+   * Note: MKS Robin TFT screens use various TFT controllers.
+   * If the screen stays white, disable 'TFT_RESET_PIN'
+   * to let the bootloader init the screen.
+   */
+  #define TFT_RESET_PIN                     PC6   // FSMC_RST
+  #define TFT_BACKLIGHT_PIN                 PD13
+
   #define DOGLCD_MOSI                       -1    // Prevent auto-define by Conditionals_post.h
   #define DOGLCD_SCK                        -1
 
@@ -187,9 +192,6 @@
   #define TOUCH_MISO_PIN                    PB14  // SPI2_MISO
   #define TOUCH_MOSI_PIN                    PB15  // SPI2_MOSI
 
-  #define TFT_RESET_PIN                     PC6   // FSMC_RST
-  #define TFT_BACKLIGHT_PIN                 PD13
-
   #define LCD_USE_DMA_FSMC                        // Use DMA transfers to send data to the TFT
   #define FSMC_CS_PIN                       PD7
   #define FSMC_RS_PIN                       PD11
diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_PRO.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_PRO.h
index b56971c7a3..7e416a9937 100644
--- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_PRO.h
+++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_PRO.h
@@ -205,12 +205,18 @@
   #error "No custom SD drive cable defined for this board."
 #endif
 
-/**
- * Note: MKS Robin TFT screens use various TFT controllers.
- * If the screen stays white, disable 'LCD_RESET_PIN'
- * to let the bootloader init the screen.
- */
+//
+// TFT with FSMC interface
+//
 #if HAS_FSMC_TFT
+  /**
+   * Note: MKS Robin TFT screens use various TFT controllers.
+   * If the screen stays white, disable 'LCD_RESET_PIN'
+   * to let the bootloader init the screen.
+   */
+  #define TFT_RESET_PIN            LCD_RESET_PIN
+  #define TFT_BACKLIGHT_PIN    LCD_BACKLIGHT_PIN
+
   #define FSMC_CS_PIN                       PD7   // NE4
   #define FSMC_RS_PIN                       PD11  // A0
   #define FSMC_DMA_DEV                      DMA2
@@ -221,8 +227,6 @@
 
   #define LCD_RESET_PIN                     PF6
   #define LCD_BACKLIGHT_PIN                 PD13
-  #define TFT_RESET_PIN            LCD_RESET_PIN
-  #define TFT_BACKLIGHT_PIN    LCD_BACKLIGHT_PIN
 
   #define TFT_BUFFER_SIZE                  14400
 
diff --git a/Marlin/src/pins/stm32f1/pins_TRIGORILLA_PRO.h b/Marlin/src/pins/stm32f1/pins_TRIGORILLA_PRO.h
index 5eefedb141..1de3729dcc 100644
--- a/Marlin/src/pins/stm32f1/pins_TRIGORILLA_PRO.h
+++ b/Marlin/src/pins/stm32f1/pins_TRIGORILLA_PRO.h
@@ -126,20 +126,24 @@
 //#define POWER_LOSS_PIN                    PG2   // PG4 PW_DET
 #define FIL_RUNOUT_PIN                      PA15  // MT_DET
 
-/**
- * Note: MKS Robin TFT screens use various TFT controllers
- * Supported screens are based on the ILI9341, ST7789V and ILI9328 (320x240)
- * ILI9488 is not supported.
- * Define init sequences for other screens in u8g_dev_tft_320x240_upscale_from_128x64.cpp
- *
- * If the screen stays white, disable 'LCD_RESET_PIN' to let the bootloader init the screen.
- *
- * Setting an 'LCD_RESET_PIN' may cause a flicker when entering the LCD menu
- * because Marlin uses the reset as a failsafe to revive a glitchy LCD.
- */
+//
+// TFT with FSMC interface
+//
 #if HAS_FSMC_TFT
+  /**
+   * Note: MKS Robin TFT screens use various TFT controllers
+   * Supported screens are based on the ILI9341, ST7789V and ILI9328 (320x240)
+   * ILI9488 is not supported.
+   * Define init sequences for other screens in u8g_dev_tft_320x240_upscale_from_128x64.cpp
+   *
+   * If the screen stays white, disable 'LCD_RESET_PIN' to let the bootloader init the screen.
+   *
+   * Setting an 'LCD_RESET_PIN' may cause a flicker when entering the LCD menu
+   * because Marlin uses the reset as a failsafe to revive a glitchy LCD.
+   */
   #define TFT_RESET_PIN                     PF11
   #define TFT_BACKLIGHT_PIN                 PD13
+
   #define FSMC_CS_PIN                       PD7   // NE4
   #define FSMC_RS_PIN                       PD11  // A0
 
diff --git a/Marlin/src/pins/stm32f4/pins_ANET_ET4.h b/Marlin/src/pins/stm32f4/pins_ANET_ET4.h
index 1e1f5251c1..d2ee2e013c 100644
--- a/Marlin/src/pins/stm32f4/pins_ANET_ET4.h
+++ b/Marlin/src/pins/stm32f4/pins_ANET_ET4.h
@@ -136,14 +136,18 @@
 //
 // LCD / Controller
 //
-#define TFT_RESET_PIN                       PE6
-#define TFT_CS_PIN                          PD7
-#define TFT_RS_PIN                          PD13
-#define TFT_INTERFACE_FSMC_8BIT
+#if HAS_SPI_TFT || HAS_FSMC_TFT
+  #define TFT_RESET_PIN                     PE6
+  #define TFT_CS_PIN                        PD7
+  #define TFT_RS_PIN                        PD13
 
-#define LCD_USE_DMA_FSMC                          // Use DMA transfers to send data to the TFT
-#define FSMC_CS_PIN                   TFT_CS_PIN
-#define FSMC_RS_PIN                   TFT_RS_PIN
+  #if HAS_FSMC_TFT
+    #define LCD_USE_DMA_FSMC                      // Use DMA transfers to send data to the TFT
+    #define FSMC_CS_PIN               TFT_CS_PIN
+    #define FSMC_RS_PIN               TFT_RS_PIN
+    #define TFT_INTERFACE_FSMC_8BIT
+  #endif
+#endif
 
 //
 // Touch Screen
diff --git a/Marlin/src/pins/stm32f4/pins_LERDGE_K.h b/Marlin/src/pins/stm32f4/pins_LERDGE_K.h
index b92056ea86..3b75e7072a 100644
--- a/Marlin/src/pins/stm32f4/pins_LERDGE_K.h
+++ b/Marlin/src/pins/stm32f4/pins_LERDGE_K.h
@@ -230,9 +230,8 @@
 #define BEEPER_PIN                          PC7
 
 //
-// LCD / Controller
+// TFT with FSMC interface
 //
-
 #if HAS_FSMC_TFT
   //#define TFT_DRIVER             LERDGE_ST7796