diff --git a/Marlin/src/HAL/HAL_LPC1768/WInterrupts.cpp b/Marlin/src/HAL/HAL_LPC1768/WInterrupts.cpp index 1c73db03c1..80de9f3697 100644 --- a/Marlin/src/HAL/HAL_LPC1768/WInterrupts.cpp +++ b/Marlin/src/HAL/HAL_LPC1768/WInterrupts.cpp @@ -130,8 +130,8 @@ extern "C" void GpioDisableInt(const uint32_t port, const uint32_t pin) { } } -bool isPowerOf2(unsigned int n) { - return n == 1 || (n & (n - 1)) == 0; +constexpr bool isPowerOf2(const uint16_t n) { + return IS_POWER_OF_2(n); } #if 0 diff --git a/Marlin/src/HAL/HAL_STM32F7/HAL_STM32F7.h b/Marlin/src/HAL/HAL_STM32F7/HAL_STM32F7.h index 03ab69a1ed..814c21096f 100644 --- a/Marlin/src/HAL/HAL_STM32F7/HAL_STM32F7.h +++ b/Marlin/src/HAL/HAL_STM32F7/HAL_STM32F7.h @@ -98,7 +98,7 @@ #define NUM_SERIAL 1 #endif -#define _BV(b) (1UL << (b)) +#define _BV(b) (1 << (b)) /** * TODO: review this to return 1 for pins that are not analog input diff --git a/Marlin/src/HAL/HAL_STM32F7/fastio_STM32F7.h b/Marlin/src/HAL/HAL_STM32F7/fastio_STM32F7.h index e22acc6670..dd8ca1e579 100644 --- a/Marlin/src/HAL/HAL_STM32F7/fastio_STM32F7.h +++ b/Marlin/src/HAL/HAL_STM32F7/fastio_STM32F7.h @@ -29,7 +29,7 @@ #ifndef _FASTIO_STM32F7_H #define _FASTIO_STM32F7_H -#define _BV(b) (1UL << (b)) +#define _BV(b) (1 << (b)) #define READ(IO) digitalRead(IO) #define WRITE(IO, v) digitalWrite(IO,v) diff --git a/Marlin/src/core/macros.h b/Marlin/src/core/macros.h index 945233a457..342b702d76 100644 --- a/Marlin/src/core/macros.h +++ b/Marlin/src/core/macros.h @@ -95,13 +95,18 @@ #define STRINGIFY(M) STRINGIFY_(M) // Macros for bit masks -#undef _BV // Marlin needs 32-bit unsigned! -#define _BV(b) (1UL << (b)) -#define TEST(n,b) (((n)&_BV(b))!=0) +#undef _BV +#define _BV(b) (1<<(b)) +#define TEST(n,b) !!((n)&_BV(b)) #define SBI(n,b) (n |= _BV(b)) #define CBI(n,b) (n &= ~_BV(b)) #define SET_BIT(n,b,value) (n) ^= ((-value)^(n)) & (_BV(b)) +#define _BV32(b) (1UL << (b)) +#define TEST32(n,b) !!((n)&_BV32(b)) +#define SBI32(n,b) (n |= _BV32(b)) +#define CBI32(n,b) (n &= ~_BV32(b)) + // Macros for maths shortcuts #ifndef M_PI #define M_PI 3.14159265358979323846 diff --git a/Marlin/src/gcode/parser.h b/Marlin/src/gcode/parser.h index 8d5582a4e4..d4bd897fba 100644 --- a/Marlin/src/gcode/parser.h +++ b/Marlin/src/gcode/parser.h @@ -108,7 +108,7 @@ public: static void set(const char c, char * const ptr) { const uint8_t ind = LETTER_BIT(c); if (ind >= COUNT(param)) return; // Only A-Z - SBI(codebits, ind); // parameter exists + SBI32(codebits, ind); // parameter exists param[ind] = ptr ? ptr - command_ptr : 0; // parameter offset or 0 #if ENABLED(DEBUG_GCODE_PARSER) if (codenum == 800) { @@ -125,7 +125,7 @@ public: static bool seen(const char c) { const uint8_t ind = LETTER_BIT(c); if (ind >= COUNT(param)) return false; // Only A-Z - const bool b = TEST(codebits, ind); + const bool b = TEST32(codebits, ind); if (b) { char * const ptr = command_ptr + param[ind]; value_ptr = param[ind] && valid_float(ptr) ? ptr : (char*)NULL; @@ -135,7 +135,7 @@ public: static bool seen_any() { return !!codebits; } - #define SEEN_TEST(L) TEST(codebits, LETTER_BIT(L)) + #define SEEN_TEST(L) TEST32(codebits, LETTER_BIT(L)) #else // !FASTER_GCODE_PARSER