From d69c2a90b7721c2b779d31572faff5fd848d8ea0 Mon Sep 17 00:00:00 2001
From: Scott Lahteine <github@thinkyhead.com>
Date: Wed, 5 Aug 2020 23:21:41 -0500
Subject: [PATCH] Simple rename of hex_print

---
 .../src/HAL/STM32_F4_F7/STM32F7/TMC2660.cpp   |  2 +-
 Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp   |  2 +-
 Marlin/src/feature/tmc_util.cpp               |  2 +-
 Marlin/src/gcode/calibrate/M100.cpp           |  2 +-
 Marlin/src/gcode/eeprom/M500-M504.cpp         |  2 +-
 Marlin/src/gcode/parser.h                     |  2 +-
 Marlin/src/inc/Conditionals_adv.h             |  5 ++
 Marlin/src/libs/hex_print.cpp                 | 90 +++++++++++++++++++
 .../{hex_print_routines.h => hex_print.h}     |  0
 Marlin/src/libs/hex_print_routines.cpp        | 90 -------------------
 10 files changed, 101 insertions(+), 96 deletions(-)
 create mode 100644 Marlin/src/libs/hex_print.cpp
 rename Marlin/src/libs/{hex_print_routines.h => hex_print.h} (100%)
 delete mode 100644 Marlin/src/libs/hex_print_routines.cpp

diff --git a/Marlin/src/HAL/STM32_F4_F7/STM32F7/TMC2660.cpp b/Marlin/src/HAL/STM32_F4_F7/STM32F7/TMC2660.cpp
index b0304590293..4d116f440b8 100644
--- a/Marlin/src/HAL/STM32_F4_F7/STM32F7/TMC2660.cpp
+++ b/Marlin/src/HAL/STM32_F4_F7/STM32F7/TMC2660.cpp
@@ -40,7 +40,7 @@
 #include "../../../module/stepper/indirection.h"
 #include "../../../module/printcounter.h"
 #include "../../../libs/duration_t.h"
-#include "../../../libs/hex_print_routines.h"
+#include "../../../libs/hex_print.h"
 
 //some default values used in initialization
 #define DEFAULT_MICROSTEPPING_VALUE 32
diff --git a/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp b/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp
index f8219ac7e7d..760d2cdd1ea 100644
--- a/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp
+++ b/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp
@@ -28,7 +28,7 @@
 
   #include "../../../MarlinCore.h"
   #include "../../../HAL/shared/eeprom_api.h"
-  #include "../../../libs/hex_print_routines.h"
+  #include "../../../libs/hex_print.h"
   #include "../../../module/configuration_store.h"
   #include "../../../lcd/ultralcd.h"
   #include "../../../module/stepper.h"
diff --git a/Marlin/src/feature/tmc_util.cpp b/Marlin/src/feature/tmc_util.cpp
index 495d6a9f5bb..781253079ed 100644
--- a/Marlin/src/feature/tmc_util.cpp
+++ b/Marlin/src/feature/tmc_util.cpp
@@ -34,7 +34,7 @@
 
 #if ENABLED(TMC_DEBUG)
   #include "../module/planner.h"
-  #include "../libs/hex_print_routines.h"
+  #include "../libs/hex_print.h"
   #if ENABLED(MONITOR_DRIVER_STATUS)
     static uint16_t report_tmc_status_interval; // = 0
   #endif
diff --git a/Marlin/src/gcode/calibrate/M100.cpp b/Marlin/src/gcode/calibrate/M100.cpp
index ea054125b7c..f03b13e233d 100644
--- a/Marlin/src/gcode/calibrate/M100.cpp
+++ b/Marlin/src/gcode/calibrate/M100.cpp
@@ -26,7 +26,7 @@
 
 #include "../gcode.h"
 #include "../queue.h"
-#include "../../libs/hex_print_routines.h"
+#include "../../libs/hex_print.h"
 
 #include "../../MarlinCore.h" // for idle()
 
