From de462f2b8a72716bf6e6558e63a1002658da7907 Mon Sep 17 00:00:00 2001
From: Scott Lahteine <github@thinkyhead.com>
Date: Wed, 3 Jul 2019 19:11:30 -0500
Subject: [PATCH] Revert "Sort out settings.load with SD EEPROM emulation
 (#14458)"

This reverts commit 108d0df56532e4eb30467d36b0fb2aa5bf4f50be.
---
 .../HAL/HAL_ESP32/persistent_store_spiffs.cpp   |  4 ++--
 .../HAL/HAL_STM32F1/persistent_store_sdcard.cpp |  2 +-
 Marlin/src/Marlin.cpp                           | 17 +++--------------
 Marlin/src/inc/Conditionals_post.h              |  4 ----
 Marlin/src/lcd/ultralcd.cpp                     | 11 +----------
 Marlin/src/sd/cardreader.cpp                    |  8 ++++++++
 6 files changed, 15 insertions(+), 31 deletions(-)

diff --git a/Marlin/src/HAL/HAL_ESP32/persistent_store_spiffs.cpp b/Marlin/src/HAL/HAL_ESP32/persistent_store_spiffs.cpp
index 0ba5fff65..5227da356 100644
--- a/Marlin/src/HAL/HAL_ESP32/persistent_store_spiffs.cpp
+++ b/Marlin/src/HAL/HAL_ESP32/persistent_store_spiffs.cpp
@@ -24,7 +24,7 @@
 
 #include "../../inc/MarlinConfig.h"
 
-#if ENABLED(SD_EEPROM_EMULATION)
+#if ENABLED(EEPROM_SETTINGS) && DISABLED(FLASH_EEPROM_EMULATION)
 
 #include "../shared/persistent_store_api.h"
 
@@ -102,5 +102,5 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t
 
 size_t PersistentStore::capacity() { return HAL_ESP32_EEPROM_SIZE; }
 
-#endif // SD_EEPROM_EMULATION
+#endif // EEPROM_SETTINGS
 #endif // ARDUINO_ARCH_ESP32
diff --git a/Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp b/Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp
index 08bc20150..324409357 100644
--- a/Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp
+++ b/Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp
@@ -28,7 +28,7 @@
 
 #include "../../inc/MarlinConfig.h"
 
-#if ENABLED(SD_EEPROM_EMULATION)
+#if ENABLED(EEPROM_SETTINGS) && NONE(FLASH_EEPROM_EMULATION, SPI_EEPROM, I2C_EEPROM)
 
 #include "../shared/persistent_store_api.h"
 
diff --git a/Marlin/src/Marlin.cpp b/Marlin/src/Marlin.cpp
index bbc049942..e73066fab 100644
--- a/Marlin/src/Marlin.cpp
+++ b/Marlin/src/Marlin.cpp
@@ -941,9 +941,7 @@ void setup() {
 
   // Load data from EEPROM if available (or use defaults)
   // This also updates variables in the planner, elsewhere
-  #if DISABLED(SD_EEPROM_EMULATION)
-    (void)settings.load();
-  #endif
+  (void)settings.load();
 
   #if HAS_M206_COMMAND
     // Initialize current position based on home_offset
@@ -1096,17 +1094,8 @@ void setup() {
     init_closedloop();
   #endif
 
-  #if !HAS_SPI_LCD
-
-    #if ENABLED(SD_EEPROM_EMULATION)
-      SERIAL_ECHOLNPGM("Loading settings from SD");
-      (void)settings.load();
-    #endif
-
-    #if ENABLED(INIT_SDCARD_ON_BOOT)
-      card.beginautostart();
-    #endif
-
+  #if ENABLED(INIT_SDCARD_ON_BOOT) && !HAS_SPI_LCD
+    card.beginautostart();
   #endif
 
   #if HAS_TRINAMIC && DISABLED(PS_DEFAULT_OFF)
diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h
index 36b4fd7e0..af1a95138 100644
--- a/Marlin/src/inc/Conditionals_post.h
+++ b/Marlin/src/inc/Conditionals_post.h
@@ -1734,7 +1734,3 @@
     #define INIT_SDCARD_ON_BOOT
   #endif
 #endif
-
-#if ENABLED(EEPROM_SETTINGS) && NONE(FLASH_EEPROM_EMULATION, SPI_EEPROM, I2C_EEPROM)
-  #define SD_EEPROM_EMULATION
-#endif
diff --git a/Marlin/src/lcd/ultralcd.cpp b/Marlin/src/lcd/ultralcd.cpp
index 9dc9ca1cd..fb4975585 100644
--- a/Marlin/src/lcd/ultralcd.cpp
+++ b/Marlin/src/lcd/ultralcd.cpp
@@ -81,10 +81,6 @@
 
 #include "../Marlin.h"
 
-#if ENABLED(SD_EEPROM_EMULATION)
-  #include "../module/configuration_store.h"
-#endif
-
 #if ENABLED(POWER_LOSS_RECOVERY)
   #include "../feature/power_loss_recovery.h"
 #endif
@@ -787,13 +783,8 @@ void MarlinUI::update() {
       if (sd_status) {
         safe_delay(500); // Some boards need a delay to get settled
         card.initsd();
-        if (old_sd_status == 2) {
-          #if ENABLED(SD_EEPROM_EMULATION)
-            SERIAL_ECHOLNPGM("Loading settings from SD");
-            (void)settings.load();
-          #endif
+        if (old_sd_status == 2)
           card.beginautostart();  // Initial boot
-        }
         else
           set_status_P(PSTR(MSG_SD_INSERTED));
       }
diff --git a/Marlin/src/sd/cardreader.cpp b/Marlin/src/sd/cardreader.cpp
index a8574569d..efd955259 100644
--- a/Marlin/src/sd/cardreader.cpp
+++ b/Marlin/src/sd/cardreader.cpp
@@ -353,6 +353,9 @@ void CardReader::initsd() {
   else {
     flag.detected = true;
     SERIAL_ECHO_MSG(MSG_SD_CARD_OK);
+    #if ENABLED(EEPROM_SETTINGS) && DISABLED(FLASH_EEPROM_EMULATION)
+      (void)settings.load();
+    #endif
   }
   setroot();
 
@@ -558,6 +561,11 @@ void CardReader::checkautostart() {
 
   if (!isDetected()) initsd();
 
+  #if ENABLED(EEPROM_SETTINGS) && DISABLED(FLASH_EEPROM_EMULATION)
+    SERIAL_ECHOLNPGM("Loading settings from SD");
+    (void)settings.load();
+  #endif
+
   if (isDetected()
     #if ENABLED(POWER_LOSS_RECOVERY)
       && !recovery.valid() // Don't run auto#.g when a resume file exists