From 2cdde0833946ee3b04c08cf2f83f2453f4fda0a1 Mon Sep 17 00:00:00 2001
From: Scott Lahteine <github@thinkyhead.com>
Date: Mon, 30 Oct 2017 14:34:11 -0500
Subject: [PATCH] Apply items specified in code review

Followup to #8122
---
 Marlin/src/inc/Conditionals_post.h  | 16 ++++++++++++++++
 Marlin/src/lcd/ultralcd.cpp         |  5 ++---
 Marlin/src/pins/pins_AZSMZ_MINI.h   | 19 -------------------
 Marlin/src/pins/pins_MKS_SBASE.h    | 19 -------------------
 Marlin/src/pins/pins_RAMPS_RE_ARM.h | 18 ------------------
 Marlin/src/sd/SdFatConfig.h         |  4 +---
 6 files changed, 19 insertions(+), 62 deletions(-)

diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h
index 06f9a54594..02ba9d71b7 100644
--- a/Marlin/src/inc/Conditionals_post.h
+++ b/Marlin/src/inc/Conditionals_post.h
@@ -1162,4 +1162,20 @@
   #define NOT_A_PIN 0 // For PINS_DEBUGGING
 #endif
 
+// Force SDCARD_SORT_ALPHA to be enabled for Graphical LCD on LPC1768
+// because of a bug in the shared SPI implementation. (See #8122)
+#if defined(TARGET_LPC1768) && ENABLED(REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER)
+  #define SDCARD_SORT_ALPHA         // Keeps one directory level in RAM. Changing
+                                    // directory levels still glitches the screen,
+                                    // but the following LCD update cleans it up.
+  #undef SDSORT_LIMIT
+  #undef SDSORT_USES_RAM
+  #undef SDSORT_USES_STACK
+  #undef SDSORT_CACHE_NAMES
+  #define SDSORT_LIMIT       256    // Maximum number of sorted items (10-256). Costs 27 bytes each.
+  #define SDSORT_USES_RAM    true   // Pre-allocate a static array for faster pre-sorting.
+  #define SDSORT_USES_STACK  false  // Prefer the stack for pre-sorting to give back some SRAM. (Negated by next 2 options.)
+  #define SDSORT_CACHE_NAMES true   // Keep sorted items in RAM longer for speedy performance. Most expensive option.
+#endif
+
 #endif // CONDITIONALS_POST_H
