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 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 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 using axis codes X, Y, Z, E
  29. * Report driver currents when no axis specified
  30. */
  31. void GcodeSuite::M906() {
  32. #define TMC_SAY_CURRENT(Q) tmc_get_current(stepper##Q, TMC_##Q)
  33. #define TMC_SET_CURRENT(Q) tmc_set_current(stepper##Q, TMC_##Q, value)
  34. bool report = true;
  35. const uint8_t index = parser.byteval('I');
  36. LOOP_XYZE(i) if (uint16_t value = parser.intval(axis_codes[i])) {
  37. report = false;
  38. switch (i) {
  39. case X_AXIS:
  40. #if X_IS_TRINAMIC
  41. if (index == 0) TMC_SET_CURRENT(X);
  42. #endif
  43. #if X2_IS_TRINAMIC
  44. if (index == 1) TMC_SET_CURRENT(X2);
  45. #endif
  46. break;
  47. case Y_AXIS:
  48. #if Y_IS_TRINAMIC
  49. if (index == 0) TMC_SET_CURRENT(Y);
  50. #endif
  51. #if Y2_IS_TRINAMIC
  52. if (index == 1) TMC_SET_CURRENT(Y2);
  53. #endif
  54. break;
  55. case Z_AXIS:
  56. #if Z_IS_TRINAMIC
  57. if (index == 0) TMC_SET_CURRENT(Z);
  58. #endif
  59. #if Z2_IS_TRINAMIC
  60. if (index == 1) TMC_SET_CURRENT(Z2);
  61. #endif
  62. break;
  63. case E_AXIS: {
  64. if (get_target_extruder_from_command()) return;
  65. switch (target_extruder) {
  66. #if E0_IS_TRINAMIC
  67. case 0: TMC_SET_CURRENT(E0); break;
  68. #endif
  69. #if E1_IS_TRINAMIC
  70. case 1: TMC_SET_CURRENT(E1); break;
  71. #endif
  72. #if E2_IS_TRINAMIC
  73. case 2: TMC_SET_CURRENT(E2); break;
  74. #endif
  75. #if E3_IS_TRINAMIC
  76. case 3: TMC_SET_CURRENT(E3); break;
  77. #endif
  78. #if E4_IS_TRINAMIC
  79. case 4: TMC_SET_CURRENT(E4); break;
  80. #endif
  81. }
  82. } break;
  83. }
  84. }
  85. if (report) LOOP_XYZE(i) switch (i) {
  86. case X_AXIS:
  87. #if X_IS_TRINAMIC
  88. TMC_SAY_CURRENT(X);
  89. #endif
  90. #if X2_IS_TRINAMIC
  91. TMC_SAY_CURRENT(X2);
  92. #endif
  93. break;
  94. case Y_AXIS:
  95. #if Y_IS_TRINAMIC
  96. TMC_SAY_CURRENT(Y);
  97. #endif
  98. #if Y2_IS_TRINAMIC
  99. TMC_SAY_CURRENT(Y2);
  100. #endif
  101. break;
  102. case Z_AXIS:
  103. #if Z_IS_TRINAMIC
  104. TMC_SAY_CURRENT(Z);
  105. #endif
  106. #if Z2_IS_TRINAMIC
  107. TMC_SAY_CURRENT(Z2);
  108. #endif
  109. break;
  110. case E_AXIS:
  111. #if E0_IS_TRINAMIC
  112. TMC_SAY_CURRENT(E0);
  113. #endif
  114. #if E1_IS_TRINAMIC
  115. TMC_SAY_CURRENT(E1);
  116. #endif
  117. #if E2_IS_TRINAMIC
  118. TMC_SAY_CURRENT(E2);
  119. #endif
  120. #if E3_IS_TRINAMIC
  121. TMC_SAY_CURRENT(E3);
  122. #endif
  123. #if E4_IS_TRINAMIC
  124. TMC_SAY_CURRENT(E4);
  125. #endif
  126. break;
  127. }
  128. }
  129. #endif // HAS_TRINAMIC