From c3b58f1938c215e4c3b22f65052990b5e1adc823 Mon Sep 17 00:00:00 2001
From: Eduard Sukharev <sukharev.eh@gmail.com>
Date: Tue, 13 Sep 2022 20:31:59 +0300
Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20Fix=20MKS=20TinyBee=20+=20MKS=20?=
 =?UTF-8?q?MINI=2012864=20SD=20blank=20on=20write=20(#24670)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 Marlin/src/HAL/ESP32/u8g_esp32_spi.cpp   | 12 ++++++++++++
 Marlin/src/pins/esp32/pins_MKS_TINYBEE.h |  7 +++++--
 ini/features.ini                         |  2 +-
 3 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/Marlin/src/HAL/ESP32/u8g_esp32_spi.cpp b/Marlin/src/HAL/ESP32/u8g_esp32_spi.cpp
index a445035b2b4..bd7ecdc9f21 100644
--- a/Marlin/src/HAL/ESP32/u8g_esp32_spi.cpp
+++ b/Marlin/src/HAL/ESP32/u8g_esp32_spi.cpp
@@ -32,6 +32,13 @@
 #include "HAL.h"
 #include "SPI.h"
 
+#if ENABLED(SDSUPPORT)
+  #include "../../sd/cardreader.h"
+  #if ENABLED(ESP3D_WIFISUPPORT)
+    #include "sd_ESP32.h"
+  #endif
+#endif
+
 static SPISettings spiConfig;
 
 
@@ -45,6 +52,11 @@ static SPISettings spiConfig;
 
 uint8_t u8g_eps_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) {
   static uint8_t msgInitCount = 2; // Ignore all messages until 2nd U8G_COM_MSG_INIT
+
+  #if ENABLED(PAUSE_LCD_FOR_BUSY_SD)
+    if (card.flag.saving || card.flag.logging || TERN0(ESP3D_WIFISUPPORT, sd_busy_lock == true)) return 0;
+  #endif
+
   if (msgInitCount) {
     if (msg == U8G_COM_MSG_INIT) msgInitCount--;
     if (msgInitCount) return -1;
diff --git a/Marlin/src/pins/esp32/pins_MKS_TINYBEE.h b/Marlin/src/pins/esp32/pins_MKS_TINYBEE.h
index 04210bb2344..37ce4ee94e5 100644
--- a/Marlin/src/pins/esp32/pins_MKS_TINYBEE.h
+++ b/Marlin/src/pins/esp32/pins_MKS_TINYBEE.h
@@ -166,12 +166,12 @@
   #define LCD_BACKLIGHT_PIN                   -1
 
   #if ENABLED(MKS_MINI_12864)
-  // MKS MINI12864 and MKS LCD12864B; If using MKS LCD12864A (Need to remove RPK2 resistor)
+    // MKS MINI12864 and MKS LCD12864B; If using MKS LCD12864A (Need to remove RPK2 resistor)
     #define DOGLCD_CS                EXP1_06_PIN
     #define DOGLCD_A0                EXP1_07_PIN
     #define LCD_RESET_PIN                     -1
   #elif ENABLED(FYSETC_MINI_12864_2_1)
-  // MKS_MINI_12864_V3, BTT_MINI_12864_V1, FYSETC_MINI_12864_2_1
+    // MKS_MINI_12864_V3, BTT_MINI_12864_V1, FYSETC_MINI_12864_2_1
     #define DOGLCD_CS                EXP1_03_PIN
     #define DOGLCD_A0                EXP1_04_PIN
     #define LCD_RESET_PIN            EXP1_05_PIN
@@ -179,6 +179,9 @@
     #if SD_CONNECTION_IS(ONBOARD)
       #define FORCE_SOFT_SPI
     #endif
+    #if BOTH(MKS_MINI_12864_V3, SDSUPPORT)
+      #define PAUSE_LCD_FOR_BUSY_SD
+    #endif
   #else
    #define LCD_PINS_D4               EXP1_05_PIN
     #if ENABLED(REPRAP_DISCOUNT_SMART_CONTROLLER)
diff --git a/ini/features.ini b/ini/features.ini
index 2f26aa25236..72d73ea86fe 100644
--- a/ini/features.ini
+++ b/ini/features.ini
@@ -238,7 +238,7 @@ HAS_SERVOS                             = src_filter=+<src/module/servo.cpp> +<sr
 MORGAN_SCARA                           = src_filter=+<src/gcode/scara>
 HAS_MICROSTEPS                         = src_filter=+<src/gcode/control/M350_M351.cpp>
 (ESP3D_)?WIFISUPPORT                   = AsyncTCP, ESP Async WebServer
-                                         ESP3DLib=https://github.com/luc-github/ESP3DLib/archive/master.zip
+                                         ESP3DLib=https://github.com/eduard-sukharev/ESP3DLib/archive/patch-1.zip
                                          arduinoWebSockets=links2004/WebSockets@2.3.4
                                          luc-github/ESP32SSDP@1.1.1
                                          lib_ignore=ESPAsyncTCP