From a46bac3100124cd3d1782ee98d731baa838733bd Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 14 Mar 2018 07:25:27 -0500 Subject: [PATCH] Add 'I' parameter to M906/M913/M914; 'T' to M906/M913 --- Marlin/src/gcode/feature/trinamic/M906.cpp | 50 +++--- .../src/gcode/feature/trinamic/M911-M915.cpp | 71 ++++---- Marlin/src/module/configuration_store.cpp | 152 ++++++++++++------ 3 files changed, 166 insertions(+), 107 deletions(-) diff --git a/Marlin/src/gcode/feature/trinamic/M906.cpp b/Marlin/src/gcode/feature/trinamic/M906.cpp index 7e33187c36..8ba6453339 100644 --- a/Marlin/src/gcode/feature/trinamic/M906.cpp +++ b/Marlin/src/gcode/feature/trinamic/M906.cpp @@ -37,50 +37,54 @@ void GcodeSuite::M906() { #define TMC_SET_CURRENT(Q) tmc_set_current(stepper##Q, TMC_##Q, value) bool report = true; + const uint8_t index = parser.byteval('I'); LOOP_XYZE(i) if (uint16_t value = parser.intval(axis_codes[i])) { report = false; switch (i) { case X_AXIS: #if X_IS_TRINAMIC - TMC_SET_CURRENT(X); + if (index == 0) TMC_SET_CURRENT(X); #endif #if X2_IS_TRINAMIC - TMC_SET_CURRENT(X2); + if (index == 1) TMC_SET_CURRENT(X2); #endif break; case Y_AXIS: #if Y_IS_TRINAMIC - TMC_SET_CURRENT(Y); + if (index == 0) TMC_SET_CURRENT(Y); #endif #if Y2_IS_TRINAMIC - TMC_SET_CURRENT(Y2); + if (index == 1) TMC_SET_CURRENT(Y2); #endif break; case Z_AXIS: #if Z_IS_TRINAMIC - TMC_SET_CURRENT(Z); + if (index == 0) TMC_SET_CURRENT(Z); #endif #if Z2_IS_TRINAMIC - TMC_SET_CURRENT(Z2); - #endif - break; - case E_AXIS: - #if E0_IS_TRINAMIC - TMC_SET_CURRENT(E0); - #endif - #if E1_IS_TRINAMIC - TMC_SET_CURRENT(E1); - #endif - #if E2_IS_TRINAMIC - TMC_SET_CURRENT(E2); - #endif - #if E3_IS_TRINAMIC - TMC_SET_CURRENT(E3); - #endif - #if E4_IS_TRINAMIC - TMC_SET_CURRENT(E4); + if (index == 1) TMC_SET_CURRENT(Z2); #endif break; + case E_AXIS: { + if (get_target_extruder_from_command()) return; + switch (target_extruder) { + #if E0_IS_TRINAMIC + case 0: TMC_SET_CURRENT(E0); break; + #endif + #if E1_IS_TRINAMIC + case 1: TMC_SET_CURRENT(E1); break; + #endif + #if E2_IS_TRINAMIC + case 2: TMC_SET_CURRENT(E2); break; + #endif + #if E3_IS_TRINAMIC + case 3: TMC_SET_CURRENT(E3); break; + #endif + #if E4_IS_TRINAMIC + case 4: TMC_SET_CURRENT(E4); break; + #endif + } + } break; } } diff --git a/Marlin/src/gcode/feature/trinamic/M911-M915.cpp b/Marlin/src/gcode/feature/trinamic/M911-M915.cpp index 9a48f5caef..fa02aaadff 100644 --- a/Marlin/src/gcode/feature/trinamic/M911-M915.cpp +++ b/Marlin/src/gcode/feature/trinamic/M911-M915.cpp @@ -86,50 +86,54 @@ void GcodeSuite::M912() { #define TMC_SET_PWMTHRS_E(E) do{ const uint8_t extruder = E; tmc_set_pwmthrs(stepperE##E, TMC_E##E, value, planner.axis_steps_per_mm[E_AXIS_N]); }while(0) bool report = true; + const uint8_t index = parser.byteval('I'); LOOP_XYZE(i) if (int32_t value = parser.longval(axis_codes[i])) { report = false; switch (i) { case X_AXIS: #if X_IS_TRINAMIC - TMC_SET_PWMTHRS(X,X); + if (index == 0) TMC_SET_PWMTHRS(X,X); #endif #if X2_IS_TRINAMIC - TMC_SET_PWMTHRS(X,X2); + if (index == 1) TMC_SET_PWMTHRS(X,X2); #endif break; case Y_AXIS: #if Y_IS_TRINAMIC - TMC_SET_PWMTHRS(Y,Y); + if (index == 0) TMC_SET_PWMTHRS(Y,Y); #endif #if Y2_IS_TRINAMIC - TMC_SET_PWMTHRS(Y,Y2); + if (index == 1) TMC_SET_PWMTHRS(Y,Y2); #endif break; case Z_AXIS: #if Z_IS_TRINAMIC - TMC_SET_PWMTHRS(Z,Z); + if (index == 0) TMC_SET_PWMTHRS(Z,Z); #endif #if Z2_IS_TRINAMIC - TMC_SET_PWMTHRS(Z,Z2); - #endif - break; - case E_AXIS: - #if E0_IS_TRINAMIC - TMC_SET_PWMTHRS_E(0); - #endif - #if E1_IS_TRINAMIC - TMC_SET_PWMTHRS_E(1); - #endif - #if E2_IS_TRINAMIC - TMC_SET_PWMTHRS_E(2); - #endif - #if E3_IS_TRINAMIC - TMC_SET_PWMTHRS_E(3); - #endif - #if E4_IS_TRINAMIC - TMC_SET_PWMTHRS_E(4); + if (index == 1) TMC_SET_PWMTHRS(Z,Z2); #endif break; + case E_AXIS: { + if (get_target_extruder_from_command()) return; + switch (target_extruder) { + #if E0_IS_TRINAMIC + case 0: TMC_SET_PWMTHRS_E(0); break; + #endif + #if E_STEPPERS > 1 && E1_IS_TRINAMIC + case 1: TMC_SET_PWMTHRS_E(1); break; + #endif + #if E_STEPPERS > 2 && E2_IS_TRINAMIC + case 2: TMC_SET_PWMTHRS_E(2); break; + #endif + #if E_STEPPERS > 3 && E3_IS_TRINAMIC + case 3: TMC_SET_PWMTHRS_E(3); break; + #endif + #if E_STEPPERS > 4 && E4_IS_TRINAMIC + case 4: TMC_SET_PWMTHRS_E(4); break; + #endif + } + } break; } } @@ -162,16 +166,16 @@ void GcodeSuite::M912() { #if E0_IS_TRINAMIC TMC_SAY_PWMTHRS_E(0); #endif - #if E1_IS_TRINAMIC + #if E_STEPPERS > 1 && E1_IS_TRINAMIC TMC_SAY_PWMTHRS_E(1); #endif - #if E2_IS_TRINAMIC + #if E_STEPPERS > 2 && E2_IS_TRINAMIC TMC_SAY_PWMTHRS_E(2); #endif - #if E3_IS_TRINAMIC + #if E_STEPPERS > 3 && E3_IS_TRINAMIC TMC_SAY_PWMTHRS_E(3); #endif - #if E4_IS_TRINAMIC + #if E_STEPPERS > 4 && E4_IS_TRINAMIC TMC_SAY_PWMTHRS_E(4); #endif break; @@ -188,32 +192,33 @@ void GcodeSuite::M912() { #define TMC_SET_SGT(Q) tmc_set_sgt(stepper##Q, TMC_##Q, value) bool report = true; + const uint8_t index = parser.byteval('I'); LOOP_XYZ(i) if (parser.seen(axis_codes[i])) { const int8_t value = (int8_t)constrain(parser.value_int(), -63, 64); report = false; switch (i) { case X_AXIS: #if ENABLED(X_IS_TMC2130) || ENABLED(IS_TRAMS) - TMC_SET_SGT(X); + if (index == 0) TMC_SET_SGT(X); #endif #if ENABLED(X2_IS_TMC2130) - TMC_SET_SGT(X2); + if (index == 1) TMC_SET_SGT(X2); #endif break; case Y_AXIS: #if ENABLED(Y_IS_TMC2130) || ENABLED(IS_TRAMS) - TMC_SET_SGT(Y); + if (index == 0) TMC_SET_SGT(Y); #endif #if ENABLED(Y2_IS_TMC2130) - TMC_SET_SGT(Y2); + if (index == 1) TMC_SET_SGT(Y2); #endif break; case Z_AXIS: #if ENABLED(Z_IS_TMC2130) || ENABLED(IS_TRAMS) - TMC_SET_SGT(Z); + if (index == 0) TMC_SET_SGT(Z); #endif #if ENABLED(Z2_IS_TMC2130) - TMC_SET_SGT(Z2); + if (index == 1) TMC_SET_SGT(Z2); #endif break; } diff --git a/Marlin/src/module/configuration_store.cpp b/Marlin/src/module/configuration_store.cpp index eb1d9db1d8..f45307106e 100644 --- a/Marlin/src/module/configuration_store.cpp +++ b/Marlin/src/module/configuration_store.cpp @@ -1892,6 +1892,14 @@ void MarlinSettings::reset(PORTARG_SOLO) { #define CONFIG_ECHO_START do{ if (!forReplay) SERIAL_ECHO_START_P(port); }while(0) + #if HAS_TRINAMIC + void say_M906() { SERIAL_ECHOPGM_P(port, " M906 "); } + void say_M913() { SERIAL_ECHOPGM_P(port, " M913 "); } + #if ENABLED(SENSORLESS_HOMING) + void say_M914() { SERIAL_ECHOPGM_P(port, " M914 "); } + #endif + #endif + #if ENABLED(ADVANCED_PAUSE_FEATURE) void say_M603() { SERIAL_ECHOPGM_P(port, " M603 "); } #endif @@ -2373,34 +2381,51 @@ void MarlinSettings::reset(PORTARG_SOLO) { SERIAL_ECHOLNPGM_P(port, "Stepper driver current:"); } CONFIG_ECHO_START; - SERIAL_ECHOPGM_P(port, " M906"); #if X_IS_TRINAMIC - SERIAL_ECHOPAIR_P(port, " X", stepperX.getCurrent()); - #elif X2_IS_TRINAMIC - SERIAL_ECHOPAIR_P(port, " X", stepperX2.getCurrent()); + say_M906(); + SERIAL_ECHOLNPAIR_P(port, "X", stepperX.getCurrent()); + #endif + #if X2_IS_TRINAMIC + say_M906(); + SERIAL_ECHOLNPAIR_P(port, "I1 X", stepperX2.getCurrent()); #endif #if Y_IS_TRINAMIC - SERIAL_ECHOPAIR_P(port, " Y", stepperY.getCurrent()); - #elif Y2_IS_TRINAMIC - SERIAL_ECHOPAIR_P(port, " Y", stepperY2.getCurrent()); + say_M906(); + SERIAL_ECHOLNPAIR_P(port, "Y", stepperY.getCurrent()); + #endif + #if Y2_IS_TRINAMIC + say_M906(); + SERIAL_ECHOLNPAIR_P(port, "I1 Y", stepperY2.getCurrent()); #endif #if Z_IS_TRINAMIC - SERIAL_ECHOPAIR_P(port, " Z", stepperZ.getCurrent()); - #elif Z2_IS_TRINAMIC - SERIAL_ECHOPAIR_P(port, " Z", stepperZ2.getCurrent()); + say_M906(); + SERIAL_ECHOLNPAIR_P(port, "Z", stepperZ.getCurrent()); + #endif + #if Z2_IS_TRINAMIC + say_M906(); + SERIAL_ECHOLNPAIR_P(port, "I1 Z", stepperZ2.getCurrent()); #endif #if E0_IS_TRINAMIC - SERIAL_ECHOPAIR_P(port, " E", stepperE0.getCurrent()); - #elif E1_IS_TRINAMIC - SERIAL_ECHOPAIR_P(port, " E", stepperE1.getCurrent()); - #elif E2_IS_TRINAMIC - SERIAL_ECHOPAIR_P(port, " E", stepperE2.getCurrent()); - #elif E3_IS_TRINAMIC - SERIAL_ECHOPAIR_P(port, " E", stepperE3.getCurrent()); - #elif E4_IS_TRINAMIC - SERIAL_ECHOPAIR_P(port, " E", stepperE4.getCurrent()); + say_M906(); + SERIAL_ECHOLNPAIR_P(port, "T0 E", stepperE0.getCurrent()); #endif - SERIAL_EOL(); + #if E_STEPPERS > 1 && E1_IS_TRINAMIC + say_M906(); + SERIAL_ECHOLNPAIR_P(port, "T1 E", stepperE1.getCurrent()); + #endif + #if E_STEPPERS > 2 && E2_IS_TRINAMIC + say_M906(); + SERIAL_ECHOLNPAIR_P(port, "T2 E", stepperE2.getCurrent()); + #endif + #if E_STEPPERS > 3 && E3_IS_TRINAMIC + say_M906(); + SERIAL_ECHOLNPAIR_P(port, "T3 E", stepperE3.getCurrent()); + #endif + #if E_STEPPERS > 4 && E4_IS_TRINAMIC + say_M906(); + SERIAL_ECHOLNPAIR_P(port, "T4 E", stepperE4.getCurrent()); + #endif + SERIAL_EOL_P(port); /** * TMC2130 / TMC2208 / TRAMS Hybrid Threshold @@ -2410,34 +2435,51 @@ void MarlinSettings::reset(PORTARG_SOLO) { SERIAL_ECHOLNPGM_P(port, "Hybrid Threshold:"); } CONFIG_ECHO_START; - SERIAL_ECHOPGM_P(port, " M913"); #if X_IS_TRINAMIC - SERIAL_ECHOPAIR_P(port, " X", TMC_GET_PWMTHRS(X, X)); - #elif X2_IS_TRINAMIC - SERIAL_ECHOPAIR_P(port, " X", TMC_GET_PWMTHRS(X, X2)); + say_M913(); + SERIAL_ECHOLNPAIR_P(port, "X", TMC_GET_PWMTHRS(X, X)); + #endif + #if X2_IS_TRINAMIC + say_M913(); + SERIAL_ECHOLNPAIR_P(port, "I1 X", TMC_GET_PWMTHRS(X, X2)); #endif #if Y_IS_TRINAMIC - SERIAL_ECHOPAIR_P(port, " Y", TMC_GET_PWMTHRS(Y, Y)); - #elif Y2_IS_TRINAMIC - SERIAL_ECHOPAIR_P(port, " Y", TMC_GET_PWMTHRS(Y, Y2)); + say_M913(); + SERIAL_ECHOLNPAIR_P(port, "Y", TMC_GET_PWMTHRS(Y, Y)); + #endif + #if Y2_IS_TRINAMIC + say_M913(); + SERIAL_ECHOLNPAIR_P(port, "I1 Y", TMC_GET_PWMTHRS(Y, Y2)); #endif #if Z_IS_TRINAMIC - SERIAL_ECHOPAIR_P(port, " Z", TMC_GET_PWMTHRS(Z, Z)); - #elif Z2_IS_TRINAMIC - SERIAL_ECHOPAIR_P(port, " Z", TMC_GET_PWMTHRS(Z, Z2)); + say_M913(); + SERIAL_ECHOLNPAIR_P(port, "Z", TMC_GET_PWMTHRS(Z, Z)); + #endif + #if Z2_IS_TRINAMIC + say_M913(); + SERIAL_ECHOLNPAIR_P(port, "I1 Z", TMC_GET_PWMTHRS(Z, Z2)); #endif #if E0_IS_TRINAMIC - SERIAL_ECHOPAIR_P(port, " E", TMC_GET_PWMTHRS(E, E0)); - #elif E1_IS_TRINAMIC - SERIAL_ECHOPAIR_P(port, " E", TMC_GET_PWMTHRS(E, E1)); - #elif E2_IS_TRINAMIC - SERIAL_ECHOPAIR_P(port, " E", TMC_GET_PWMTHRS(E, E2)); - #elif E3_IS_TRINAMIC - SERIAL_ECHOPAIR_P(port, " E", TMC_GET_PWMTHRS(E, E3)); - #elif E4_IS_TRINAMIC - SERIAL_ECHOPAIR_P(port, " E", TMC_GET_PWMTHRS(E, E4)); + say_M913(); + SERIAL_ECHOLNPAIR_P(port, "T0 E", TMC_GET_PWMTHRS(E, E0)); #endif - SERIAL_EOL(); + #if E_STEPPERS > 1 && E1_IS_TRINAMIC + say_M913(); + SERIAL_ECHOLNPAIR_P(port, "T1 E", TMC_GET_PWMTHRS(E, E1)); + #endif + #if E_STEPPERS > 2 && E2_IS_TRINAMIC + say_M913(); + SERIAL_ECHOLNPAIR_P(port, "T2 E", TMC_GET_PWMTHRS(E, E2)); + #endif + #if E_STEPPERS > 3 && E3_IS_TRINAMIC + say_M913(); + SERIAL_ECHOLNPAIR_P(port, "T3 E", TMC_GET_PWMTHRS(E, E3)); + #endif + #if E_STEPPERS > 4 && E4_IS_TRINAMIC + say_M913(); + SERIAL_ECHOLNPAIR_P(port, "T4 E", TMC_GET_PWMTHRS(E, E4)); + #endif + SERIAL_EOL_P(port); /** * TMC2130 Sensorless homing thresholds @@ -2448,29 +2490,37 @@ void MarlinSettings::reset(PORTARG_SOLO) { SERIAL_ECHOLNPGM_P(port, "Sensorless homing threshold:"); } CONFIG_ECHO_START; - SERIAL_ECHOPGM_P(port, " M914"); #ifdef X_HOMING_SENSITIVITY #if ENABLED(X_IS_TMC2130) || ENABLED(IS_TRAMS) - SERIAL_ECHOPAIR_P(port, " X", stepperX.sgt()); - #elif ENABLED(X2_IS_TMC2130) - SERIAL_ECHOPAIR_P(port, " X", stepperX2.sgt()); + say_M914(); + SERIAL_ECHOLNPAIR_P(port, "X", stepperX.sgt()); + #endif + #if ENABLED(X2_IS_TMC2130) + say_M914(); + SERIAL_ECHOLNPAIR_P(port, "I1 X", stepperX2.sgt()); #endif #endif #ifdef Y_HOMING_SENSITIVITY #if ENABLED(Y_IS_TMC2130) || ENABLED(IS_TRAMS) - SERIAL_ECHOPAIR_P(port, " Y", stepperY.sgt()); - #elif ENABLED(Y2_IS_TMC2130) - SERIAL_ECHOPAIR_P(port, " Y", stepperY2.sgt()); + say_M914(); + SERIAL_ECHOLNPAIR_P(port, "Y", stepperY.sgt()); + #endif + #if ENABLED(Y2_IS_TMC2130) + say_M914(); + SERIAL_ECHOLNPAIR_P(port, "I1 Y", stepperY2.sgt()); #endif #endif #ifdef Z_HOMING_SENSITIVITY #if ENABLED(Z_IS_TMC2130) || ENABLED(IS_TRAMS) - SERIAL_ECHOPAIR_P(port, " Z", stepperZ.sgt()); - #elif ENABLED(Z2_IS_TMC2130) - SERIAL_ECHOPAIR_P(port, " Z", stepperZ2.sgt()); + say_M914(); + SERIAL_ECHOLNPAIR_P(port, "Z", stepperZ.sgt()); + #endif + #if ENABLED(Z2_IS_TMC2130) + say_M914(); + SERIAL_ECHOLNPAIR_P(port, "I1 Z", stepperZ2.sgt()); #endif #endif - SERIAL_EOL(); + SERIAL_EOL_P(port); #endif #endif // HAS_TRINAMIC