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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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(FSTR_P const fstr) {
  28. SERIAL_ERROR_START();
  29. SERIAL_ECHOF(fstr);
  30. SERIAL_ECHOLNPGM(" driver is backward!");
  31. ui.status_printf(2, F(S_FMT S_FMT), FTOP(fstr), 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(F(STRINGIFY(AXIS))); \
  42. } \
  43. }while(0)
  44. #define TEST_BACKWARD(AXIS, BIT) TERN_(HAS_##AXIS##_ENABLE, _TEST_BACKWARD(AXIS, BIT))
  45. TEST_BACKWARD(X, 0);
  46. TEST_BACKWARD(X2, 1);
  47. TEST_BACKWARD(Y, 2);
  48. TEST_BACKWARD(Y2, 3);
  49. TEST_BACKWARD(Z, 4);
  50. TEST_BACKWARD(Z2, 5);
  51. TEST_BACKWARD(Z3, 6);
  52. TEST_BACKWARD(Z4, 7);
  53. TEST_BACKWARD(I, 8);
  54. TEST_BACKWARD(J, 9);
  55. TEST_BACKWARD(K, 10);
  56. TEST_BACKWARD(U, 11);
  57. TEST_BACKWARD(V, 12);
  58. TEST_BACKWARD(W, 13);
  59. TEST_BACKWARD(E0, 14);
  60. TEST_BACKWARD(E1, 15);
  61. TEST_BACKWARD(E2, 16);
  62. TEST_BACKWARD(E3, 17);
  63. TEST_BACKWARD(E4, 18);
  64. TEST_BACKWARD(E5, 19);
  65. TEST_BACKWARD(E6, 20);
  66. TEST_BACKWARD(E7, 21);
  67. if (!axis_plug_backward)
  68. WRITE(SAFE_POWER_PIN, HIGH);
  69. }
  70. void stepper_driver_backward_report() {
  71. if (!axis_plug_backward) return;
  72. auto _report_if_backward = [](FSTR_P const axis, uint8_t bit) {
  73. if (TEST(axis_plug_backward, bit))
  74. stepper_driver_backward_error(axis);
  75. };
  76. #define REPORT_BACKWARD(axis, bit) TERN_(HAS_##axis##_ENABLE, _report_if_backward(F(STRINGIFY(axis)), bit))
  77. REPORT_BACKWARD(X, 0);
  78. REPORT_BACKWARD(X2, 1);
  79. REPORT_BACKWARD(Y, 2);
  80. REPORT_BACKWARD(Y2, 3);
  81. REPORT_BACKWARD(Z, 4);
  82. REPORT_BACKWARD(Z2, 5);
  83. REPORT_BACKWARD(Z3, 6);
  84. REPORT_BACKWARD(Z4, 7);
  85. REPORT_BACKWARD(I, 8);
  86. REPORT_BACKWARD(J, 9);
  87. REPORT_BACKWARD(K, 10);
  88. REPORT_BACKWARD(U, 11);
  89. REPORT_BACKWARD(V, 12);
  90. REPORT_BACKWARD(W, 13);
  91. REPORT_BACKWARD(E0, 14);
  92. REPORT_BACKWARD(E1, 15);
  93. REPORT_BACKWARD(E2, 16);
  94. REPORT_BACKWARD(E3, 17);
  95. REPORT_BACKWARD(E4, 18);
  96. REPORT_BACKWARD(E5, 19);
  97. REPORT_BACKWARD(E6, 20);
  98. REPORT_BACKWARD(E7, 21);
  99. }
  100. #endif // HAS_DRIVER_SAFE_POWER_PROTECT