Skip to content

Commit e4604b1

Browse files
committed
simplify sensitive pins
1 parent 22107c4 commit e4604b1

File tree

4 files changed

+531
-947
lines changed

4 files changed

+531
-947
lines changed

Marlin/src/HAL/AVR/HAL.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ typedef Servo hal_servo_t;
159159
#define GET_PIN_MAP_INDEX(pin) pin
160160
#define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
161161

162-
#define HAL_SENSITIVE_PINS 0, 1,
162+
#define HAL_SENSITIVE_PINS 0, 1
163163

164164
#ifdef __AVR_AT90USB1286__
165165
#define JTAG_DISABLE() do{ MCUCR = 0x80; MCUCR = 0x80; }while(0)

Marlin/src/HAL/LPC1768/HAL.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ constexpr pin_t GET_PIN_MAP_PIN(const int16_t index) {
159159
// Parse a G-code word into a pin index
160160
int16_t PARSED_PIN_INDEX(const char code, const int16_t dval);
161161
// P0.6 thru P0.9 are for the onboard SD card
162-
#define HAL_SENSITIVE_PINS P0_06, P0_07, P0_08, P0_09,
162+
#define HAL_SENSITIVE_PINS P0_06, P0_07, P0_08, P0_09
163163

164164
// ------------------------
165165
// Defines

Marlin/src/MarlinCore.cpp

+10-14
Original file line numberDiff line numberDiff line change
@@ -308,22 +308,18 @@ bool wait_for_heatup = false;
308308
#pragma GCC diagnostic push
309309
#pragma GCC diagnostic ignored "-Wnarrowing"
310310

311-
#ifndef RUNTIME_ONLY_ANALOG_TO_DIGITAL
312-
template <pin_t ...D>
313-
constexpr pin_t OnlyPins<_SP_END, D...>::table[sizeof...(D)];
314-
#endif
311+
#define DIO_PIN(P) TERN(TARGET_LPC1768, P, analogInputToDigitalPin(P))
315312

316313
bool pin_is_protected(const pin_t pin) {
317-
#ifdef RUNTIME_ONLY_ANALOG_TO_DIGITAL
318-
static const pin_t sensitive_pins[] PROGMEM = { SENSITIVE_PINS };
319-
const size_t pincount = COUNT(sensitive_pins);
320-
#else
321-
static constexpr size_t pincount = OnlyPins<SENSITIVE_PINS>::size;
322-
static const pin_t (&sensitive_pins)[pincount] PROGMEM = OnlyPins<SENSITIVE_PINS>::table;
323-
#endif
324-
for (uint8_t i = 0; i < pincount; ++i) {
325-
const pin_t * const pptr = &sensitive_pins[i];
326-
if (pin == (sizeof(pin_t) == 2 ? (pin_t)pgm_read_word(pptr) : (pin_t)pgm_read_byte(pptr))) return true;
314+
for (uint8_t i = 0; i < COUNT(sensitive_dio); ++i) {
315+
const pin_t * const pptr = &sensitive_dio[i];
316+
const pin_t p = sizeof(pin_t) == 2 ? (pin_t)pgm_read_word(pptr) : (pin_t)pgm_read_byte(pptr);
317+
if (pin == p) return true;
318+
}
319+
for (uint8_t i = 0; i < COUNT(sensitive_aio); ++i) {
320+
const pin_t * const pptr = &sensitive_aio[i];
321+
const pin_t p = sizeof(pin_t) == 2 ? (pin_t)pgm_read_word(pptr) : (pin_t)pgm_read_byte(pptr);
322+
if (pin == DIO_PIN(p)) return true;
327323
}
328324
return false;
329325
}

0 commit comments

Comments
 (0)