1
0
mirror of https://github.com/MarlinFirmware/Marlin.git synced 2024-11-27 13:56:24 +00:00

🎨 Condense reverse-protection code

This commit is contained in:
Scott Lahteine 2021-09-28 02:39:11 -05:00
parent 33e0855e2c
commit f2ba845dad

View File

@ -39,7 +39,7 @@ void stepper_driver_backward_check() {
OUT_WRITE(SAFE_POWER_PIN, LOW);
#define TEST_BACKWARD(AXIS, BIT) do { \
#define _TEST_BACKWARD(AXIS, BIT) do { \
SET_INPUT(AXIS##_ENABLE_PIN); \
OUT_WRITE(AXIS##_STEP_PIN, false); \
delay(20); \
@ -49,57 +49,31 @@ void stepper_driver_backward_check() {
} \
}while(0)
#if HAS_X_ENABLE
TEST_BACKWARD(X, 0);
#endif
#if HAS_X2_ENABLE
TEST_BACKWARD(X2, 1);
#endif
#define TEST_BACKWARD(AXIS, BIT) TERN_(HAS_##AXIS##_ENABLE, _TEST_BACKWARD(AXIS, BIT))
#if HAS_Y_ENABLE
TEST_BACKWARD(Y, 2);
#endif
#if HAS_Y2_ENABLE
TEST_BACKWARD(Y2, 3);
#endif
TEST_BACKWARD(X, 0);
TEST_BACKWARD(X2, 1);
#if HAS_Z_ENABLE
TEST_BACKWARD(Z, 4);
#endif
#if HAS_Z2_ENABLE
TEST_BACKWARD(Z2, 5);
#endif
#if HAS_Z3_ENABLE
TEST_BACKWARD(Z3, 6);
#endif
#if HAS_Z4_ENABLE
TEST_BACKWARD(Z4, 7);
#endif
TEST_BACKWARD(Y, 2);
TEST_BACKWARD(Y2, 3);
#if HAS_E0_ENABLE
TEST_BACKWARD(E0, 8);
#endif
#if HAS_E1_ENABLE
TEST_BACKWARD(E1, 9);
#endif
#if HAS_E2_ENABLE
TEST_BACKWARD(E2, 10);
#endif
#if HAS_E3_ENABLE
TEST_BACKWARD(E3, 11);
#endif
#if HAS_E4_ENABLE
TEST_BACKWARD(E4, 12);
#endif
#if HAS_E5_ENABLE
TEST_BACKWARD(E5, 13);
#endif
#if HAS_E6_ENABLE
TEST_BACKWARD(E6, 14);
#endif
#if HAS_E7_ENABLE
TEST_BACKWARD(E7, 15);
#endif
TEST_BACKWARD(Z, 4);
TEST_BACKWARD(Z2, 5);
TEST_BACKWARD(Z3, 6);
TEST_BACKWARD(Z4, 7);
TEST_BACKWARD(I, 8);
TEST_BACKWARD(J, 9);
TEST_BACKWARD(K, 10);
TEST_BACKWARD(E0, 11);
TEST_BACKWARD(E1, 12);
TEST_BACKWARD(E2, 13);
TEST_BACKWARD(E3, 14);
TEST_BACKWARD(E4, 15);
TEST_BACKWARD(E5, 16);
TEST_BACKWARD(E6, 17);
TEST_BACKWARD(E7, 18);
if (!axis_plug_backward)
WRITE(SAFE_POWER_PIN, HIGH);
@ -113,59 +87,31 @@ void stepper_driver_backward_report() {
stepper_driver_backward_error(axis);
};
#define REPORT_BACKWARD(axis, bit) _report_if_backward(PSTR(STRINGIFY(axis)), bit)
#define REPORT_BACKWARD(axis, bit) TERN_(HAS_##axis##_ENABLE, _report_if_backward(PSTR(STRINGIFY(axis)), bit))
#if HAS_X_ENABLE
REPORT_BACKWARD(X, 0);
#endif
#if HAS_X2_ENABLE
REPORT_BACKWARD(X2, 1);
#endif
REPORT_BACKWARD(X, 0);
REPORT_BACKWARD(X2, 1);
#if HAS_Y_ENABLE
REPORT_BACKWARD(Y, 2);
#endif
#if HAS_Y2_ENABLE
REPORT_BACKWARD(Y2, 3);
#endif
REPORT_BACKWARD(Y, 2);
REPORT_BACKWARD(Y2, 3);
#if HAS_Z_ENABLE
REPORT_BACKWARD(Z, 4);
#endif
#if HAS_Z2_ENABLE
REPORT_BACKWARD(Z2, 5);
#endif
#if HAS_Z3_ENABLE
REPORT_BACKWARD(Z3, 6);
#endif
#if HAS_Z4_ENABLE
REPORT_BACKWARD(Z4, 7);
#endif
REPORT_BACKWARD(Z, 4);
REPORT_BACKWARD(Z2, 5);
REPORT_BACKWARD(Z3, 6);
REPORT_BACKWARD(Z4, 7);
#if HAS_E0_ENABLE
REPORT_BACKWARD(E0, 8);
#endif
#if HAS_E1_ENABLE
REPORT_BACKWARD(E1, 9);
#endif
#if HAS_E2_ENABLE
REPORT_BACKWARD(E2, 10);
#endif
#if HAS_E3_ENABLE
REPORT_BACKWARD(E3, 11);
#endif
#if HAS_E4_ENABLE
REPORT_BACKWARD(E4, 12);
#endif
#if HAS_E5_ENABLE
REPORT_BACKWARD(E5, 13);
#endif
#if HAS_E6_ENABLE
REPORT_BACKWARD(E6, 14);
#endif
#if HAS_E7_ENABLE
REPORT_BACKWARD(E7, 15);
#endif
REPORT_BACKWARD(I, 8);
REPORT_BACKWARD(J, 9);
REPORT_BACKWARD(K, 10);
REPORT_BACKWARD(E0, 11);
REPORT_BACKWARD(E1, 12);
REPORT_BACKWARD(E2, 13);
REPORT_BACKWARD(E3, 14);
REPORT_BACKWARD(E4, 15);
REPORT_BACKWARD(E5, 16);
REPORT_BACKWARD(E6, 17);
REPORT_BACKWARD(E7, 18);
}
#endif // HAS_DRIVER_SAFE_POWER_PROTECT