From cfc13ed7f3fd20d2d07d64602e39e732a1cb982a Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 14 Mar 2018 05:43:18 -0500 Subject: [PATCH] Quiet M906/M913/M914 with axes. Patch for DISTINCT_E_FACTORS. --- Marlin/src/feature/tmc_util.cpp | 1 + Marlin/src/feature/tmc_util.h | 3 - Marlin/src/gcode/feature/trinamic/M906.cpp | 130 ++++++++--- .../src/gcode/feature/trinamic/M911-M915.cpp | 219 ++++++++++++------ 4 files changed, 247 insertions(+), 106 deletions(-) diff --git a/Marlin/src/feature/tmc_util.cpp b/Marlin/src/feature/tmc_util.cpp index 8364fa8690..d2a4ca55d0 100644 --- a/Marlin/src/feature/tmc_util.cpp +++ b/Marlin/src/feature/tmc_util.cpp @@ -331,6 +331,7 @@ void _tmc_say_sgt(const TMC_AxisEnum axis, const int8_t sgt) { } } #endif + #if ENABLED(HAVE_TMC2208) static void tmc_status(TMC2208Stepper &st, const TMC_debug_enum i) { switch (i) { diff --git a/Marlin/src/feature/tmc_util.h b/Marlin/src/feature/tmc_util.h index 544eaa07a4..5ddbad2329 100644 --- a/Marlin/src/feature/tmc_util.h +++ b/Marlin/src/feature/tmc_util.h @@ -55,7 +55,6 @@ void tmc_get_current(TMC &st, const TMC_AxisEnum axis) { template void tmc_set_current(TMC &st, const TMC_AxisEnum axis, const int mA) { st.setCurrent(mA, R_SENSE, HOLD_MULTIPLIER); - tmc_get_current(st, axis); } template void tmc_report_otpw(TMC &st, const TMC_AxisEnum axis) { @@ -73,7 +72,6 @@ void tmc_get_pwmthrs(TMC &st, const TMC_AxisEnum axis, const uint16_t spmm) { template void tmc_set_pwmthrs(TMC &st, const TMC_AxisEnum axis, const int32_t thrs, const uint32_t spmm) { st.TPWMTHRS(_tmc_thrs(st.microsteps(), thrs, spmm)); - tmc_get_pwmthrs(st, axis, spmm); } template void tmc_get_sgt(TMC &st, const TMC_AxisEnum axis) { @@ -82,7 +80,6 @@ void tmc_get_sgt(TMC &st, const TMC_AxisEnum axis) { template void tmc_set_sgt(TMC &st, const TMC_AxisEnum axis, const int8_t sgt_val) { st.sgt(sgt_val); - tmc_get_sgt(st, axis); } void monitor_tmc_driver(); diff --git a/Marlin/src/gcode/feature/trinamic/M906.cpp b/Marlin/src/gcode/feature/trinamic/M906.cpp index 2de386813d..7e33187c36 100644 --- a/Marlin/src/gcode/feature/trinamic/M906.cpp +++ b/Marlin/src/gcode/feature/trinamic/M906.cpp @@ -33,46 +33,100 @@ * Report driver currents when no axis specified */ void GcodeSuite::M906() { - uint16_t values[XYZE]; - LOOP_XYZE(i) values[i] = parser.intval(axis_codes[i]); + #define TMC_SAY_CURRENT(Q) tmc_get_current(stepper##Q, TMC_##Q) + #define TMC_SET_CURRENT(Q) tmc_set_current(stepper##Q, TMC_##Q, value) - #define TMC_SET_GET_CURRENT(P,Q) do { \ - if (values[P##_AXIS]) tmc_set_current(stepper##Q, TMC_##Q, values[P##_AXIS]); \ - else tmc_get_current(stepper##Q, TMC_##Q); } while(0) + bool report = true; + 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); + #endif + #if X2_IS_TRINAMIC + TMC_SET_CURRENT(X2); + #endif + break; + case Y_AXIS: + #if Y_IS_TRINAMIC + TMC_SET_CURRENT(Y); + #endif + #if Y2_IS_TRINAMIC + TMC_SET_CURRENT(Y2); + #endif + break; + case Z_AXIS: + #if Z_IS_TRINAMIC + 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); + #endif + break; + } + } - #if X_IS_TRINAMIC - TMC_SET_GET_CURRENT(X,X); - #endif - #if X2_IS_TRINAMIC - TMC_SET_GET_CURRENT(X,X2); - #endif - #if Y_IS_TRINAMIC - TMC_SET_GET_CURRENT(Y,Y); - #endif - #if Y2_IS_TRINAMIC - TMC_SET_GET_CURRENT(Y,Y2); - #endif - #if Z_IS_TRINAMIC - TMC_SET_GET_CURRENT(Z,Z); - #endif - #if Z2_IS_TRINAMIC - TMC_SET_GET_CURRENT(Z,Z2); - #endif - #if E0_IS_TRINAMIC - TMC_SET_GET_CURRENT(E,E0); - #endif - #if E1_IS_TRINAMIC - TMC_SET_GET_CURRENT(E,E1); - #endif - #if E2_IS_TRINAMIC - TMC_SET_GET_CURRENT(E,E2); - #endif - #if E3_IS_TRINAMIC - TMC_SET_GET_CURRENT(E,E3); - #endif - #if E4_IS_TRINAMIC - TMC_SET_GET_CURRENT(E,E4); - #endif + if (report) LOOP_XYZE(i) switch (i) { + case X_AXIS: + #if X_IS_TRINAMIC + TMC_SAY_CURRENT(X); + #endif + #if X2_IS_TRINAMIC + TMC_SAY_CURRENT(X2); + #endif + break; + case Y_AXIS: + #if Y_IS_TRINAMIC + TMC_SAY_CURRENT(Y); + #endif + #if Y2_IS_TRINAMIC + TMC_SAY_CURRENT(Y2); + #endif + break; + case Z_AXIS: + #if Z_IS_TRINAMIC + TMC_SAY_CURRENT(Z); + #endif + #if Z2_IS_TRINAMIC + TMC_SAY_CURRENT(Z2); + #endif + break; + case E_AXIS: + #if E0_IS_TRINAMIC + TMC_SAY_CURRENT(E0); + #endif + #if E1_IS_TRINAMIC + TMC_SAY_CURRENT(E1); + #endif + #if E2_IS_TRINAMIC + TMC_SAY_CURRENT(E2); + #endif + #if E3_IS_TRINAMIC + TMC_SAY_CURRENT(E3); + #endif + #if E4_IS_TRINAMIC + TMC_SAY_CURRENT(E4); + #endif + break; + } } #endif // HAS_TRINAMIC diff --git a/Marlin/src/gcode/feature/trinamic/M911-M915.cpp b/Marlin/src/gcode/feature/trinamic/M911-M915.cpp index 1efc3c220e..9a48f5caef 100644 --- a/Marlin/src/gcode/feature/trinamic/M911-M915.cpp +++ b/Marlin/src/gcode/feature/trinamic/M911-M915.cpp @@ -80,46 +80,102 @@ void GcodeSuite::M912() { */ #if ENABLED(HYBRID_THRESHOLD) void GcodeSuite::M913() { - uint16_t values[XYZE]; - LOOP_XYZE(i) values[i] = parser.intval(axis_codes[i]); + #define TMC_SAY_PWMTHRS(P,Q) tmc_get_pwmthrs(stepper##Q, TMC_##Q, planner.axis_steps_per_mm[P##_AXIS]) + #define TMC_SET_PWMTHRS(P,Q) tmc_set_pwmthrs(stepper##Q, TMC_##Q, value, planner.axis_steps_per_mm[P##_AXIS]) + #define TMC_SAY_PWMTHRS_E(E) do{ const uint8_t extruder = E; tmc_get_pwmthrs(stepperE##E, TMC_E##E, planner.axis_steps_per_mm[E_AXIS_N]); }while(0) + #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) - #define TMC_SET_GET_PWMTHRS(P,Q) do { \ - if (values[P##_AXIS]) tmc_set_pwmthrs(stepper##Q, TMC_##Q, values[P##_AXIS], planner.axis_steps_per_mm[P##_AXIS]); \ - else tmc_get_pwmthrs(stepper##Q, TMC_##Q, planner.axis_steps_per_mm[P##_AXIS]); } while(0) + bool report = true; + 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); + #endif + #if X2_IS_TRINAMIC + TMC_SET_PWMTHRS(X,X2); + #endif + break; + case Y_AXIS: + #if Y_IS_TRINAMIC + TMC_SET_PWMTHRS(Y,Y); + #endif + #if Y2_IS_TRINAMIC + TMC_SET_PWMTHRS(Y,Y2); + #endif + break; + case Z_AXIS: + #if Z_IS_TRINAMIC + 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); + #endif + break; + } + } - #if X_IS_TRINAMIC - TMC_SET_GET_PWMTHRS(X,X); - #endif - #if X2_IS_TRINAMIC - TMC_SET_GET_PWMTHRS(X,X2); - #endif - #if Y_IS_TRINAMIC - TMC_SET_GET_PWMTHRS(Y,Y); - #endif - #if Y2_IS_TRINAMIC - TMC_SET_GET_PWMTHRS(Y,Y2); - #endif - #if Z_IS_TRINAMIC - TMC_SET_GET_PWMTHRS(Z,Z); - #endif - #if Z2_IS_TRINAMIC - TMC_SET_GET_PWMTHRS(Z,Z2); - #endif - #if E0_IS_TRINAMIC - TMC_SET_GET_PWMTHRS(E,E0); - #endif - #if E1_IS_TRINAMIC - TMC_SET_GET_PWMTHRS(E,E1); - #endif - #if E2_IS_TRINAMIC - TMC_SET_GET_PWMTHRS(E,E2); - #endif - #if E3_IS_TRINAMIC - TMC_SET_GET_PWMTHRS(E,E3); - #endif - #if E4_IS_TRINAMIC - TMC_SET_GET_PWMTHRS(E,E4); - #endif + if (report) LOOP_XYZE(i) switch (i) { + case X_AXIS: + #if X_IS_TRINAMIC + TMC_SAY_PWMTHRS(X,X); + #endif + #if X2_IS_TRINAMIC + TMC_SAY_PWMTHRS(X,X2); + #endif + break; + case Y_AXIS: + #if Y_IS_TRINAMIC + TMC_SAY_PWMTHRS(Y,Y); + #endif + #if Y2_IS_TRINAMIC + TMC_SAY_PWMTHRS(Y,Y2); + #endif + break; + case Z_AXIS: + #if Z_IS_TRINAMIC + TMC_SAY_PWMTHRS(Z,Z); + #endif + #if Z2_IS_TRINAMIC + TMC_SAY_PWMTHRS(Z,Z2); + #endif + break; + case E_AXIS: + #if E0_IS_TRINAMIC + TMC_SAY_PWMTHRS_E(0); + #endif + #if E1_IS_TRINAMIC + TMC_SAY_PWMTHRS_E(1); + #endif + #if E2_IS_TRINAMIC + TMC_SAY_PWMTHRS_E(2); + #endif + #if E3_IS_TRINAMIC + TMC_SAY_PWMTHRS_E(3); + #endif + #if E4_IS_TRINAMIC + TMC_SAY_PWMTHRS_E(4); + #endif + break; + } } #endif // HYBRID_THRESHOLD @@ -128,34 +184,67 @@ void GcodeSuite::M912() { */ #if ENABLED(SENSORLESS_HOMING) void GcodeSuite::M914() { - #define TMC_SET_GET_SGT(P,Q) do { \ - if (parser.seen(axis_codes[P##_AXIS])) tmc_set_sgt(stepper##Q, TMC_##Q, parser.value_int()); \ - else tmc_get_sgt(stepper##Q, TMC_##Q); } while(0) + #define TMC_SAY_SGT(Q) tmc_get_sgt(stepper##Q, TMC_##Q) + #define TMC_SET_SGT(Q) tmc_set_sgt(stepper##Q, TMC_##Q, value) - #ifdef X_HOMING_SENSITIVITY - #if ENABLED(X_IS_TMC2130) || ENABLED(IS_TRAMS) - TMC_SET_GET_SGT(X,X); - #endif - #if ENABLED(X2_IS_TMC2130) - TMC_SET_GET_SGT(X,X2); - #endif - #endif - #ifdef Y_HOMING_SENSITIVITY - #if ENABLED(Y_IS_TMC2130) || ENABLED(IS_TRAMS) - TMC_SET_GET_SGT(Y,Y); - #endif - #if ENABLED(Y2_IS_TMC2130) - TMC_SET_GET_SGT(Y,Y2); - #endif - #endif - #ifdef Z_HOMING_SENSITIVITY - #if ENABLED(Z_IS_TMC2130) || ENABLED(IS_TRAMS) - TMC_SET_GET_SGT(Z,Z); - #endif - #if ENABLED(Z2_IS_TMC2130) - TMC_SET_GET_SGT(Z,Z2); - #endif - #endif + bool report = true; + 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); + #endif + #if ENABLED(X2_IS_TMC2130) + TMC_SET_SGT(X2); + #endif + break; + case Y_AXIS: + #if ENABLED(Y_IS_TMC2130) || ENABLED(IS_TRAMS) + TMC_SET_SGT(Y); + #endif + #if ENABLED(Y2_IS_TMC2130) + TMC_SET_SGT(Y2); + #endif + break; + case Z_AXIS: + #if ENABLED(Z_IS_TMC2130) || ENABLED(IS_TRAMS) + TMC_SET_SGT(Z); + #endif + #if ENABLED(Z2_IS_TMC2130) + TMC_SET_SGT(Z2); + #endif + break; + } + } + + if (report) LOOP_XYZ(i) switch (i) { + case X_AXIS: + #if ENABLED(X_IS_TMC2130) || ENABLED(IS_TRAMS) + TMC_SAY_SGT(X); + #endif + #if ENABLED(X2_IS_TMC2130) + TMC_SAY_SGT(X2); + #endif + break; + case Y_AXIS: + #if ENABLED(Y_IS_TMC2130) || ENABLED(IS_TRAMS) + TMC_SAY_SGT(Y); + #endif + #if ENABLED(Y2_IS_TMC2130) + TMC_SAY_SGT(Y2); + #endif + break; + case Z_AXIS: + #if ENABLED(Z_IS_TMC2130) || ENABLED(IS_TRAMS) + TMC_SAY_SGT(Z); + #endif + #if ENABLED(Z2_IS_TMC2130) + TMC_SAY_SGT(Z2); + #endif + break; + } } #endif // SENSORLESS_HOMING