2017-09-06 06:28:31 -05:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2019-02-12 15:06:53 -06:00
|
|
|
* Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2017-09-06 06:28:31 -05: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-17 18:34:04 -05:00
|
|
|
#include "../../../inc/MarlinConfig.h"
|
|
|
|
|
2017-12-15 15:03:14 -06:00
|
|
|
#if HAS_TRINAMIC
|
2017-09-17 18:34:04 -05:00
|
|
|
|
|
|
|
#include "../../gcode.h"
|
2017-12-15 15:03:14 -06:00
|
|
|
#include "../../../feature/tmc_util.h"
|
2017-09-17 18:34:04 -05:00
|
|
|
#include "../../../module/stepper_indirection.h"
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
/**
|
2019-04-22 13:44:57 -05:00
|
|
|
* M906: Set motor current in milliamps.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* X[current] - Set mA current for X driver(s)
|
|
|
|
* Y[current] - Set mA current for Y driver(s)
|
|
|
|
* Z[current] - Set mA current for Z driver(s)
|
|
|
|
* E[current] - Set mA current for E driver(s)
|
|
|
|
*
|
|
|
|
* I[index] - Axis sub-index (Omit or 0 for X, Y, Z; 1 for X2, Y2, Z2; 2 for Z3.)
|
|
|
|
* T[index] - Extruder index (Zero-based. Omit for E0 only.)
|
|
|
|
*
|
|
|
|
* With no parameters report driver currents.
|
2017-09-06 06:28:31 -05:00
|
|
|
*/
|
2017-12-29 13:38:08 -06:00
|
|
|
void GcodeSuite::M906() {
|
2018-10-03 02:48:49 -05:00
|
|
|
#define TMC_SAY_CURRENT(Q) tmc_get_current(stepper##Q)
|
2018-05-10 00:05:15 -05:00
|
|
|
#define TMC_SET_CURRENT(Q) tmc_set_current(stepper##Q, value)
|
2018-01-09 19:14:07 -06:00
|
|
|
|
2018-03-14 05:43:18 -05:00
|
|
|
bool report = true;
|
2018-11-01 16:13:33 -05:00
|
|
|
|
|
|
|
#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)
|
2018-11-02 22:29:32 -05:00
|
|
|
const uint8_t index = parser.byteval('I');
|
2018-11-01 16:13:33 -05:00
|
|
|
#endif
|
|
|
|
|
2018-03-14 05:43:18 -05:00
|
|
|
LOOP_XYZE(i) if (uint16_t value = parser.intval(axis_codes[i])) {
|
|
|
|
report = false;
|
|
|
|
switch (i) {
|
|
|
|
case X_AXIS:
|
2018-07-14 06:13:06 -05:00
|
|
|
#if AXIS_IS_TMC(X)
|
2018-03-14 07:25:27 -05:00
|
|
|
if (index == 0) TMC_SET_CURRENT(X);
|
2018-03-14 05:43:18 -05:00
|
|
|
#endif
|
2018-07-14 06:13:06 -05:00
|
|
|
#if AXIS_IS_TMC(X2)
|
2018-03-14 07:25:27 -05:00
|
|
|
if (index == 1) TMC_SET_CURRENT(X2);
|
2018-03-14 05:43:18 -05:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case Y_AXIS:
|
2018-07-14 06:13:06 -05:00
|
|
|
#if AXIS_IS_TMC(Y)
|
2018-03-14 07:25:27 -05:00
|
|
|
if (index == 0) TMC_SET_CURRENT(Y);
|
2018-03-14 05:43:18 -05:00
|
|
|
#endif
|
2018-07-14 06:13:06 -05:00
|
|
|
#if AXIS_IS_TMC(Y2)
|
2018-03-14 07:25:27 -05:00
|
|
|
if (index == 1) TMC_SET_CURRENT(Y2);
|
2018-03-14 05:43:18 -05:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case Z_AXIS:
|
2018-07-14 06:13:06 -05:00
|
|
|
#if AXIS_IS_TMC(Z)
|
2018-03-14 07:25:27 -05:00
|
|
|
if (index == 0) TMC_SET_CURRENT(Z);
|
2018-03-14 05:43:18 -05:00
|
|
|
#endif
|
2018-07-14 06:13:06 -05:00
|
|
|
#if AXIS_IS_TMC(Z2)
|
2018-03-14 07:25:27 -05:00
|
|
|
if (index == 1) TMC_SET_CURRENT(Z2);
|
2018-03-14 05:43:18 -05:00
|
|
|
#endif
|
2018-06-19 11:55:49 -05:00
|
|
|
#if AXIS_IS_TMC(Z3)
|
|
|
|
if (index == 2) TMC_SET_CURRENT(Z3);
|
|
|
|
#endif
|
2018-03-14 05:43:18 -05:00
|
|
|
break;
|
2018-03-14 07:25:27 -05:00
|
|
|
case E_AXIS: {
|
2018-11-14 17:33:04 -06:00
|
|
|
const int8_t target_extruder = get_target_extruder_from_command();
|
|
|
|
if (target_extruder < 0) return;
|
2018-03-14 07:25:27 -05:00
|
|
|
switch (target_extruder) {
|
2018-07-14 06:13:06 -05:00
|
|
|
#if AXIS_IS_TMC(E0)
|
2018-03-14 07:25:27 -05:00
|
|
|
case 0: TMC_SET_CURRENT(E0); break;
|
|
|
|
#endif
|
2018-07-14 06:13:06 -05:00
|
|
|
#if AXIS_IS_TMC(E1)
|
2018-03-14 07:25:27 -05:00
|
|
|
case 1: TMC_SET_CURRENT(E1); break;
|
|
|
|
#endif
|
2018-07-14 06:13:06 -05:00
|
|
|
#if AXIS_IS_TMC(E2)
|
2018-03-14 07:25:27 -05:00
|
|
|
case 2: TMC_SET_CURRENT(E2); break;
|
|
|
|
#endif
|
2018-07-14 06:13:06 -05:00
|
|
|
#if AXIS_IS_TMC(E3)
|
2018-03-14 07:25:27 -05:00
|
|
|
case 3: TMC_SET_CURRENT(E3); break;
|
|
|
|
#endif
|
2018-07-14 06:13:06 -05:00
|
|
|
#if AXIS_IS_TMC(E4)
|
2018-03-14 07:25:27 -05:00
|
|
|
case 4: TMC_SET_CURRENT(E4); break;
|
|
|
|
#endif
|
2018-09-13 01:35:55 -05:00
|
|
|
#if AXIS_IS_TMC(E5)
|
|
|
|
case 5: TMC_SET_CURRENT(E5); break;
|
|
|
|
#endif
|
2018-03-14 07:25:27 -05:00
|
|
|
}
|
|
|
|
} break;
|
2018-03-14 05:43:18 -05:00
|
|
|
}
|
|
|
|
}
|
2017-09-06 06:28:31 -05:00
|
|
|
|
2018-07-12 22:31:51 -05:00
|
|
|
if (report) {
|
2018-07-14 06:13:06 -05:00
|
|
|
#if AXIS_IS_TMC(X)
|
2018-07-12 22:31:51 -05:00
|
|
|
TMC_SAY_CURRENT(X);
|
|
|
|
#endif
|
2018-07-14 06:13:06 -05:00
|
|
|
#if AXIS_IS_TMC(X2)
|
2018-07-12 22:31:51 -05:00
|
|
|
TMC_SAY_CURRENT(X2);
|
|
|
|
#endif
|
2018-07-14 06:13:06 -05:00
|
|
|
#if AXIS_IS_TMC(Y)
|
2018-07-12 22:31:51 -05:00
|
|
|
TMC_SAY_CURRENT(Y);
|
|
|
|
#endif
|
2018-07-14 06:13:06 -05:00
|
|
|
#if AXIS_IS_TMC(Y2)
|
2018-07-12 22:31:51 -05:00
|
|
|
TMC_SAY_CURRENT(Y2);
|
|
|
|
#endif
|
2018-07-14 06:13:06 -05:00
|
|
|
#if AXIS_IS_TMC(Z)
|
2018-07-12 22:31:51 -05:00
|
|
|
TMC_SAY_CURRENT(Z);
|
|
|
|
#endif
|
2018-07-14 06:13:06 -05:00
|
|
|
#if AXIS_IS_TMC(Z2)
|
2018-07-12 22:31:51 -05:00
|
|
|
TMC_SAY_CURRENT(Z2);
|
|
|
|
#endif
|
2018-06-19 11:55:49 -05:00
|
|
|
#if AXIS_IS_TMC(Z3)
|
|
|
|
TMC_SAY_CURRENT(Z3);
|
|
|
|
#endif
|
2018-07-14 06:13:06 -05:00
|
|
|
#if AXIS_IS_TMC(E0)
|
2018-07-12 22:31:51 -05:00
|
|
|
TMC_SAY_CURRENT(E0);
|
|
|
|
#endif
|
2018-07-14 06:13:06 -05:00
|
|
|
#if AXIS_IS_TMC(E1)
|
2018-07-12 22:31:51 -05:00
|
|
|
TMC_SAY_CURRENT(E1);
|
|
|
|
#endif
|
2018-07-14 06:13:06 -05:00
|
|
|
#if AXIS_IS_TMC(E2)
|
2018-07-12 22:31:51 -05:00
|
|
|
TMC_SAY_CURRENT(E2);
|
|
|
|
#endif
|
2018-07-14 06:13:06 -05:00
|
|
|
#if AXIS_IS_TMC(E3)
|
2018-07-12 22:31:51 -05:00
|
|
|
TMC_SAY_CURRENT(E3);
|
|
|
|
#endif
|
2018-07-14 06:13:06 -05:00
|
|
|
#if AXIS_IS_TMC(E4)
|
2018-07-12 22:31:51 -05:00
|
|
|
TMC_SAY_CURRENT(E4);
|
|
|
|
#endif
|
2018-09-13 01:35:55 -05:00
|
|
|
#if AXIS_IS_TMC(E5)
|
|
|
|
TMC_SAY_CURRENT(E5);
|
|
|
|
#endif
|
2018-03-14 05:43:18 -05:00
|
|
|
}
|
2017-09-06 06:28:31 -05:00
|
|
|
}
|
2017-09-17 18:34:04 -05:00
|
|
|
|
2017-12-15 15:03:14 -06:00
|
|
|
#endif // HAS_TRINAMIC
|