From 85599abba7a0fb7c1700e3be2279120d5c02d673 Mon Sep 17 00:00:00 2001 From: DerAndere <26200979+DerAndere1@users.noreply.github.com> Date: Mon, 4 Apr 2022 04:43:42 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=B8=20Better=20M350,=20M114=20with=20m?= =?UTF-8?q?ore=20axes=20(#23986)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/gcode/control/M350_M351.cpp | 22 ++- Marlin/src/gcode/feature/L6470/M906.cpp | 2 +- Marlin/src/gcode/feature/trinamic/M569.cpp | 2 +- Marlin/src/gcode/feature/trinamic/M919.cpp | 2 +- Marlin/src/gcode/motion/G5.cpp | 2 +- Marlin/src/module/stepper.cpp | 156 ++++++++++++--------- 6 files changed, 107 insertions(+), 79 deletions(-) diff --git a/Marlin/src/gcode/control/M350_M351.cpp b/Marlin/src/gcode/control/M350_M351.cpp index 68e49ee50b..7fab861b65 100644 --- a/Marlin/src/gcode/control/M350_M351.cpp +++ b/Marlin/src/gcode/control/M350_M351.cpp @@ -27,35 +27,45 @@ #include "../gcode.h" #include "../../module/stepper.h" +#if NUM_AXES == XYZ && EXTRUDERS >= 1 + #define HAS_M350_B_PARAM 1 // "5th axis" (after E0) for an original XYZEB setup. + #if AXIS_COLLISION('B') + #error "M350 parameter 'B' collision with axis name." + #endif +#endif + /** * M350: Set axis microstepping modes. S sets mode for all drivers. * * Warning: Steps-per-unit remains unchanged. */ void GcodeSuite::M350() { - if (parser.seen('S')) LOOP_LE_N(i, 4) stepper.microstep_mode(i, parser.value_byte()); - LOOP_LOGICAL_AXES(i) if (parser.seen(axis_codes[i])) stepper.microstep_mode(i, parser.value_byte()); - if (parser.seen('B')) stepper.microstep_mode(4, parser.value_byte()); + if (parser.seen('S')) LOOP_DISTINCT_AXES(i) stepper.microstep_mode(i, parser.value_byte()); + LOOP_LOGICAL_AXES(i) if (parser.seen(AXIS_CHAR(i))) stepper.microstep_mode(i, parser.value_byte()); + TERN_(HAS_M350_B_PARAM, if (parser.seenval('B')) stepper.microstep_mode(E_AXIS + 1, parser.value_byte())); stepper.microstep_readings(); } /** * M351: Toggle MS1 MS2 pins directly with axis codes X Y Z . . . E [B] * S# determines MS1, MS2 or MS3, X# sets the pin high/low. + * + * Parameter 'B' sets "5th axis" (after E0) only for an original XYZEB setup. */ void GcodeSuite::M351() { + const int8_t bval = TERN(HAS_M350_B_PARAM, parser.byteval('B', -1), -1); UNUSED(bval); if (parser.seenval('S')) switch (parser.value_byte()) { case 1: LOOP_LOGICAL_AXES(i) if (parser.seenval(AXIS_CHAR(i))) stepper.microstep_ms(i, parser.value_byte(), -1, -1); - if (parser.seenval('B')) stepper.microstep_ms(4, parser.value_byte(), -1, -1); + TERN_(HAS_M350_B_PARAM, if (bval >= 0) stepper.microstep_ms(E_AXIS + 1, bval != 0, -1, -1)); break; case 2: LOOP_LOGICAL_AXES(i) if (parser.seenval(AXIS_CHAR(i))) stepper.microstep_ms(i, -1, parser.value_byte(), -1); - if (parser.seenval('B')) stepper.microstep_ms(4, -1, parser.value_byte(), -1); + TERN_(HAS_M350_B_PARAM, if (bval >= 0) stepper.microstep_ms(E_AXIS + 1, -1, bval != 0, -1)); break; case 3: LOOP_LOGICAL_AXES(i) if (parser.seenval(AXIS_CHAR(i))) stepper.microstep_ms(i, -1, -1, parser.value_byte()); - if (parser.seenval('B')) stepper.microstep_ms(4, -1, -1, parser.value_byte()); + TERN_(HAS_M350_B_PARAM, if (bval >= 0) stepper.microstep_ms(E_AXIS + 1, -1, -1, bval != 0)); break; } stepper.microstep_readings(); diff --git a/Marlin/src/gcode/feature/L6470/M906.cpp b/Marlin/src/gcode/feature/L6470/M906.cpp index f89fe8b927..26c637df27 100644 --- a/Marlin/src/gcode/feature/L6470/M906.cpp +++ b/Marlin/src/gcode/feature/L6470/M906.cpp @@ -25,7 +25,7 @@ #if HAS_L64XX #if AXIS_COLLISION('I') - #error "M906 parameter collision with axis name." + #error "M906 parameter 'I' collision with axis name." #endif #include "../../gcode.h" diff --git a/Marlin/src/gcode/feature/trinamic/M569.cpp b/Marlin/src/gcode/feature/trinamic/M569.cpp index f4c4967142..44675a850e 100644 --- a/Marlin/src/gcode/feature/trinamic/M569.cpp +++ b/Marlin/src/gcode/feature/trinamic/M569.cpp @@ -25,7 +25,7 @@ #if HAS_STEALTHCHOP #if AXIS_COLLISION('I') - #error "M569 parameter collision with axis name." + #error "M569 parameter 'I' collision with axis name." #endif #include "../../gcode.h" diff --git a/Marlin/src/gcode/feature/trinamic/M919.cpp b/Marlin/src/gcode/feature/trinamic/M919.cpp index 6f3dcf729a..fa349e7f16 100644 --- a/Marlin/src/gcode/feature/trinamic/M919.cpp +++ b/Marlin/src/gcode/feature/trinamic/M919.cpp @@ -25,7 +25,7 @@ #if HAS_TRINAMIC_CONFIG #if AXIS_COLLISION('I') - #error "M919 parameter collision with axis name." + #error "M919 parameter 'I' collision with axis name." #endif #include "../../gcode.h" diff --git a/Marlin/src/gcode/motion/G5.cpp b/Marlin/src/gcode/motion/G5.cpp index 316a59b650..c47f443d41 100644 --- a/Marlin/src/gcode/motion/G5.cpp +++ b/Marlin/src/gcode/motion/G5.cpp @@ -25,7 +25,7 @@ #if ENABLED(BEZIER_CURVE_SUPPORT) #if AXIS_COLLISION('I') || AXIS_COLLISION('J') - #error "G5 parameter collision with axis name." + #error "G5 parameter 'I' or 'J' collision with axis name." #endif #include "../../module/motion.h" diff --git a/Marlin/src/module/stepper.cpp b/Marlin/src/module/stepper.cpp index 6c552959ee..60eb635965 100644 --- a/Marlin/src/module/stepper.cpp +++ b/Marlin/src/module/stepper.cpp @@ -3679,7 +3679,7 @@ void Stepper::report_positions() { void Stepper::microstep_ms(const uint8_t driver, const int8_t ms1, const int8_t ms2, const int8_t ms3) { if (ms1 >= 0) switch (driver) { #if HAS_X_MS_PINS || HAS_X2_MS_PINS - case 0: + case X_AXIS: #if HAS_X_MS_PINS WRITE(X_MS1_PIN, ms1); #endif @@ -3689,7 +3689,7 @@ void Stepper::report_positions() { break; #endif #if HAS_Y_MS_PINS || HAS_Y2_MS_PINS - case 1: + case Y_AXIS: #if HAS_Y_MS_PINS WRITE(Y_MS1_PIN, ms1); #endif @@ -3699,7 +3699,7 @@ void Stepper::report_positions() { break; #endif #if HAS_SOME_Z_MS_PINS - case 2: + case Z_AXIS: #if HAS_Z_MS_PINS WRITE(Z_MS1_PIN, ms1); #endif @@ -3714,52 +3714,52 @@ void Stepper::report_positions() { #endif break; #endif + #if HAS_I_MS_PINS + case I_AXIS: WRITE(I_MS1_PIN, ms1); break + #endif + #if HAS_J_MS_PINS + case J_AXIS: WRITE(J_MS1_PIN, ms1); break + #endif + #if HAS_K_MS_PINS + case K_AXIS: WRITE(K_MS1_PIN, ms1); break + #endif + #if HAS_U_MS_PINS + case U_AXIS: WRITE(U_MS1_PIN, ms1); break + #endif + #if HAS_V_MS_PINS + case V_AXIS: WRITE(V_MS1_PIN, ms1); break + #endif + #if HAS_W_MS_PINS + case W_AXIS: WRITE(W_MS1_PIN, ms1); break + #endif #if HAS_E0_MS_PINS - case 3: WRITE(E0_MS1_PIN, ms1); break; + case E_AXIS: WRITE(E0_MS1_PIN, ms1); break; #endif #if HAS_E1_MS_PINS - case 4: WRITE(E1_MS1_PIN, ms1); break; + case (E_AXIS + 1): WRITE(E1_MS1_PIN, ms1); break; #endif #if HAS_E2_MS_PINS - case 5: WRITE(E2_MS1_PIN, ms1); break; + case (E_AXIS + 2): WRITE(E2_MS1_PIN, ms1); break; #endif #if HAS_E3_MS_PINS - case 6: WRITE(E3_MS1_PIN, ms1); break; + case (E_AXIS + 3): WRITE(E3_MS1_PIN, ms1); break; #endif #if HAS_E4_MS_PINS - case 7: WRITE(E4_MS1_PIN, ms1); break; + case (E_AXIS + 4): WRITE(E4_MS1_PIN, ms1); break; #endif #if HAS_E5_MS_PINS - case 8: WRITE(E5_MS1_PIN, ms1); break; + case (E_AXIS + 5): WRITE(E5_MS1_PIN, ms1); break; #endif #if HAS_E6_MS_PINS - case 9: WRITE(E6_MS1_PIN, ms1); break; + case (E_AXIS + 6): WRITE(E6_MS1_PIN, ms1); break; #endif #if HAS_E7_MS_PINS - case 10: WRITE(E7_MS1_PIN, ms1); break; - #endif - #if HAS_I_MS_PINS - case 11: WRITE(I_MS1_PIN, ms1); break - #endif - #if HAS_J_MS_PINS - case 12: WRITE(J_MS1_PIN, ms1); break - #endif - #if HAS_K_MS_PINS - case 13: WRITE(K_MS1_PIN, ms1); break - #endif - #if HAS_U_MS_PINS - case 14: WRITE(U_MS1_PIN, ms1); break - #endif - #if HAS_V_MS_PINS - case 15: WRITE(V_MS1_PIN, ms1); break - #endif - #if HAS_W_MS_PINS - case 16: WRITE(W_MS1_PIN, ms1); break + case (E_AXIS + 7): WRITE(E7_MS1_PIN, ms1); break; #endif } if (ms2 >= 0) switch (driver) { #if HAS_X_MS_PINS || HAS_X2_MS_PINS - case 0: + case X_AXIS: #if HAS_X_MS_PINS WRITE(X_MS2_PIN, ms2); #endif @@ -3769,7 +3769,7 @@ void Stepper::report_positions() { break; #endif #if HAS_Y_MS_PINS || HAS_Y2_MS_PINS - case 1: + case Y_AXIS: #if HAS_Y_MS_PINS WRITE(Y_MS2_PIN, ms2); #endif @@ -3779,7 +3779,7 @@ void Stepper::report_positions() { break; #endif #if HAS_SOME_Z_MS_PINS - case 2: + case Z_AXIS: #if HAS_Z_MS_PINS WRITE(Z_MS2_PIN, ms2); #endif @@ -3794,52 +3794,52 @@ void Stepper::report_positions() { #endif break; #endif + #if HAS_I_MS_PINS + case I_AXIS: WRITE(I_MS2_PIN, ms2); break + #endif + #if HAS_J_MS_PINS + case J_AXIS: WRITE(J_MS2_PIN, ms2); break + #endif + #if HAS_K_MS_PINS + case K_AXIS: WRITE(K_MS2_PIN, ms2); break + #endif + #if HAS_U_MS_PINS + case U_AXIS: WRITE(U_MS2_PIN, ms2); break + #endif + #if HAS_V_MS_PINS + case V_AXIS: WRITE(V_MS2_PIN, ms2); break + #endif + #if HAS_W_MS_PINS + case W_AXIS: WRITE(W_MS2_PIN, ms2); break + #endif #if HAS_E0_MS_PINS - case 3: WRITE(E0_MS2_PIN, ms2); break; + case E_AXIS: WRITE(E0_MS2_PIN, ms2); break; #endif #if HAS_E1_MS_PINS - case 4: WRITE(E1_MS2_PIN, ms2); break; + case (E_AXIS + 1): WRITE(E1_MS2_PIN, ms2); break; #endif #if HAS_E2_MS_PINS - case 5: WRITE(E2_MS2_PIN, ms2); break; + case (E_AXIS + 2): WRITE(E2_MS2_PIN, ms2); break; #endif #if HAS_E3_MS_PINS - case 6: WRITE(E3_MS2_PIN, ms2); break; + case (E_AXIS + 3): WRITE(E3_MS2_PIN, ms2); break; #endif #if HAS_E4_MS_PINS - case 7: WRITE(E4_MS2_PIN, ms2); break; + case (E_AXIS + 4): WRITE(E4_MS2_PIN, ms2); break; #endif #if HAS_E5_MS_PINS - case 8: WRITE(E5_MS2_PIN, ms2); break; + case (E_AXIS + 5): WRITE(E5_MS2_PIN, ms2); break; #endif #if HAS_E6_MS_PINS - case 9: WRITE(E6_MS2_PIN, ms2); break; + case (E_AXIS + 6): WRITE(E6_MS2_PIN, ms2); break; #endif #if HAS_E7_MS_PINS - case 10: WRITE(E7_MS2_PIN, ms2); break; - #endif - #if HAS_I_MS_PINS - case 11: WRITE(I_MS2_PIN, ms2); break - #endif - #if HAS_J_MS_PINS - case 12: WRITE(J_MS2_PIN, ms2); break - #endif - #if HAS_K_MS_PINS - case 13: WRITE(K_MS2_PIN, ms2); break - #endif - #if HAS_U_MS_PINS - case 14: WRITE(U_MS2_PIN, ms2); break - #endif - #if HAS_V_MS_PINS - case 15: WRITE(V_MS2_PIN, ms2); break - #endif - #if HAS_W_MS_PINS - case 16: WRITE(W_MS2_PIN, ms2); break + case (E_AXIS + 7): WRITE(E7_MS2_PIN, ms2); break; #endif } if (ms3 >= 0) switch (driver) { #if HAS_X_MS_PINS || HAS_X2_MS_PINS - case 0: + case X_AXIS: #if HAS_X_MS_PINS && PIN_EXISTS(X_MS3) WRITE(X_MS3_PIN, ms3); #endif @@ -3849,7 +3849,7 @@ void Stepper::report_positions() { break; #endif #if HAS_Y_MS_PINS || HAS_Y2_MS_PINS - case 1: + case Y_AXIS: #if HAS_Y_MS_PINS && PIN_EXISTS(Y_MS3) WRITE(Y_MS3_PIN, ms3); #endif @@ -3859,7 +3859,7 @@ void Stepper::report_positions() { break; #endif #if HAS_SOME_Z_MS_PINS - case 2: + case Z_AXIS: #if HAS_Z_MS_PINS && PIN_EXISTS(Z_MS3) WRITE(Z_MS3_PIN, ms3); #endif @@ -3874,29 +3874,47 @@ void Stepper::report_positions() { #endif break; #endif + #if HAS_I_MS_PINS + case I_AXIS: WRITE(I_MS3_PIN, ms3); break + #endif + #if HAS_J_MS_PINS + case J_AXIS: WRITE(J_MS3_PIN, ms3); break + #endif + #if HAS_K_MS_PINS + case K_AXIS: WRITE(K_MS3_PIN, ms3); break + #endif + #if HAS_U_MS_PINS + case U_AXIS: WRITE(U_MS3_PIN, ms3); break + #endif + #if HAS_V_MS_PINS + case V_AXIS: WRITE(V_MS3_PIN, ms3); break + #endif + #if HAS_W_MS_PINS + case W_AXIS: WRITE(W_MS3_PIN, ms3); break + #endif #if HAS_E0_MS_PINS && PIN_EXISTS(E0_MS3) - case 3: WRITE(E0_MS3_PIN, ms3); break; + case E_AXIS: WRITE(E0_MS3_PIN, ms3); break; #endif #if HAS_E1_MS_PINS && PIN_EXISTS(E1_MS3) - case 4: WRITE(E1_MS3_PIN, ms3); break; + case (E_AXIS + 1): WRITE(E1_MS3_PIN, ms3); break; #endif #if HAS_E2_MS_PINS && PIN_EXISTS(E2_MS3) - case 5: WRITE(E2_MS3_PIN, ms3); break; + case (E_AXIS + 2): WRITE(E2_MS3_PIN, ms3); break; #endif #if HAS_E3_MS_PINS && PIN_EXISTS(E3_MS3) - case 6: WRITE(E3_MS3_PIN, ms3); break; + case (E_AXIS + 3): WRITE(E3_MS3_PIN, ms3); break; #endif #if HAS_E4_MS_PINS && PIN_EXISTS(E4_MS3) - case 7: WRITE(E4_MS3_PIN, ms3); break; + case (E_AXIS + 4): WRITE(E4_MS3_PIN, ms3); break; #endif #if HAS_E5_MS_PINS && PIN_EXISTS(E5_MS3) - case 8: WRITE(E5_MS3_PIN, ms3); break; + case (E_AXIS + 5): WRITE(E5_MS3_PIN, ms3); break; #endif #if HAS_E6_MS_PINS && PIN_EXISTS(E6_MS3) - case 9: WRITE(E6_MS3_PIN, ms3); break; + case (E_AXIS + 6): WRITE(E6_MS3_PIN, ms3); break; #endif #if HAS_E7_MS_PINS && PIN_EXISTS(E7_MS3) - case 10: WRITE(E7_MS3_PIN, ms3); break; + case (E_AXIS + 7): WRITE(E7_MS3_PIN, ms3); break; #endif } }