From ccb4d11696ff886430463bafe020246582f75c42 Mon Sep 17 00:00:00 2001
From: John Robertson <john@cirtech.co.uk>
Date: Sat, 18 Mar 2023 10:33:15 +0000
Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Sanity-check=20PRINTCOUNTER=5FSA?=
 =?UTF-8?q?VE=5FINTERVAL=20+=20ESP32=20I2S=20Exp=20(#25527)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
---
 Marlin/src/HAL/ESP32/inc/SanityCheck.h         | 4 ++++
 Marlin/src/HAL/LPC1768/inc/Conditionals_post.h | 2 +-
 Marlin/src/HAL/STM32/inc/Conditionals_post.h   | 2 +-
 Marlin/src/inc/Warnings.cpp                    | 2 +-
 Marlin/src/module/printcounter.cpp             | 2 +-
 5 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/Marlin/src/HAL/ESP32/inc/SanityCheck.h b/Marlin/src/HAL/ESP32/inc/SanityCheck.h
index 8c5621f10c0..2d1b8503309 100644
--- a/Marlin/src/HAL/ESP32/inc/SanityCheck.h
+++ b/Marlin/src/HAL/ESP32/inc/SanityCheck.h
@@ -56,3 +56,7 @@
 #if BOTH(I2S_STEPPER_STREAM, LIN_ADVANCE) && DISABLED(EXPERIMENTAL_I2S_LA)
   #error "I2S stream is currently incompatible with LIN_ADVANCE."
 #endif
+
+#if BOTH(I2S_STEPPER_STREAM, PRINTCOUNTER) && PRINTCOUNTER_SAVE_INTERVAL > 0 && DISABLED(PRINTCOUNTER_SYNC)
+  #error "PRINTCOUNTER_SAVE_INTERVAL may cause issues on ESP32 with an I2S expander. Define PRINTCOUNTER_SYNC in Configuration.h for an imperfect solution."
+#endif
diff --git a/Marlin/src/HAL/LPC1768/inc/Conditionals_post.h b/Marlin/src/HAL/LPC1768/inc/Conditionals_post.h
index 35499500081..a0bf4215383 100644
--- a/Marlin/src/HAL/LPC1768/inc/Conditionals_post.h
+++ b/Marlin/src/HAL/LPC1768/inc/Conditionals_post.h
@@ -30,5 +30,5 @@
 // LPC1768 boards seem to lose steps when saving to EEPROM during print (issue #20785)
 // TODO: Which other boards are incompatible?
 #if defined(MCU_LPC1768) && ENABLED(FLASH_EEPROM_EMULATION) && PRINTCOUNTER_SAVE_INTERVAL > 0
-  #define PRINTCOUNTER_SYNC 1
+  #define PRINTCOUNTER_SYNC
 #endif
diff --git a/Marlin/src/HAL/STM32/inc/Conditionals_post.h b/Marlin/src/HAL/STM32/inc/Conditionals_post.h
index c5ce66a26f5..83ce077c754 100644
--- a/Marlin/src/HAL/STM32/inc/Conditionals_post.h
+++ b/Marlin/src/HAL/STM32/inc/Conditionals_post.h
@@ -30,5 +30,5 @@
 
 // Some STM32F4 boards may lose steps when saving to EEPROM during print (PR #17946)
 #if defined(STM32F4xx) && ENABLED(FLASH_EEPROM_EMULATION) && PRINTCOUNTER_SAVE_INTERVAL > 0
-  #define PRINTCOUNTER_SYNC 1
+  #define PRINTCOUNTER_SYNC
 #endif
diff --git a/Marlin/src/inc/Warnings.cpp b/Marlin/src/inc/Warnings.cpp
index f6dd97c096e..70ff5417f93 100644
--- a/Marlin/src/inc/Warnings.cpp
+++ b/Marlin/src/inc/Warnings.cpp
@@ -715,7 +715,7 @@
   #warning "Creality 4.2.2 boards come with a variety of stepper drivers. Check the board label (typically on SD Card module) and set the correct *_DRIVER_TYPE! (C=HR4988, E=A4988, A=TMC2208, B=TMC2209, H=TMC2225, H8=HR4988). (Define NO_CREALITY_422_DRIVER_WARNING to suppress this warning.)"
 #endif
 
-#if PRINTCOUNTER_SYNC
+#if ENABLED(PRINTCOUNTER_SYNC)
   #warning "To prevent step loss, motion will pause for PRINTCOUNTER auto-save."
 #endif
 
diff --git a/Marlin/src/module/printcounter.cpp b/Marlin/src/module/printcounter.cpp
index 3b6239c667e..f3d9ec8a9d8 100644
--- a/Marlin/src/module/printcounter.cpp
+++ b/Marlin/src/module/printcounter.cpp
@@ -41,7 +41,7 @@ Stopwatch print_job_timer;      // Global Print Job Timer instance
   #include "../libs/buzzer.h"
 #endif
 
-#if PRINTCOUNTER_SYNC
+#if ENABLED(PRINTCOUNTER_SYNC)
   #include "../module/planner.h"
 #endif