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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "../../../inc/MarlinConfig.h"
  23. #if HAS_DIGIPOTSS || HAS_MOTOR_CURRENT_PWM || EITHER(DIGIPOT_I2C, DAC_STEPPER_CURRENT)
  24. #include "../../gcode.h"
  25. #if HAS_DIGIPOTSS || HAS_MOTOR_CURRENT_PWM
  26. #include "../../../module/stepper.h"
  27. #endif
  28. #if ENABLED(DIGIPOT_I2C)
  29. #include "../../../feature/digipot/digipot.h"
  30. #endif
  31. #if ENABLED(DAC_STEPPER_CURRENT)
  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_DIGIPOTSS
  39. LOOP_XYZE(i) if (parser.seenval(axis_codes[i])) stepper.digipot_current(i, parser.value_int());
  40. if (parser.seenval('B')) stepper.digipot_current(4, parser.value_int());
  41. if (parser.seenval('S')) LOOP_LE_N(i, 4) stepper.digipot_current(i, parser.value_int());
  42. #elif HAS_MOTOR_CURRENT_PWM
  43. #if ANY_PIN(MOTOR_CURRENT_PWM_X, MOTOR_CURRENT_PWM_Y, MOTOR_CURRENT_PWM_XY)
  44. if (parser.seenval('X') || parser.seenval('Y')) stepper.digipot_current(0, parser.value_int());
  45. #endif
  46. #if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
  47. if (parser.seenval('Z')) stepper.digipot_current(1, parser.value_int());
  48. #endif
  49. #if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
  50. if (parser.seenval('E')) stepper.digipot_current(2, parser.value_int());
  51. #endif
  52. #endif
  53. #if ENABLED(DIGIPOT_I2C)
  54. // this one uses actual amps in floating point
  55. LOOP_XYZE(i) if (parser.seenval(axis_codes[i])) digipot_i2c_set_current(i, parser.value_float());
  56. // Additional extruders use B,C,D for channels 4,5,6.
  57. // TODO: Change these parameters because 'E' is used. B<index>?
  58. for (uint8_t i = E_AXIS + 1; i < DIGIPOT_I2C_NUM_CHANNELS; i++)
  59. if (parser.seenval('B' + i - (E_AXIS + 1))) digipot_i2c_set_current(i, parser.value_float());
  60. #endif
  61. #if ENABLED(DAC_STEPPER_CURRENT)
  62. if (parser.seenval('S')) {
  63. const float dac_percent = parser.value_float();
  64. LOOP_LE_N(i, 4) dac_current_percent(i, dac_percent);
  65. }
  66. LOOP_XYZE(i) if (parser.seenval(axis_codes[i])) dac_current_percent(i, parser.value_float());
  67. #endif
  68. }
  69. #if HAS_DIGIPOTSS || ENABLED(DAC_STEPPER_CURRENT)
  70. /**
  71. * M908: Control digital trimpot directly (M908 P<pin> S<current>)
  72. */
  73. void GcodeSuite::M908() {
  74. #if HAS_DIGIPOTSS
  75. stepper.digitalPotWrite(parser.intval('P'), parser.intval('S'));
  76. #endif
  77. #if ENABLED(DAC_STEPPER_CURRENT)
  78. dac_current_raw(parser.byteval('P', -1), parser.ushortval('S', 0));
  79. #endif
  80. }
  81. #endif // HAS_DIGIPOTSS || DAC_STEPPER_CURRENT
  82. #if ENABLED(DAC_STEPPER_CURRENT)
  83. void GcodeSuite::M909() { dac_print_values(); }
  84. void GcodeSuite::M910() { dac_commit_eeprom(); }
  85. #endif // DAC_STEPPER_CURRENT
  86. #endif // HAS_DIGIPOTSS || DAC_STEPPER_CURRENT || HAS_MOTOR_CURRENT_PWM || DIGIPOT_I2C