From 31920a52857a166c41289533d13391102899c213 Mon Sep 17 00:00:00 2001
From: Scott Lahteine <github@thinkyhead.com>
Date: Thu, 1 Feb 2018 21:46:10 -0600
Subject: [PATCH] Add / use 32-bit wide bit macros

---
 Marlin/MarlinSPI.h |  2 +-
 Marlin/gcode.h     |  4 ++--
 Marlin/macros.h    | 11 ++++++++---
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/Marlin/MarlinSPI.h b/Marlin/MarlinSPI.h
index 93f9fb2b08..61e85fc63c 100644
--- a/Marlin/MarlinSPI.h
+++ b/Marlin/MarlinSPI.h
@@ -48,7 +48,7 @@ class SPI<MISO_PIN, MOSI_PIN, SCK_PIN> {
     }
     FORCE_INLINE static uint8_t receive() {
       SPDR = 0;
-      for (;!TEST(SPSR, SPIF););
+      while (!TEST(SPSR, SPIF)) { /* nada */ }
       return SPDR;
     }
 
diff --git a/Marlin/gcode.h b/Marlin/gcode.h
index 069beec1f5..cb3d84f1b4 100644
--- a/Marlin/gcode.h
+++ b/Marlin/gcode.h
@@ -136,7 +136,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) {
         #if ENABLED(DEBUG_GCODE_PARSER)
           if (codenum == 800) {
@@ -151,7 +151,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
 
diff --git a/Marlin/macros.h b/Marlin/macros.h
index 584d555a83..13027044dc 100644
--- a/Marlin/macros.h
+++ b/Marlin/macros.h
@@ -101,13 +101,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))
+
 // Macro to check that a number if a power if 2
 #define IS_POWER_OF_2(x) ((x) && !((x) & ((x) - 1)))