From 915f610782df36ef241b8c207ea799d8b206aa15 Mon Sep 17 00:00:00 2001
From: jdegenstein <jdegenstein@users.noreply.github.com>
Date: Thu, 6 Jan 2022 19:03:02 -0600
Subject: [PATCH] =?UTF-8?q?=F0=9F=93=8C=20LCD=5FFOR=5FMELZI=20for=20BTT=20?=
 =?UTF-8?q?E3=20RRF=20(#23453)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 Marlin/src/pins/stm32f4/pins_BTT_E3_RRF.h | 48 ++++++++++++++++++++---
 1 file changed, 43 insertions(+), 5 deletions(-)

diff --git a/Marlin/src/pins/stm32f4/pins_BTT_E3_RRF.h b/Marlin/src/pins/stm32f4/pins_BTT_E3_RRF.h
index 740164a197..554b2704c7 100644
--- a/Marlin/src/pins/stm32f4/pins_BTT_E3_RRF.h
+++ b/Marlin/src/pins/stm32f4/pins_BTT_E3_RRF.h
@@ -197,11 +197,11 @@
 
 #if HAS_WIRED_LCD
 
-  #if ENABLED(CR10_STOCKDISPLAY)
+  #if EITHER(CR10_STOCKDISPLAY, LCD_FOR_MELZI)
 
     #define BEEPER_PIN                      PE8
-    #define BTN_ENC                         PE9
 
+    #define BTN_ENC                         PE9
     #define BTN_EN1                         PE7
     #define BTN_EN2                         PB2
 
@@ -209,6 +209,40 @@
     #define LCD_PINS_ENABLE                 PE11
     #define LCD_PINS_D4                     PE10
 
+    #if ENABLED(LCD_FOR_MELZI)
+
+      #error "CAUTION! LCD_FOR_MELZI requires wiring modifications. See 'pins_BTT_E3_RRF.h' for details. Comment out this line to continue."
+
+     /** LCD_FOR_MELZI display pinout
+      *
+      *               BTT E3 RRF                                   Display Ribbon
+      *                ------                                         ------
+      * (BEEPER)  PE8 |10  9 | PE9  (BTN_ENC)                    GND |10  9 | 5V
+      * (BTN_EN1) PE7 | 8  7 | RESET                          BEEPER | 8  7 | ESTOP    (RESET)
+      * (BTN_EN2) PB2   6  5 | PE10 (LCD_D4)       (BTN_ENC) ENC_BTN | 6  5 | LCD_SCLK (LCD_D4)
+      * (LCD_RS)  PB1 | 4  3 | PE11 (LCD_EN)       (BTN_EN2) ENC_A   | 4  3 | LCD_DATA (LCD_EN)
+      *           GND | 2  1 | 5V                  (BTN_EN1) ENC_B   | 2  1 | LCD_CS   (LCD_RS)
+      *                ------                                         ------
+      *                 EXP1                                          Ribbon
+      *
+      * Needs custom cable:
+      *
+      *    Board   Adapter   Display Ribbon (coming from display)
+      *
+      *   EXP1-1 ----------- EXP1-9
+      *   EXP1-2 ----------- EXP1-10
+      *   EXP1-3 ----------- EXP1-3
+      *   EXP1-4 ----------- EXP1-1
+      *   EXP1-5 ----------- EXP1-5
+      *   EXP1-6 ----------- EXP1-4
+      *   EXP1-7 ----------- EXP1-7
+      *   EXP1-8 ----------- EXP1-8
+      *   EXP1-9 ----------- EXP1-6
+      *  EXP1-10 ----------- EXP1-8
+      */
+
+    #endif
+
   #elif ENABLED(ZONESTAR_LCD)                     // ANET A8 LCD Controller - Must convert to 3.3V - CONNECTING TO 5V WILL DAMAGE THE BOARD!
 
     #error "CAUTION! ZONESTAR_LCD requires wiring modifications. See 'pins_BTT_E3_RRF.h' for details. Comment out this line to continue."
@@ -275,11 +309,15 @@
     #endif
 
   #else
-    #error "Only CR10_STOCKDISPLAY, ZONESTAR_LCD, ENDER2_STOCKDISPLAY, MKS_MINI_12864, and TFTGLCD_PANEL_(SPI|I2C) are currently supported on the BTT_E3_RRF."
+    #error "Only CR10_STOCKDISPLAY, ZONESTAR_LCD, ENDER2_STOCKDISPLAY, MKS_MINI_12864, LCD_FOR_MELZI, and TFTGLCD_PANEL_(SPI|I2C) are currently supported on the BTT_E3_RRF."
   #endif
 
   // Alter timing for graphical display
-  #if IS_U8GLIB_ST7920
+  #if ENABLED(LCD_FOR_MELZI)                      // LCD_FOR_MELZI default timing is too fast. This works but may be reduced.
+    #define BOARD_ST7920_DELAY_1             200
+    #define BOARD_ST7920_DELAY_2             400
+    #define BOARD_ST7920_DELAY_3            1200
+  #elif IS_U8GLIB_ST7920
     #define BOARD_ST7920_DELAY_1              96
     #define BOARD_ST7920_DELAY_2              48
     #define BOARD_ST7920_DELAY_3             600
@@ -306,7 +344,7 @@
    * Needs custom cable:
    *
    *    Board   Adapter   Display
-   *           _________
+   *
    *   EXP1-1 ----------- EXP1-10
    *   EXP1-2 ----------- EXP1-9
    *   SPI1-4 ----------- EXP1-6