Apply REPEAT, RREPEAT, and loop macros (#16757)

This commit is contained in:
Scott Lahteine
2020-02-01 21:00:53 -06:00
committed by GitHub
parent 0e72c315a0
commit 4716dac874
10 changed files with 82 additions and 221 deletions

View File

@@ -139,56 +139,28 @@ class FilamentSensorBase {
#define INIT_RUNOUT_PIN(P) SET_INPUT(P)
#endif
INIT_RUNOUT_PIN(FIL_RUNOUT_PIN);
#if NUM_RUNOUT_SENSORS > 1
INIT_RUNOUT_PIN(FIL_RUNOUT2_PIN);
#if NUM_RUNOUT_SENSORS > 2
INIT_RUNOUT_PIN(FIL_RUNOUT3_PIN);
#if NUM_RUNOUT_SENSORS > 3
INIT_RUNOUT_PIN(FIL_RUNOUT4_PIN);
#if NUM_RUNOUT_SENSORS > 4
INIT_RUNOUT_PIN(FIL_RUNOUT5_PIN);
#if NUM_RUNOUT_SENSORS > 5
INIT_RUNOUT_PIN(FIL_RUNOUT6_PIN);
#endif
#endif
#endif
#endif
#endif
#define _INIT_RUNOUT(N) INIT_RUNOUT_PIN(FIL_RUNOUT##N##_PIN);
REPEAT_S(1, INCREMENT(NUM_RUNOUT_SENSORS), _INIT_RUNOUT)
#undef _INIT_RUNOUT
}
// Return a bitmask of runout pin states
static inline uint8_t poll_runout_pins() {
return (
(READ(FIL_RUNOUT_PIN ) ? _BV(0) : 0)
#if NUM_RUNOUT_SENSORS > 1
| (READ(FIL_RUNOUT2_PIN) ? _BV(1) : 0)
#if NUM_RUNOUT_SENSORS > 2
| (READ(FIL_RUNOUT3_PIN) ? _BV(2) : 0)
#if NUM_RUNOUT_SENSORS > 3
| (READ(FIL_RUNOUT4_PIN) ? _BV(3) : 0)
#if NUM_RUNOUT_SENSORS > 4
| (READ(FIL_RUNOUT5_PIN) ? _BV(4) : 0)
#if NUM_RUNOUT_SENSORS > 5
| (READ(FIL_RUNOUT6_PIN) ? _BV(5) : 0)
#endif
#endif
#endif
#endif
#endif
);
#define _OR_RUNOUT(N) | (READ(FIL_RUNOUT##N##_PIN) ? _BV((N) - 1) : 0)
return (0 REPEAT_S(1, INCREMENT(NUM_RUNOUT_SENSORS), _OR_RUNOUT));
#undef _OR_RUNOUT
}
// Return a bitmask of runout flag states (1 bits always indicates runout)
static inline uint8_t poll_runout_states() {
return poll_runout_pins() ^ uint8_t(
return (poll_runout_pins()
#if DISABLED(FIL_RUNOUT_INVERTING)
_BV(NUM_RUNOUT_SENSORS) - 1
#else
0
^ uint8_t(_BV(NUM_RUNOUT_SENSORS) - 1)
#endif
);
}
#undef INIT_RUNOUT_PIN
};
#if ENABLED(FILAMENT_MOTION_SENSOR)