Browse Source

🎨 Condense reverse-protection code

vanilla_fb_2.0.x
Scott Lahteine 3 years ago
committed by Scott Lahteine
parent
commit
eacb660e4b
  1. 114
      Marlin/src/feature/stepper_driver_safety.cpp

114
Marlin/src/feature/stepper_driver_safety.cpp

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

Loading…
Cancel
Save