diff --git a/Marlin/src/lcd/ultralcd.cpp b/Marlin/src/lcd/ultralcd.cpp
index 1bac1ac792..314080d79b 100644
--- a/Marlin/src/lcd/ultralcd.cpp
+++ b/Marlin/src/lcd/ultralcd.cpp
@@ -3775,9 +3775,8 @@ void kill_screen(const char* lcd_msg) {
     void lcd_sdcard_menu() {
       ENCODER_DIRECTION_MENUS();
 
-      const uint16_t fileCnt = card.get_num_Files();  // Only access SD card if sort not active
-                                                      // This minimizes garbage on RepRap Discount Full Graphics Smart Controller
-                                                      // when using the Re-ARM card.
+      const uint16_t fileCnt = card.get_num_Files();
+
       START_MENU();
       MENU_BACK(MSG_MAIN);
       card.getWorkDirName();
diff --git a/Marlin/src/pins/pins_AZSMZ_MINI.h b/Marlin/src/pins/pins_AZSMZ_MINI.h
index df830b02f1..ef421bed3e 100644
--- a/Marlin/src/pins/pins_AZSMZ_MINI.h
+++ b/Marlin/src/pins/pins_AZSMZ_MINI.h
@@ -112,25 +112,6 @@
 #define ENET_TXD0          P1_0
 #define ENET_TXD1          P1_1
 
-
-#if (ENABLED(REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER) && !defined(SDCARD_SORT_ALPHA)) // needed because of shared SPI
-  #define SDCARD_SORT_ALPHA         // Using SORT feature to keep one directory level in RAM
-                                    // When going up/down directory levels the SD card is
-                                    // accessed but the garbage/lines are removed when the
-                                    // LCD updates
-
-  #define SDSORT_LIMIT       256    // Maximum number of sorted items (10-256). Costs 27 bytes each.
-  #define FOLDER_SORTING     -1     // -1=above  0=none  1=below
-  #define SDSORT_GCODE       false  // Allow turning sorting on/off with LCD and M34 g-code.
-  #define SDSORT_USES_RAM    true   // Pre-allocate a static array for faster pre-sorting.
-  #define SDSORT_USES_STACK  false  // Prefer the stack for pre-sorting to give back some SRAM. (Negated by next 2 options.)
-  #define SDSORT_CACHE_NAMES true   // Keep sorted items in RAM longer for speedy performance. Most expensive option.
-  #define SDSORT_DYNAMIC_RAM false  // Use dynamic allocation (within SD menus). Least expensive option. Set SDSORT_LIMIT before use!
-  #define SDSORT_CACHE_VFATS 2      // Maximum number of 13-byte VFAT entries to use for sorting.
-                                    // Note: Only affects SCROLL_LONG_FILENAMES with SDSORT_CACHE_NAMES but not SDSORT_DYNAMIC_RAM.
-  #define MAX_VFAT_ENTRIES SDSORT_CACHE_VFATS
-#endif
-
 /**
  *  PWMs
  *
diff --git a/Marlin/src/pins/pins_MKS_SBASE.h b/Marlin/src/pins/pins_MKS_SBASE.h
index 771f1a9586..5da1bf2ac0 100644
--- a/Marlin/src/pins/pins_MKS_SBASE.h
+++ b/Marlin/src/pins/pins_MKS_SBASE.h
@@ -174,25 +174,6 @@
 #define ENET_TXD0          P1_0   // J12-11
 #define ENET_TXD1          P1_1   // J12-12
 
-
-#if (ENABLED(REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER) && !defined(SDCARD_SORT_ALPHA)) // needed because of shared SPI
-  #define SDCARD_SORT_ALPHA         // Using SORT feature to keep one directory level in RAM
-                                    // When going up/down directory levels the SD card is
-                                    // accessed but the garbage/lines are removed when the
-                                    // LCD updates
-
-  #define SDSORT_LIMIT       256    // Maximum number of sorted items (10-256). Costs 27 bytes each.
-  #define FOLDER_SORTING     -1     // -1=above  0=none  1=below
-  #define SDSORT_GCODE       false  // Allow turning sorting on/off with LCD and M34 g-code.
-  #define SDSORT_USES_RAM    true   // Pre-allocate a static array for faster pre-sorting.
-  #define SDSORT_USES_STACK  false  // Prefer the stack for pre-sorting to give back some SRAM. (Negated by next 2 options.)
-  #define SDSORT_CACHE_NAMES true   // Keep sorted items in RAM longer for speedy performance. Most expensive option.
-  #define SDSORT_DYNAMIC_RAM false  // Use dynamic allocation (within SD menus). Least expensive option. Set SDSORT_LIMIT before use!
-  #define SDSORT_CACHE_VFATS 2      // Maximum number of 13-byte VFAT entries to use for sorting.
-                                    // Note: Only affects SCROLL_LONG_FILENAMES with SDSORT_CACHE_NAMES but not SDSORT_DYNAMIC_RAM.
-  #define MAX_VFAT_ENTRIES SDSORT_CACHE_VFATS
-#endif
-
 /**
  *  PWMs
  *
diff --git a/Marlin/src/pins/pins_RAMPS_RE_ARM.h b/Marlin/src/pins/pins_RAMPS_RE_ARM.h
index c220e2ad50..992f9b3879 100644
--- a/Marlin/src/pins/pins_RAMPS_RE_ARM.h
+++ b/Marlin/src/pins/pins_RAMPS_RE_ARM.h
@@ -259,24 +259,6 @@
     //#define SHIFT_EN            P1_22  // J5-4 & AUX-4
   #endif
 
-  #if (ENABLED(REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER) && !defined(SDCARD_SORT_ALPHA)) // needed because of shared SPI
-    #define SDCARD_SORT_ALPHA         // Using SORT feature to keep one directory level in RAM
-                                      // When going up/down directory levels the SD card is
-                                      // accessed but the garbage/lines are removed when the
-                                      // LCD updates
-
-    #define SDSORT_LIMIT       256    // Maximum number of sorted items (10-256). Costs 27 bytes each.
-    #define FOLDER_SORTING     -1     // -1=above  0=none  1=below
-    #define SDSORT_GCODE       false  // Allow turning sorting on/off with LCD and M34 g-code.
-    #define SDSORT_USES_RAM    true   // Pre-allocate a static array for faster pre-sorting.
-    #define SDSORT_USES_STACK  false  // Prefer the stack for pre-sorting to give back some SRAM. (Negated by next 2 options.)
-    #define SDSORT_CACHE_NAMES true   // Keep sorted items in RAM longer for speedy performance. Most expensive option.
-    #define SDSORT_DYNAMIC_RAM false  // Use dynamic allocation (within SD menus). Least expensive option. Set SDSORT_LIMIT before use!
-    #define SDSORT_CACHE_VFATS 2      // Maximum number of 13-byte VFAT entries to use for sorting.
-                                      // Note: Only affects SCROLL_LONG_FILENAMES with SDSORT_CACHE_NAMES but not SDSORT_DYNAMIC_RAM.
-    #define MAX_VFAT_ENTRIES SDSORT_CACHE_VFATS
-  #endif
-
   #if ENABLED(VIKI2) || ENABLED(miniVIKI)
     // #define LCD_SCREEN_ROT_180
 
diff --git a/Marlin/src/sd/SdFatConfig.h b/Marlin/src/sd/SdFatConfig.h
index 7044920ffc..5d057c929f 100644
--- a/Marlin/src/sd/SdFatConfig.h
+++ b/Marlin/src/sd/SdFatConfig.h
@@ -134,9 +134,7 @@
 #define FILENAME_LENGTH 13 // Number of UTF-16 characters per entry
 
 // Number of VFAT entries used. Each entry has 13 UTF-16 characters
-#ifdef MAX_VFAT_ENTRIES
-  #undef MAX_VFAT_ENTRIES
-#endif  
+#undef MAX_VFAT_ENTRIES
 #if ENABLED(SCROLL_LONG_FILENAMES)
   #define MAX_VFAT_ENTRIES (5)
 #else
-- 
GitLab