🚸 Refine stepper-driver-related G-codes (#23372)

This commit is contained in:
Scott Lahteine
2021-12-28 05:43:10 -06:00
committed by Scott Lahteine
parent 56adbc3ebf
commit 99c237e05e
8 changed files with 171 additions and 180 deletions

View File

@@ -28,6 +28,12 @@
#include "../../../feature/tmc_util.h"
#include "../../../module/stepper/indirection.h"
template<typename TMC>
static void tmc_print_current(TMC &st) {
st.printLabel();
SERIAL_ECHOLNPGM(" driver current: ", st.getMilliamps());
}
/**
* M906: Set motor current in milliamps.
*
@@ -48,8 +54,10 @@ void GcodeSuite::M906() {
bool report = true;
#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) || AXIS_IS_TMC(Z4) || AXIS_IS_TMC(I) || AXIS_IS_TMC(J) || AXIS_IS_TMC(K)
const uint8_t index = parser.byteval('I');
#if AXIS_IS_TMC(X2) || AXIS_IS_TMC(Y2) || AXIS_IS_TMC(Z2) || AXIS_IS_TMC(Z3) || AXIS_IS_TMC(Z4)
const int8_t index = parser.byteval('I', -1);
#else
constexpr int8_t index = -1;
#endif
LOOP_LOGICAL_AXES(i) if (uint16_t value = parser.intval(axis_codes[i])) {
@@ -57,20 +65,20 @@ void GcodeSuite::M906() {
switch (i) {
case X_AXIS:
#if AXIS_IS_TMC(X)
if (index == 0) TMC_SET_CURRENT(X);
if (index < 0 || index == 0) TMC_SET_CURRENT(X);
#endif
#if AXIS_IS_TMC(X2)
if (index == 1) TMC_SET_CURRENT(X2);
if (index < 0 || index == 1) TMC_SET_CURRENT(X2);
#endif
break;
#if HAS_Y_AXIS
case Y_AXIS:
#if AXIS_IS_TMC(Y)
if (index == 0) TMC_SET_CURRENT(Y);
if (index < 0 || index == 0) TMC_SET_CURRENT(Y);
#endif
#if AXIS_IS_TMC(Y2)
if (index == 1) TMC_SET_CURRENT(Y2);
if (index < 0 || index == 1) TMC_SET_CURRENT(Y2);
#endif
break;
#endif
@@ -78,16 +86,16 @@ void GcodeSuite::M906() {
#if HAS_Z_AXIS
case Z_AXIS:
#if AXIS_IS_TMC(Z)
if (index == 0) TMC_SET_CURRENT(Z);
if (index < 0 || index == 0) TMC_SET_CURRENT(Z);
#endif
#if AXIS_IS_TMC(Z2)
if (index == 1) TMC_SET_CURRENT(Z2);
if (index < 0 || index == 1) TMC_SET_CURRENT(Z2);
#endif
#if AXIS_IS_TMC(Z3)
if (index == 2) TMC_SET_CURRENT(Z3);
if (index < 0 || index == 2) TMC_SET_CURRENT(Z3);
#endif
#if AXIS_IS_TMC(Z4)
if (index == 3) TMC_SET_CURRENT(Z4);
if (index < 0 || index == 3) TMC_SET_CURRENT(Z4);
#endif
break;
#endif
@@ -104,34 +112,31 @@ void GcodeSuite::M906() {
#if E_STEPPERS
case E_AXIS: {
const int8_t target_e_stepper = get_target_e_stepper_from_command(0);
if (target_e_stepper < 0) return;
switch (target_e_stepper) {
#if AXIS_IS_TMC(E0)
case 0: TMC_SET_CURRENT(E0); break;
#endif
#if AXIS_IS_TMC(E1)
case 1: TMC_SET_CURRENT(E1); break;
#endif
#if AXIS_IS_TMC(E2)
case 2: TMC_SET_CURRENT(E2); break;
#endif
#if AXIS_IS_TMC(E3)
case 3: TMC_SET_CURRENT(E3); break;
#endif
#if AXIS_IS_TMC(E4)
case 4: TMC_SET_CURRENT(E4); break;
#endif
#if AXIS_IS_TMC(E5)
case 5: TMC_SET_CURRENT(E5); break;
#endif
#if AXIS_IS_TMC(E6)
case 6: TMC_SET_CURRENT(E6); break;
#endif
#if AXIS_IS_TMC(E7)
case 7: TMC_SET_CURRENT(E7); break;
#endif
}
const int8_t eindex = get_target_e_stepper_from_command(-2);
#if AXIS_IS_TMC(E0)
if (eindex < 0 || eindex == 0) TMC_SET_CURRENT(E0);
#endif
#if AXIS_IS_TMC(E1)
if (eindex < 0 || eindex == 1) TMC_SET_CURRENT(E1);
#endif
#if AXIS_IS_TMC(E2)
if (eindex < 0 || eindex == 2) TMC_SET_CURRENT(E2);
#endif
#if AXIS_IS_TMC(E3)
if (eindex < 0 || eindex == 3) TMC_SET_CURRENT(E3);
#endif
#if AXIS_IS_TMC(E4)
if (eindex < 0 || eindex == 4) TMC_SET_CURRENT(E4);
#endif
#if AXIS_IS_TMC(E5)
if (eindex < 0 || eindex == 5) TMC_SET_CURRENT(E5);
#endif
#if AXIS_IS_TMC(E6)
if (eindex < 0 || eindex == 6) TMC_SET_CURRENT(E6);
#endif
#if AXIS_IS_TMC(E7)
if (eindex < 0 || eindex == 7) TMC_SET_CURRENT(E7);
#endif
} break;
#endif
}