🐛 Fix compact sensitive pins array (#22184)

This commit is contained in:
Scott Lahteine 2021-06-20 22:49:57 -05:00
parent f3e0bc7a4b
commit a0f7f0e9e2
2 changed files with 13 additions and 10 deletions

View File

@ -282,19 +282,22 @@ bool wait_for_heatup = true;
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnarrowing" #pragma GCC diagnostic ignored "-Wnarrowing"
#ifdef RUNTIME_ONLY_ANALOG_TO_DIGITAL #ifndef RUNTIME_ONLY_ANALOG_TO_DIGITAL
static const pin_t sensitive_pins[] PROGMEM = { SENSITIVE_PINS };
#else
template <pin_t ...D> template <pin_t ...D>
constexpr pin_t OnlyPins<-2, D...>::table[sizeof...(D)]; constexpr pin_t OnlyPins<_SP_END, D...>::table[sizeof...(D)];
#define sensitive_pins OnlyPins<SENSITIVE_PINS>::table
#endif #endif
bool pin_is_protected(const pin_t pin) { bool pin_is_protected(const pin_t pin) {
LOOP_L_N(i, COUNT(sensitive_pins)) { #ifdef RUNTIME_ONLY_ANALOG_TO_DIGITAL
pin_t sensitive_pin; static const pin_t sensitive_pins[] PROGMEM = { SENSITIVE_PINS };
memcpy_P(&sensitive_pin, &sensitive_pins[i], sizeof(pin_t)); const size_t pincount = COUNT(sensitive_pins);
if (pin == sensitive_pin) return true; #else
static constexpr size_t pincount = OnlyPins<SENSITIVE_PINS>::size;
static const pin_t (&sensitive_pins)[pincount] PROGMEM = OnlyPins<SENSITIVE_PINS>::table;
#endif
LOOP_L_N(i, pincount) {
const pin_t * const pptr = &sensitive_pins[i];
if (pin == (sizeof(pin_t) == 2 ? (pin_t)pgm_read_word(pptr) : (pin_t)pgm_read_byte(pptr))) return true;
} }
return false; return false;
} }

View File

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