From 3fd8ef52c5d4a51a25207ba2e3d67a783cbdea88 Mon Sep 17 00:00:00 2001
From: Gustavo Alvarez <462213+sl1pkn07@users.noreply.github.com>
Date: Tue, 5 May 2020 09:38:06 +0200
Subject: [PATCH] More FTDI EVE fixes (RAMPS, Cheetah) (#17759)

---
 Marlin/Configuration_adv.h                    |  2 +-
 .../lib/ftdi_eve_touch_ui/pin_mappings.h      | 51 ++++++++---------
 Marlin/src/pins/ramps/pins_RAMPS.h            |  2 +
 Marlin/src/pins/stm32f1/pins_FYSETC_CHEETAH.h | 56 +++++++++++++++----
 4 files changed, 72 insertions(+), 39 deletions(-)

diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h
index 6fca978d5c..8d6e67582d 100644
--- a/Marlin/Configuration_adv.h
+++ b/Marlin/Configuration_adv.h
@@ -1387,7 +1387,7 @@
   //#define CR10_TFT_PINMAP     // Rudolph Riedel's CR10 pin mapping
   //#define S6_TFT_PINMAP       // FYSETC S6 pin mapping
   //#define CHEETAH_TFT_PINMAP  // FYSETC Cheetah pin mapping
-  //#define E3_EXP1_PINMAP      // E3 type boards (SKR E3/DIP, FYSETC Cheetah and Stock boards) EXP1 pin mapping
+  //#define E3_EXP1_PINMAP      // E3 type boards (SKR E3/DIP, and Stock boards) EXP1 pin mapping
   //#define GENERIC_EXP2_PINMAP // GENERIC EXP2 pin mapping
 
   //#define OTHER_PIN_LAYOUT  // Define pins manually below
diff --git a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/pin_mappings.h b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/pin_mappings.h
index 2187ebd8ee..3b9dc56bc1 100644
--- a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/pin_mappings.h
+++ b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/pin_mappings.h
@@ -27,31 +27,13 @@
  * without adding new pin definitions to the board.
  */
 
-#ifdef CHEETAH_TFT_PINMAP
-  #ifndef __MARLIN_FIRMWARE__
-    #error "This pin mapping requires Marlin."
-  #endif
-
-    #define CLCD_SPI_BUS    2
-
-    #define CLCD_MOD_RESET  PC9
-    #define CLCD_SPI_CS     PB12
-
-    //#define CLCD_USE_SOFT_SPI
-    #if ENABLED(CLCD_USE_SOFT_SPI)
-      #define CLCD_SOFT_SPI_MOSI PB15
-      #define CLCD_SOFT_SPI_MISO PB14
-      #define CLCD_SOFT_SPI_SCLK PB13
-    #endif
-#endif
-
 #ifdef S6_TFT_PINMAP
   #ifndef __MARLIN_FIRMWARE__
     #error "This pin mapping requires Marlin."
   #endif
 
-  #define CLCD_SPI_CS         PC7
-  #define CLCD_MOD_RESET      PC6
+  #define CLCD_SPI_CS                    PC7
+  #define CLCD_MOD_RESET                 PC6
 #endif
 
 #ifdef CR10_TFT_PINMAP
@@ -60,13 +42,13 @@
   #endif
 
   #define CLCD_USE_SOFT_SPI
-  #define CLCD_SOFT_SPI_SCLK  LCD_PINS_D4      // PORTA1               Pin 6
-  #define CLCD_SOFT_SPI_MOSI  LCD_PINS_ENABLE  // PORTC1               Pin 8
-  #define CLCD_SPI_CS         LCD_PINS_RS      // PORTA3               Pin 7
-  #define CLCD_SOFT_SPI_MISO  16               // PORTC0   BTN_ENC     Pin 2
-  #define CLCD_MOD_RESET      11               // PORTD3   BTN_EN1     Pin 3
-  #define CLCD_AUX_0          10               // PORTD2   BTN_EN2     Pin 5
-  #define CLCD_AUX_1          BEEPER_PIN       // PORTA4               Pin 1
+  #define CLCD_SOFT_SPI_SCLK             LCD_PINS_D4      // PORTA1               Pin 6
+  #define CLCD_SOFT_SPI_MOSI             LCD_PINS_ENABLE  // PORTC1               Pin 8
+  #define CLCD_SPI_CS                    LCD_PINS_RS      // PORTA3               Pin 7
+  #define CLCD_SOFT_SPI_MISO             16               // PORTC0   BTN_ENC     Pin 2
+  #define CLCD_MOD_RESET                 11               // PORTD3   BTN_EN1     Pin 3
+  #define CLCD_AUX_0                     10               // PORTD2   BTN_EN2     Pin 5
+  #define CLCD_AUX_1                     BEEPER_PIN       // PORTA4               Pin 1
 #endif
 
 /**
@@ -181,3 +163,18 @@
   #define CLCD_MOD_RESET                 BTN_EN1
   #define CLCD_SPI_CS                    LCD_PINS_RS
 #endif
+
+#ifdef CHEETAH_TFT_PINMAP
+  #ifndef __MARLIN_FIRMWARE__
+    #error "This pin mapping requires Marlin."
+  #endif
+
+  #define CLCD_MOD_RESET                 BTN_EN2
+  #define CLCD_SPI_CS                    LCD_PINS_RS
+
+  #if ENABLED(CLCD_USE_SOFT_SPI)
+    #define CLCD_SOFT_SPI_MOSI           LCD_PINS_ENABLE
+    #define CLCD_SOFT_SPI_MISO           LCD_PINS_RS
+    #define CLCD_SOFT_SPI_SCLK           LCD_PINS_D4
+  #endif
+#endif
diff --git a/Marlin/src/pins/ramps/pins_RAMPS.h b/Marlin/src/pins/ramps/pins_RAMPS.h
index c27b766688..4ba2628b09 100644
--- a/Marlin/src/pins/ramps/pins_RAMPS.h
+++ b/Marlin/src/pins/ramps/pins_RAMPS.h
@@ -753,6 +753,8 @@
    *   EXP2-1 ----------- EXP1-2
    *  EXP1-10 ----------- EXP1-1
    *
+   *  NOTE: The MISO pin should not get a 5V signal.
+   *        To fix, insert a 1N4148 diode in the MISO line.
    */
 
   #define BEEPER_PIN                          37
diff --git a/Marlin/src/pins/stm32f1/pins_FYSETC_CHEETAH.h b/Marlin/src/pins/stm32f1/pins_FYSETC_CHEETAH.h
index 63377f8e16..140e1acfb4 100644
--- a/Marlin/src/pins/stm32f1/pins_FYSETC_CHEETAH.h
+++ b/Marlin/src/pins/stm32f1/pins_FYSETC_CHEETAH.h
@@ -107,15 +107,35 @@
 //
 // LCD Pins
 //
+/**
+ *                 _____
+ *             5V | 1 2 | GND
+ *    (MOSI) PB15 | 3 4 | PB12 (LCD_EN)
+ *     (SCK) PB13 | 5 6   PC11 (BTN_EN1)
+ *  (LCD_RS) PB14 | 7 8 | PC10 (BTN_EN2)
+ * (BTN_ENC) PC12 | 9 10| PC9  (BEEPER)
+ *                 -----
+ *                 EXP1
+ */
+
+#define EXPA1_03_PIN                        PB15
+#define EXPA1_04_PIN                        PB12
+#define EXPA1_05_PIN                        PB13
+#define EXPA1_06_PIN                        PC11
+#define EXPA1_07_PIN                        PB14
+#define EXPA1_08_PIN                        PC10
+#define EXPA1_09_PIN                        PC12
+#define EXPA1_10_PIN                        PC9
+
 #if HAS_SPI_LCD
 
-  #define BEEPER_PIN                        PC9
+  #define BEEPER_PIN                EXPA1_10_PIN
 
   #if HAS_GRAPHICAL_LCD
-    #define DOGLCD_A0                       PB14
-    #define DOGLCD_CS                       PB12
-    #define DOGLCD_SCK                      PB13
-    #define DOGLCD_MOSI                     PB15
+    #define DOGLCD_A0               EXPA1_07_PIN
+    #define DOGLCD_CS               EXPA1_04_PIN
+    #define DOGLCD_SCK              EXPA1_05_PIN
+    #define DOGLCD_MOSI             EXPA1_03_PIN
     //#define LCD_SCREEN_ROT_90
     //#define LCD_SCREEN_ROT_180
     //#define LCD_SCREEN_ROT_270
@@ -125,9 +145,9 @@
     #endif
   #endif
 
-  #define LCD_PINS_RS                       PB12  // CS -- SOFT SPI for ENDER3 LCD
-  #define LCD_PINS_D4                       PB13  // SCLK
-  #define LCD_PINS_ENABLE                   PB15  // DATA MOSI
+  #define LCD_PINS_RS               EXPA1_04_PIN  // CS -- SOFT SPI for ENDER3 LCD
+  #define LCD_PINS_D4               EXPA1_05_PIN  // SCLK
+  #define LCD_PINS_ENABLE           EXPA1_03_PIN  // DATA MOSI
 
   // not connected to a pin
   #define SD_DETECT_PIN                     PC3
@@ -145,9 +165,23 @@
   //#define LCD_CONTRAST_INIT 190
 
   #if ENABLED(NEWPANEL)
-    #define BTN_EN1                         PC11
-    #define BTN_EN2                         PC10
-    #define BTN_ENC                         PC12
+    #define BTN_EN1                 EXPA1_06_PIN
+    #define BTN_EN2                 EXPA1_08_PIN
+    #define BTN_ENC                 EXPA1_09_PIN
   #endif
 
 #endif
+
+#if ENABLED(TOUCH_UI_FTDI_EVE)
+  #define BEEPER_PIN                EXPA1_10_PIN
+
+  #define BTN_EN2                   EXPA1_08_PIN
+
+  #define CLCD_SPI_BUS 2
+  //#define CLCD_USE_SOFT_SPI
+  #if ENABLED(CLCD_USE_SOFT_SPI)
+    #define LCD_PINS_RS             EXPA1_04_PIN
+    #define LCD_PINS_D4             EXPA1_07_PIN
+    #define LCD_PINS_ENABLE         EXPA1_05_PIN
+  #endif
+#endif
-- 
GitLab