diff --git a/Marlin/src/gcode/eeprom/M500-M504.cpp b/Marlin/src/gcode/eeprom/M500-M504.cpp
index 5aee68ba997..30fa2b6e250 100644
--- a/Marlin/src/gcode/eeprom/M500-M504.cpp
+++ b/Marlin/src/gcode/eeprom/M500-M504.cpp
@@ -60,7 +60,7 @@ void GcodeSuite::M502() {
 #if ENABLED(EEPROM_SETTINGS)
 
   #if ENABLED(MARLIN_DEV_MODE)
-    #include "../../libs/hex_print_routines.h"
+    #include "../../libs/hex_print.h"
   #endif
 
   /**
diff --git a/Marlin/src/gcode/parser.h b/Marlin/src/gcode/parser.h
index 5474e5e5f39..eb614c33b4c 100644
--- a/Marlin/src/gcode/parser.h
+++ b/Marlin/src/gcode/parser.h
@@ -31,7 +31,7 @@
 
 //#define DEBUG_GCODE_PARSER
 #if ENABLED(DEBUG_GCODE_PARSER)
-  #include "../libs/hex_print_routines.h"
+  #include "../libs/hex_print.h"
 #endif
 
 #if ENABLED(TEMPERATURE_UNITS_SUPPORT)
diff --git a/Marlin/src/inc/Conditionals_adv.h b/Marlin/src/inc/Conditionals_adv.h
index 7b35dc77557..a057034ab67 100644
--- a/Marlin/src/inc/Conditionals_adv.h
+++ b/Marlin/src/inc/Conditionals_adv.h
@@ -378,3 +378,8 @@
 #if ENABLED(EEPROM_SETTINGS) && NONE(I2C_EEPROM, SPI_EEPROM, QSPI_EEPROM, FLASH_EEPROM_EMULATION, SRAM_EEPROM_EMULATION, SDCARD_EEPROM_EMULATION)
   #define NO_EEPROM_SELECTED 1
 #endif
+
+// Flag whether hex_print.cpp is used
+#if ANY(AUTO_BED_LEVELING_UBL, M100_FREE_MEMORY_WATCHER, DEBUG_GCODE_PARSER, TMC_DEBUG, MARLIN_DEV_MODE)
+  #define NEED_HEX_PRINT 1
+#endif
diff --git a/Marlin/src/libs/hex_print.cpp b/Marlin/src/libs/hex_print.cpp
new file mode 100644
index 00000000000..6bcc00e420a
--- /dev/null
+++ b/Marlin/src/libs/hex_print.cpp
@@ -0,0 +1,90 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "../inc/MarlinConfig.h"
+#include "../gcode/parser.h"
+
+#if NEED_HEX_PRINT
+
+#include "hex_print.h"
+
+#ifdef CPU_32_BIT
+  constexpr int byte_start = 4;
+  static char _hex[] = "0x00000000";
+#else
+  constexpr int byte_start = 0;
+  static char _hex[] = "0x0000";
+#endif
+
+char* hex_byte(const uint8_t b) {
+  _hex[byte_start + 4] = hex_nybble(b >> 4);
+  _hex[byte_start + 5] = hex_nybble(b);
+  return &_hex[byte_start + 4];
+}
+
+inline void _hex_word(const uint16_t w) {
+  _hex[byte_start + 2] = hex_nybble(w >> 12);
+  _hex[byte_start + 3] = hex_nybble(w >> 8);
+  _hex[byte_start + 4] = hex_nybble(w >> 4);
+  _hex[byte_start + 5] = hex_nybble(w);
+}
+
+char* hex_word(const uint16_t w) {
+  _hex_word(w);
+  return &_hex[byte_start + 2];
+}
+
+#ifdef CPU_32_BIT
+  char* hex_long(const uint32_t l) {
+    _hex[2] = hex_nybble(l >> 28);
+    _hex[3] = hex_nybble(l >> 24);
+    _hex[4] = hex_nybble(l >> 20);
+    _hex[5] = hex_nybble(l >> 16);
+    _hex_word((uint16_t)(l & 0xFFFF));
+    return &_hex[2];
+  }
+#endif
+
+char* hex_address(const void * const w) {
+  #ifdef CPU_32_BIT
+    (void)hex_long((ptr_int_t)w);
+  #else
+    (void)hex_word((ptr_int_t)w);
+  #endif
+  return _hex;
+}
+
+void print_hex_nybble(const uint8_t n)       { SERIAL_CHAR(hex_nybble(n));  }
+void print_hex_byte(const uint8_t b)         { SERIAL_ECHO(hex_byte(b));    }
+void print_hex_word(const uint16_t w)        { SERIAL_ECHO(hex_word(w));    }
+void print_hex_address(const void * const w) { SERIAL_ECHO(hex_address(w)); }
+
+void print_hex_long(const uint32_t w, const char delimiter) {
+  SERIAL_ECHOPGM("0x");
+  for (int B = 24; B >= 8; B -= 8){
+    print_hex_byte(w >> B);
+    SERIAL_CHAR(delimiter);
+  }
+  print_hex_byte(w);
+}
+
+#endif // NEED_HEX_PRINT
diff --git a/Marlin/src/libs/hex_print_routines.h b/Marlin/src/libs/hex_print.h
similarity index 100%
rename from Marlin/src/libs/hex_print_routines.h
rename to Marlin/src/libs/hex_print.h
diff --git a/Marlin/src/libs/hex_print_routines.cpp b/Marlin/src/libs/hex_print_routines.cpp
deleted file mode 100644
index 5909ffd7d01..00000000000
--- a/Marlin/src/libs/hex_print_routines.cpp
+++ /dev/null
@@ -1,90 +0,0 @@
-/**
- * Marlin 3D Printer Firmware
- * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
- *
- * Based on Sprinter and grbl.
- * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
- *
- */
-
-#include "../inc/MarlinConfig.h"
-#include "../gcode/parser.h"
-
-#if ANY(AUTO_BED_LEVELING_UBL, M100_FREE_MEMORY_WATCHER, DEBUG_GCODE_PARSER, TMC_DEBUG, MARLIN_DEV_MODE)
-
-  #include "hex_print_routines.h"
-
-  #ifdef CPU_32_BIT
-    constexpr int byte_start = 4;
-    static char _hex[] = "0x00000000";
-  #else
-    constexpr int byte_start = 0;
-    static char _hex[] = "0x0000";
-  #endif
-
-  char* hex_byte(const uint8_t b) {
-    _hex[byte_start + 4] = hex_nybble(b >> 4);
-    _hex[byte_start + 5] = hex_nybble(b);
-    return &_hex[byte_start + 4];
-  }
-
-  inline void _hex_word(const uint16_t w) {
-    _hex[byte_start + 2] = hex_nybble(w >> 12);
-    _hex[byte_start + 3] = hex_nybble(w >> 8);
-    _hex[byte_start + 4] = hex_nybble(w >> 4);
-    _hex[byte_start + 5] = hex_nybble(w);
-  }
-
-  char* hex_word(const uint16_t w) {
-    _hex_word(w);
-    return &_hex[byte_start + 2];
-  }
-
-  #ifdef CPU_32_BIT
-    char* hex_long(const uint32_t l) {
-      _hex[2] = hex_nybble(l >> 28);
-      _hex[3] = hex_nybble(l >> 24);
-      _hex[4] = hex_nybble(l >> 20);
-      _hex[5] = hex_nybble(l >> 16);
-      _hex_word((uint16_t)(l & 0xFFFF));
-      return &_hex[2];
-    }
-  #endif
-
-  char* hex_address(const void * const w) {
-    #ifdef CPU_32_BIT
-      (void)hex_long((ptr_int_t)w);
-    #else
-      (void)hex_word((ptr_int_t)w);
-    #endif
-    return _hex;
-  }
-
-  void print_hex_nybble(const uint8_t n)       { SERIAL_CHAR(hex_nybble(n));  }
-  void print_hex_byte(const uint8_t b)         { SERIAL_ECHO(hex_byte(b));    }
-  void print_hex_word(const uint16_t w)        { SERIAL_ECHO(hex_word(w));    }
-  void print_hex_address(const void * const w) { SERIAL_ECHO(hex_address(w)); }
-
-  void print_hex_long(const uint32_t w, const char delimiter) {
-    SERIAL_ECHOPGM("0x");
-    for (int B = 24; B >= 8; B -= 8){
-      print_hex_byte(w >> B);
-      SERIAL_CHAR(delimiter);
-    }
-    print_hex_byte(w);
-  }
-
-#endif // AUTO_BED_LEVELING_UBL || M100_FREE_MEMORY_WATCHER || DEBUG_GCODE_PARSER