Add TMC micro-steps sanity check (#17044)

Co-authored-by: Scott Lahteine <github@thinkyhead.com>
This commit is contained in:
Jason Smith 2020-03-02 11:13:04 -08:00 committed by GitHub
parent 2c4e054e9a
commit 66334820ca
Signed by: GitHub
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2150,6 +2150,47 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
#endif
#undef INVALID_TMC_ADDRESS
#define _TMC_MICROSTEP_IS_VALID(MS) (MS == 0 || MS == 2 || MS == 4 || MS == 8 || MS == 16 || MS == 32 || MS == 64 || MS == 128 || MS == 256)
#define TMC_MICROSTEP_IS_VALID(M) (!AXIS_IS_TMC(M) || _TMC_MICROSTEP_IS_VALID(M##_MICROSTEPS))
#define INVALID_TMC_MS(ST) static_assert(0, "Invalid " STRINGIFY(ST) "_MICROSTEPS. Valid values are 0, 2, 4, 8, 16, 32, 64, 128, and 256.")
#if !TMC_MICROSTEP_IS_VALID(X)
INVALID_TMC_MS(X);
#elif !TMC_MICROSTEP_IS_VALID(Y)
INVALID_TMC_MS(Y)
#elif !TMC_MICROSTEP_IS_VALID(Z)
INVALID_TMC_MS(Z)
#elif !TMC_MICROSTEP_IS_VALID(X2)
INVALID_TMC_MS(X2);
#elif !TMC_MICROSTEP_IS_VALID(Y2)
INVALID_TMC_MS(Y2)
#elif !TMC_MICROSTEP_IS_VALID(Z2)
INVALID_TMC_MS(Z2)
#elif !TMC_MICROSTEP_IS_VALID(Z3)
INVALID_TMC_MS(Z3)
#elif !TMC_MICROSTEP_IS_VALID(Z4)
INVALID_TMC_MS(Z4)
#elif !TMC_MICROSTEP_IS_VALID(E0)
INVALID_TMC_MS(E0)
#elif !TMC_MICROSTEP_IS_VALID(E1)
INVALID_TMC_MS(E1)
#elif !TMC_MICROSTEP_IS_VALID(E2)
INVALID_TMC_MS(E2)
#elif !TMC_MICROSTEP_IS_VALID(E3)
INVALID_TMC_MS(E3)
#elif !TMC_MICROSTEP_IS_VALID(E4)
INVALID_TMC_MS(E4)
#elif !TMC_MICROSTEP_IS_VALID(E5)
INVALID_TMC_MS(E5)
#elif !TMC_MICROSTEP_IS_VALID(E6)
INVALID_TMC_MS(E6)
#elif !TMC_MICROSTEP_IS_VALID(E7)
INVALID_TMC_MS(E7)
#endif
#undef INVALID_TMC_MS
#undef TMC_MICROSTEP_IS_VALID
#undef _TMC_MICROSTEP_IS_VALID
#if ENABLED(DELTA) && (ENABLED(STEALTHCHOP_XY) != ENABLED(STEALTHCHOP_Z))
#error "STEALTHCHOP_XY and STEALTHCHOP_Z must be the same on DELTA."
#endif