From 4812ed5053983212c9ec8a6229a150a1af7822f1 Mon Sep 17 00:00:00 2001
From: Scott Lahteine <thinkyhead@users.noreply.github.com>
Date: Mon, 1 May 2023 18:45:42 -0500
Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Misc.=20code=20cleanup?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 Marlin/src/HAL/DUE/MinSerial.cpp              | 22 +++++++++----------
 Marlin/src/HAL/LPC1768/MinSerial.cpp          | 22 +++++++++----------
 Marlin/src/HAL/STM32/MinSerial.cpp            | 22 +++++++++----------
 Marlin/src/feature/pause.cpp                  |  2 +-
 Marlin/src/feature/runout.h                   | 14 ++++++------
 Marlin/src/gcode/queue.cpp                    |  4 ++--
 Marlin/src/gcode/queue.h                      |  4 ++--
 .../lcd/extui/ia_creality/creality_extui.cpp  |  4 ++--
 .../lcd/extui/ia_creality/ia_creality_extui.h |  3 ++-
 Marlin/src/lcd/extui/mks_ui/pic_manager.cpp   |  3 ++-
 .../variants/MARLIN_F103Rx/PeripheralPins.c   |  0
 .../variants/MARLIN_F103Rx/PinNamesVar.h      |  2 +-
 .../variants/MARLIN_F407ZE/PeripheralPins.c   |  3 +--
 13 files changed, 53 insertions(+), 52 deletions(-)
 mode change 100755 => 100644 buildroot/share/PlatformIO/variants/MARLIN_F103Rx/PeripheralPins.c

diff --git a/Marlin/src/HAL/DUE/MinSerial.cpp b/Marlin/src/HAL/DUE/MinSerial.cpp
index e5b3dbfe6f36..505a712aa9a1 100644
--- a/Marlin/src/HAL/DUE/MinSerial.cpp
+++ b/Marlin/src/HAL/DUE/MinSerial.cpp
@@ -73,18 +73,18 @@ void install_min_serial() {
 }
 
 #if DISABLED(DYNAMIC_VECTORTABLE)
