Browse Source

🐛 Fix compact sensitive pins array (#22184)

Scott Lahteine 3 years ago
parent
commit
44c41ce54f
No account linked to committer's email address
2 changed files with 13 additions and 10 deletions
  1. 12
    9
      Marlin/src/MarlinCore.cpp
  2. 1
    1
      Marlin/src/pins/sensitive_pins.h

+ 12
- 9
Marlin/src/MarlinCore.cpp View File

@@ -282,19 +282,22 @@ bool wait_for_heatup = true;
282 282
 #pragma GCC diagnostic push
283 283
 #pragma GCC diagnostic ignored "-Wnarrowing"
284 284
 
285
-#ifdef RUNTIME_ONLY_ANALOG_TO_DIGITAL
286
-  static const pin_t sensitive_pins[] PROGMEM = { SENSITIVE_PINS };
287
-#else
285
+#ifndef RUNTIME_ONLY_ANALOG_TO_DIGITAL
288 286
   template <pin_t ...D>
289
-  constexpr pin_t OnlyPins<-2, D...>::table[sizeof...(D)];
290
-  #define sensitive_pins OnlyPins<SENSITIVE_PINS>::table
287
+  constexpr pin_t OnlyPins<_SP_END, D...>::table[sizeof...(D)];
291 288
 #endif
292 289
 
293 290
 bool pin_is_protected(const pin_t pin) {
294
-  LOOP_L_N(i, COUNT(sensitive_pins)) {
295
-    pin_t sensitive_pin;
296
-    memcpy_P(&sensitive_pin, &sensitive_pins[i], sizeof(pin_t));
297
-    if (pin == sensitive_pin) return true;
291
+  #ifdef RUNTIME_ONLY_ANALOG_TO_DIGITAL
292
+    static const pin_t sensitive_pins[] PROGMEM = { SENSITIVE_PINS };
293
+    const size_t pincount = COUNT(sensitive_pins);
294
+  #else
295
+    static constexpr size_t pincount = OnlyPins<SENSITIVE_PINS>::size;
296
+    static const pin_t (&sensitive_pins)[pincount] PROGMEM = OnlyPins<SENSITIVE_PINS>::table;
297
+  #endif
298
+  LOOP_L_N(i, pincount) {
299
+    const pin_t * const pptr = &sensitive_pins[i];
300
+    if (pin == (sizeof(pin_t) == 2 ? (pin_t)pgm_read_word(pptr) : (pin_t)pgm_read_byte(pptr))) return true;
298 301
   }
299 302
   return false;
300 303
 }

+ 1
- 1
Marlin/src/pins/sensitive_pins.h View File

@@ -882,7 +882,7 @@
882 882
 
883 883
   // Remove -2 from the front, emit the rest, cease propagation
884 884
   template<pin_t ...D>
885
-  struct OnlyPins<_SP_END, D...> { static constexpr pin_t table[sizeof...(D)] PROGMEM = { D... }; };
885
+  struct OnlyPins<_SP_END, D...> { static constexpr size_t size = sizeof...(D); static constexpr pin_t table[sizeof...(D)] PROGMEM = { D... }; };
886 886
 #endif
887 887
 
888 888
 #define SENSITIVE_PINS \

Loading…
Cancel
Save