From efc396bd0521bcdfd56e32dbc6d52f9a26cd3849 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 16 Jan 2021 19:03:06 -0600 Subject: [PATCH] General cleanup, use _BV --- Marlin/src/HAL/DUE/fastio.h | 2 +- Marlin/src/HAL/DUE/timers.cpp | 2 +- Marlin/src/HAL/ESP32/Servo.h | 2 +- Marlin/src/HAL/LPC1768/eeprom_flash.cpp | 2 +- Marlin/src/HAL/LPC1768/timers.h | 2 +- Marlin/src/HAL/SAMD51/fastio.h | 2 +- Marlin/src/HAL/SAMD51/timers.cpp | 2 +- Marlin/src/HAL/STM32F1/Servo.cpp | 2 +- Marlin/src/HAL/TEENSY31_32/fastio.h | 2 +- Marlin/src/HAL/TEENSY35_36/fastio.h | 2 +- Marlin/src/HAL/shared/Marduino.h | 16 ++--- .../src/HAL/shared/backtrace/unwarmbytab.cpp | 69 ++++++++----------- Marlin/src/core/macros.h | 8 +-- Marlin/src/feature/direct_stepping.h | 4 +- .../extui/lib/anycubic_chiron/chiron_tft.cpp | 8 +-- .../lib/anycubic_chiron/chiron_tft_defs.h | 2 +- .../src/lcd/extui/lib/mks_ui/draw_preHeat.cpp | 2 +- Marlin/src/lcd/menu/menu_temperature.cpp | 4 -- Marlin/src/lcd/menu/menu_tune.cpp | 4 -- 19 files changed, 56 insertions(+), 81 deletions(-) diff --git a/Marlin/src/HAL/DUE/fastio.h b/Marlin/src/HAL/DUE/fastio.h index 5fb8b4d015..f375cb6b29 100644 --- a/Marlin/src/HAL/DUE/fastio.h +++ b/Marlin/src/HAL/DUE/fastio.h @@ -50,7 +50,7 @@ #define PWM_PIN(P) WITHIN(P, 2, 13) #ifndef MASK - #define MASK(PIN) (1 << PIN) + #define MASK(PIN) _BV(PIN) #endif /** diff --git a/Marlin/src/HAL/DUE/timers.cpp b/Marlin/src/HAL/DUE/timers.cpp index 9b937d1a7c..65073c510d 100644 --- a/Marlin/src/HAL/DUE/timers.cpp +++ b/Marlin/src/HAL/DUE/timers.cpp @@ -121,7 +121,7 @@ void HAL_timer_disable_interrupt(const uint8_t timer_num) { // missing from CMSIS: Check if interrupt is enabled or not static bool NVIC_GetEnabledIRQ(IRQn_Type IRQn) { - return (NVIC->ISER[(uint32_t)(IRQn) >> 5] & (1 << ((uint32_t)(IRQn) & 0x1F))) != 0; + return TEST(NVIC->ISER[uint32_t(IRQn) >> 5], uint32_t(IRQn) & 0x1F); } bool HAL_timer_interrupt_enabled(const uint8_t timer_num) { diff --git a/Marlin/src/HAL/ESP32/Servo.h b/Marlin/src/HAL/ESP32/Servo.h index b0d9294527..8542092d66 100644 --- a/Marlin/src/HAL/ESP32/Servo.h +++ b/Marlin/src/HAL/ESP32/Servo.h @@ -30,7 +30,7 @@ class Servo { MAX_PULSE_WIDTH = 2400, // Longest pulse sent to a servo TAU_MSEC = 20, TAU_USEC = (TAU_MSEC * 1000), - MAX_COMPARE = ((1 << 16) - 1), // 65535 + MAX_COMPARE = _BV(16) - 1, // 65535 CHANNEL_MAX_NUM = 16; public: diff --git a/Marlin/src/HAL/LPC1768/eeprom_flash.cpp b/Marlin/src/HAL/LPC1768/eeprom_flash.cpp index 3c0c3c8ec3..38d2705d51 100644 --- a/Marlin/src/HAL/LPC1768/eeprom_flash.cpp +++ b/Marlin/src/HAL/LPC1768/eeprom_flash.cpp @@ -25,7 +25,7 @@ * Emulate EEPROM storage using Flash Memory * * Use a single 32K flash sector to store EEPROM data. To reduce the - * number of erase operations a simple "levelling" scheme is used that + * number of erase operations a simple "leveling" scheme is used that * maintains a number of EEPROM "slots" within the larger flash sector. * Each slot is used in turn and the entire sector is only erased when all * slots have been used. diff --git a/Marlin/src/HAL/LPC1768/timers.h b/Marlin/src/HAL/LPC1768/timers.h index e6744fb005..4b63854685 100644 --- a/Marlin/src/HAL/LPC1768/timers.h +++ b/Marlin/src/HAL/LPC1768/timers.h @@ -152,7 +152,7 @@ FORCE_INLINE static void HAL_timer_disable_interrupt(const uint8_t timer_num) { // This function is missing from CMSIS FORCE_INLINE static bool NVIC_GetEnableIRQ(IRQn_Type IRQn) { - return (NVIC->ISER[((uint32_t)IRQn) >> 5] & (1 << ((uint32_t)IRQn) & 0x1F)) != 0; + return TEST(NVIC->ISER[uint32_t(IRQn) >> 5], uint32_t(IRQn) & 0x1F); } FORCE_INLINE static bool HAL_timer_interrupt_enabled(const uint8_t timer_num) { diff --git a/Marlin/src/HAL/SAMD51/fastio.h b/Marlin/src/HAL/SAMD51/fastio.h index c456dfce30..a95b7cac0c 100644 --- a/Marlin/src/HAL/SAMD51/fastio.h +++ b/Marlin/src/HAL/SAMD51/fastio.h @@ -31,7 +31,7 @@ */ #ifndef MASK - #define MASK(PIN) (1 << PIN) + #define MASK(PIN) _BV(PIN) #endif /** diff --git a/Marlin/src/HAL/SAMD51/timers.cpp b/Marlin/src/HAL/SAMD51/timers.cpp index a68af2e074..5c55d32407 100644 --- a/Marlin/src/HAL/SAMD51/timers.cpp +++ b/Marlin/src/HAL/SAMD51/timers.cpp @@ -157,7 +157,7 @@ void HAL_timer_disable_interrupt(const uint8_t timer_num) { // missing from CMSIS: Check if interrupt is enabled or not static bool NVIC_GetEnabledIRQ(IRQn_Type IRQn) { - return (NVIC->ISER[(uint32_t)(IRQn) >> 5] & (1 << ((uint32_t)(IRQn) & 0x1F))) != 0; + return TEST(NVIC->ISER[uint32_t(IRQn) >> 5], uint32_t(IRQn) & 0x1F); } bool HAL_timer_interrupt_enabled(const uint8_t timer_num) { diff --git a/Marlin/src/HAL/STM32F1/Servo.cpp b/Marlin/src/HAL/STM32F1/Servo.cpp index e1ee831493..36f7c6d512 100644 --- a/Marlin/src/HAL/STM32F1/Servo.cpp +++ b/Marlin/src/HAL/STM32F1/Servo.cpp @@ -45,7 +45,7 @@ uint8_t ServoCount = 0; * * This uses the smallest prescaler that allows an overflow < 2^16. */ -#define MAX_OVERFLOW UINT16_MAX //((1 << 16) - 1) +#define MAX_OVERFLOW UINT16_MAX // _BV(16) - 1 #define CYC_MSEC (1000 * CYCLES_PER_MICROSECOND) #define TAU_MSEC 20 #define TAU_USEC (TAU_MSEC * 1000) diff --git a/Marlin/src/HAL/TEENSY31_32/fastio.h b/Marlin/src/HAL/TEENSY31_32/fastio.h index 9a299de9c7..622799ec8c 100644 --- a/Marlin/src/HAL/TEENSY31_32/fastio.h +++ b/Marlin/src/HAL/TEENSY31_32/fastio.h @@ -28,7 +28,7 @@ */ #ifndef MASK - #define MASK(PIN) (1 << PIN) + #define MASK(PIN) _BV(PIN) #endif #define GPIO_BITBAND_ADDR(reg, bit) (((uint32_t)&(reg) - 0x40000000) * 32 + (bit) * 4 + 0x42000000) diff --git a/Marlin/src/HAL/TEENSY35_36/fastio.h b/Marlin/src/HAL/TEENSY35_36/fastio.h index 9a299de9c7..622799ec8c 100644 --- a/Marlin/src/HAL/TEENSY35_36/fastio.h +++ b/Marlin/src/HAL/TEENSY35_36/fastio.h @@ -28,7 +28,7 @@ */ #ifndef MASK - #define MASK(PIN) (1 << PIN) + #define MASK(PIN) _BV(PIN) #endif #define GPIO_BITBAND_ADDR(reg, bit) (((uint32_t)&(reg) - 0x40000000) * 32 + (bit) * 4 + 0x42000000) diff --git a/Marlin/src/HAL/shared/Marduino.h b/Marlin/src/HAL/shared/Marduino.h index 3003f3cc28..2580723511 100644 --- a/Marlin/src/HAL/shared/Marduino.h +++ b/Marlin/src/HAL/shared/Marduino.h @@ -28,9 +28,9 @@ #undef DISABLED // Redefined by ESP32 #undef M_PI // Redefined by all #undef _BV // Redefined by some -#undef sq // Redefined by teensy3/wiring.h #undef SBI // Redefined by arduino/const_functions.h #undef CBI // Redefined by arduino/const_functions.h +#undef sq // Redefined by teensy3/wiring.h #undef UNUSED // Redefined by stm32f4xx_hal_def.h #include // NOTE: If included earlier then this line is a NOOP @@ -40,18 +40,16 @@ #undef _BV #define _BV(b) (1UL << (b)) +#ifndef SBI + #define SBI(A,B) (A |= _BV(B)) +#endif +#ifndef CBI + #define CBI(A,B) (A &= ~_BV(B)) +#endif #undef sq #define sq(x) ((x)*(x)) -#ifndef SBI - #define SBI(A,B) (A |= (1 << (B))) -#endif - -#ifndef CBI - #define CBI(A,B) (A &= ~(1 << (B))) -#endif - #ifndef __AVR__ #ifndef strchr_P // Some platforms define a macro (DUE, teensy35) inline const char* strchr_P(const char *s, int c) { return strchr(s,c); } diff --git a/Marlin/src/HAL/shared/backtrace/unwarmbytab.cpp b/Marlin/src/HAL/shared/backtrace/unwarmbytab.cpp index bfc062af20..f1ee81ed4a 100644 --- a/Marlin/src/HAL/shared/backtrace/unwarmbytab.cpp +++ b/Marlin/src/HAL/shared/backtrace/unwarmbytab.cpp @@ -128,11 +128,8 @@ static UnwResult UnwTabStateInit(const UnwindCallbacks *cb, UnwTabState *ucb, ui * Execute unwinding instructions */ static UnwResult UnwTabExecuteInstructions(const UnwindCallbacks *cb, UnwTabState *ucb) { - int instruction; - uint32_t mask; - uint32_t reg; - uint32_t vsp; + uint32_t mask, reg, vsp; /* Consume all instruction byte */ while ((instruction = UnwTabGetNextInstruction(cb, ucb)) != -1) { @@ -140,12 +137,12 @@ static UnwResult UnwTabExecuteInstructions(const UnwindCallbacks *cb, UnwTabStat if ((instruction & 0xC0) == 0x00) { // ARM_EXIDX_CMD_DATA_POP /* vsp = vsp + (xxxxxx << 2) + 4 */ ucb->vrs[13] += ((instruction & 0x3F) << 2) + 4; - } else - if ((instruction & 0xC0) == 0x40) { // ARM_EXIDX_CMD_DATA_PUSH + } + else if ((instruction & 0xC0) == 0x40) { // ARM_EXIDX_CMD_DATA_PUSH /* vsp = vsp - (xxxxxx << 2) - 4 */ ucb->vrs[13] -= ((instruction & 0x3F) << 2) - 4; - } else - if ((instruction & 0xF0) == 0x80) { + } + else if ((instruction & 0xF0) == 0x80) { /* pop under mask {r15-r12},{r11-r4} or refuse to unwind */ instruction = instruction << 8 | UnwTabGetNextInstruction(cb, ucb); @@ -171,17 +168,17 @@ static UnwResult UnwTabExecuteInstructions(const UnwindCallbacks *cb, UnwTabStat } /* Patch up the vrs sp if it was in the mask */ - if ((instruction & (1 << (13 - 4))) != 0) + if (instruction & (1 << (13 - 4))) ucb->vrs[13] = vsp; - - } else - if ((instruction & 0xF0) == 0x90 && // ARM_EXIDX_CMD_REG_TO_SP - instruction != 0x9D && - instruction != 0x9F) { + } + else if ((instruction & 0xF0) == 0x90 // ARM_EXIDX_CMD_REG_TO_SP + && instruction != 0x9D + && instruction != 0x9F + ) { /* vsp = r[nnnn] */ ucb->vrs[13] = ucb->vrs[instruction & 0x0F]; - } else - if ((instruction & 0xF0) == 0xA0) { // ARM_EXIDX_CMD_REG_POP + } + else if ((instruction & 0xF0) == 0xA0) { // ARM_EXIDX_CMD_REG_POP /* pop r4-r[4+nnn] or pop r4-r[4+nnn], r14*/ vsp = ucb->vrs[13]; @@ -204,8 +201,8 @@ static UnwResult UnwTabExecuteInstructions(const UnwindCallbacks *cb, UnwTabStat ucb->vrs[13] = vsp; - } else - if (instruction == 0xB0) { // ARM_EXIDX_CMD_FINISH + } + else if (instruction == 0xB0) { // ARM_EXIDX_CMD_FINISH /* finished */ if (ucb->vrs[15] == 0) ucb->vrs[15] = ucb->vrs[14]; @@ -213,8 +210,8 @@ static UnwResult UnwTabExecuteInstructions(const UnwindCallbacks *cb, UnwTabStat /* All done unwinding */ return UNWIND_SUCCESS; - } else - if (instruction == 0xB1) { // ARM_EXIDX_CMD_REG_POP + } + else if (instruction == 0xB1) { // ARM_EXIDX_CMD_REG_POP /* pop register under mask {r3,r2,r1,r0} */ vsp = ucb->vrs[13]; mask = UnwTabGetNextInstruction(cb, ucb); @@ -234,16 +231,15 @@ static UnwResult UnwTabExecuteInstructions(const UnwindCallbacks *cb, UnwTabStat } ucb->vrs[13] = (uint32_t)vsp; - } else - if (instruction == 0xB2) { // ARM_EXIDX_CMD_DATA_POP + } + else if (instruction == 0xB2) { // ARM_EXIDX_CMD_DATA_POP /* vps = vsp + 0x204 + (uleb128 << 2) */ ucb->vrs[13] += 0x204 + (UnwTabGetNextInstruction(cb, ucb) << 2); - - } else - if (instruction == 0xB3 || // ARM_EXIDX_CMD_VFP_POP - instruction == 0xC8 || - instruction == 0xC9) { - + } + else if (instruction == 0xB3 // ARM_EXIDX_CMD_VFP_POP + || instruction == 0xC8 + || instruction == 0xC9 + ) { /* pop VFP double-precision registers */ vsp = ucb->vrs[13]; @@ -266,27 +262,20 @@ static UnwResult UnwTabExecuteInstructions(const UnwindCallbacks *cb, UnwTabStat } ucb->vrs[13] = vsp; - - } else - if ((instruction & 0xF8) == 0xB8 || - (instruction & 0xF8) == 0xD0) { - + } + else if ((instruction & 0xF8) == 0xB8 || (instruction & 0xF8) == 0xD0) { /* Pop VFP double precision registers D[8]-D[8+nnn] */ ucb->vrs[14] = 0x80 | (instruction & 0x07); - - if ((instruction & 0xF8) == 0xD0) { + if ((instruction & 0xF8) == 0xD0) ucb->vrs[14] = 1 << 17; - } - - } else + } + else return UNWIND_UNSUPPORTED_DWARF_INSTR; } - return UNWIND_SUCCESS; } static inline __attribute__((always_inline)) uint32_t read_psp() { - /* Read the current PSP and return its value as a pointer */ uint32_t psp; diff --git a/Marlin/src/core/macros.h b/Marlin/src/core/macros.h index 56e80b87dc..d5b3342437 100644 --- a/Marlin/src/core/macros.h +++ b/Marlin/src/core/macros.h @@ -84,17 +84,13 @@ #define _BV(n) (1<<(n)) #define TEST(n,b) (!!((n)&_BV(b))) #define SET_BIT_TO(N,B,TF) do{ if (TF) SBI(N,B); else CBI(N,B); }while(0) - #ifndef SBI - #define SBI(A,B) (A |= (1 << (B))) + #define SBI(A,B) (A |= _BV(B)) #endif - #ifndef CBI - #define CBI(A,B) (A &= ~(1 << (B))) + #define CBI(A,B) (A &= ~_BV(B)) #endif - #define TBI(N,B) (N ^= _BV(B)) - #define _BV32(b) (1UL << (b)) #define TEST32(n,b) !!((n)&_BV32(b)) #define SBI32(n,b) (n |= _BV32(b)) diff --git a/Marlin/src/feature/direct_stepping.h b/Marlin/src/feature/direct_stepping.h index cde9d1a0b4..b3007731cd 100644 --- a/Marlin/src/feature/direct_stepping.h +++ b/Marlin/src/feature/direct_stepping.h @@ -93,8 +93,8 @@ namespace DirectStepping { static constexpr int DIRECTIONAL = dir ? 1 : 0; static constexpr int SEGMENTS = segments; - static constexpr int NUM_SEGMENTS = 1 << BITS_SEGMENT; - static constexpr int SEGMENT_STEPS = (1 << (BITS_SEGMENT - DIRECTIONAL)) - 1; + static constexpr int NUM_SEGMENTS = _BV(BITS_SEGMENT); + static constexpr int SEGMENT_STEPS = _BV(BITS_SEGMENT - DIRECTIONAL) - 1; static constexpr int TOTAL_STEPS = SEGMENT_STEPS * SEGMENTS; static constexpr int PAGE_SIZE = (NUM_AXES * BITS_SEGMENT * SEGMENTS) / 8; diff --git a/Marlin/src/lcd/extui/lib/anycubic_chiron/chiron_tft.cpp b/Marlin/src/lcd/extui/lib/anycubic_chiron/chiron_tft.cpp index 226fb7291e..2c3217b224 100644 --- a/Marlin/src/lcd/extui/lib/anycubic_chiron/chiron_tft.cpp +++ b/Marlin/src/lcd/extui/lib/anycubic_chiron/chiron_tft.cpp @@ -86,9 +86,9 @@ namespace Anycubic { safe_delay(200); - // Enable levelling and Disable end stops during print + // Enable leveling and Disable end stops during print // as Z home places nozzle above the bed so we need to allow it past the end stops - injectCommands_P(AC_cmnd_enable_levelling); + injectCommands_P(AC_cmnd_enable_leveling); // Startup tunes are defined in Tunes.h //PlayTune(BEEPER_PIN, Anycubic_PowerOn, 1); @@ -762,7 +762,7 @@ namespace Anycubic { selectedmeshpoint.x = selectedmeshpoint.y = 99; } break; - case 'D': // Save Z Offset tables and restore levelling state + case 'D': // Save Z Offset tables and restore leveling state if (!isPrinting()) { setAxisPosition_mm(1.0,Z); injectCommands_P(PSTR("M500")); @@ -784,7 +784,7 @@ namespace Anycubic { float Zshift = atof(&panel_command[4]); setSoftEndstopState(false); // disable endstops // Allow temporary Z position nudging during print - // From the levelling panel use the all points UI to adjust the print pos. + // From the leveling panel use the all points UI to adjust the print pos. if (isPrinting()) { #if ACDEBUG(AC_INFO) SERIAL_ECHOLNPAIR("Change Zoffset from:", live_Zoffset, " to ", live_Zoffset + Zshift); diff --git a/Marlin/src/lcd/extui/lib/anycubic_chiron/chiron_tft_defs.h b/Marlin/src/lcd/extui/lib/anycubic_chiron/chiron_tft_defs.h index af030df580..408c0d7484 100644 --- a/Marlin/src/lcd/extui/lib/anycubic_chiron/chiron_tft_defs.h +++ b/Marlin/src/lcd/extui/lib/anycubic_chiron/chiron_tft_defs.h @@ -105,7 +105,7 @@ #define AC_cmnd_manual_load_filament PSTR("M83\nG1 E50 F700\nM82") // replace the manual panel commands with something a little faster #define AC_cmnd_manual_unload_filament PSTR("M83\nG1 E-50 F1200\nM82") -#define AC_cmnd_enable_levelling PSTR("M420 S1 V1") +#define AC_cmnd_enable_leveling PSTR("M420 S1 V1") #define AC_cmnd_power_loss_recovery PSTR("G28 X Y R5\nG28 Z") // Lift, home X and Y then home Z when in 'safe' position namespace Anycubic { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_preHeat.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_preHeat.cpp index 43f82bca24..273462ac90 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_preHeat.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_preHeat.cpp @@ -56,7 +56,7 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) { thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = (float)HEATER_0_MAXTEMP - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1); } } - #if !defined(SINGLENOZZLE) && HAS_MULTI_EXTRUDER + #if DISABLED(SINGLENOZZLE) && HAS_MULTI_EXTRUDER else if ((int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target > (HEATER_1_MAXTEMP - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1))) { thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = (float)HEATER_1_MAXTEMP - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1); } diff --git a/Marlin/src/lcd/menu/menu_temperature.cpp b/Marlin/src/lcd/menu/menu_temperature.cpp index 7b6d7f1a1d..2e5aff1006 100644 --- a/Marlin/src/lcd/menu/menu_temperature.cpp +++ b/Marlin/src/lcd/menu/menu_temperature.cpp @@ -35,10 +35,6 @@ #include "../../module/motion.h" #endif -#if ENABLED(SINGLENOZZLE) - #include "../../module/tool_change.h" -#endif - // // "Temperature" submenu items // diff --git a/Marlin/src/lcd/menu/menu_tune.cpp b/Marlin/src/lcd/menu/menu_tune.cpp index 87168ba1e7..5da25ce59a 100644 --- a/Marlin/src/lcd/menu/menu_tune.cpp +++ b/Marlin/src/lcd/menu/menu_tune.cpp @@ -38,10 +38,6 @@ #include "../../feature/bedlevel/bedlevel.h" #endif -#if ENABLED(SINGLENOZZLE) - #include "../../module/tool_change.h" -#endif - #if ENABLED(BABYSTEPPING) #include "../../feature/babystep.h"