My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

stepper_driver_safety.cpp 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "../inc/MarlinConfig.h"
  23. #include "../lcd/marlinui.h"
  24. #if HAS_DRIVER_SAFE_POWER_PROTECT
  25. #include "stepper_driver_safety.h"
  26. static uint32_t axis_plug_backward = 0;
  27. void stepper_driver_backward_error(PGM_P str) {
  28. SERIAL_ERROR_START();
  29. SERIAL_ECHOPGM_P(str);
  30. SERIAL_ECHOLNPGM(" driver is backward!");
  31. ui.status_printf_P(2, PSTR(S_FMT S_FMT), str, GET_TEXT(MSG_DRIVER_BACKWARD));
  32. }
  33. void stepper_driver_backward_check() {
  34. OUT_WRITE(SAFE_POWER_PIN, LOW);
  35. #define TEST_BACKWARD(AXIS, BIT) do { \
  36. SET_INPUT(AXIS##_ENABLE_PIN); \
  37. OUT_WRITE(AXIS##_STEP_PIN, false); \
  38. delay(20); \
  39. if (READ(AXIS##_ENABLE_PIN) == false) { \
  40. SBI(axis_plug_backward, BIT); \
  41. stepper_driver_backward_error(PSTR(STRINGIFY(AXIS))); \
  42. } \
  43. }while(0)
  44. #if HAS_X_ENABLE
  45. TEST_BACKWARD(X, 0);
  46. #endif
  47. #if HAS_X2_ENABLE
  48. TEST_BACKWARD(X2, 1);
  49. #endif
  50. #if HAS_Y_ENABLE
  51. TEST_BACKWARD(Y, 2);
  52. #endif
  53. #if HAS_Y2_ENABLE
  54. TEST_BACKWARD(Y2, 3);
  55. #endif
  56. #if HAS_Z_ENABLE
  57. TEST_BACKWARD(Z, 4);
  58. #endif
  59. #if HAS_Z2_ENABLE
  60. TEST_BACKWARD(Z2, 5);
  61. #endif
  62. #if HAS_Z3_ENABLE
  63. TEST_BACKWARD(Z3, 6);
  64. #endif
  65. #if HAS_Z4_ENABLE
  66. TEST_BACKWARD(Z4, 7);
  67. #endif
  68. #if HAS_E0_ENABLE
  69. TEST_BACKWARD(E0, 8);
  70. #endif
  71. #if HAS_E1_ENABLE
  72. TEST_BACKWARD(E1, 9);
  73. #endif
  74. #if HAS_E2_ENABLE
  75. TEST_BACKWARD(E2, 10);
  76. #endif
  77. #if HAS_E3_ENABLE
  78. TEST_BACKWARD(E3, 11);
  79. #endif
  80. #if HAS_E4_ENABLE
  81. TEST_BACKWARD(E4, 12);
  82. #endif
  83. #if HAS_E5_ENABLE
  84. TEST_BACKWARD(E5, 13);
  85. #endif
  86. #if HAS_E6_ENABLE
  87. TEST_BACKWARD(E6, 14);
  88. #endif
  89. #if HAS_E7_ENABLE
  90. TEST_BACKWARD(E7, 15);
  91. #endif
  92. if (!axis_plug_backward)
  93. WRITE(SAFE_POWER_PIN, HIGH);
  94. }
  95. void stepper_driver_backward_report() {
  96. if (!axis_plug_backward) return;
  97. auto _report_if_backward = [](PGM_P axis, uint8_t bit) {
  98. if (TEST(axis_plug_backward, bit))
  99. stepper_driver_backward_error(axis);
  100. };
  101. #define REPORT_BACKWARD(axis, bit) _report_if_backward(PSTR(STRINGIFY(axis)), bit)
  102. #if HAS_X_ENABLE
  103. REPORT_BACKWARD(X, 0);
  104. #endif
  105. #if HAS_X2_ENABLE
  106. REPORT_BACKWARD(X2, 1);
  107. #endif
  108. #if HAS_Y_ENABLE
  109. REPORT_BACKWARD(Y, 2);
  110. #endif
  111. #if HAS_Y2_ENABLE
  112. REPORT_BACKWARD(Y2, 3);
  113. #endif
  114. #if HAS_Z_ENABLE
  115. REPORT_BACKWARD(Z, 4);
  116. #endif
  117. #if HAS_Z2_ENABLE
  118. REPORT_BACKWARD(Z2, 5);
  119. #endif
  120. #if HAS_Z3_ENABLE
  121. REPORT_BACKWARD(Z3, 6);
  122. #endif
  123. #if HAS_Z4_ENABLE
  124. REPORT_BACKWARD(Z4, 7);
  125. #endif
  126. #if HAS_E0_ENABLE
  127. REPORT_BACKWARD(E0, 8);
  128. #endif
  129. #if HAS_E1_ENABLE
  130. REPORT_BACKWARD(E1, 9);
  131. #endif
  132. #if HAS_E2_ENABLE
  133. REPORT_BACKWARD(E2, 10);
  134. #endif
  135. #if HAS_E3_ENABLE
  136. REPORT_BACKWARD(E3, 11);
  137. #endif
  138. #if HAS_E4_ENABLE
  139. REPORT_BACKWARD(E4, 12);
  140. #endif
  141. #if HAS_E5_ENABLE
  142. REPORT_BACKWARD(E5, 13);
  143. #endif
  144. #if HAS_E6_ENABLE
  145. REPORT_BACKWARD(E6, 14);
  146. #endif
  147. #if HAS_E7_ENABLE
  148. REPORT_BACKWARD(E7, 15);
  149. #endif
  150. }
  151. #endif // HAS_DRIVER_SAFE_POWER_PROTECT