-extern "C" {
-  __attribute__((naked)) void JumpHandler_ASM() {
-    __asm__ __volatile__ (
-      "b CommonHandler_ASM\n"
-    );
+  extern "C" {
+    __attribute__((naked)) void JumpHandler_ASM() {
+      __asm__ __volatile__ (
+        "b CommonHandler_ASM\n"
+      );
+    }
+    void __attribute__((naked, alias("JumpHandler_ASM"))) HardFault_Handler();
+    void __attribute__((naked, alias("JumpHandler_ASM"))) BusFault_Handler();
+    void __attribute__((naked, alias("JumpHandler_ASM"))) UsageFault_Handler();
+    void __attribute__((naked, alias("JumpHandler_ASM"))) MemManage_Handler();
+    void __attribute__((naked, alias("JumpHandler_ASM"))) NMI_Handler();
   }
-  void __attribute__((naked, alias("JumpHandler_ASM"))) HardFault_Handler();
-  void __attribute__((naked, alias("JumpHandler_ASM"))) BusFault_Handler();
-  void __attribute__((naked, alias("JumpHandler_ASM"))) UsageFault_Handler();
-  void __attribute__((naked, alias("JumpHandler_ASM"))) MemManage_Handler();
-  void __attribute__((naked, alias("JumpHandler_ASM"))) NMI_Handler();
-}
 #endif
 
 #endif // POSTMORTEM_DEBUGGING
diff --git a/Marlin/src/HAL/LPC1768/MinSerial.cpp b/Marlin/src/HAL/LPC1768/MinSerial.cpp
index 7a1c038c0b0b..368bcb5259cd 100644
--- a/Marlin/src/HAL/LPC1768/MinSerial.cpp
+++ b/Marlin/src/HAL/LPC1768/MinSerial.cpp
@@ -33,18 +33,18 @@ static void TX(char c) { _DBC(c); }
 void install_min_serial() { HAL_min_serial_out = &TX; }
 
 #if DISABLED(DYNAMIC_VECTORTABLE)
-extern "C" {
-  __attribute__((naked)) void JumpHandler_ASM() {
-    __asm__ __volatile__ (
-      "b CommonHandler_ASM\n"
-    );
+  extern "C" {
+    __attribute__((naked)) void JumpHandler_ASM() {
+      __asm__ __volatile__ (
+        "b CommonHandler_ASM\n"
+      );
+    }
+    void __attribute__((naked, alias("JumpHandler_ASM"))) HardFault_Handler();
+    void __attribute__((naked, alias("JumpHandler_ASM"))) BusFault_Handler();
+    void __attribute__((naked, alias("JumpHandler_ASM"))) UsageFault_Handler();
+    void __attribute__((naked, alias("JumpHandler_ASM"))) MemManage_Handler();
+    void __attribute__((naked, alias("JumpHandler_ASM"))) NMI_Handler();
   }
-  void __attribute__((naked, alias("JumpHandler_ASM"))) HardFault_Handler();
-  void __attribute__((naked, alias("JumpHandler_ASM"))) BusFault_Handler();
-  void __attribute__((naked, alias("JumpHandler_ASM"))) UsageFault_Handler();
-  void __attribute__((naked, alias("JumpHandler_ASM"))) MemManage_Handler();
-  void __attribute__((naked, alias("JumpHandler_ASM"))) NMI_Handler();
-}
 #endif
 
 #endif // POSTMORTEM_DEBUGGING
diff --git a/Marlin/src/HAL/STM32/MinSerial.cpp b/Marlin/src/HAL/STM32/MinSerial.cpp
index b0fcff20c172..c2260f4f26e0 100644
--- a/Marlin/src/HAL/STM32/MinSerial.cpp
+++ b/Marlin/src/HAL/STM32/MinSerial.cpp
@@ -135,18 +135,18 @@ void install_min_serial() {
 }
 
 #if NONE(DYNAMIC_VECTORTABLE, STM32F0xx, STM32G0xx) // Cortex M0 can't jump to a symbol that's too far from the current function, so we work around this in exception_arm.cpp
-extern "C" {
-  __attribute__((naked)) void JumpHandler_ASM() {
-    __asm__ __volatile__ (
-      "b CommonHandler_ASM\n"
-    );
+  extern "C" {
+    __attribute__((naked)) void JumpHandler_ASM() {
+      __asm__ __volatile__ (
+        "b CommonHandler_ASM\n"
+      );
+    }
+    void __attribute__((naked, alias("JumpHandler_ASM"), nothrow)) HardFault_Handler();
+    void __attribute__((naked, alias("JumpHandler_ASM"), nothrow)) BusFault_Handler();
+    void __attribute__((naked, alias("JumpHandler_ASM"), nothrow)) UsageFault_Handler();
+    void __attribute__((naked, alias("JumpHandler_ASM"), nothrow)) MemManage_Handler();
+    void __attribute__((naked, alias("JumpHandler_ASM"), nothrow)) NMI_Handler();
   }
-  void __attribute__((naked, alias("JumpHandler_ASM"), nothrow)) HardFault_Handler();
-  void __attribute__((naked, alias("JumpHandler_ASM"), nothrow)) BusFault_Handler();
-  void __attribute__((naked, alias("JumpHandler_ASM"), nothrow)) UsageFault_Handler();
-  void __attribute__((naked, alias("JumpHandler_ASM"), nothrow)) MemManage_Handler();
-  void __attribute__((naked, alias("JumpHandler_ASM"), nothrow)) NMI_Handler();
-}
 #endif
 
 #endif // POSTMORTEM_DEBUGGING
diff --git a/Marlin/src/feature/pause.cpp b/Marlin/src/feature/pause.cpp
index 7b814e57f742..504a9f61c78a 100644
--- a/Marlin/src/feature/pause.cpp
+++ b/Marlin/src/feature/pause.cpp
@@ -445,7 +445,7 @@ bool pause_print(const_float_t retract, const xyz_pos_t &park_point, const bool
   // Wait for buffered blocks to complete
   planner.synchronize();
 
-  #if ENABLED(ADVANCED_PAUSE_FANS_PAUSE) && HAS_FAN
+  #if BOTH(ADVANCED_PAUSE_FANS_PAUSE, HAS_FAN)
     thermalManager.set_fans_paused(true);
   #endif
 
diff --git a/Marlin/src/feature/runout.h b/Marlin/src/feature/runout.h
index e839db3f5edf..fb4d0c269479 100644
--- a/Marlin/src/feature/runout.h
+++ b/Marlin/src/feature/runout.h
@@ -191,13 +191,13 @@ class FilamentSensorBase {
   public:
     static void setup() {
       #define _INIT_RUNOUT_PIN(P,S,U,D) do{ if (ENABLED(U)) SET_INPUT_PULLUP(P); else if (ENABLED(D)) SET_INPUT_PULLDOWN(P); else SET_INPUT(P); }while(0);
-      #define  INIT_RUNOUT_PIN(N) _INIT_RUNOUT_PIN(FIL_RUNOUT##N##_PIN, FIL_RUNOUT##N##_STATE, FIL_RUNOUT##N##_PULLUP, FIL_RUNOUT##N##_PULLDOWN)
-      REPEAT_1(NUM_RUNOUT_SENSORS, INIT_RUNOUT_PIN);
+      #define  INIT_RUNOUT_PIN(N) _INIT_RUNOUT_PIN(FIL_RUNOUT##N##_PIN, FIL_RUNOUT##N##_STATE, FIL_RUNOUT##N##_PULLUP, FIL_RUNOUT##N##_PULLDOWN);
+      REPEAT_1(NUM_RUNOUT_SENSORS, INIT_RUNOUT_PIN)
       #undef INIT_RUNOUT_PIN
 
       #if ENABLED(FILAMENT_SWITCH_AND_MOTION)
-        #define INIT_MOTION_PIN(N) _INIT_RUNOUT_PIN(FIL_MOTION##N##_PIN, FIL_MOTION##N##_STATE, FIL_MOTION##N##_PULLUP, FIL_MOTION##N##_PULLDOWN)
-        REPEAT_1(NUM_MOTION_SENSORS, INIT_MOTION_PIN);
+        #define INIT_MOTION_PIN(N) _INIT_RUNOUT_PIN(FIL_MOTION##N##_PIN, FIL_MOTION##N##_STATE, FIL_MOTION##N##_PULLUP, FIL_MOTION##N##_PULLDOWN);
+        REPEAT_1(NUM_MOTION_SENSORS, INIT_MOTION_PIN)
         #undef  INIT_MOTION_PIN
       #endif
       #undef _INIT_RUNOUT_PIN
@@ -212,9 +212,9 @@ class FilamentSensorBase {
 
     // Return a bitmask of runout flag states (1 bits always indicates runout)
     static uint8_t poll_runout_states() {
-      #define _OR_RUNOUT(N) | (FIL_RUNOUT##N##_STATE ? 0 : _BV(N - 1))
-      return poll_runout_pins() ^ uint8_t(0 REPEAT_1(NUM_RUNOUT_SENSORS, _OR_RUNOUT));
-      #undef _OR_RUNOUT
+      #define _INVERT_BIT(N) | (FIL_RUNOUT##N##_STATE ? 0 : _BV(N - 1))
+      return poll_runout_pins() ^ uint8_t(0 REPEAT_1(NUM_RUNOUT_SENSORS, _INVERT_BIT));
+      #undef _INVERT_BIT
     }
 
     #if ENABLED(FILAMENT_SWITCH_AND_MOTION)
diff --git a/Marlin/src/gcode/queue.cpp b/Marlin/src/gcode/queue.cpp
index af8e87743657..b64aa951129e 100644
--- a/Marlin/src/gcode/queue.cpp
+++ b/Marlin/src/gcode/queue.cpp
@@ -99,7 +99,7 @@ PGM_P GCodeQueue::injected_commands_P; // = nullptr
  */
 char GCodeQueue::injected_commands[64]; // = { 0 }
 
-void GCodeQueue::RingBuffer::commit_command(bool skip_ok
+void GCodeQueue::RingBuffer::commit_command(const bool skip_ok
   OPTARG(HAS_MULTI_SERIAL, serial_index_t serial_ind/*=-1*/)
 ) {
   commands[index_w].skip_ok = skip_ok;
@@ -113,7 +113,7 @@ void GCodeQueue::RingBuffer::commit_command(bool skip_ok
  * Return true if the command was successfully added.
  * Return false for a full buffer, or if the 'command' is a comment.
  */
-bool GCodeQueue::RingBuffer::enqueue(const char *cmd, bool skip_ok/*=true*/
+bool GCodeQueue::RingBuffer::enqueue(const char *cmd, const bool skip_ok/*=true*/
   OPTARG(HAS_MULTI_SERIAL, serial_index_t serial_ind/*=-1*/)
 ) {
   if (*cmd == ';' || length >= BUFSIZE) return false;
diff --git a/Marlin/src/gcode/queue.h b/Marlin/src/gcode/queue.h
index 2cb72f2e1571..25b9f5cf9b21 100644
--- a/Marlin/src/gcode/queue.h
+++ b/Marlin/src/gcode/queue.h
@@ -79,11 +79,11 @@ class GCodeQueue {
 
     void advance_pos(uint8_t &p, const int inc) { if (++p >= BUFSIZE) p = 0; length += inc; }
 
-    void commit_command(bool skip_ok
+    void commit_command(const bool skip_ok
       OPTARG(HAS_MULTI_SERIAL, serial_index_t serial_ind = serial_index_t())
     );
 
-    bool enqueue(const char *cmd, bool skip_ok = true
+    bool enqueue(const char *cmd, const bool skip_ok=true
       OPTARG(HAS_MULTI_SERIAL, serial_index_t serial_ind = serial_index_t())
     );
 
diff --git a/Marlin/src/lcd/extui/ia_creality/creality_extui.cpp b/Marlin/src/lcd/extui/ia_creality/creality_extui.cpp
index 1f40f2a037d2..3ba8322f0085 100644
--- a/Marlin/src/lcd/extui/ia_creality/creality_extui.cpp
+++ b/Marlin/src/lcd/extui/ia_creality/creality_extui.cpp
@@ -1066,7 +1066,7 @@ namespace ExtUI {
           TPShowStatus    = false;
           ZERO(ChangeMaterialbuf);
           ChangeMaterialbuf[1] = ChangeMaterialbuf[0] = 10;
-          RTS_SndData(10 * ChangeMaterialbuf[0], FilamentUnit1); // It's ChangeMaterialbuf for show,instead of current_position[E_AXIS] in them.
+          RTS_SndData(10 * ChangeMaterialbuf[0], FilamentUnit1); // It's ChangeMaterialbuf for show, instead of current_position.e in them.
           RTS_SndData(10 * ChangeMaterialbuf[1], FilamentUnit2);
           RTS_SndData(getActualTemp_celsius(H0), NozzleTemp);
           RTS_SndData(getTargetTemp_celsius(H0), NozzlePreheat);
@@ -1381,7 +1381,7 @@ namespace ExtUI {
             case 0xF0: // not to cancel heating
               break;
           }
-          RTS_SndData(10 * ChangeMaterialbuf[0], FilamentUnit1); // It's ChangeMaterialbuf for show,instead of current_position[E_AXIS] in them.
+          RTS_SndData(10 * ChangeMaterialbuf[0], FilamentUnit1); // It's ChangeMaterialbuf for show, instead of current_position.e in them.
           RTS_SndData(10 * ChangeMaterialbuf[1], FilamentUnit2);
         }
         else if (recdat.addr == FilamentUnit1) {
diff --git a/Marlin/src/lcd/extui/ia_creality/ia_creality_extui.h b/Marlin/src/lcd/extui/ia_creality/ia_creality_extui.h
index 0d932556638c..ba5df4fe77cd 100644
--- a/Marlin/src/lcd/extui/ia_creality/ia_creality_extui.h
+++ b/Marlin/src/lcd/extui/ia_creality/ia_creality_extui.h
@@ -31,9 +31,10 @@
  *
  * ***************************************/
 
-#include "string.h"
 #include "../ui_api.h"
 
+#include <string.h>
+
 /*********************************/
 #define FHONE   (0x5A)
 #define FHTWO   (0xA5)
diff --git a/Marlin/src/lcd/extui/mks_ui/pic_manager.cpp b/Marlin/src/lcd/extui/mks_ui/pic_manager.cpp
index 6570176a29f6..6e39c9a36e8f 100644
--- a/Marlin/src/lcd/extui/mks_ui/pic_manager.cpp
+++ b/Marlin/src/lcd/extui/mks_ui/pic_manager.cpp
@@ -24,7 +24,6 @@
 
 #if HAS_TFT_LVGL_UI
 
-#include "string.h"
 #include "draw_ui.h"
 #include "pic_manager.h"
 #include "draw_ready_print.h"
@@ -34,6 +33,8 @@
 #include "../../../sd/cardreader.h"
 #include "../../../MarlinCore.h"
 
+#include <string.h>
+
 extern uint16_t DeviceCode;
 
 #if HAS_MEDIA
diff --git a/buildroot/share/PlatformIO/variants/MARLIN_F103Rx/PeripheralPins.c b/buildroot/share/PlatformIO/variants/MARLIN_F103Rx/PeripheralPins.c
old mode 100755
new mode 100644
diff --git a/buildroot/share/PlatformIO/variants/MARLIN_F103Rx/PinNamesVar.h b/buildroot/share/PlatformIO/variants/MARLIN_F103Rx/PinNamesVar.h
index d9e759f5d0cd..d9076b4dfb59 100644
--- a/buildroot/share/PlatformIO/variants/MARLIN_F103Rx/PinNamesVar.h
+++ b/buildroot/share/PlatformIO/variants/MARLIN_F103Rx/PinNamesVar.h
@@ -27,4 +27,4 @@
 #ifdef USBCON
   USB_DM = PA_11,
   USB_DP = PA_12,
-#endif
\ No newline at end of file
+#endif
diff --git a/buildroot/share/PlatformIO/variants/MARLIN_F407ZE/PeripheralPins.c b/buildroot/share/PlatformIO/variants/MARLIN_F407ZE/PeripheralPins.c
index d0905853a9a9..de796f4ef535 100644
--- a/buildroot/share/PlatformIO/variants/MARLIN_F407ZE/PeripheralPins.c
+++ b/buildroot/share/PlatformIO/variants/MARLIN_F407ZE/PeripheralPins.c
@@ -413,7 +413,7 @@ const PinMap PinMap_USB_OTG_HS[] = {
     */
   {NC,    NP,    0}
 };
-
+#endif
 
 #ifdef HAL_SD_MODULE_ENABLED
 WEAK const PinMap PinMap_SD[] = {
@@ -430,4 +430,3 @@ WEAK const PinMap PinMap_SD[] = {
   {NC,    NP,    0}
 };
 #endif
-#endif