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.

M906.cpp 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2019 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 <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "../../../inc/MarlinConfig.h"
  23. #if HAS_TRINAMIC
  24. #include "../../gcode.h"
  25. #include "../../../feature/tmc_util.h"
  26. #include "../../../module/stepper/indirection.h"
  27. /**
  28. * M906: Set motor current in milliamps.
  29. *
  30. * Parameters:
  31. * X[current] - Set mA current for X driver(s)
  32. * Y[current] - Set mA current for Y driver(s)
  33. * Z[current] - Set mA current for Z driver(s)
  34. * E[current] - Set mA current for E driver(s)
  35. *
  36. * I[index] - Axis sub-index (Omit or 0 for X, Y, Z; 1 for X2, Y2, Z2; 2 for Z3; 3 for Z4.)
  37. * T[index] - Extruder index (Zero-based. Omit for E0 only.)
  38. *
  39. * With no parameters report driver currents.
  40. */
  41. void GcodeSuite::M906() {
  42. #define TMC_SAY_CURRENT(Q) tmc_print_current(stepper##Q)
  43. #define TMC_SET_CURRENT(Q) stepper##Q.rms_current(value)
  44. bool report = true;
  45. #if AXIS_IS_TMC(X) || AXIS_IS_TMC(X2) || AXIS_IS_TMC(Y) || AXIS_IS_TMC(Y2) || AXIS_IS_TMC(Z) || AXIS_IS_TMC(Z2) || AXIS_IS_TMC(Z3) || AXIS_IS_TMC(Z4)
  46. const uint8_t index = parser.byteval('I');
  47. #endif
  48. LOOP_XYZE(i) if (uint16_t value = parser.intval(axis_codes[i])) {
  49. report = false;
  50. switch (i) {
  51. case X_AXIS:
  52. #if AXIS_IS_TMC(X)
  53. if (index == 0) TMC_SET_CURRENT(X);
  54. #endif
  55. #if AXIS_IS_TMC(X2)
  56. if (index == 1) TMC_SET_CURRENT(X2);
  57. #endif
  58. break;
  59. case Y_AXIS:
  60. #if AXIS_IS_TMC(Y)
  61. if (index == 0) TMC_SET_CURRENT(Y);
  62. #endif
  63. #if AXIS_IS_TMC(Y2)
  64. if (index == 1) TMC_SET_CURRENT(Y2);
  65. #endif
  66. break;
  67. case Z_AXIS:
  68. #if AXIS_IS_TMC(Z)
  69. if (index == 0) TMC_SET_CURRENT(Z);
  70. #endif
  71. #if AXIS_IS_TMC(Z2)
  72. if (index == 1) TMC_SET_CURRENT(Z2);
  73. #endif
  74. #if AXIS_IS_TMC(Z3)
  75. if (index == 2) TMC_SET_CURRENT(Z3);
  76. #endif
  77. #if AXIS_IS_TMC(Z4)
  78. if (index == 3) TMC_SET_CURRENT(Z4);
  79. #endif
  80. break;
  81. case E_AXIS: {
  82. const int8_t target_extruder = get_target_extruder_from_command();
  83. if (target_extruder < 0) return;
  84. switch (target_extruder) {
  85. #if AXIS_IS_TMC(E0)
  86. case 0: TMC_SET_CURRENT(E0); break;
  87. #endif
  88. #if AXIS_IS_TMC(E1)
  89. case 1: TMC_SET_CURRENT(E1); break;
  90. #endif
  91. #if AXIS_IS_TMC(E2)
  92. case 2: TMC_SET_CURRENT(E2); break;
  93. #endif
  94. #if AXIS_IS_TMC(E3)
  95. case 3: TMC_SET_CURRENT(E3); break;
  96. #endif
  97. #if AXIS_IS_TMC(E4)
  98. case 4: TMC_SET_CURRENT(E4); break;
  99. #endif
  100. #if AXIS_IS_TMC(E5)
  101. case 5: TMC_SET_CURRENT(E5); break;
  102. #endif
  103. }
  104. } break;
  105. }
  106. }
  107. if (report) {
  108. #if AXIS_IS_TMC(X)
  109. TMC_SAY_CURRENT(X);
  110. #endif
  111. #if AXIS_IS_TMC(X2)
  112. TMC_SAY_CURRENT(X2);
  113. #endif
  114. #if AXIS_IS_TMC(Y)
  115. TMC_SAY_CURRENT(Y);
  116. #endif
  117. #if AXIS_IS_TMC(Y2)
  118. TMC_SAY_CURRENT(Y2);
  119. #endif
  120. #if AXIS_IS_TMC(Z)
  121. TMC_SAY_CURRENT(Z);
  122. #endif
  123. #if AXIS_IS_TMC(Z2)
  124. TMC_SAY_CURRENT(Z2);
  125. #endif
  126. #if AXIS_IS_TMC(Z3)
  127. TMC_SAY_CURRENT(Z3);
  128. #endif
  129. #if AXIS_IS_TMC(Z4)
  130. TMC_SAY_CURRENT(Z4);
  131. #endif
  132. #if AXIS_IS_TMC(E0)
  133. TMC_SAY_CURRENT(E0);
  134. #endif
  135. #if AXIS_IS_TMC(E1)
  136. TMC_SAY_CURRENT(E1);
  137. #endif
  138. #if AXIS_IS_TMC(E2)
  139. TMC_SAY_CURRENT(E2);
  140. #endif
  141. #if AXIS_IS_TMC(E3)
  142. TMC_SAY_CURRENT(E3);
  143. #endif
  144. #if AXIS_IS_TMC(E4)
  145. TMC_SAY_CURRENT(E4);
  146. #endif
  147. #if AXIS_IS_TMC(E5)
  148. TMC_SAY_CURRENT(E5);
  149. #endif
  150. }
  151. }
  152. #endif // HAS_TRINAMIC