Skip to content

Commit

Permalink
🐛 Fix compact sensitive pins array (MarlinFirmware#22184)
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Jun 21, 2021
1 parent f3e0bc7 commit a0f7f0e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
21 changes: 12 additions & 9 deletions Marlin/src/MarlinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,19 +282,22 @@ bool wait_for_heatup = true;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnarrowing"

#ifdef RUNTIME_ONLY_ANALOG_TO_DIGITAL
static const pin_t sensitive_pins[] PROGMEM = { SENSITIVE_PINS };
#else
#ifndef RUNTIME_ONLY_ANALOG_TO_DIGITAL
template <pin_t ...D>
constexpr pin_t OnlyPins<-2, D...>::table[sizeof...(D)];
#define sensitive_pins OnlyPins<SENSITIVE_PINS>::table
constexpr pin_t OnlyPins<_SP_END, D...>::table[sizeof...(D)];
#endif

bool pin_is_protected(const pin_t pin) {
LOOP_L_N(i, COUNT(sensitive_pins)) {
pin_t sensitive_pin;
memcpy_P(&sensitive_pin, &sensitive_pins[i], sizeof(pin_t));
if (pin == sensitive_pin) return true;
#ifdef RUNTIME_ONLY_ANALOG_TO_DIGITAL
static const pin_t sensitive_pins[] PROGMEM = { SENSITIVE_PINS };
const size_t pincount = COUNT(sensitive_pins);
#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;
}
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/pins/sensitive_pins.h
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@

// Remove -2 from the front, emit the rest, cease propagation
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

#define SENSITIVE_PINS \
Expand Down

0 comments on commit a0f7f0e

Please sign in to comment.