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.

M907-M910.cpp 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 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. #if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM || HAS_MOTOR_CURRENT_I2C || HAS_MOTOR_CURRENT_DAC
  24. #include "../../gcode.h"
  25. #if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM
  26. #include "../../../module/stepper.h"
  27. #endif
  28. #if HAS_MOTOR_CURRENT_I2C
  29. #include "../../../feature/digipot/digipot.h"
  30. #endif
  31. #if HAS_MOTOR_CURRENT_DAC
  32. #include "../../../feature/dac/stepper_dac.h"
  33. #endif
  34. /**
  35. * M907: Set digital trimpot motor current using axis codes X, Y, Z, E, B, S
  36. */
  37. void GcodeSuite::M907() {
  38. #if HAS_MOTOR_CURRENT_SPI
  39. if (!parser.seen("BS" LOGICAL_AXES_STRING))
  40. return M907_report();
  41. LOOP_LOGICAL_AXES(i) if (parser.seenval(axis_codes[i])) stepper.set_digipot_current(i, parser.value_int());
  42. if (parser.seenval('B')) stepper.set_digipot_current(4, parser.value_int());
  43. if (parser.seenval('S')) LOOP_LE_N(i, 4) stepper.set_digipot_current(i, parser.value_int());
  44. #elif HAS_MOTOR_CURRENT_PWM
  45. if (!parser.seen(
  46. #if ANY_PIN(MOTOR_CURRENT_PWM_X, MOTOR_CURRENT_PWM_Y, MOTOR_CURRENT_PWM_XY)
  47. "XY"
  48. #endif
  49. #if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
  50. "Z"
  51. #endif
  52. #if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
  53. "E"
  54. #endif
  55. )) return M907_report();
  56. #if ANY_PIN(MOTOR_CURRENT_PWM_X, MOTOR_CURRENT_PWM_Y, MOTOR_CURRENT_PWM_XY)
  57. if (parser.seenval('X') || parser.seenval('Y')) stepper.set_digipot_current(0, parser.value_int());
  58. #endif
  59. #if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
  60. if (parser.seenval('Z')) stepper.set_digipot_current(1, parser.value_int());
  61. #endif
  62. #if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
  63. if (parser.seenval('E')) stepper.set_digipot_current(2, parser.value_int());
  64. #endif
  65. #endif
  66. #if HAS_MOTOR_CURRENT_I2C
  67. // this one uses actual amps in floating point
  68. LOOP_LOGICAL_AXES(i) if (parser.seenval(axis_codes[i])) digipot_i2c.set_current(i, parser.value_float());
  69. // Additional extruders use B,C,D for channels 4,5,6.
  70. // TODO: Change these parameters because 'E' is used. B<index>?
  71. #if HAS_EXTRUDERS
  72. for (uint8_t i = E_AXIS + 1; i < DIGIPOT_I2C_NUM_CHANNELS; i++)
  73. if (parser.seenval('B' + i - (E_AXIS + 1))) digipot_i2c.set_current(i, parser.value_float());
  74. #endif
  75. #endif
  76. #if HAS_MOTOR_CURRENT_DAC
  77. if (parser.seenval('S')) {
  78. const float dac_percent = parser.value_float();
  79. LOOP_LE_N(i, 4) stepper_dac.set_current_percent(i, dac_percent);
  80. }
  81. LOOP_LOGICAL_AXES(i) if (parser.seenval(axis_codes[i])) stepper_dac.set_current_percent(i, parser.value_float());
  82. #endif
  83. }
  84. #if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM
  85. void GcodeSuite::M907_report(const bool forReplay/*=true*/) {
  86. report_heading_etc(forReplay, PSTR(STR_STEPPER_MOTOR_CURRENTS));
  87. #if HAS_MOTOR_CURRENT_PWM
  88. SERIAL_ECHOLNPGM_P( // PWM-based has 3 values:
  89. PSTR(" M907 X"), stepper.motor_current_setting[0] // X and Y
  90. , SP_Z_STR, stepper.motor_current_setting[1] // Z
  91. , SP_E_STR, stepper.motor_current_setting[2] // E
  92. );
  93. #elif HAS_MOTOR_CURRENT_SPI
  94. SERIAL_ECHOPGM(" M907"); // SPI-based has 5 values:
  95. LOOP_LOGICAL_AXES(q) { // X Y Z (I J K) E (map to X Y Z (I J K) E0 by default)
  96. SERIAL_CHAR(' ', axis_codes[q]);
  97. SERIAL_ECHO(stepper.motor_current_setting[q]);
  98. }
  99. SERIAL_CHAR(' ', 'B'); // B (maps to E1 by default)
  100. SERIAL_ECHOLN(stepper.motor_current_setting[4]);
  101. #endif
  102. }
  103. #endif // HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM
  104. #if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_DAC
  105. /**
  106. * M908: Control digital trimpot directly (M908 P<pin> S<current>)
  107. */
  108. void GcodeSuite::M908() {
  109. TERN_(HAS_MOTOR_CURRENT_SPI, stepper.set_digipot_value_spi(parser.intval('P'), parser.intval('S')));
  110. TERN_(HAS_MOTOR_CURRENT_DAC, stepper_dac.set_current_value(parser.byteval('P', -1), parser.ushortval('S', 0)));
  111. }
  112. #if HAS_MOTOR_CURRENT_DAC
  113. void GcodeSuite::M909() { stepper_dac.print_values(); }
  114. void GcodeSuite::M910() { stepper_dac.commit_eeprom(); }
  115. #endif // HAS_MOTOR_CURRENT_DAC
  116. #endif // HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_DAC
  117. #endif // HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM || HAS_MOTOR_CURRENT_I2C || HAS_MOTOR_CURRENT_DAC