2017-09-06 11:28:31 +00:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2019-02-12 21:06:53 +00:00
|
|
|
* Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2017-09-06 11:28:31 +00:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
|
|
|
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-09-23 23:09:14 +00:00
|
|
|
#include "../../../inc/MarlinConfig.h"
|
|
|
|
|
2019-03-17 04:43:06 +00:00
|
|
|
#if HAS_DIGIPOTSS || HAS_MOTOR_CURRENT_PWM || EITHER(DIGIPOT_I2C, DAC_STEPPER_CURRENT)
|
2017-09-23 23:09:14 +00:00
|
|
|
|
2017-09-17 23:45:21 +00:00
|
|
|
#include "../../gcode.h"
|
|
|
|
|
|
|
|
#if HAS_DIGIPOTSS || HAS_MOTOR_CURRENT_PWM
|
|
|
|
#include "../../../module/stepper.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(DIGIPOT_I2C)
|
|
|
|
#include "../../../feature/digipot/digipot.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(DAC_STEPPER_CURRENT)
|
|
|
|
#include "../../../feature/dac/stepper_dac.h"
|
|
|
|
#endif
|
|
|
|
|
2017-09-06 11:28:31 +00:00
|
|
|
/**
|
|
|
|
* M907: Set digital trimpot motor current using axis codes X, Y, Z, E, B, S
|
|
|
|
*/
|
2017-09-17 23:45:21 +00:00
|
|
|
void GcodeSuite::M907() {
|
2017-09-06 11:28:31 +00:00
|
|
|
#if HAS_DIGIPOTSS
|
|
|
|
|
2019-02-27 03:03:13 +00:00
|
|
|
LOOP_XYZE(i) if (parser.seenval(axis_codes[i])) stepper.digipot_current(i, parser.value_int());
|
|
|
|
if (parser.seenval('B')) stepper.digipot_current(4, parser.value_int());
|
|
|
|
if (parser.seenval('S')) for (uint8_t i = 0; i <= 4; i++) stepper.digipot_current(i, parser.value_int());
|
2017-09-06 11:28:31 +00:00
|
|
|
|
|
|
|
#elif HAS_MOTOR_CURRENT_PWM
|
|
|
|
|
2019-03-17 04:43:06 +00:00
|
|
|
#if ANY_PIN(MOTOR_CURRENT_PWM_X, MOTOR_CURRENT_PWM_Y, MOTOR_CURRENT_PWM_XY)
|
2019-02-27 03:03:13 +00:00
|
|
|
if (parser.seenval('X') || parser.seenval('Y')) stepper.digipot_current(0, parser.value_int());
|
2017-09-06 11:28:31 +00:00
|
|
|
#endif
|
|
|
|
#if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
|
2019-02-27 03:03:13 +00:00
|
|
|
if (parser.seenval('Z')) stepper.digipot_current(1, parser.value_int());
|
2017-09-06 11:28:31 +00:00
|
|
|
#endif
|
|
|
|
#if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
|
2019-02-27 03:03:13 +00:00
|
|
|
if (parser.seenval('E')) stepper.digipot_current(2, parser.value_int());
|
2017-09-06 11:28:31 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(DIGIPOT_I2C)
|
|
|
|
// this one uses actual amps in floating point
|
2019-02-27 03:03:13 +00:00
|
|
|
LOOP_XYZE(i) if (parser.seenval(axis_codes[i])) digipot_i2c_set_current(i, parser.value_float());
|
2017-09-06 11:28:31 +00:00
|
|
|
// for each additional extruder (named B,C,D,E..., channels 4,5,6,7...)
|
2019-02-27 03:03:13 +00:00
|
|
|
for (uint8_t i = NUM_AXIS; i < DIGIPOT_I2C_NUM_CHANNELS; i++) if (parser.seenval('B' + i - (NUM_AXIS))) digipot_i2c_set_current(i, parser.value_float());
|
2017-09-06 11:28:31 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(DAC_STEPPER_CURRENT)
|
2019-02-27 03:03:13 +00:00
|
|
|
if (parser.seenval('S')) {
|
2017-09-06 11:28:31 +00:00
|
|
|
const float dac_percent = parser.value_float();
|
|
|
|
for (uint8_t i = 0; i <= 4; i++) dac_current_percent(i, dac_percent);
|
|
|
|
}
|
2019-02-27 03:03:13 +00:00
|
|
|
LOOP_XYZE(i) if (parser.seenval(axis_codes[i])) dac_current_percent(i, parser.value_float());
|
2017-09-06 11:28:31 +00:00
|
|
|
#endif
|
|
|
|
}
|
2017-09-23 23:09:14 +00:00
|
|
|
|
|
|
|
#if HAS_DIGIPOTSS || ENABLED(DAC_STEPPER_CURRENT)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* M908: Control digital trimpot directly (M908 P<pin> S<current>)
|
|
|
|
*/
|
|
|
|
void GcodeSuite::M908() {
|
|
|
|
#if HAS_DIGIPOTSS
|
2019-06-11 12:41:54 +00:00
|
|
|
stepper.digitalPotWrite(parser.intval('P'), parser.intval('S'));
|
2017-09-23 23:09:14 +00:00
|
|
|
#endif
|
|
|
|
#if ENABLED(DAC_STEPPER_CURRENT)
|
2019-06-11 12:41:54 +00:00
|
|
|
dac_current_raw(parser.byteval('P', -1), parser.ushortval('S', 0));
|
2017-09-23 23:09:14 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // HAS_DIGIPOTSS || DAC_STEPPER_CURRENT
|
|
|
|
|
|
|
|
#if ENABLED(DAC_STEPPER_CURRENT)
|
|
|
|
|
|
|
|
void GcodeSuite::M909() { dac_print_values(); }
|
|
|
|
void GcodeSuite::M910() { dac_commit_eeprom(); }
|
|
|
|
|
|
|
|
#endif // DAC_STEPPER_CURRENT
|
|
|
|
|
|
|
|
#endif // HAS_DIGIPOTSS || DAC_STEPPER_CURRENT || HAS_MOTOR_CURRENT_PWM || DIGIPOT_I2C
|