From 64d092935b27ff89955f0430eef5815b15e5a92d Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 7 Mar 2020 22:20:41 -0600 Subject: [PATCH] More useful ENABLED / DISABLED macros (#17054) --- Marlin/Configuration_adv.h | 2 +- Marlin/src/HAL/HAL_AVR/MarlinSerial.h | 18 +- Marlin/src/HAL/HAL_DUE/MarlinSerial.h | 16 +- Marlin/src/HAL/HAL_LPC1768/inc/SanityCheck.h | 14 +- Marlin/src/HAL/shared/MarlinSerial.h | 67 ---- Marlin/src/MarlinCore.cpp | 48 +-- Marlin/src/core/drivers.h | 134 ++++---- Marlin/src/core/macros.h | 28 +- Marlin/src/core/utility.cpp | 85 ++---- Marlin/src/feature/Max7219_Debug_LEDs.cpp | 22 +- Marlin/src/feature/babystep.cpp | 9 +- Marlin/src/feature/bltouch.cpp | 12 +- Marlin/src/feature/power_loss_recovery.h | 6 +- Marlin/src/gcode/calibrate/G28.cpp | 58 +--- Marlin/src/gcode/calibrate/G425.cpp | 8 +- Marlin/src/gcode/host/M115.cpp | 109 ++----- Marlin/src/inc/Conditionals_LCD.h | 124 +++++--- Marlin/src/inc/Conditionals_adv.h | 56 +++- Marlin/src/inc/Conditionals_post.h | 305 ++++++++++++------- Marlin/src/inc/SanityCheck.h | 33 +- Marlin/src/lcd/ultralcd.h | 16 +- Marlin/src/module/configuration_store.cpp | 192 ++++-------- Marlin/src/module/motion.cpp | 24 +- Marlin/src/module/motion.h | 10 +- Marlin/src/module/probe.h | 2 +- Marlin/src/sd/cardreader.h | 6 +- 26 files changed, 637 insertions(+), 767 deletions(-) delete mode 100644 Marlin/src/HAL/shared/MarlinSerial.h diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index c3cb6c1ca..856a7f028 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -1047,7 +1047,7 @@ */ //#define POWER_LOSS_RECOVERY #if ENABLED(POWER_LOSS_RECOVERY) - //#define PLR_ENABLED_DEFAULT true // Power Loss Recovery enabled by default. (Set with 'M413 Sn' & M500) + #define PLR_ENABLED_DEFAULT false // Power Loss Recovery enabled by default. (Set with 'M413 Sn' & M500) //#define BACKUP_POWER_SUPPLY // Backup power / UPS to move the steppers on power loss //#define POWER_LOSS_ZRAISE 2 // (mm) Z axis raise on resume (on power loss with UPS) //#define POWER_LOSS_PIN 44 // Pin to detect power loss. Set to -1 to disable default pin on boards without module. diff --git a/Marlin/src/HAL/HAL_AVR/MarlinSerial.h b/Marlin/src/HAL/HAL_AVR/MarlinSerial.h index 33870e2ca..cd7aad90a 100644 --- a/Marlin/src/HAL/HAL_AVR/MarlinSerial.h +++ b/Marlin/src/HAL/HAL_AVR/MarlinSerial.h @@ -31,10 +31,10 @@ * Templatized 01 October 2018 by Eduardo José Tagle to allow multiple instances */ -#include "../shared/MarlinSerial.h" - #include +#include "../../inc/MarlinConfigPre.h" + #ifndef SERIAL_PORT #define SERIAL_PORT 0 #endif @@ -261,12 +261,12 @@ static constexpr int PORT = serial; static constexpr unsigned int RX_SIZE = RX_BUFFER_SIZE; static constexpr unsigned int TX_SIZE = TX_BUFFER_SIZE; - static constexpr bool XONOFF = bSERIAL_XON_XOFF; - static constexpr bool EMERGENCYPARSER = bEMERGENCY_PARSER; - static constexpr bool DROPPED_RX = bSERIAL_STATS_DROPPED_RX; - static constexpr bool RX_OVERRUNS = bSERIAL_STATS_RX_BUFFER_OVERRUNS; - static constexpr bool RX_FRAMING_ERRORS = bSERIAL_STATS_RX_FRAMING_ERRORS; - static constexpr bool MAX_RX_QUEUED = bSERIAL_STATS_MAX_RX_QUEUED; + static constexpr bool XONOFF = ENABLED(SERIAL_XON_XOFF); + static constexpr bool EMERGENCYPARSER = ENABLED(EMERGENCY_PARSER); + static constexpr bool DROPPED_RX = ENABLED(SERIAL_STATS_DROPPED_RX); + static constexpr bool RX_OVERRUNS = ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS); + static constexpr bool RX_FRAMING_ERRORS = ENABLED(SERIAL_STATS_RX_FRAMING_ERRORS); + static constexpr bool MAX_RX_QUEUED = ENABLED(SERIAL_STATS_MAX_RX_QUEUED); }; extern MarlinSerial> customizedSerial1; @@ -304,7 +304,7 @@ static constexpr bool XONOFF = false; static constexpr bool EMERGENCYPARSER = false; static constexpr bool DROPPED_RX = false; - static constexpr bool RX_OVERRUNS = bDGUS_SERIAL_STATS_RX_BUFFER_OVERRUNS; + static constexpr bool RX_OVERRUNS = HAS_DGUS_LCD && ENABLED(DGUS_SERIAL_STATS_RX_BUFFER_OVERRUNS); static constexpr bool RX_FRAMING_ERRORS = false; static constexpr bool MAX_RX_QUEUED = false; }; diff --git a/Marlin/src/HAL/HAL_DUE/MarlinSerial.h b/Marlin/src/HAL/HAL_DUE/MarlinSerial.h index af7d2b7ad..eb26a5644 100644 --- a/Marlin/src/HAL/HAL_DUE/MarlinSerial.h +++ b/Marlin/src/HAL/HAL_DUE/MarlinSerial.h @@ -27,10 +27,10 @@ * Based on MarlinSerial for AVR, copyright (c) 2006 Nicholas Zambetti. All right reserved. */ -#include "../shared/MarlinSerial.h" - #include +#include "../../inc/MarlinConfigPre.h" + #define DEC 10 #define HEX 16 #define OCT 8 @@ -163,12 +163,12 @@ struct MarlinSerialCfg { static constexpr int PORT = serial; static constexpr unsigned int RX_SIZE = RX_BUFFER_SIZE; static constexpr unsigned int TX_SIZE = TX_BUFFER_SIZE; - static constexpr bool XONOFF = bSERIAL_XON_XOFF; - static constexpr bool EMERGENCYPARSER = bEMERGENCY_PARSER; - static constexpr bool DROPPED_RX = bSERIAL_STATS_DROPPED_RX; - static constexpr bool RX_OVERRUNS = bSERIAL_STATS_RX_BUFFER_OVERRUNS; - static constexpr bool RX_FRAMING_ERRORS = bSERIAL_STATS_RX_FRAMING_ERRORS; - static constexpr bool MAX_RX_QUEUED = bSERIAL_STATS_MAX_RX_QUEUED; + static constexpr bool XONOFF = ENABLED(SERIAL_XON_XOFF); + static constexpr bool EMERGENCYPARSER = ENABLED(EMERGENCY_PARSER); + static constexpr bool DROPPED_RX = ENABLED(SERIAL_STATS_DROPPED_RX); + static constexpr bool RX_OVERRUNS = ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS); + static constexpr bool RX_FRAMING_ERRORS = ENABLED(SERIAL_STATS_RX_FRAMING_ERRORS); + static constexpr bool MAX_RX_QUEUED = ENABLED(SERIAL_STATS_MAX_RX_QUEUED); }; #if SERIAL_PORT >= 0 diff --git a/Marlin/src/HAL/HAL_LPC1768/inc/SanityCheck.h b/Marlin/src/HAL/HAL_LPC1768/inc/SanityCheck.h index f301f0219..949c7f489 100644 --- a/Marlin/src/HAL/HAL_LPC1768/inc/SanityCheck.h +++ b/Marlin/src/HAL/HAL_LPC1768/inc/SanityCheck.h @@ -57,9 +57,7 @@ * Because PWM hardware channels all share the same frequency, along with the * fallback software channels, FAST_PWM_FAN is incompatible with Servos. */ -#if NUM_SERVOS > 0 && ENABLED(FAST_PWM_FAN) - #error "BLTOUCH and Servos are incompatible with FAST_PWM_FAN on LPC176x boards." -#endif +static_assert(!(NUM_SERVOS && ENABLED(FAST_PWM_FAN)), "BLTOUCH and Servos are incompatible with FAST_PWM_FAN on LPC176x boards."); /** * Test LPC176x-specific configuration values for errors at compile-time. @@ -69,13 +67,13 @@ // #error "SPINDLE_LASER_PWM_PIN must use SERVO0, SERVO1 or SERVO3 connector" //#endif -#if IS_RE_ARM_BOARD && ENABLED(REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER) && HAS_DRIVER(TMC2130) && DISABLED(TMC_USE_SW_SPI) - #error "Re-ARM with REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER and TMC2130 require TMC_USE_SW_SPI" +#if MB(RAMPS_14_RE_ARM_EFB, RAMPS_14_RE_ARM_EEB, RAMPS_14_RE_ARM_EFF, RAMPS_14_RE_ARM_EEF, RAMPS_14_RE_ARM_SF) + #if ENABLED(REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER) && HAS_DRIVER(TMC2130) && DISABLED(TMC_USE_SW_SPI) + #error "Re-ARM with REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER and TMC2130 requires TMC_USE_SW_SPI." + #endif #endif -#if ENABLED(BAUD_RATE_GCODE) - #error "BAUD_RATE_GCODE is not yet supported on LPC176x." -#endif +static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported on LPC176x."); /** * Flag any serial port conflicts diff --git a/Marlin/src/HAL/shared/MarlinSerial.h b/Marlin/src/HAL/shared/MarlinSerial.h deleted file mode 100644 index 3770f61b3..000000000 --- a/Marlin/src/HAL/shared/MarlinSerial.h +++ /dev/null @@ -1,67 +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 . - * - */ -#pragma once - -/** - * HAL/shared/MarlinSerial.h - */ - -#include "../../inc/MarlinConfigPre.h" - -constexpr bool - #if HAS_DGUS_LCD - bDGUS_SERIAL_STATS_RX_BUFFER_OVERRUNS = (false - #if ENABLED(DGUS_SERIAL_STATS_RX_BUFFER_OVERRUNS) - || true - #endif - ), - #endif - bSERIAL_XON_XOFF = (false - #if ENABLED(SERIAL_XON_XOFF) - || true - #endif - ), - bEMERGENCY_PARSER = (false - #if ENABLED(EMERGENCY_PARSER) - || true - #endif - ), - bSERIAL_STATS_DROPPED_RX = (false - #if ENABLED(SERIAL_STATS_DROPPED_RX) - || true - #endif - ), - bSERIAL_STATS_RX_BUFFER_OVERRUNS = (false - #if ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS) - || true - #endif - ), - bSERIAL_STATS_RX_FRAMING_ERRORS = (false - #if ENABLED(SERIAL_STATS_RX_FRAMING_ERRORS) - || true - #endif - ), - bSERIAL_STATS_MAX_RX_QUEUED = (false - #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED) - || true - #endif - ); diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index 85320e332..39287d423 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -241,11 +241,8 @@ void setup_powerhold() { OUT_WRITE(SUICIDE_PIN, !SUICIDE_PIN_INVERTING); #endif #if ENABLED(PSU_CONTROL) - #if ENABLED(PSU_DEFAULT_OFF) - powersupply_on = true; PSU_OFF(); - #else - powersupply_on = false; PSU_ON(); - #endif + powersupply_on = ENABLED(PSU_DEFAULT_OFF); + if (ENABLED(PSU_DEFAULT_OFF)) PSU_OFF(); else PSU_ON(); #endif } @@ -425,14 +422,8 @@ void startOrResumeJob() { switch (card.sdprinting_done_state) { #if HAS_RESUME_CONTINUE // Display "Click to Continue..." - case 1: - did_state = queue.enqueue_P(PSTR("M0Q1S" - #if HAS_LCD_MENU - "1800" // ...for 30 minutes with LCD - #else - "60" // ...for 1 minute with no LCD - #endif - )); + case 1: // 30 min timeout with LCD, 1 min without + did_state = queue.enqueue_P(PSTR("M0Q1S" TERN(HAS_LCD_MENU, "1800", "60"))); break; #endif @@ -501,31 +492,19 @@ inline void manage_inactivity(const bool ignore_stepper_queue=false) { } // Prevent steppers timing-out in the middle of M600 - #if BOTH(ADVANCED_PAUSE_FEATURE, PAUSE_PARK_NO_STEPPER_TIMEOUT) - #define MOVE_AWAY_TEST !did_pause_print - #else - #define MOVE_AWAY_TEST true - #endif + #define STAY_TEST (BOTH(ADVANCED_PAUSE_FEATURE, PAUSE_PARK_NO_STEPPER_TIMEOUT) && did_pause_print) if (stepper_inactive_time) { static bool already_shutdown_steppers; // = false if (planner.has_blocks_queued()) gcode.reset_stepper_timeout(); - else if (MOVE_AWAY_TEST && !ignore_stepper_queue && ELAPSED(ms, gcode.previous_move_ms + stepper_inactive_time)) { + else if (!STAY_TEST && !ignore_stepper_queue && ELAPSED(ms, gcode.previous_move_ms + stepper_inactive_time)) { if (!already_shutdown_steppers) { already_shutdown_steppers = true; // L6470 SPI will consume 99% of free time without this - #if ENABLED(DISABLE_INACTIVE_X) - DISABLE_AXIS_X(); - #endif - #if ENABLED(DISABLE_INACTIVE_Y) - DISABLE_AXIS_Y(); - #endif - #if ENABLED(DISABLE_INACTIVE_Z) - DISABLE_AXIS_Z(); - #endif - #if ENABLED(DISABLE_INACTIVE_E) - disable_e_steppers(); - #endif + if (ENABLED(DISABLE_INACTIVE_X)) DISABLE_AXIS_X(); + if (ENABLED(DISABLE_INACTIVE_Y)) DISABLE_AXIS_Y(); + if (ENABLED(DISABLE_INACTIVE_Z)) DISABLE_AXIS_Z(); + if (ENABLED(DISABLE_INACTIVE_E)) disable_e_steppers(); #if HAS_LCD_MENU && ENABLED(AUTO_BED_LEVELING_UBL) if (ubl.lcd_map_control) { ubl.lcd_map_control = false; @@ -1191,7 +1170,6 @@ void setup() { */ void loop() { do { - idle(); #if ENABLED(SDSUPPORT) @@ -1204,9 +1182,5 @@ void loop() { endstops.event_handler(); - } while (false // Return to caller for best compatibility - #ifdef __AVR__ - || true // Loop forever on slower (AVR) boards - #endif - ); + } while (ENABLED(__AVR__)); // Loop forever on slower (AVR) boards } diff --git a/Marlin/src/core/drivers.h b/Marlin/src/core/drivers.h index 2c89d001f..833899bdc 100644 --- a/Marlin/src/core/drivers.h +++ b/Marlin/src/core/drivers.h @@ -82,101 +82,97 @@ #define _OR_ADTE(N,T) || AXIS_DRIVER_TYPE_E(N,T) #define HAS_E_DRIVER(T) (0 RREPEAT2(E_STEPPERS, _OR_ADTE, T)) -#define HAS_DRIVER(T) ( AXIS_DRIVER_TYPE_X(T) || AXIS_DRIVER_TYPE_X2(T) \ - || AXIS_DRIVER_TYPE_Y(T) || AXIS_DRIVER_TYPE_Y2(T) \ - || AXIS_DRIVER_TYPE_Z(T) || AXIS_DRIVER_TYPE_Z2(T) \ - || AXIS_DRIVER_TYPE_Z3(T) || AXIS_DRIVER_TYPE_Z4(T) \ - || HAS_E_DRIVER(T) ) +#define HAS_DRIVER(T) ( AXIS_DRIVER_TYPE_X(T) || AXIS_DRIVER_TYPE_Y(T) || AXIS_DRIVER_TYPE_Z(T) \ + || AXIS_DRIVER_TYPE_X2(T) || AXIS_DRIVER_TYPE_Y2(T) || AXIS_DRIVER_TYPE_Z2(T) \ + || AXIS_DRIVER_TYPE_Z3(T) || AXIS_DRIVER_TYPE_Z4(T) || HAS_E_DRIVER(T) ) // Test for supported TMC drivers that require advanced configuration // Does not match standalone configurations -#define HAS_TRINAMIC_CONFIG ( HAS_DRIVER(TMC2130) \ - || HAS_DRIVER(TMC2160) \ - || HAS_DRIVER(TMC2208) \ - || HAS_DRIVER(TMC2209) \ - || HAS_DRIVER(TMC2660) \ - || HAS_DRIVER(TMC5130) \ - || HAS_DRIVER(TMC5160) ) +#if ( HAS_DRIVER(TMC2130) || HAS_DRIVER(TMC2160) \ + || HAS_DRIVER(TMC2208) || HAS_DRIVER(TMC2209) \ + || HAS_DRIVER(TMC2660) \ + || HAS_DRIVER(TMC5130) || HAS_DRIVER(TMC5160) ) + #define HAS_TRINAMIC_CONFIG 1 +#endif #define HAS_TRINAMIC HAS_TRINAMIC_CONFIG -#define HAS_TRINAMIC_STANDALONE ( HAS_DRIVER(TMC2130_STANDALONE) \ - || HAS_DRIVER(TMC2208_STANDALONE) \ - || HAS_DRIVER(TMC2209_STANDALONE) \ - || HAS_DRIVER(TMC26X_STANDALONE) \ - || HAS_DRIVER(TMC2660_STANDALONE) \ - || HAS_DRIVER(TMC5130_STANDALONE) \ - || HAS_DRIVER(TMC5160_STANDALONE) \ - || HAS_DRIVER(TMC2160_STANDALONE) ) +#if ( HAS_DRIVER(TMC2130_STANDALONE) || HAS_DRIVER(TMC2160_STANDALONE) \ + || HAS_DRIVER(TMC2208_STANDALONE) || HAS_DRIVER(TMC2209_STANDALONE) \ + || HAS_DRIVER(TMC26X_STANDALONE) || HAS_DRIVER(TMC2660_STANDALONE) \ + || HAS_DRIVER(TMC5130_STANDALONE) || HAS_DRIVER(TMC5160_STANDALONE) ) + #define HAS_TRINAMIC_STANDALONE 1 +#endif -#define HAS_TMCX1X0 ( HAS_DRIVER(TMC2130) || HAS_DRIVER(TMC2160) \ - || HAS_DRIVER(TMC5130) || HAS_DRIVER(TMC5160)) +#if HAS_DRIVER(TMC2130) || HAS_DRIVER(TMC2160) || HAS_DRIVER(TMC5130) || HAS_DRIVER(TMC5160) + #define HAS_TMCX1X0 1 +#endif -#define HAS_TMC220x (HAS_DRIVER(TMC2208) || HAS_DRIVER(TMC2209)) +#if HAS_DRIVER(TMC2208) || HAS_DRIVER(TMC2209) + #define HAS_TMC220x 1 +#endif -#define AXIS_IS_TMC(A) ( AXIS_DRIVER_TYPE(A,TMC2130) \ - || AXIS_DRIVER_TYPE(A,TMC2160) \ - || AXIS_DRIVER_TYPE(A,TMC2208) \ - || AXIS_DRIVER_TYPE(A,TMC2209) \ +#define AXIS_IS_TMC(A) ( AXIS_DRIVER_TYPE(A,TMC2130) || AXIS_DRIVER_TYPE(A,TMC2160) \ + || AXIS_DRIVER_TYPE(A,TMC2208) || AXIS_DRIVER_TYPE(A,TMC2209) \ || AXIS_DRIVER_TYPE(A,TMC2660) \ - || AXIS_DRIVER_TYPE(A,TMC5130) \ - || AXIS_DRIVER_TYPE(A,TMC5160) ) + || AXIS_DRIVER_TYPE(A,TMC5130) || AXIS_DRIVER_TYPE(A,TMC5160) ) // Test for a driver that uses SPI - this allows checking whether a _CS_ pin // is considered sensitive -#define AXIS_HAS_SPI(A) ( AXIS_DRIVER_TYPE(A,TMC2130) \ - || AXIS_DRIVER_TYPE(A,TMC2160) \ +#define AXIS_HAS_SPI(A) ( AXIS_DRIVER_TYPE(A,TMC2130) || AXIS_DRIVER_TYPE(A,TMC2160) \ || AXIS_DRIVER_TYPE(A,TMC2660) \ - || AXIS_DRIVER_TYPE(A,TMC5130) \ - || AXIS_DRIVER_TYPE(A,TMC5160) ) + || AXIS_DRIVER_TYPE(A,TMC5130) || AXIS_DRIVER_TYPE(A,TMC5160) ) -#define AXIS_HAS_UART(A) ( AXIS_DRIVER_TYPE(A,TMC2208) \ - || AXIS_DRIVER_TYPE(A,TMC2209) ) +#define AXIS_HAS_UART(A) ( AXIS_DRIVER_TYPE(A,TMC2208) || AXIS_DRIVER_TYPE(A,TMC2209) ) #define AXIS_HAS_RXTX AXIS_HAS_UART -#define AXIS_HAS_SW_SERIAL(A) ((AXIS_HAS_UART(A) && !defined(A##_HARDWARE_SERIAL))) +#define AXIS_HAS_SW_SERIAL(A) ( AXIS_HAS_UART(A) && !defined(A##_HARDWARE_SERIAL) ) -#define AXIS_HAS_STALLGUARD(A) ( AXIS_DRIVER_TYPE(A,TMC2130) \ - || AXIS_DRIVER_TYPE(A,TMC2160) \ +#define AXIS_HAS_STALLGUARD(A) ( AXIS_DRIVER_TYPE(A,TMC2130) || AXIS_DRIVER_TYPE(A,TMC2160) \ || AXIS_DRIVER_TYPE(A,TMC2209) \ || AXIS_DRIVER_TYPE(A,TMC2660) \ - || AXIS_DRIVER_TYPE(A,TMC5130) \ - || AXIS_DRIVER_TYPE(A,TMC5160) ) + || AXIS_DRIVER_TYPE(A,TMC5130) || AXIS_DRIVER_TYPE(A,TMC5160) ) -#define AXIS_HAS_STEALTHCHOP(A) ( AXIS_DRIVER_TYPE(A,TMC2130) \ - || AXIS_DRIVER_TYPE(A,TMC2160) \ - || AXIS_DRIVER_TYPE(A,TMC2208) \ - || AXIS_DRIVER_TYPE(A,TMC2209) \ - || AXIS_DRIVER_TYPE(A,TMC5130) \ - || AXIS_DRIVER_TYPE(A,TMC5160) ) +#define AXIS_HAS_STEALTHCHOP(A) ( AXIS_DRIVER_TYPE(A,TMC2130) || AXIS_DRIVER_TYPE(A,TMC2160) \ + || AXIS_DRIVER_TYPE(A,TMC2208) || AXIS_DRIVER_TYPE(A,TMC2209) \ + || AXIS_DRIVER_TYPE(A,TMC5130) || AXIS_DRIVER_TYPE(A,TMC5160) ) -#define AXIS_HAS_SG_RESULT(A) ( AXIS_DRIVER_TYPE(A,TMC2130) \ - || AXIS_DRIVER_TYPE(A,TMC2160) \ - || AXIS_DRIVER_TYPE(A,TMC2208) \ - || AXIS_DRIVER_TYPE(A,TMC2209) ) +#define AXIS_HAS_SG_RESULT(A) ( AXIS_DRIVER_TYPE(A,TMC2130) || AXIS_DRIVER_TYPE(A,TMC2160) \ + || AXIS_DRIVER_TYPE(A,TMC2208) || AXIS_DRIVER_TYPE(A,TMC2209) ) #define AXIS_HAS_COOLSTEP(A) ( AXIS_DRIVER_TYPE(A,TMC2130) \ || AXIS_DRIVER_TYPE(A,TMC2209) \ - || AXIS_DRIVER_TYPE(A,TMC5130) \ - || AXIS_DRIVER_TYPE(A,TMC5160) ) + || AXIS_DRIVER_TYPE(A,TMC5130) || AXIS_DRIVER_TYPE(A,TMC5160) ) #define _OR_EAH(N,T) || AXIS_HAS_##T(E##N) #define E_AXIS_HAS(T) (0 _OR_EAH(0,T) _OR_EAH(1,T) _OR_EAH(2,T) _OR_EAH(3,T) _OR_EAH(4,T) _OR_EAH(5,T) _OR_EAH(6,T) _OR_EAH(7,T)) -#define ANY_AXIS_HAS(T) ( AXIS_HAS_##T(X) || AXIS_HAS_##T(X2) \ - || AXIS_HAS_##T(Y) || AXIS_HAS_##T(Y2) \ - || AXIS_HAS_##T(Z) || AXIS_HAS_##T(Z2) \ - || AXIS_HAS_##T(Z3) || AXIS_HAS_##T(Z4) \ - || E_AXIS_HAS(T) ) - -#define HAS_STEALTHCHOP ANY_AXIS_HAS(STEALTHCHOP) -#define HAS_STALLGUARD ANY_AXIS_HAS(STALLGUARD) -#define HAS_SG_RESULT ANY_AXIS_HAS(SG_RESULT) -#define HAS_COOLSTEP ANY_AXIS_HAS(COOLSTEP) -#define HAS_TMC_UART ANY_AXIS_HAS(RXTX) -#define HAS_TMC_SPI ANY_AXIS_HAS(SPI) -#define HAS_TMC_SW_SERIAL ANY_AXIS_HAS(SW_SERIAL) +#define ANY_AXIS_HAS(T) ( AXIS_HAS_##T(X) || AXIS_HAS_##T(Y) || AXIS_HAS_##T(Z) \ + || AXIS_HAS_##T(X2) || AXIS_HAS_##T(Y2) || AXIS_HAS_##T(Z2) \ + || AXIS_HAS_##T(Z3) || AXIS_HAS_##T(Z4) || E_AXIS_HAS(T) ) + +#if ANY_AXIS_HAS(STEALTHCHOP) + #define HAS_STEALTHCHOP 1 +#endif +#if ANY_AXIS_HAS(STALLGUARD) + #define HAS_STALLGUARD 1 +#endif +#if ANY_AXIS_HAS(SG_RESULT) + #define HAS_SG_RESULT 1 +#endif +#if ANY_AXIS_HAS(COOLSTEP) + #define HAS_COOLSTEP 1 +#endif +#if ANY_AXIS_HAS(RXTX) + #define HAS_TMC_UART 1 +#endif +#if ANY_AXIS_HAS(SPI) + #define HAS_TMC_SPI 1 +#endif + +// Defines that can't be evaluated now +#define HAS_TMC_SW_SERIAL ANY_AXIS_HAS(SW_SERIAL) // // Stretching 'drivers.h' to include LPC/SAMD51 SD options @@ -187,7 +183,11 @@ #define _SDCARD_ID(V) _CAT(_SDCARD_, V) #define SD_CONNECTION_IS(V) (_SDCARD_ID(SDCARD_CONNECTION) == _SDCARD_ID(V)) -#define HAS_L64XX (HAS_DRIVER(L6470) || HAS_DRIVER(L6474) || HAS_DRIVER(L6480) || HAS_DRIVER(POWERSTEP01)) -#define HAS_L64XX_NOT_L6474 (HAS_L64XX && !HAS_DRIVER(L6474)) +#if HAS_DRIVER(L6470) || HAS_DRIVER(L6474) || HAS_DRIVER(L6480) || HAS_DRIVER(POWERSTEP01) + #define HAS_L64XX 1 +#endif +#if HAS_L64XX && !HAS_DRIVER(L6474) + #define HAS_L64XX_NOT_L6474 1 +#endif #define AXIS_IS_L64XX(A) (AXIS_DRIVER_TYPE_##A(L6470) || AXIS_DRIVER_TYPE_##A(L6474) || AXIS_DRIVER_TYPE_##A(L6480) || AXIS_DRIVER_TYPE_##A(POWERSTEP01)) diff --git a/Marlin/src/core/macros.h b/Marlin/src/core/macros.h index 557234208..32f8e5490 100644 --- a/Marlin/src/core/macros.h +++ b/Marlin/src/core/macros.h @@ -177,18 +177,23 @@ // Macros to support option testing #define _CAT(a,V...) a##V #define CAT(a,V...) _CAT(a,V) -#define SWITCH_ENABLED_false 0 -#define SWITCH_ENABLED_true 1 -#define SWITCH_ENABLED_0 0 -#define SWITCH_ENABLED_1 1 -#define SWITCH_ENABLED_0x0 0 -#define SWITCH_ENABLED_0x1 1 -#define SWITCH_ENABLED_ 1 -#define _ENA_1(O) _CAT(SWITCH_ENABLED_, O) -#define _DIS_1(O) !_ENA_1(O) + +#define _ISENA_ ~,1 +#define _ISENA_1 ~,1 +#define _ISENA_0x1 ~,1 +#define _ISENA_true ~,1 +#define _ISENA(V...) IS_PROBE(V) + +#define _ENA_1(O) _ISENA(CAT(_IS,CAT(ENA_, O))) +#define _DIS_1(O) NOT(_ENA_1(O)) #define ENABLED(V...) DO(ENA,&&,V) #define DISABLED(V...) DO(DIS,&&,V) +#define TERN(O,A,B) _TERN(_ENA_1(O),B,A) // OPTION converted to to '0' or '1' +#define _TERN(E,V...) __TERN(_CAT(T_,E),V) // Prepend 'T_' to get 'T_0' or 'T_1' +#define __TERN(T,V...) ___TERN(_CAT(_NO,T),V) // Prepend '_NO' to get '_NOT_0' or '_NOT_1' +#define ___TERN(P,V...) THIRD(P,V) // If first argument has a comma, A. Else B. + #define ANY(V...) !DISABLED(V) #define NONE(V...) DISABLED(V) #define ALL(V...) ENABLED(V) @@ -390,8 +395,9 @@ // // Primitives supporting precompiler REPEAT // -#define FIRST(a,...) a -#define SECOND(a,b,...) b +#define FIRST(a,...) a +#define SECOND(a,b,...) b +#define THIRD(a,b,c,...) c // Defer expansion #define EMPTY() diff --git a/Marlin/src/core/utility.cpp b/Marlin/src/core/utility.cpp index d2e3459d1..19247ff69 100644 --- a/Marlin/src/core/utility.cpp +++ b/Marlin/src/core/utility.cpp @@ -57,39 +57,23 @@ void safe_delay(millis_t ms) { void log_machine_info() { SERIAL_ECHOLNPGM("Machine Type: " - #if ENABLED(DELTA) - "Delta" - #elif IS_SCARA - "SCARA" - #elif IS_CORE - "Core" - #else - "Cartesian" - #endif + TERN(DELTA, "Delta", "") + TERN(IS_SCARA, "SCARA", "") + TERN(IS_CORE, "Core", "") + TERN(IS_CARTESIAN, "Cartesian", "") ); SERIAL_ECHOLNPGM("Probe: " - #if ENABLED(PROBE_MANUALLY) - "PROBE_MANUALLY" - #elif ENABLED(NOZZLE_AS_PROBE) - "NOZZLE_AS_PROBE" - #elif ENABLED(FIX_MOUNTED_PROBE) - "FIX_MOUNTED_PROBE" - #elif ENABLED(BLTOUCH) - "BLTOUCH" - #elif HAS_Z_SERVO_PROBE - "SERVO PROBE" - #elif ENABLED(TOUCH_MI_PROBE) - "TOUCH_MI_PROBE" - #elif ENABLED(Z_PROBE_SLED) - "Z_PROBE_SLED" - #elif ENABLED(Z_PROBE_ALLEN_KEY) - "Z_PROBE_ALLEN_KEY" - #elif ENABLED(SOLENOID_PROBE) - "SOLENOID_PROBE" - #else - "NONE" - #endif + TERN(PROBE_MANUALLY, "PROBE_MANUALLY", "") + TERN(NOZZLE_AS_PROBE, "NOZZLE_AS_PROBE", "") + TERN(FIX_MOUNTED_PROBE, "FIX_MOUNTED_PROBE", "") + TERN(BLTOUCH, "BLTOUCH", "") + TERN(HAS_Z_SERVO_PROBE, TERN(BLTOUCH, "BLTOUCH", "SERVO PROBE"), "") + TERN(TOUCH_MI_PROBE, "TOUCH_MI_PROBE", "") + TERN(Z_PROBE_SLED, "Z_PROBE_SLED", "") + TERN(Z_PROBE_ALLEN_KEY, "Z_PROBE_ALLEN_KEY", "") + TERN(SOLENOID_PROBE, "SOLENOID_PROBE", "") + TERN(PROBE_SELECTED, "", "NONE") ); #if HAS_BED_PROBE @@ -107,20 +91,10 @@ void safe_delay(millis_t ms) { else SERIAL_ECHOPGM(" (Aligned With"); - if (probe.offset_xy.y > 0) { - #if IS_SCARA - SERIAL_ECHOPGM("-Distal"); - #else - SERIAL_ECHOPGM("-Back"); - #endif - } - else if (probe.offset_xy.y < 0) { - #if IS_SCARA - SERIAL_ECHOPGM("-Proximal"); - #else - SERIAL_ECHOPGM("-Front"); - #endif - } + if (probe.offset_xy.y > 0) + serialprintPGM(ENABLED(IS_SCARA) ? PSTR("-Distal") : PSTR("-Back")); + else if (probe.offset_xy.y < 0) + serialprintPGM(ENABLED(IS_SCARA) ? PSTR("-Proximal") : PSTR("-Front")); else if (probe.offset_xy.x != 0) SERIAL_ECHOPGM("-Center"); @@ -128,27 +102,18 @@ void safe_delay(millis_t ms) { #endif - if (probe.offset.z < 0) - SERIAL_ECHOPGM("Below"); - else if (probe.offset.z > 0) - SERIAL_ECHOPGM("Above"); - else - SERIAL_ECHOPGM("Same Z as"); + serialprintPGM(probe.offset.z < 0 ? PSTR("Below") : probe.offset.z > 0 ? PSTR("Above") : PSTR("Same Z as")); SERIAL_ECHOLNPGM(" Nozzle)"); #endif #if HAS_ABL_OR_UBL - SERIAL_ECHOPGM("Auto Bed Leveling: "); - #if ENABLED(AUTO_BED_LEVELING_LINEAR) - SERIAL_ECHOLNPGM("LINEAR"); - #elif ENABLED(AUTO_BED_LEVELING_BILINEAR) - SERIAL_ECHOLNPGM("BILINEAR"); - #elif ENABLED(AUTO_BED_LEVELING_3POINT) - SERIAL_ECHOLNPGM("3POINT"); - #elif ENABLED(AUTO_BED_LEVELING_UBL) - SERIAL_ECHOLNPGM("UBL"); - #endif + SERIAL_ECHOPGM("Auto Bed Leveling: " + TERN(AUTO_BED_LEVELING_LINEAR, "LINEAR", "") + TERN(AUTO_BED_LEVELING_BILINEAR, "BILINEAR", "") + TERN(AUTO_BED_LEVELING_3POINT, "3POINT", "") + TERN(AUTO_BED_LEVELING_UBL, "UBL", "") + ); if (planner.leveling_active) { SERIAL_ECHOLNPGM(" (enabled)"); diff --git a/Marlin/src/feature/Max7219_Debug_LEDs.cpp b/Marlin/src/feature/Max7219_Debug_LEDs.cpp index e81116aee..e9ed522e8 100644 --- a/Marlin/src/feature/Max7219_Debug_LEDs.cpp +++ b/Marlin/src/feature/Max7219_Debug_LEDs.cpp @@ -48,24 +48,16 @@ #include "../MarlinCore.h" #include "../HAL/shared/Delay.h" -#define HAS_SIDE_BY_SIDE (ENABLED(MAX7219_SIDE_BY_SIDE) && MAX7219_NUMBER_UNITS > 1) +#if ENABLED(MAX7219_SIDE_BY_SIDE) && MAX7219_NUMBER_UNITS > 1 + #define HAS_SIDE_BY_SIDE 1 +#endif #if _ROT == 0 || _ROT == 180 - #if HAS_SIDE_BY_SIDE - #define MAX7219_X_LEDS 8 - #define MAX7219_Y_LEDS MAX7219_LINES - #else - #define MAX7219_Y_LEDS 8 - #define MAX7219_X_LEDS MAX7219_LINES - #endif + #define MAX7219_X_LEDS TERN(HAS_SIDE_BY_SIDE, 8, MAX7219_LINES) + #define MAX7219_Y_LEDS TERN(HAS_SIDE_BY_SIDE, MAX7219_LINES, 8) #elif _ROT == 90 || _ROT == 270 - #if HAS_SIDE_BY_SIDE - #define MAX7219_Y_LEDS 8 - #define MAX7219_X_LEDS MAX7219_LINES - #else - #define MAX7219_X_LEDS 8 - #define MAX7219_Y_LEDS MAX7219_LINES - #endif + #define MAX7219_X_LEDS TERN(HAS_SIDE_BY_SIDE, MAX7219_LINES, 8) + #define MAX7219_Y_LEDS TERN(HAS_SIDE_BY_SIDE, 8, MAX7219_LINES) #else #error "MAX7219_ROTATE must be a multiple of +/- 90°." #endif diff --git a/Marlin/src/feature/babystep.cpp b/Marlin/src/feature/babystep.cpp index bf9e9a78b..5d2dc47be 100644 --- a/Marlin/src/feature/babystep.cpp +++ b/Marlin/src/feature/babystep.cpp @@ -55,14 +55,7 @@ void Babystep::add_mm(const AxisEnum axis, const float &mm) { void Babystep::add_steps(const AxisEnum axis, const int16_t distance) { - #if ENABLED(BABYSTEP_WITHOUT_HOMING) - #define CAN_BABYSTEP(AXIS) true - #else - extern uint8_t axis_known_position; - #define CAN_BABYSTEP(AXIS) TEST(axis_known_position, AXIS) - #endif - - if (!CAN_BABYSTEP(axis)) return; + if (DISABLED(BABYSTEP_WITHOUT_HOMING) && !TEST(axis_known_position, axis)) return; accum += distance; // Count up babysteps for the UI #if ENABLED(BABYSTEP_DISPLAY_TOTAL) diff --git a/Marlin/src/feature/bltouch.cpp b/Marlin/src/feature/bltouch.cpp index 77d85c419..efe575ec6 100644 --- a/Marlin/src/feature/bltouch.cpp +++ b/Marlin/src/feature/bltouch.cpp @@ -73,20 +73,12 @@ void BLTouch::init(const bool set_voltage/*=false*/) { ); } - const bool should_set = last_written_mode != (false - #if ENABLED(BLTOUCH_SET_5V_MODE) - || true - #endif - ); + const bool should_set = last_written_mode != ENABLED(BLTOUCH_SET_5V_MODE); #endif if (should_set && set_voltage) - mode_conv_proc((false - #if ENABLED(BLTOUCH_SET_5V_MODE) - || true - #endif - )); + mode_conv_proc(ENABLED(BLTOUCH_SET_5V_MODE)); } void BLTouch::clear() { diff --git a/Marlin/src/feature/power_loss_recovery.h b/Marlin/src/feature/power_loss_recovery.h index 6c4b5d5c3..049656078 100644 --- a/Marlin/src/feature/power_loss_recovery.h +++ b/Marlin/src/feature/power_loss_recovery.h @@ -159,11 +159,7 @@ class PrintJobRecovery { static inline void cancel() { purge(); card.autostart_index = 0; } static void load(); - static void save(const bool force=false - #if ENABLED(SAVE_EACH_CMD_MODE) - || true - #endif - ); + static void save(const bool force=ENABLED(SAVE_EACH_CMD_MODE)); #if PIN_EXISTS(POWER_LOSS) static inline void outage() { diff --git a/Marlin/src/gcode/calibrate/G28.cpp b/Marlin/src/gcode/calibrate/G28.cpp index f75462fb9..63c746405 100644 --- a/Marlin/src/gcode/calibrate/G28.cpp +++ b/Marlin/src/gcode/calibrate/G28.cpp @@ -62,13 +62,7 @@ current_position.set(0.0, 0.0); sync_plan_position(); - const int x_axis_home_dir = - #if ENABLED(DUAL_X_CARRIAGE) - x_home_dir(active_extruder) - #else - home_dir(X_AXIS) - #endif - ; + const int x_axis_home_dir = x_home_dir(active_extruder); const float mlx = max_length(X_AXIS), mly = max_length(Y_AXIS), @@ -310,6 +304,8 @@ void GcodeSuite::G28() { #if ENABLED(DELTA) + constexpr bool doZ = true; // for NANODLP_Z_SYNC if your DLP is on a DELTA + home_delta(); #if ENABLED(IMPROVE_HOMING_RELIABILITY) @@ -330,12 +326,10 @@ void GcodeSuite::G28() { #endif - const float z_homing_height = ( - #if ENABLED(UNKNOWN_Z_NO_RAISE) - !TEST(axis_known_position, Z_AXIS) ? 0 : - #endif - (parser.seenval('R') ? parser.value_linear_units() : Z_HOMING_HEIGHT) - ); + const float z_homing_height = + (DISABLED(UNKNOWN_Z_NO_RAISE) || TEST(axis_known_position, Z_AXIS)) + ? (parser.seenval('R') ? parser.value_linear_units() : Z_HOMING_HEIGHT) + : 0; if (z_homing_height && (doX || doY)) { // Raise Z before homing any other axes and z is not already high enough (never lower z) @@ -355,20 +349,13 @@ void GcodeSuite::G28() { // Home Y (before X) #if ENABLED(HOME_Y_BEFORE_X) - if (doY - #if ENABLED(CODEPENDENT_XY_HOMING) - || doX - #endif - ) homeaxis(Y_AXIS); + if (doY || (doX && ENABLED(CODEPENDENT_XY_HOMING))) + homeaxis(Y_AXIS); #endif // Home X - if (doX - #if ENABLED(CODEPENDENT_XY_HOMING) && DISABLED(HOME_Y_BEFORE_X) - || doY - #endif - ) { + if (doX || (doY && ENABLED(CODEPENDENT_XY_HOMING) && DISABLED(HOME_Y_BEFORE_X))) { #if ENABLED(DUAL_X_CARRIAGE) @@ -396,9 +383,8 @@ void GcodeSuite::G28() { } // Home Y (after X) - #if DISABLED(HOME_Y_BEFORE_X) - if (doY) homeaxis(Y_AXIS); - #endif + if (DISABLED(HOME_Y_BEFORE_X) && doY) + homeaxis(Y_AXIS); #if ENABLED(IMPROVE_HOMING_RELIABILITY) end_slow_homing(slow_homing); @@ -487,7 +473,7 @@ void GcodeSuite::G28() { do_blocking_move_to_z(delta_clip_start_height); #endif - #if HAS_LEVELING && ENABLED(RESTORE_LEVELING_AFTER_G28) + #if ENABLED(RESTORE_LEVELING_AFTER_G28) set_bed_leveling_enabled(leveling_was_active); #endif @@ -495,12 +481,7 @@ void GcodeSuite::G28() { // Restore the active tool after homing #if HOTENDS > 1 && (DISABLED(DELTA) || ENABLED(DELTA_HOME_TO_SAFE_ZONE)) - #if EITHER(PARKING_EXTRUDER, DUAL_X_CARRIAGE) - #define NO_FETCH false // fetch the previous toolhead - #else - #define NO_FETCH true - #endif - tool_change(old_tool_index, NO_FETCH); + tool_change(old_tool_index, NONE(PARKING_EXTRUDER, DUAL_X_CARRIAGE)); // Do move if one of these #endif #if HAS_HOMING_CURRENT @@ -523,15 +504,8 @@ void GcodeSuite::G28() { report_current_position(); - #if ENABLED(NANODLP_Z_SYNC) - #if ENABLED(NANODLP_ALL_AXIS) - #define _HOME_SYNC true // For any axis, output sync text. - #else - #define _HOME_SYNC doZ // Only for Z-axis - #endif - if (_HOME_SYNC) - SERIAL_ECHOLNPGM(STR_Z_MOVE_COMP); - #endif + if (ENABLED(NANODLP_Z_SYNC) && (doZ || ENABLED(NANODLP_ALL_AXIS))) + SERIAL_ECHOLNPGM(STR_Z_MOVE_COMP); if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< G28"); diff --git a/Marlin/src/gcode/calibrate/G425.cpp b/Marlin/src/gcode/calibrate/G425.cpp index d2db4ce30..4cf0f62a0 100644 --- a/Marlin/src/gcode/calibrate/G425.cpp +++ b/Marlin/src/gcode/calibrate/G425.cpp @@ -56,8 +56,12 @@ #define CALIBRATION_MEASUREMENT_CERTAIN 0.5 // mm #endif -#define HAS_X_CENTER BOTH(CALIBRATION_MEASURE_LEFT, CALIBRATION_MEASURE_RIGHT) -#define HAS_Y_CENTER BOTH(CALIBRATION_MEASURE_FRONT, CALIBRATION_MEASURE_BACK) +#if BOTH(CALIBRATION_MEASURE_LEFT, CALIBRATION_MEASURE_RIGHT) + #define HAS_X_CENTER 1 +#endif +#if BOTH(CALIBRATION_MEASURE_FRONT, CALIBRATION_MEASURE_BACK) + #define HAS_Y_CENTER 1 +#endif enum side_t : uint8_t { TOP, RIGHT, FRONT, LEFT, BACK, NUM_SIDES }; diff --git a/Marlin/src/gcode/host/M115.cpp b/Marlin/src/gcode/host/M115.cpp index 4d2c5d5d6..d74f909c4 100644 --- a/Marlin/src/gcode/host/M115.cpp +++ b/Marlin/src/gcode/host/M115.cpp @@ -54,39 +54,19 @@ void GcodeSuite::M115() { #endif // SERIAL_XON_XOFF - cap_line(PSTR("SERIAL_XON_XOFF") - #if ENABLED(SERIAL_XON_XOFF) - , true - #endif - ); + cap_line(PSTR("SERIAL_XON_XOFF"), ENABLED(SERIAL_XON_XOFF)); // BINARY_FILE_TRANSFER (M28 B1) - cap_line(PSTR("BINARY_FILE_TRANSFER") - #if ENABLED(BINARY_FILE_TRANSFER) - , true - #endif - ); + cap_line(PSTR("BINARY_FILE_TRANSFER"), ENABLED(BINARY_FILE_TRANSFER)); // EEPROM (M500, M501) - cap_line(PSTR("EEPROM") - #if ENABLED(EEPROM_SETTINGS) - , true - #endif - ); + cap_line(PSTR("EEPROM"), ENABLED(EEPROM_SETTINGS)); // Volumetric Extrusion (M200) - cap_line(PSTR("VOLUMETRIC") - #if DISABLED(NO_VOLUMETRICS) - , true - #endif - ); + cap_line(PSTR("VOLUMETRIC"), DISABLED(NO_VOLUMETRICS)); // AUTOREPORT_TEMP (M155) - cap_line(PSTR("AUTOREPORT_TEMP") - #if ENABLED(AUTO_REPORT_TEMPERATURES) - , true - #endif - ); + cap_line(PSTR("AUTOREPORT_TEMP"), ENABLED(AUTO_REPORT_TEMPERATURES)); // PROGRESS (M530 S L, M531 , M532 X L) cap_line(PSTR("PROGRESS")); @@ -95,93 +75,42 @@ void GcodeSuite::M115() { cap_line(PSTR("PRINT_JOB"), true); // AUTOLEVEL (G29) - cap_line(PSTR("AUTOLEVEL") - #if HAS_AUTOLEVEL - , true - #endif - ); + cap_line(PSTR("AUTOLEVEL"), ENABLED(HAS_AUTOLEVEL)); // Z_PROBE (G30) - cap_line(PSTR("Z_PROBE") - #if HAS_BED_PROBE - , true - #endif - ); + cap_line(PSTR("Z_PROBE"), ENABLED(HAS_BED_PROBE)); // MESH_REPORT (M420 V) - cap_line(PSTR("LEVELING_DATA") - #if HAS_LEVELING - , true - #endif - ); + cap_line(PSTR("LEVELING_DATA"), ENABLED(HAS_LEVELING)); // BUILD_PERCENT (M73) - cap_line(PSTR("BUILD_PERCENT") - #if ENABLED(LCD_SET_PROGRESS_MANUALLY) - , true - #endif - ); + cap_line(PSTR("BUILD_PERCENT"), ENABLED(LCD_SET_PROGRESS_MANUALLY)); // SOFTWARE_POWER (M80, M81) - cap_line(PSTR("SOFTWARE_POWER") - #if ENABLED(PSU_CONTROL) - , true - #endif - ); + cap_line(PSTR("SOFTWARE_POWER"), ENABLED(PSU_CONTROL)); // CASE LIGHTS (M355) - cap_line(PSTR("TOGGLE_LIGHTS") - #if HAS_CASE_LIGHT - , true - #endif - ); - cap_line(PSTR("CASE_LIGHT_BRIGHTNESS") - #if HAS_CASE_LIGHT - , PWM_PIN(CASE_LIGHT_PIN) - #endif - ); + cap_line(PSTR("TOGGLE_LIGHTS"), ENABLED(HAS_CASE_LIGHT)); + + cap_line(PSTR("CASE_LIGHT_BRIGHTNESS"), TERN(HAS_CASE_LIGHT, PWM_PIN(CASE_LIGHT_PIN), 0)); // EMERGENCY_PARSER (M108, M112, M410, M876) - cap_line(PSTR("EMERGENCY_PARSER") - #if ENABLED(EMERGENCY_PARSER) - , true - #endif - ); + cap_line(PSTR("EMERGENCY_PARSER"), ENABLED(EMERGENCY_PARSER)); // PROMPT SUPPORT (M876) - cap_line(PSTR("PROMPT_SUPPORT") - #if ENABLED(HOST_PROMPT_SUPPORT) - , true - #endif - ); + cap_line(PSTR("PROMPT_SUPPORT"), ENABLED(HOST_PROMPT_SUPPORT)); // AUTOREPORT_SD_STATUS (M27 extension) - cap_line(PSTR("AUTOREPORT_SD_STATUS") - #if ENABLED(AUTO_REPORT_SD_STATUS) - , true - #endif - ); + cap_line(PSTR("AUTOREPORT_SD_STATUS"), ENABLED(AUTO_REPORT_SD_STATUS)); // THERMAL_PROTECTION - cap_line(PSTR("THERMAL_PROTECTION") - #if (ENABLED(THERMAL_PROTECTION_HOTENDS) || !EXTRUDERS) && (ENABLED(THERMAL_PROTECTION_BED) || !HAS_HEATED_BED) && (ENABLED(THERMAL_PROTECTION_CHAMBER) || !HAS_HEATED_CHAMBER) - , true - #endif - ); + cap_line(PSTR("THERMAL_PROTECTION"), ENABLED(THERMALLY_SAFE)); // MOTION_MODES (M80-M89) - cap_line(PSTR("MOTION_MODES") - #if ENABLED(GCODE_MOTION_MODES) - , true - #endif - ); + cap_line(PSTR("MOTION_MODES"), ENABLED(GCODE_MOTION_MODES)); // CHAMBER_TEMPERATURE (M141, M191) - cap_line(PSTR("CHAMBER_TEMPERATURE") - #if HAS_HEATED_CHAMBER - , true - #endif - ); + cap_line(PSTR("CHAMBER_TEMPERATURE"), ENABLED(HAS_HEATED_CHAMBER)); #endif // EXTENDED_CAPABILITIES_REPORT } diff --git a/Marlin/src/inc/Conditionals_LCD.h b/Marlin/src/inc/Conditionals_LCD.h index b4da3439b..7011e02ca 100644 --- a/Marlin/src/inc/Conditionals_LCD.h +++ b/Marlin/src/inc/Conditionals_LCD.h @@ -26,6 +26,15 @@ * Conditionals that need to be set before Configuration_adv.h or pins.h */ +#if ENABLED(MORGAN_SCARA) + #define IS_SCARA 1 + #define IS_KINEMATIC 1 +#elif ENABLED(DELTA) + #define IS_KINEMATIC 1 +#else + #define IS_CARTESIAN 1 +#endif + #if ENABLED(CARTESIO_UI) #define DOGLCD @@ -193,7 +202,9 @@ #endif // 128x64 I2C OLED LCDs - SSD1306/SSD1309/SH1106 -#define HAS_SSD1306_OLED_I2C ANY(U8GLIB_SSD1306, U8GLIB_SSD1309, U8GLIB_SH1106) +#if ANY(U8GLIB_SSD1306, U8GLIB_SSD1309, U8GLIB_SH1106) + #define HAS_SSD1306_OLED_I2C 1 +#endif #if HAS_SSD1306_OLED_I2C #define IS_ULTRA_LCD #define DOGLCD @@ -347,19 +358,34 @@ #endif // Extensible UI serial touch screens. (See src/lcd/extensible_ui) -#if ANY(MALYAN_LCD, DGUS_LCD, TOUCH_UI_FTDI_EVE) +#if ANY(DGUS_LCD_UI_ORIGIN, DGUS_LCD_UI_FYSETC, DGUS_LCD_UI_HIPRECY) + #define HAS_DGUS_LCD 1 +#endif + +#if ANY(HAS_DGUS_LCD, MALYAN_LCD, TOUCH_UI_FTDI_EVE) #define IS_EXTUI #define EXTENSIBLE_UI #endif // Aliases for LCD features -#define HAS_SPI_LCD ENABLED(ULTRA_LCD) -#define HAS_DISPLAY (HAS_SPI_LCD || ENABLED(EXTENSIBLE_UI)) -#define HAS_GRAPHICAL_LCD ENABLED(DOGLCD) -#define HAS_CHARACTER_LCD (HAS_SPI_LCD && !HAS_GRAPHICAL_LCD) -#define HAS_LCD_MENU (ENABLED(ULTIPANEL) && DISABLED(NO_LCD_MENUS)) -#define HAS_ADC_BUTTONS ENABLED(ADC_KEYPAD) -#define HAS_DGUS_LCD ANY(DGUS_LCD_UI_ORIGIN, DGUS_LCD_UI_FYSETC, DGUS_LCD_UI_HIPRECY) +#if EITHER(ULTRA_LCD, EXTENSIBLE_UI) + #define HAS_DISPLAY 1 + #if ENABLED(ULTRA_LCD) + #define HAS_SPI_LCD 1 + #if ENABLED(DOGLCD) + #define HAS_GRAPHICAL_LCD 1 + #else + #define HAS_CHARACTER_LCD 1 + #endif + #endif +#endif + +#if ENABLED(ULTIPANEL) && DISABLED(NO_LCD_MENUS) + #define HAS_LCD_MENU 1 +#endif +#if ENABLED(ADC_KEYPAD) + #define HAS_ADC_BUTTONS 1 +#endif #if HAS_GRAPHICAL_LCD #ifndef LCD_PIXEL_WIDTH @@ -447,12 +473,17 @@ #define ARRAY_BY_HOTENDS(V...) ARRAY_N(HOTENDS, V) #define ARRAY_BY_HOTENDS1(v1) ARRAY_BY_HOTENDS(v1, v1, v1, v1, v1, v1, v1, v1) -#define DO_SWITCH_EXTRUDER (ENABLED(SWITCHING_EXTRUDER) && (DISABLED(SWITCHING_NOZZLE) || SWITCHING_EXTRUDER_SERVO_NR != SWITCHING_NOZZLE_SERVO_NR)) -#define SWITCHING_NOZZLE_TWO_SERVOS defined(SWITCHING_NOZZLE_E1_SERVO_NR) +#if ENABLED(SWITCHING_EXTRUDER) && (DISABLED(SWITCHING_NOZZLE) || SWITCHING_EXTRUDER_SERVO_NR != SWITCHING_NOZZLE_SERVO_NR) + #define DO_SWITCH_EXTRUDER 1 +#endif -#define HAS_DUPLICATION_MODE EITHER(DUAL_X_CARRIAGE, MULTI_NOZZLE_DUPLICATION) +#ifdef SWITCHING_NOZZLE_E1_SERVO_NR + #define SWITCHING_NOZZLE_TWO_SERVOS 1 +#endif -#define HAS_HOTEND_OFFSET (HOTENDS > 1) +#if HOTENDS > 1 + #define HAS_HOTEND_OFFSET 1 +#endif /** * Default hotend offsets, if not defined @@ -509,6 +540,10 @@ #endif #endif +#ifndef NUM_SERVOS + #define NUM_SERVOS 0 +#endif + #ifndef PREHEAT_1_LABEL #define PREHEAT_1_LABEL "PLA" #endif @@ -520,8 +555,12 @@ /** * Set a flag for a servo probe (or BLTouch) */ -#define HAS_Z_SERVO_PROBE (defined(Z_PROBE_SERVO_NR) && Z_PROBE_SERVO_NR >= 0) -#define HAS_SERVO_ANGLES (HAS_Z_SERVO_PROBE || EITHER(SWITCHING_EXTRUDER, SWITCHING_NOZZLE)) +#if defined(Z_PROBE_SERVO_NR) && Z_PROBE_SERVO_NR >= 0 + #define HAS_Z_SERVO_PROBE 1 +#endif +#if HAS_Z_SERVO_PROBE || EITHER(SWITCHING_EXTRUDER, SWITCHING_NOZZLE) + #define HAS_SERVO_ANGLES 1 +#endif #if !HAS_SERVO_ANGLES #undef EDITABLE_SERVO_ANGLES #endif @@ -529,20 +568,31 @@ /** * Set flags for enabled probes */ -#define HAS_BED_PROBE (HAS_Z_SERVO_PROBE || ANY(FIX_MOUNTED_PROBE, NOZZLE_AS_PROBE, TOUCH_MI_PROBE, Z_PROBE_ALLEN_KEY, Z_PROBE_SLED, SOLENOID_PROBE, SENSORLESS_PROBING, RACK_AND_PINION_PROBE)) -#define PROBE_SELECTED (HAS_BED_PROBE || EITHER(PROBE_MANUALLY, MESH_BED_LEVELING)) +#if ANY(HAS_Z_SERVO_PROBE, FIX_MOUNTED_PROBE, NOZZLE_AS_PROBE, TOUCH_MI_PROBE, Z_PROBE_ALLEN_KEY, Z_PROBE_SLED, SOLENOID_PROBE, SENSORLESS_PROBING, RACK_AND_PINION_PROBE) + #define HAS_BED_PROBE 1 +#endif + +#if HAS_BED_PROBE || EITHER(PROBE_MANUALLY, MESH_BED_LEVELING) + #define PROBE_SELECTED 1 +#endif #if HAS_BED_PROBE - #define HAS_PROBE_XY_OFFSET DISABLED(NOZZLE_AS_PROBE) - #define HAS_CUSTOM_PROBE_PIN DISABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) - #define HOMING_Z_WITH_PROBE (Z_HOME_DIR < 0 && !HAS_CUSTOM_PROBE_PIN) + #if DISABLED(NOZZLE_AS_PROBE) + #define HAS_PROBE_XY_OFFSET 1 + #endif + #if DISABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) + #define HAS_CUSTOM_PROBE_PIN 1 + #endif + #if Z_HOME_DIR < 0 && !HAS_CUSTOM_PROBE_PIN + #define HOMING_Z_WITH_PROBE 1 + #endif #ifndef Z_PROBE_LOW_POINT #define Z_PROBE_LOW_POINT -5 #endif #if ENABLED(Z_PROBE_ALLEN_KEY) - #define PROBE_TRIGGERED_WHEN_STOWED_TEST // Extra test for Allen Key Probe + #define PROBE_TRIGGERED_WHEN_STOWED_TEST 1 // Extra test for Allen Key Probe #endif - #ifdef MULTIPLE_PROBING + #if MULTIPLE_PROBING > 1 #if EXTRA_PROBING #define TOTAL_PROBING (MULTIPLE_PROBING + EXTRA_PROBING) #else @@ -558,23 +608,6 @@ #define GRID_MAX_POINTS ((GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y)) #endif -#define HAS_EXTRA_ENDSTOPS ANY(X_DUAL_ENDSTOPS, Y_DUAL_ENDSTOPS, Z_MULTI_ENDSTOPS) -#define HAS_SOFTWARE_ENDSTOPS EITHER(MIN_SOFTWARE_ENDSTOPS, MAX_SOFTWARE_ENDSTOPS) -#define HAS_RESUME_CONTINUE ANY(EXTENSIBLE_UI, NEWPANEL, EMERGENCY_PARSER) -#define HAS_COLOR_LEDS ANY(BLINKM, RGB_LED, RGBW_LED, PCA9632, PCA9533, NEOPIXEL_LED) -#define HAS_LEDS_OFF_FLAG (BOTH(PRINTER_EVENT_LEDS, SDSUPPORT) && HAS_RESUME_CONTINUE) -#define HAS_PRINT_PROGRESS EITHER(SDSUPPORT, LCD_SET_PROGRESS_MANUALLY) -#define HAS_PRINT_PROGRESS_PERMYRIAD (HAS_PRINT_PROGRESS && EITHER(PRINT_PROGRESS_SHOW_DECIMALS, SHOW_REMAINING_TIME)) -#define HAS_SERVICE_INTERVALS (ENABLED(PRINTCOUNTER) && (SERVICE_INTERVAL_1 > 0 || SERVICE_INTERVAL_2 > 0 || SERVICE_INTERVAL_3 > 0)) -#define HAS_FILAMENT_SENSOR ENABLED(FILAMENT_RUNOUT_SENSOR) - -#define HAS_GAMES ANY(MARLIN_BRICKOUT, MARLIN_INVADERS, MARLIN_SNAKE, MARLIN_MAZE) -#define HAS_GAME_MENU (1 < ENABLED(MARLIN_BRICKOUT) + ENABLED(MARLIN_INVADERS) + ENABLED(MARLIN_SNAKE) + ENABLED(MARLIN_MAZE)) - -#define IS_SCARA ENABLED(MORGAN_SCARA) -#define IS_KINEMATIC (ENABLED(DELTA) || IS_SCARA) -#define IS_CARTESIAN !IS_KINEMATIC - #ifndef INVERT_X_DIR #define INVERT_X_DIR false #endif @@ -592,16 +625,15 @@ #define BOOT_MARLIN_LOGO_SMALL #endif -#define IS_RE_ARM_BOARD MB(RAMPS_14_RE_ARM_EFB, RAMPS_14_RE_ARM_EEB, RAMPS_14_RE_ARM_EFF, RAMPS_14_RE_ARM_EEF, RAMPS_14_RE_ARM_SF) - -// Linear advance uses Jerk since E is an isolated axis -#define HAS_LINEAR_E_JERK (DISABLED(CLASSIC_JERK) && ENABLED(LIN_ADVANCE)) - // This flag indicates some kind of jerk storage is needed -#define HAS_CLASSIC_JERK (ENABLED(CLASSIC_JERK) || IS_KINEMATIC) +#if ENABLED(CLASSIC_JERK) || IS_KINEMATIC + #define HAS_CLASSIC_JERK 1 +#endif // E jerk exists with JD disabled (of course) but also when Linear Advance is disabled on Delta/SCARA -#define HAS_CLASSIC_E_JERK (ENABLED(CLASSIC_JERK) || (IS_KINEMATIC && DISABLED(LIN_ADVANCE))) +#if ENABLED(CLASSIC_JERK) || (IS_KINEMATIC && DISABLED(LIN_ADVANCE)) + #define HAS_CLASSIC_E_JERK 1 +#endif #ifndef SPI_SPEED #define SPI_SPEED SPI_FULL_SPEED diff --git a/Marlin/src/inc/Conditionals_adv.h b/Marlin/src/inc/Conditionals_adv.h index ea2578c46..8c286e64d 100644 --- a/Marlin/src/inc/Conditionals_adv.h +++ b/Marlin/src/inc/Conditionals_adv.h @@ -56,6 +56,50 @@ #undef SHOW_TEMP_ADC_VALUES #endif +#if EITHER(DUAL_X_CARRIAGE, MULTI_NOZZLE_DUPLICATION) + #define HAS_DUPLICATION_MODE 1 +#endif + +#if ENABLED(PRINTCOUNTER) && (SERVICE_INTERVAL_1 > 0 || SERVICE_INTERVAL_2 > 0 || SERVICE_INTERVAL_3 > 0) + #define HAS_SERVICE_INTERVALS 1 +#endif + +#if ENABLED(FILAMENT_RUNOUT_SENSOR) + #define HAS_FILAMENT_SENSOR 1 +#endif + +#if EITHER(SDSUPPORT, LCD_SET_PROGRESS_MANUALLY) + #define HAS_PRINT_PROGRESS 1 +#endif + +#if HAS_PRINT_PROGRESS && EITHER(PRINT_PROGRESS_SHOW_DECIMALS, SHOW_REMAINING_TIME) + #define HAS_PRINT_PROGRESS_PERMYRIAD 1 +#endif + +#if ANY(MARLIN_BRICKOUT, MARLIN_INVADERS, MARLIN_SNAKE, MARLIN_MAZE) + #define HAS_GAMES 1 + #if (1 < ENABLED(MARLIN_BRICKOUT) + ENABLED(MARLIN_INVADERS) + ENABLED(MARLIN_SNAKE) + ENABLED(MARLIN_MAZE)) + #define HAS_GAME_MENU 1 + #endif +#endif + +#if ANY(X_DUAL_ENDSTOPS, Y_DUAL_ENDSTOPS, Z_MULTI_ENDSTOPS) + #define HAS_EXTRA_ENDSTOPS 1 +#endif +#if EITHER(MIN_SOFTWARE_ENDSTOPS, MAX_SOFTWARE_ENDSTOPS) + #define HAS_SOFTWARE_ENDSTOPS 1 +#endif +#if ANY(EXTENSIBLE_UI, NEWPANEL, EMERGENCY_PARSER) + #define HAS_RESUME_CONTINUE 1 +#endif + +#if ANY(BLINKM, RGB_LED, RGBW_LED, PCA9632, PCA9533, NEOPIXEL_LED) + #define HAS_COLOR_LEDS 1 +#endif +#if ALL(HAS_RESUME_CONTINUE, PRINTER_EVENT_LEDS, SDSUPPORT) + #define HAS_LEDS_OFF_FLAG 1 +#endif + #if !NUM_SERIAL #undef BAUD_RATE_GCODE #endif @@ -65,10 +109,6 @@ #define NUM_Z_STEPPER_DRIVERS 1 #endif -#ifndef PLR_ENABLED_DEFAULT - #define PLR_ENABLED_DEFAULT true -#endif - #if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS) #undef Z_STEPPER_ALIGN_AMP #endif @@ -171,10 +211,14 @@ #endif // If platform requires early initialization of watchdog to properly boot -#define EARLY_WATCHDOG (ENABLED(USE_WATCHDOG) && defined(ARDUINO_ARCH_SAM)) +#if ENABLED(USE_WATCHDOG) && defined(ARDUINO_ARCH_SAM) + #define EARLY_WATCHDOG 1 +#endif // Extensible UI pin mapping for RepRapDiscount -#define TOUCH_UI_ULTIPANEL ENABLED(TOUCH_UI_FTDI_EVE) && ANY(AO_EXP1_PINMAP, AO_EXP2_PINMAP, CR10_TFT_PINMAP) +#if ENABLED(TOUCH_UI_FTDI_EVE) && ANY(AO_EXP1_PINMAP, AO_EXP2_PINMAP, CR10_TFT_PINMAP) + #define TOUCH_UI_ULTIPANEL 1 +#endif // Poll-based jogging for joystick and other devices #if ENABLED(JOYSTICK) diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index 32243afc3..0a7d7aa52 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -30,6 +30,11 @@ // Extras for CI testing #endif +// Linear advance uses Jerk since E is an isolated axis +#if DISABLED(CLASSIC_JERK) && ENABLED(LIN_ADVANCE) + #define HAS_LINEAR_E_JERK 1 +#endif + #ifdef TEENSYDUINO #undef max #define max(a,b) ((a)>(b)?(a):(b)) @@ -63,13 +68,8 @@ // Define center values for future use #define _X_HALF_BED ((X_BED_SIZE) / 2) #define _Y_HALF_BED ((Y_BED_SIZE) / 2) -#if ENABLED(BED_CENTER_AT_0_0) - #define X_CENTER 0 - #define Y_CENTER 0 -#else - #define X_CENTER _X_HALF_BED - #define Y_CENTER _Y_HALF_BED -#endif +#define X_CENTER TERN(BED_CENTER_AT_0_0, 0, _X_HALF_BED) +#define Y_CENTER TERN(BED_CENTER_AT_0_0, 0, _Y_HALF_BED) // Get the linear boundaries of the bed #define X_MIN_BED (X_CENTER - _X_HALF_BED) @@ -92,10 +92,18 @@ /** * CoreXY, CoreXZ, and CoreYZ - and their reverse */ -#define CORE_IS_XY EITHER(COREXY, COREYX) -#define CORE_IS_XZ EITHER(COREXZ, COREZX) -#define CORE_IS_YZ EITHER(COREYZ, COREZY) -#define IS_CORE (CORE_IS_XY || CORE_IS_XZ || CORE_IS_YZ) +#if EITHER(COREXY, COREYX) + #define CORE_IS_XY 1 +#endif +#if EITHER(COREXZ, COREZX) + #define CORE_IS_XZ 1 +#endif +#if EITHER(COREYZ, COREZY) + #define CORE_IS_YZ 1 +#endif +#if CORE_IS_XY || CORE_IS_XZ || CORE_IS_YZ + #define IS_CORE 1 +#endif #if IS_CORE #if CORE_IS_XY #define CORE_AXIS_1 A_AXIS @@ -110,11 +118,7 @@ #define CORE_AXIS_1 B_AXIS #define CORE_AXIS_2 C_AXIS #endif - #if ANY(COREYX, COREZX, COREZY) - #define CORESIGN(n) (-(n)) - #else - #define CORESIGN(n) (n) - #endif + #define CORESIGN(n) (ANY(COREYX, COREZX, COREZY) ? (-(n)) : (n)) #endif /** @@ -139,33 +143,23 @@ */ #ifdef MANUAL_X_HOME_POS #define X_HOME_POS MANUAL_X_HOME_POS -#elif ENABLED(BED_CENTER_AT_0_0) - #if ENABLED(DELTA) - #define X_HOME_POS 0 - #else - #define X_HOME_POS (X_HOME_DIR < 0 ? X_MIN_POS : X_MAX_POS) - #endif #else - #if ENABLED(DELTA) - #define X_HOME_POS (X_MIN_POS + (X_BED_SIZE) * 0.5) + #define X_END_POS (X_HOME_DIR < 0 ? X_MIN_POS : X_MAX_POS) + #if ENABLED(BED_CENTER_AT_0_0) + #define X_HOME_POS TERN(DELTA, 0, X_END_POS) #else - #define X_HOME_POS (X_HOME_DIR < 0 ? X_MIN_POS : X_MAX_POS) + #define X_HOME_POS TERN(DELTA, X_MIN_POS + (X_BED_SIZE) * 0.5, X_END_POS) #endif #endif #ifdef MANUAL_Y_HOME_POS #define Y_HOME_POS MANUAL_Y_HOME_POS -#elif ENABLED(BED_CENTER_AT_0_0) - #if ENABLED(DELTA) - #define Y_HOME_POS 0 - #else - #define Y_HOME_POS (Y_HOME_DIR < 0 ? Y_MIN_POS : Y_MAX_POS) - #endif #else - #if ENABLED(DELTA) - #define Y_HOME_POS (Y_MIN_POS + (Y_BED_SIZE) * 0.5) + #define Y_END_POS (Y_HOME_DIR < 0 ? Y_MIN_POS : Y_MAX_POS) + #if ENABLED(BED_CENTER_AT_0_0) + #define Y_HOME_POS TERN(DELTA, 0, Y_END_POS) #else - #define Y_HOME_POS (Y_HOME_DIR < 0 ? Y_MIN_POS : Y_MAX_POS) + #define Y_HOME_POS TERN(DELTA, Y_MIN_POS + (Y_BED_SIZE) * 0.5, Y_END_POS) #endif #endif @@ -268,7 +262,10 @@ #define _LCD_CONTRAST_INIT 17 #endif -#define HAS_LCD_CONTRAST defined(_LCD_CONTRAST_INIT) +#ifdef _LCD_CONTRAST_INIT + #define HAS_LCD_CONTRAST 1 +#endif + #if HAS_LCD_CONTRAST #ifndef LCD_CONTRAST_MIN #ifdef _LCD_CONTRAST_MIN @@ -1291,20 +1288,40 @@ // Trinamic Stepper Drivers #if HAS_TRINAMIC_CONFIG - #define STEALTHCHOP_ENABLED ANY(STEALTHCHOP_XY, STEALTHCHOP_Z, STEALTHCHOP_E) - #define USE_SENSORLESS EITHER(SENSORLESS_HOMING, SENSORLESS_PROBING) + #if ANY(STEALTHCHOP_XY, STEALTHCHOP_Z, STEALTHCHOP_E) + #define STEALTHCHOP_ENABLED 1 + #endif + #if EITHER(SENSORLESS_HOMING, SENSORLESS_PROBING) + #define USE_SENSORLESS 1 + #endif // Disable Z axis sensorless homing if a probe is used to home the Z axis #if HOMING_Z_WITH_PROBE #undef Z_STALL_SENSITIVITY #endif - #define X_SENSORLESS (AXIS_HAS_STALLGUARD(X) && defined(X_STALL_SENSITIVITY)) - #define X2_SENSORLESS (AXIS_HAS_STALLGUARD(X2) && defined(X2_STALL_SENSITIVITY)) - #define Y_SENSORLESS (AXIS_HAS_STALLGUARD(Y) && defined(Y_STALL_SENSITIVITY)) - #define Y2_SENSORLESS (AXIS_HAS_STALLGUARD(Y2) && defined(Y2_STALL_SENSITIVITY)) - #define Z_SENSORLESS (AXIS_HAS_STALLGUARD(Z) && defined(Z_STALL_SENSITIVITY)) - #define Z2_SENSORLESS (AXIS_HAS_STALLGUARD(Z2) && defined(Z2_STALL_SENSITIVITY)) - #define Z3_SENSORLESS (AXIS_HAS_STALLGUARD(Z3) && defined(Z3_STALL_SENSITIVITY)) - #define Z4_SENSORLESS (AXIS_HAS_STALLGUARD(Z4) && defined(Z4_STALL_SENSITIVITY)) + #if defined(X_STALL_SENSITIVITY) && AXIS_HAS_STALLGUARD(X) + #define X_SENSORLESS 1 + #endif + #if defined(X2_STALL_SENSITIVITY) && AXIS_HAS_STALLGUARD(X2) + #define X2_SENSORLESS 1 + #endif + #if defined(Y_STALL_SENSITIVITY) && AXIS_HAS_STALLGUARD(Y) + #define Y_SENSORLESS 1 + #endif + #if defined(Y2_STALL_SENSITIVITY) && AXIS_HAS_STALLGUARD(Y2) + #define Y2_SENSORLESS 1 + #endif + #if defined(Z_STALL_SENSITIVITY) && AXIS_HAS_STALLGUARD(Z) + #define Z_SENSORLESS 1 + #endif + #if defined(Z2_STALL_SENSITIVITY) && AXIS_HAS_STALLGUARD(Z2) + #define Z2_SENSORLESS 1 + #endif + #if defined(Z3_STALL_SENSITIVITY) && AXIS_HAS_STALLGUARD(Z3) + #define Z3_SENSORLESS 1 + #endif + #if defined(Z4_STALL_SENSITIVITY) && AXIS_HAS_STALLGUARD(Z4) + #define Z4_SENSORLESS 1 + #endif #if ENABLED(SPI_ENDSTOPS) #define X_SPI_SENSORLESS X_SENSORLESS #define Y_SPI_SENSORLESS Y_SENSORLESS @@ -1388,23 +1405,48 @@ #define HAS_HEATER_BED (PIN_EXISTS(HEATER_BED)) // Shorthand for common combinations -#define HAS_HEATED_BED (HAS_TEMP_BED && HAS_HEATER_BED) -#define BED_OR_CHAMBER (HAS_HEATED_BED || HAS_TEMP_CHAMBER) -#define HAS_TEMP_SENSOR (HAS_TEMP_HOTEND || BED_OR_CHAMBER || HAS_TEMP_PROBE) -#define HAS_HEATED_CHAMBER (HAS_TEMP_CHAMBER && PIN_EXISTS(HEATER_CHAMBER)) +#if HAS_TEMP_BED && HAS_HEATER_BED + #define HAS_HEATED_BED 1 +#endif +#if HAS_HEATED_BED || HAS_TEMP_CHAMBER + #define BED_OR_CHAMBER 1 +#endif +#if HAS_TEMP_HOTEND || BED_OR_CHAMBER || HAS_TEMP_PROBE + #define HAS_TEMP_SENSOR 1 +#endif +#if HAS_TEMP_CHAMBER && PIN_EXISTS(HEATER_CHAMBER) + #define HAS_HEATED_CHAMBER 1 +#endif // PID heating #if !HAS_HEATED_BED #undef PIDTEMPBED #endif -#define HAS_PID_HEATING EITHER(PIDTEMP, PIDTEMPBED) -#define HAS_PID_FOR_BOTH BOTH(PIDTEMP, PIDTEMPBED) +#if EITHER(PIDTEMP, PIDTEMPBED) + #define HAS_PID_HEATING 1 +#endif +#if BOTH(PIDTEMP, PIDTEMPBED) + #define HAS_PID_FOR_BOTH 1 +#endif // Thermal protection -#define HAS_THERMALLY_PROTECTED_BED (HAS_HEATED_BED && ENABLED(THERMAL_PROTECTION_BED)) -#define WATCH_HOTENDS (ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0) -#define WATCH_BED (HAS_THERMALLY_PROTECTED_BED && WATCH_BED_TEMP_PERIOD > 0) -#define WATCH_CHAMBER (HAS_HEATED_CHAMBER && ENABLED(THERMAL_PROTECTION_CHAMBER) && WATCH_CHAMBER_TEMP_PERIOD > 0) +#if HAS_HEATED_BED && ENABLED(THERMAL_PROTECTION_BED) + #define HAS_THERMALLY_PROTECTED_BED 1 +#endif +#if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0 + #define WATCH_HOTENDS 1 +#endif +#if HAS_THERMALLY_PROTECTED_BED && WATCH_BED_TEMP_PERIOD > 0 + #define WATCH_BED 1 +#endif +#if HAS_HEATED_CHAMBER && ENABLED(THERMAL_PROTECTION_CHAMBER) && WATCH_CHAMBER_TEMP_PERIOD > 0 + #define WATCH_CHAMBER 1 +#endif +#if (ENABLED(THERMAL_PROTECTION_HOTENDS) || !EXTRUDERS) \ + && (ENABLED(THERMAL_PROTECTION_BED) || !HAS_HEATED_BED) \ + && (ENABLED(THERMAL_PROTECTION_CHAMBER) || !HAS_HEATED_CHAMBER) + #define THERMALLY_SAFE 1 +#endif // Auto fans #define HAS_AUTO_FAN_0 (HOTENDS > 0 && PIN_EXISTS(E0_AUTO_FAN)) @@ -1455,22 +1497,48 @@ #define HAS_FILAMENT_WIDTH_SENSOR (PIN_EXISTS(FILWIDTH)) // User Interface -#define HAS_HOME (PIN_EXISTS(HOME)) -#define HAS_KILL (PIN_EXISTS(KILL)) -#define HAS_SUICIDE (PIN_EXISTS(SUICIDE)) -#define HAS_PHOTOGRAPH (PIN_EXISTS(PHOTOGRAPH)) -#define HAS_BUZZER (PIN_EXISTS(BEEPER) || EITHER(LCD_USE_I2C_BUZZER, PCA9632_BUZZER)) -#define USE_BEEPER (HAS_BUZZER && DISABLED(LCD_USE_I2C_BUZZER, PCA9632_BUZZER)) -#define HAS_CASE_LIGHT (PIN_EXISTS(CASE_LIGHT) && ENABLED(CASE_LIGHT_ENABLE)) +#if PIN_EXISTS(HOME) + #define HAS_HOME 1 +#endif +#if PIN_EXISTS(KILL) + #define HAS_KILL 1 +#endif +#if PIN_EXISTS(SUICIDE) + #define HAS_SUICIDE 1 +#endif +#if PIN_EXISTS(PHOTOGRAPH) + #define HAS_PHOTOGRAPH 1 +#endif +#if PIN_EXISTS(BEEPER) || EITHER(LCD_USE_I2C_BUZZER, PCA9632_BUZZER) + #define HAS_BUZZER 1 +#endif +#if HAS_BUZZER && DISABLED(LCD_USE_I2C_BUZZER, PCA9632_BUZZER) + #define USE_BEEPER 1 +#endif +#if PIN_EXISTS(CASE_LIGHT) && ENABLED(CASE_LIGHT_ENABLE) + #define HAS_CASE_LIGHT 1 +#endif // Digital control -#define HAS_STEPPER_RESET (PIN_EXISTS(STEPPER_RESET)) -#define HAS_DIGIPOTSS (PIN_EXISTS(DIGIPOTSS)) -#define HAS_MOTOR_CURRENT_PWM ANY_PIN(MOTOR_CURRENT_PWM_X, MOTOR_CURRENT_PWM_Y, MOTOR_CURRENT_PWM_XY, MOTOR_CURRENT_PWM_Z, MOTOR_CURRENT_PWM_E) +#if PIN_EXISTS(STEPPER_RESET) + #define HAS_STEPPER_RESET 1 +#endif +#if PIN_EXISTS(DIGIPOTSS) + #define HAS_DIGIPOTSS 1 +#endif +#if ANY_PIN(MOTOR_CURRENT_PWM_X, MOTOR_CURRENT_PWM_Y, MOTOR_CURRENT_PWM_XY, MOTOR_CURRENT_PWM_Z, MOTOR_CURRENT_PWM_E) + #define HAS_MOTOR_CURRENT_PWM 1 +#endif -#define HAS_SOME_Z_MICROSTEPS (HAS_Z_MICROSTEPS || HAS_Z2_MICROSTEPS || HAS_Z3_MICROSTEPS || HAS_Z4_MICROSTEPS) -#define HAS_SOME_E_MICROSTEPS (HAS_E0_MICROSTEPS || HAS_E1_MICROSTEPS || HAS_E2_MICROSTEPS || HAS_E3_MICROSTEPS || HAS_E4_MICROSTEPS || HAS_E5_MICROSTEPS || HAS_E6_MICROSTEPS || HAS_E7_MICROSTEPS) -#define HAS_MICROSTEPS (HAS_X_MICROSTEPS || HAS_X2_MICROSTEPS || HAS_Y_MICROSTEPS || HAS_Y2_MICROSTEPS || HAS_SOME_Z_MICROSTEPS || HAS_SOME_E_MICROSTEPS) +#if HAS_Z_MICROSTEPS || HAS_Z2_MICROSTEPS || HAS_Z3_MICROSTEPS || HAS_Z4_MICROSTEPS + #define HAS_SOME_Z_MICROSTEPS 1 +#endif +#if HAS_E0_MICROSTEPS || HAS_E1_MICROSTEPS || HAS_E2_MICROSTEPS || HAS_E3_MICROSTEPS || HAS_E4_MICROSTEPS || HAS_E5_MICROSTEPS || HAS_E6_MICROSTEPS || HAS_E7_MICROSTEPS + #define HAS_SOME_E_MICROSTEPS 1 +#endif +#if HAS_X_MICROSTEPS || HAS_X2_MICROSTEPS || HAS_Y_MICROSTEPS || HAS_Y2_MICROSTEPS || HAS_SOME_Z_MICROSTEPS || HAS_SOME_E_MICROSTEPS + #define HAS_MICROSTEPS 1 +#endif #if HAS_MICROSTEPS @@ -1764,21 +1832,48 @@ /** * Set granular options based on the specific type of leveling */ -#define UBL_SEGMENTED BOTH(AUTO_BED_LEVELING_UBL, DELTA) -#define ABL_PLANAR EITHER(AUTO_BED_LEVELING_LINEAR, AUTO_BED_LEVELING_3POINT) -#define ABL_GRID EITHER(AUTO_BED_LEVELING_LINEAR, AUTO_BED_LEVELING_BILINEAR) -#define HAS_ABL_NOT_UBL (ABL_PLANAR || ABL_GRID) -#define HAS_ABL_OR_UBL (HAS_ABL_NOT_UBL || ENABLED(AUTO_BED_LEVELING_UBL)) -#define HAS_LEVELING (HAS_ABL_OR_UBL || ENABLED(MESH_BED_LEVELING)) -#define HAS_AUTOLEVEL (HAS_ABL_OR_UBL && DISABLED(PROBE_MANUALLY)) -#define HAS_MESH ANY(AUTO_BED_LEVELING_BILINEAR, AUTO_BED_LEVELING_UBL, MESH_BED_LEVELING) -#define PLANNER_LEVELING (HAS_LEVELING && DISABLED(AUTO_BED_LEVELING_UBL)) -#define HAS_PROBING_PROCEDURE (HAS_ABL_OR_UBL || ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST)) -#define HAS_POSITION_MODIFIERS (ENABLED(FWRETRACT) || HAS_LEVELING || ENABLED(SKEW_CORRECTION)) -#define NEEDS_THREE_PROBE_POINTS EITHER(AUTO_BED_LEVELING_UBL, AUTO_BED_LEVELING_3POINT) - #if ENABLED(AUTO_BED_LEVELING_UBL) #undef LCD_BED_LEVELING + #if ENABLED(DELTA) + #define UBL_SEGMENTED 1 + #endif +#endif +#if EITHER(AUTO_BED_LEVELING_LINEAR, AUTO_BED_LEVELING_3POINT) + #define ABL_PLANAR 1 +#endif +#if EITHER(AUTO_BED_LEVELING_LINEAR, AUTO_BED_LEVELING_BILINEAR) + #define ABL_GRID 1 +#endif +#if ANY(AUTO_BED_LEVELING_LINEAR, AUTO_BED_LEVELING_BILINEAR, AUTO_BED_LEVELING_3POINT) + #define HAS_ABL_NOT_UBL 1 +#endif +#if ANY(AUTO_BED_LEVELING_BILINEAR, AUTO_BED_LEVELING_UBL, MESH_BED_LEVELING) + #define HAS_MESH 1 +#endif +#if EITHER(AUTO_BED_LEVELING_UBL, AUTO_BED_LEVELING_3POINT) + #define NEEDS_THREE_PROBE_POINTS 1 +#endif +#if EITHER(HAS_ABL_NOT_UBL, AUTO_BED_LEVELING_UBL) + #define HAS_ABL_OR_UBL 1 + #if DISABLED(PROBE_MANUALLY) + #define HAS_AUTOLEVEL 1 + #endif +#endif +#if EITHER(HAS_ABL_OR_UBL, MESH_BED_LEVELING) + #define HAS_LEVELING 1 + #if DISABLED(AUTO_BED_LEVELING_UBL) + #define PLANNER_LEVELING 1 + #endif +#endif +#if EITHER(HAS_ABL_OR_UBL, Z_MIN_PROBE_REPEATABILITY_TEST) + #define HAS_PROBING_PROCEDURE 1 +#endif +#if ANY(FWRETRACT, HAS_LEVELING, SKEW_CORRECTION) + #define HAS_POSITION_MODIFIERS 1 +#endif + +#if !HAS_LEVELING + #undef RESTORE_LEVELING_AFTER_G28 #endif /** @@ -1905,8 +2000,8 @@ #undef MESH_MAX_Y #endif -#if (defined(PROBE_PT_1_X) && defined(PROBE_PT_2_X) && defined(PROBE_PT_3_X) && defined(PROBE_PT_1_Y) && defined(PROBE_PT_2_Y) && defined(PROBE_PT_3_Y)) - #define HAS_FIXED_3POINT +#if defined(PROBE_PT_1_X) && defined(PROBE_PT_2_X) && defined(PROBE_PT_3_X) && defined(PROBE_PT_1_Y) && defined(PROBE_PT_2_Y) && defined(PROBE_PT_3_Y) + #define HAS_FIXED_3POINT 1 #endif /** @@ -1944,10 +2039,10 @@ * Z_HOMING_HEIGHT / Z_CLEARANCE_BETWEEN_PROBES */ #ifndef Z_HOMING_HEIGHT - #ifndef Z_CLEARANCE_BETWEEN_PROBES - #define Z_HOMING_HEIGHT 0 - #else + #ifdef Z_CLEARANCE_BETWEEN_PROBES #define Z_HOMING_HEIGHT Z_CLEARANCE_BETWEEN_PROBES + #else + #define Z_HOMING_HEIGHT 0 #endif #endif @@ -1975,15 +2070,16 @@ #endif // Updated G92 behavior shifts the workspace -#define HAS_POSITION_SHIFT DISABLED(NO_WORKSPACE_OFFSETS) -// The home offset also shifts the coordinate space -#define HAS_HOME_OFFSET (DISABLED(NO_WORKSPACE_OFFSETS) && IS_CARTESIAN) -// The SCARA home offset applies only on G28 -#define HAS_SCARA_OFFSET (DISABLED(NO_WORKSPACE_OFFSETS) && IS_SCARA) -// Cumulative offset to workspace to save some calculation -#define HAS_WORKSPACE_OFFSET (HAS_POSITION_SHIFT && HAS_HOME_OFFSET) -// M206 sets the home offset for Cartesian machines -#define HAS_M206_COMMAND (HAS_HOME_OFFSET && !IS_SCARA) +#if DISABLED(NO_WORKSPACE_OFFSETS) + #define HAS_POSITION_SHIFT 1 + #if IS_CARTESIAN + #define HAS_HOME_OFFSET 1 // The home offset also shifts the coordinate space + #define HAS_WORKSPACE_OFFSET 1 // Cumulative offset to workspace to save some calculation + #define HAS_M206_COMMAND 1 // M206 sets the home offset for Cartesian machines + #elif IS_SCARA + #define HAS_SCARA_OFFSET 1 // The SCARA home offset applies only on G28 + #endif +#endif // LCD timeout to status screen default is 15s #ifndef LCD_TIMEOUT_TO_STATUS @@ -2006,11 +2102,7 @@ #endif // Number of VFAT entries used. Each entry has 13 UTF-16 characters -#if ENABLED(SCROLL_LONG_FILENAMES) - #define MAX_VFAT_ENTRIES (5) -#else - #define MAX_VFAT_ENTRIES (2) -#endif +#define MAX_VFAT_ENTRIES TERN(SCROLL_LONG_FILENAMES, 5, 2) // Nozzle park for Delta #if BOTH(NOZZLE_PARK_FEATURE, DELTA) @@ -2022,9 +2114,8 @@ // on boards where SD card and LCD display share the same SPI bus // because of a bug in the shared SPI implementation. (See #8122) #if defined(TARGET_LPC1768) && ENABLED(REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER) && (SCK_PIN == LCD_PINS_D4) - #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. + #define SDCARD_SORT_ALPHA // Keep one directory level in RAM. Changing directory levels + // may still glitch the screen, but LCD updates clean it up. #undef SDSORT_LIMIT #undef SDSORT_USES_RAM #undef SDSORT_USES_STACK @@ -2057,19 +2148,15 @@ #ifndef LCD_WIDTH #if HAS_GRAPHICAL_LCD #define LCD_WIDTH 21 - #elif ENABLED(ULTIPANEL) - #define LCD_WIDTH 20 #else - #define LCD_WIDTH 16 + #define LCD_WIDTH TERN(ULTIPANEL, 20, 16) #endif #endif #ifndef LCD_HEIGHT #if HAS_GRAPHICAL_LCD #define LCD_HEIGHT 5 - #elif ENABLED(ULTIPANEL) - #define LCD_HEIGHT 4 #else - #define LCD_HEIGHT 2 + #define LCD_HEIGHT TERN(ULTIPANEL, 4, 2) #endif #endif #endif diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 885158afe..4c9af7c79 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -34,6 +34,37 @@ #error "Marlin requires C++11 support (gcc >= 4.7, Arduino IDE >= 1.6.8). Please upgrade your toolchain." #endif +// Make sure macros aren't borked +#define TEST1 +#define TEST2 1 +#define TEST3 0 +#define TEST4 true +#if ENABLED(TEST0) + #error "ENABLED is borked!" +#endif +#if DISABLED(TEST1) + #error "DISABLED is borked!" +#endif +#if !ENABLED(TEST2) + #error "ENABLED is borked!" +#endif +#if ENABLED(TEST3) + #error "ENABLED is borked!" +#endif +#if DISABLED(TEST4) + #error "DISABLED is borked!" +#endif +#if !ANY(TEST1, TEST2, TEST3, TEST4) || ANY(TEST0, TEST3) + #error "ANY is borked!" +#endif +#if DISABLED(TEST0, TEST1, TEST2, TEST4) + #error "DISABLED is borked!" +#endif +#undef TEST1 +#undef TEST2 +#undef TEST3 +#undef TEST4 + /** * We try our best to include sanity checks for all changed configuration * directives because users have a tendency to use outdated config files with @@ -1237,7 +1268,7 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS * Require some kind of probe for bed leveling and probe testing */ #if HAS_ABL_NOT_UBL && !PROBE_SELECTED - #error "Auto Bed Leveling requires one of these: PROBE_MANUALLY, FIX_MOUNTED_PROBE, NOZZLE_AS_PROBE, BLTOUCH, SOLENOID_PROBE, Z_PROBE_ALLEN_KEY, Z_PROBE_SLED, or a Z Servo." + #error "Auto Bed Leveling requires one of these: PROBE_MANUALLY, SENSORLESS_PROBING, BLTOUCH, FIX_MOUNTED_PROBE, NOZZLE_AS_PROBE, TOUCH_MI_PROBE, SOLENOID_PROBE, Z_PROBE_ALLEN_KEY, Z_PROBE_SLED, or a Z Servo." #endif #if ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST) diff --git a/Marlin/src/lcd/ultralcd.h b/Marlin/src/lcd/ultralcd.h index f614e2009..a16103ba4 100644 --- a/Marlin/src/lcd/ultralcd.h +++ b/Marlin/src/lcd/ultralcd.h @@ -27,10 +27,18 @@ #include "../libs/buzzer.h" #endif -#define HAS_ENCODER_ACTION (HAS_LCD_MENU || ENABLED(ULTIPANEL_FEEDMULTIPLY)) -#define HAS_ENCODER_WHEEL ((!HAS_ADC_BUTTONS && ENABLED(NEWPANEL)) || BUTTONS_EXIST(EN1, EN2)) -#define HAS_DIGITAL_BUTTONS (HAS_ENCODER_WHEEL || ANY_BUTTON(ENC, BACK, UP, DWN, LFT, RT)) -#define HAS_SHIFT_ENCODER (!HAS_ADC_BUTTONS && (ENABLED(REPRAPWORLD_KEYPAD) || (HAS_SPI_LCD && DISABLED(NEWPANEL)))) +#if HAS_LCD_MENU || ENABLED(ULTIPANEL_FEEDMULTIPLY) + #define HAS_ENCODER_ACTION 1 +#endif +#if (!HAS_ADC_BUTTONS && ENABLED(NEWPANEL)) || BUTTONS_EXIST(EN1, EN2) + #define HAS_ENCODER_WHEEL 1 +#endif +#if HAS_ENCODER_WHEEL || ANY_BUTTON(ENC, BACK, UP, DWN, LFT, RT) + #define HAS_DIGITAL_BUTTONS 1 +#endif +#if !HAS_ADC_BUTTONS && (ENABLED(REPRAPWORLD_KEYPAD) || (HAS_SPI_LCD && DISABLED(NEWPANEL))) + #define HAS_SHIFT_ENCODER 1 +#endif // I2C buttons must be read in the main thread #define HAS_SLOW_BUTTONS EITHER(LCD_I2C_VIKI, LCD_I2C_PANELOLU2) diff --git a/Marlin/src/module/configuration_store.cpp b/Marlin/src/module/configuration_store.cpp index 9d1bbaab2..16e88b7bf 100644 --- a/Marlin/src/module/configuration_store.cpp +++ b/Marlin/src/module/configuration_store.cpp @@ -181,11 +181,8 @@ typedef struct SettingsDataStruct { // float mbl_z_offset; // mbl.z_offset uint8_t mesh_num_x, mesh_num_y; // GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y - #if ENABLED(MESH_BED_LEVELING) - float mbl_z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y]; // mbl.z_values - #else - float mbl_z_values[3][3]; - #endif + float mbl_z_values[TERN(MESH_BED_LEVELING, GRID_MAX_POINTS_X, 3)] // mbl.z_values + [TERN(MESH_BED_LEVELING, GRID_MAX_POINTS_Y, 3)]; // // HAS_BED_PROBE @@ -533,11 +530,10 @@ void MarlinSettings::postprocess() { EEPROM_START(); eeprom_error = false; - #if ENABLED(FLASH_EEPROM_EMULATION) - EEPROM_SKIP(ver); // Flash doesn't allow rewriting without erase - #else - EEPROM_WRITE(ver); // invalidate data first - #endif + + // Write or Skip version. (Flash doesn't allow rewrite without erase.) + TERN(FLASH_EEPROM_EMULATION, EEPROM_SKIP, EEPROM_WRITE)(ver); + EEPROM_SKIP(working_crc); // Skip the checksum slot working_crc = 0; // clear before first "real data" @@ -564,12 +560,10 @@ void MarlinSettings::postprocess() { EEPROM_WRITE(planner_max_jerk); #endif - #if DISABLED(CLASSIC_JERK) - EEPROM_WRITE(planner.junction_deviation_mm); - #else + #if ENABLED(CLASSIC_JERK) dummyf = 0.02f; - EEPROM_WRITE(dummyf); #endif + EEPROM_WRITE(TERN(CLASSIC_JERK, dummyf, planner.junction_deviation_mm)); } // @@ -617,13 +611,7 @@ void MarlinSettings::postprocess() { // Global Leveling // { - const float zfh = ( - #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) - planner.z_fade_height - #else - 10.0 - #endif - ); + const float zfh = TERN(ENABLE_LEVELING_FADE_HEIGHT, planner.z_fade_height, 10.0f); EEPROM_WRITE(zfh); } @@ -632,22 +620,24 @@ void MarlinSettings::postprocess() { // { #if ENABLED(MESH_BED_LEVELING) - // Compile time test that sizeof(mbl.z_values) is as expected static_assert( sizeof(mbl.z_values) == (GRID_MAX_POINTS) * sizeof(mbl.z_values[0][0]), "MBL Z array is the wrong size." ); - const uint8_t mesh_num_x = GRID_MAX_POINTS_X, mesh_num_y = GRID_MAX_POINTS_Y; - EEPROM_WRITE(mbl.z_offset); - EEPROM_WRITE(mesh_num_x); - EEPROM_WRITE(mesh_num_y); - EEPROM_WRITE(mbl.z_values); - #else // For disabled MBL write a default mesh + #else dummyf = 0; - const uint8_t mesh_num_x = 3, mesh_num_y = 3; - EEPROM_WRITE(dummyf); // z_offset - EEPROM_WRITE(mesh_num_x); - EEPROM_WRITE(mesh_num_y); + #endif + + const uint8_t mesh_num_x = TERN(MESH_BED_LEVELING, GRID_MAX_POINTS_X, 3), + mesh_num_y = TERN(MESH_BED_LEVELING, GRID_MAX_POINTS_Y, 3); + + EEPROM_WRITE(TERN(MESH_BED_LEVELING, mbl.z_offset, dummyf)); + EEPROM_WRITE(mesh_num_x); + EEPROM_WRITE(mesh_num_y); + + #if ENABLED(MESH_BED_LEVELING) + EEPROM_WRITE(mbl.z_values); + #else for (uint8_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_WRITE(dummyf); #endif } @@ -682,26 +672,25 @@ void MarlinSettings::postprocess() { // { #if ENABLED(AUTO_BED_LEVELING_BILINEAR) - // Compile time test that sizeof(z_values) is as expected static_assert( sizeof(z_values) == (GRID_MAX_POINTS) * sizeof(z_values[0][0]), "Bilinear Z array is the wrong size." ); - const uint8_t grid_max_x = GRID_MAX_POINTS_X, grid_max_y = GRID_MAX_POINTS_Y; - EEPROM_WRITE(grid_max_x); // 1 byte - EEPROM_WRITE(grid_max_y); // 1 byte - EEPROM_WRITE(bilinear_grid_spacing); // 2 ints - EEPROM_WRITE(bilinear_start); // 2 ints - EEPROM_WRITE(z_values); // 9-256 floats #else - // For disabled Bilinear Grid write an empty 3x3 grid - const uint8_t grid_max_x = 3, grid_max_y = 3; const xy_pos_t bilinear_start{0}, bilinear_grid_spacing{0}; + #endif + + const uint8_t grid_max_x = TERN(AUTO_BED_LEVELING_BILINEAR, GRID_MAX_POINTS_X, 3), + grid_max_y = TERN(AUTO_BED_LEVELING_BILINEAR, GRID_MAX_POINTS_Y, 3); + EEPROM_WRITE(grid_max_x); + EEPROM_WRITE(grid_max_y); + EEPROM_WRITE(bilinear_grid_spacing); + EEPROM_WRITE(bilinear_start); + + #if ENABLED(AUTO_BED_LEVELING_BILINEAR) + EEPROM_WRITE(z_values); // 9-256 floats + #else dummyf = 0; - EEPROM_WRITE(grid_max_x); - EEPROM_WRITE(grid_max_y); - EEPROM_WRITE(bilinear_grid_spacing); - EEPROM_WRITE(bilinear_start); for (uint16_t q = grid_max_x * grid_max_y; q--;) EEPROM_WRITE(dummyf); #endif } @@ -711,16 +700,10 @@ void MarlinSettings::postprocess() { // { _FIELD_TEST(planner_leveling_active); - - #if ENABLED(AUTO_BED_LEVELING_UBL) - EEPROM_WRITE(planner.leveling_active); - EEPROM_WRITE(ubl.storage_slot); - #else - const bool ubl_active = false; - const int8_t storage_slot = -1; - EEPROM_WRITE(ubl_active); - EEPROM_WRITE(storage_slot); - #endif // AUTO_BED_LEVELING_UBL + const bool ubl_active = TERN(AUTO_BED_LEVELING_UBL, planner.leveling_active, false); + const int8_t storage_slot = TERN(AUTO_BED_LEVELING_UBL, ubl.storage_slot, -1); + EEPROM_WRITE(ubl_active); + EEPROM_WRITE(storage_slot); } // @@ -728,7 +711,6 @@ void MarlinSettings::postprocess() { // { _FIELD_TEST(servo_angles); - #if !HAS_SERVO_ANGLES uint16_t servo_angles[EEPROM_NUM_SERVOS][2] = { { 0, 0 } }; #endif @@ -753,11 +735,7 @@ void MarlinSettings::postprocess() { // { _FIELD_TEST(bltouch_last_written_mode); - #if ENABLED(BLTOUCH) - const bool &bltouch_last_written_mode = bltouch.last_written_mode; - #else - constexpr bool bltouch_last_written_mode = false; - #endif + const bool bltouch_last_written_mode = TERN(BLTOUCH, bltouch.last_written_mode, false); EEPROM_WRITE(bltouch_last_written_mode); } @@ -782,23 +760,9 @@ void MarlinSettings::postprocess() { // Write dual endstops in X, Y, Z order. Unused = 0.0 dummyf = 0; - #if ENABLED(X_DUAL_ENDSTOPS) - EEPROM_WRITE(endstops.x2_endstop_adj); // 1 float - #else - EEPROM_WRITE(dummyf); - #endif - - #if ENABLED(Y_DUAL_ENDSTOPS) - EEPROM_WRITE(endstops.y2_endstop_adj); // 1 float - #else - EEPROM_WRITE(dummyf); - #endif - - #if ENABLED(Z_MULTI_ENDSTOPS) - EEPROM_WRITE(endstops.z2_endstop_adj); // 1 float - #else - EEPROM_WRITE(dummyf); - #endif + EEPROM_WRITE(TERN(X_DUAL_ENDSTOPS, endstops.x2_endstop_adj, dummyf)); // 1 float + EEPROM_WRITE(TERN(Y_DUAL_ENDSTOPS, endstops.y2_endstop_adj, dummyf)); // 1 float + EEPROM_WRITE(TERN(Z_MULTI_ENDSTOPS, endstops.z2_endstop_adj, dummyf)); // 1 float #if ENABLED(Z_MULTI_ENDSTOPS) && NUM_Z_STEPPER_DRIVERS >= 3 EEPROM_WRITE(endstops.z3_endstop_adj); // 1 float @@ -865,12 +829,10 @@ void MarlinSettings::postprocess() { } _FIELD_TEST(lpq_len); - #if ENABLED(PID_EXTRUSION_SCALING) - EEPROM_WRITE(thermalManager.lpq_len); - #else + #if DISABLED(PID_EXTRUSION_SCALING) const int16_t lpq_len = 20; - EEPROM_WRITE(lpq_len); #endif + EEPROM_WRITE(TERN(PID_EXTRUSION_SCALING, thermalManager.lpq_len, lpq_len)); } // @@ -911,8 +873,6 @@ void MarlinSettings::postprocess() { const int16_t lcd_contrast = #if HAS_LCD_CONTRAST ui.contrast - #elif defined(DEFAULT_LCD_CONTRAST) - DEFAULT_LCD_CONTRAST #else 127 #endif @@ -925,14 +885,7 @@ void MarlinSettings::postprocess() { // { _FIELD_TEST(recovery_enabled); - - const bool recovery_enabled = - #if ENABLED(POWER_LOSS_RECOVERY) - recovery.enabled - #else - PLR_ENABLED_DEFAULT - #endif - ; + const bool recovery_enabled = TERN(POWER_LOSS_RECOVERY, recovery.enabled, ENABLED(PLR_ENABLED_DEFAULT)); EEPROM_WRITE(recovery_enabled); } @@ -941,19 +894,15 @@ void MarlinSettings::postprocess() { // { _FIELD_TEST(fwretract_settings); - - #if ENABLED(FWRETRACT) - EEPROM_WRITE(fwretract.settings); - #else + #if DISABLED(FWRETRACT) const fwretract_settings_t autoretract_defaults = { 3, 45, 0, 0, 0, 13, 0, 8 }; - EEPROM_WRITE(autoretract_defaults); #endif - #if BOTH(FWRETRACT, FWRETRACT_AUTORETRACT) - EEPROM_WRITE(fwretract.autoretract_enabled); - #else + EEPROM_WRITE(TERN(FWRETRACT, fwretract.settings, autoretract_defaults)); + + #if DISABLED(FWRETRACT_AUTORETRACT) const bool autoretract_enabled = false; - EEPROM_WRITE(autoretract_enabled); #endif + EEPROM_WRITE(TERN(FWRETRACT_AUTORETRACT, fwretract.autoretract_enabled, autoretract_enabled)); } // @@ -1270,12 +1219,10 @@ void MarlinSettings::postprocess() { _FIELD_TEST(coordinate_system); - #if ENABLED(CNC_COORDINATE_SYSTEMS) - EEPROM_WRITE(gcode.coordinate_system); - #else + #if DISABLED(CNC_COORDINATE_SYSTEMS) const xyz_pos_t coordinate_system[MAX_COORDINATE_SYSTEMS] = { { 0 } }; - EEPROM_WRITE(coordinate_system); #endif + EEPROM_WRITE(TERN(CNC_COORDINATE_SYSTEMS, gcode.coordinate_system, coordinate_system)); // // Skew correction factors @@ -1448,11 +1395,7 @@ void MarlinSettings::postprocess() { for (uint8_t q = 4; q--;) EEPROM_READ(dummyf); #endif - #if DISABLED(CLASSIC_JERK) - EEPROM_READ(planner.junction_deviation_mm); - #else - EEPROM_READ(dummyf); - #endif + EEPROM_READ(TERN(CLASSIC_JERK, dummyf, planner.junction_deviation_mm)); } // @@ -1504,13 +1447,7 @@ void MarlinSettings::postprocess() { // // Global Leveling // - { - #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) - EEPROM_READ(new_z_fade_height); - #else - EEPROM_READ(dummyf); - #endif - } + EEPROM_READ(TERN(ENABLE_LEVELING_FADE_HEIGHT, new_z_fade_height, dummyf)); // // Mesh (Manual) Bed Leveling @@ -1662,21 +1599,10 @@ void MarlinSettings::postprocess() { _FIELD_TEST(x2_endstop_adj); - #if ENABLED(X_DUAL_ENDSTOPS) - EEPROM_READ(endstops.x2_endstop_adj); // 1 float - #else - EEPROM_READ(dummyf); - #endif - #if ENABLED(Y_DUAL_ENDSTOPS) - EEPROM_READ(endstops.y2_endstop_adj); // 1 float - #else - EEPROM_READ(dummyf); - #endif - #if ENABLED(Z_MULTI_ENDSTOPS) - EEPROM_READ(endstops.z2_endstop_adj); // 1 float - #else - EEPROM_READ(dummyf); - #endif + EEPROM_READ(TERN(X_DUAL_ENDSTOPS, endstops.x2_endstop_adj, dummyf)); // 1 float + EEPROM_READ(TERN(Y_DUAL_ENDSTOPS, endstops.y2_endstop_adj, dummyf)); // 1 float + EEPROM_READ(TERN(Z_MULTI_ENDSTOPS, endstops.z2_endstop_adj, dummyf)); // 1 float + #if ENABLED(Z_MULTI_ENDSTOPS) && NUM_Z_STEPPER_DRIVERS >= 3 EEPROM_READ(endstops.z3_endstop_adj); // 1 float #else @@ -2667,7 +2593,7 @@ void MarlinSettings::reset() { // #if ENABLED(POWER_LOSS_RECOVERY) - recovery.enable(PLR_ENABLED_DEFAULT); + recovery.enable(ENABLED(PLR_ENABLED_DEFAULT)); #endif // diff --git a/Marlin/src/module/motion.cpp b/Marlin/src/module/motion.cpp index 2e7a574b3..b1c0f3790 100644 --- a/Marlin/src/module/motion.cpp +++ b/Marlin/src/module/motion.cpp @@ -1208,15 +1208,9 @@ feedRate_t get_homing_bump_feedrate(const AxisEnum axis) { #if ENABLED(SPI_ENDSTOPS) switch (axis) { - #if X_SPI_SENSORLESS - case X_AXIS: endstops.tmc_spi_homing.x = true; break; - #endif - #if Y_SPI_SENSORLESS - case Y_AXIS: endstops.tmc_spi_homing.y = true; break; - #endif - #if Z_SPI_SENSORLESS - case Z_AXIS: endstops.tmc_spi_homing.z = true; break; - #endif + case X_AXIS: if (ENABLED(X_SPI_SENSORLESS)) endstops.tmc_spi_homing.x = true; break; + case Y_AXIS: if (ENABLED(Y_SPI_SENSORLESS)) endstops.tmc_spi_homing.y = true; break; + case Z_AXIS: if (ENABLED(Z_SPI_SENSORLESS)) endstops.tmc_spi_homing.z = true; break; default: break; } #endif @@ -1280,15 +1274,9 @@ feedRate_t get_homing_bump_feedrate(const AxisEnum axis) { #if ENABLED(SPI_ENDSTOPS) switch (axis) { - #if X_SPI_SENSORLESS - case X_AXIS: endstops.tmc_spi_homing.x = false; break; - #endif - #if Y_SPI_SENSORLESS - case Y_AXIS: endstops.tmc_spi_homing.y = false; break; - #endif - #if Z_SPI_SENSORLESS - case Z_AXIS: endstops.tmc_spi_homing.z = false; break; - #endif + case X_AXIS: if (ENABLED(X_SPI_SENSORLESS)) endstops.tmc_spi_homing.x = false; break; + case Y_AXIS: if (ENABLED(Y_SPI_SENSORLESS)) endstops.tmc_spi_homing.y = false; break; + case Z_AXIS: if (ENABLED(Z_SPI_SENSORLESS)) endstops.tmc_spi_homing.z = false; break; default: break; } #endif diff --git a/Marlin/src/module/motion.h b/Marlin/src/module/motion.h index 055c6eeec..4dfbe629d 100644 --- a/Marlin/src/module/motion.h +++ b/Marlin/src/module/motion.h @@ -375,11 +375,13 @@ void homeaxis(const AxisEnum axis); FORCE_INLINE int x_home_dir(const uint8_t extruder) { return extruder ? X2_HOME_DIR : X_HOME_DIR; } -#elif ENABLED(MULTI_NOZZLE_DUPLICATION) +#else - enum DualXMode : char { - DXC_DUPLICATION_MODE = 2 - }; + #if ENABLED(MULTI_NOZZLE_DUPLICATION) + enum DualXMode : char { DXC_DUPLICATION_MODE = 2 }; + #endif + + FORCE_INLINE int x_home_dir(const uint8_t) { return home_dir(X_AXIS); } #endif diff --git a/Marlin/src/module/probe.h b/Marlin/src/module/probe.h index 4632c7c92..083867ab4 100644 --- a/Marlin/src/module/probe.h +++ b/Marlin/src/module/probe.h @@ -177,7 +177,7 @@ public: // Retrieve three points to probe the bed. Any type exposing set(X,Y) may be used. template static inline void get_three_points(T points[3]) { - #if ENABLED(HAS_FIXED_3POINT) + #if HAS_FIXED_3POINT points[0].set(PROBE_PT_1_X, PROBE_PT_1_Y); points[1].set(PROBE_PT_2_X, PROBE_PT_2_Y); points[2].set(PROBE_PT_3_X, PROBE_PT_3_Y); diff --git a/Marlin/src/sd/cardreader.h b/Marlin/src/sd/cardreader.h index be700401e..aee9ae580 100644 --- a/Marlin/src/sd/cardreader.h +++ b/Marlin/src/sd/cardreader.h @@ -276,11 +276,7 @@ private: #if ENABLED(USB_FLASH_DRIVE_SUPPORT) #define IS_SD_INSERTED() Sd2Card::isInserted() #elif PIN_EXISTS(SD_DETECT) - #if ENABLED(SD_DETECT_INVERTED) - #define IS_SD_INSERTED() READ(SD_DETECT_PIN) - #else - #define IS_SD_INSERTED() !READ(SD_DETECT_PIN) - #endif + #define IS_SD_INSERTED() (READ(SD_DETECT_PIN) != ENABLED(SD_DETECT_INVERTED)) #else // No card detect line? Assume the card is inserted. #define IS_SD_INSERTED() true