... on Z
+ * X If a backlash measurement was done on X, copy that value
+ * Y ... on Y
+ * Z ... on Z
+ *
+ * Type M425 without any arguments to show active values.
+ */
+void GcodeSuite::M425() {
+ bool noArgs = true;
+
+ auto axis_can_calibrate = [](const uint8_t a) {
+ switch (a) {
+ default:
+ case X_AXIS: return AXIS_CAN_CALIBRATE(X);
+ case Y_AXIS: return AXIS_CAN_CALIBRATE(Y);
+ case Z_AXIS: return AXIS_CAN_CALIBRATE(Z);
+ }
+ };
+
+ LOOP_XYZ(a) {
+ if (axis_can_calibrate(a) && parser.seen(XYZ_CHAR(a))) {
+ planner.synchronize();
+ backlash.distance_mm[a] = parser.has_value() ? parser.value_linear_units() : backlash.get_measurement(AxisEnum(a));
+ noArgs = false;
+ }
+ }
+
+ if (parser.seen('F')) {
+ planner.synchronize();
+ backlash.set_correction(parser.value_float());
+ noArgs = false;
+ }
+
+ #ifdef BACKLASH_SMOOTHING_MM
+ if (parser.seen('S')) {
+ planner.synchronize();
+ backlash.smoothing_mm = parser.value_linear_units();
+ noArgs = false;
+ }
+ #endif
+
+ if (noArgs) {
+ SERIAL_ECHOPGM("Backlash Correction ");
+ if (!backlash.correction) SERIAL_ECHOPGM("in");
+ SERIAL_ECHOLNPGM("active:");
+ SERIAL_ECHOLNPAIR(" Correction Amount/Fade-out: F", backlash.get_correction(), " (F1.0 = full, F0.0 = none)");
+ SERIAL_ECHOPGM(" Backlash Distance (mm): ");
+ LOOP_XYZ(a) if (axis_can_calibrate(a)) {
+ SERIAL_CHAR(' ', XYZ_CHAR(a));
+ SERIAL_ECHO(backlash.distance_mm[a]);
+ SERIAL_EOL();
+ }
+
+ #ifdef BACKLASH_SMOOTHING_MM
+ SERIAL_ECHOLNPAIR(" Smoothing (mm): S", backlash.smoothing_mm);
+ #endif
+
+ #if ENABLED(MEASURE_BACKLASH_WHEN_PROBING)
+ SERIAL_ECHOPGM(" Average measured backlash (mm):");
+ if (backlash.has_any_measurement()) {
+ LOOP_XYZ(a) if (axis_can_calibrate(a) && backlash.has_measurement(AxisEnum(a))) {
+ SERIAL_CHAR(' ', XYZ_CHAR(a));
+ SERIAL_ECHO(backlash.get_measurement(AxisEnum(a)));
+ }
+ }
+ else
+ SERIAL_ECHOPGM(" (Not yet measured)");
+ SERIAL_EOL();
+ #endif
+ }
+}
+
+#endif // BACKLASH_GCODE
diff --git a/Marlin/src/gcode/calibrate/M48.cpp b/Marlin/src/gcode/calibrate/M48.cpp
new file mode 100644
index 0000000..97aea59
--- /dev/null
+++ b/Marlin/src/gcode/calibrate/M48.cpp
@@ -0,0 +1,275 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../inc/MarlinConfig.h"
+
+#if ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST)
+
+#include "../gcode.h"
+#include "../../module/motion.h"
+#include "../../module/probe.h"
+#include "../../lcd/marlinui.h"
+
+#include "../../feature/bedlevel/bedlevel.h"
+
+#if HAS_LEVELING
+ #include "../../module/planner.h"
+#endif
+
+/**
+ * M48: Z probe repeatability measurement function.
+ *
+ * Usage:
+ * M48
+ * P = Number of sampled points (4-50, default 10)
+ * X = Sample X position
+ * Y = Sample Y position
+ * V = Verbose level (0-4, default=1)
+ * E = Engage Z probe for each reading
+ * L = Number of legs of movement before probe
+ * S = Schizoid (Or Star if you prefer)
+ *
+ * This function requires the machine to be homed before invocation.
+ */
+
+void GcodeSuite::M48() {
+
+ if (homing_needed_error()) return;
+
+ const int8_t verbose_level = parser.byteval('V', 1);
+ if (!WITHIN(verbose_level, 0, 4)) {
+ SERIAL_ECHOLNPGM("?(V)erbose level implausible (0-4).");
+ return;
+ }
+
+ if (verbose_level > 0)
+ SERIAL_ECHOLNPGM("M48 Z-Probe Repeatability Test");
+
+ const int8_t n_samples = parser.byteval('P', 10);
+ if (!WITHIN(n_samples, 4, 50)) {
+ SERIAL_ECHOLNPGM("?Sample size not plausible (4-50).");
+ return;
+ }
+
+ const ProbePtRaise raise_after = parser.boolval('E') ? PROBE_PT_STOW : PROBE_PT_RAISE;
+
+ // Test at the current position by default, overridden by X and Y
+ const xy_pos_t test_position = {
+ parser.linearval('X', current_position.x + probe.offset_xy.x), // If no X use the probe's current X position
+ parser.linearval('Y', current_position.y + probe.offset_xy.y) // If no Y, ditto
+ };
+
+ if (!probe.can_reach(test_position)) {
+ ui.set_status_P(GET_TEXT(MSG_M48_OUT_OF_BOUNDS), 99);
+ SERIAL_ECHOLNPGM("? (X,Y) out of bounds.");
+ return;
+ }
+
+ // Get the number of leg moves per test-point
+ bool seen_L = parser.seen('L');
+ uint8_t n_legs = seen_L ? parser.value_byte() : 0;
+ if (n_legs > 15) {
+ SERIAL_ECHOLNPGM("?Legs of movement implausible (0-15).");
+ return;
+ }
+ if (n_legs == 1) n_legs = 2;
+
+ // Schizoid motion as an optional stress-test
+ const bool schizoid_flag = parser.boolval('S');
+ if (schizoid_flag && !seen_L) n_legs = 7;
+
+ if (verbose_level > 2)
+ SERIAL_ECHOLNPGM("Positioning the probe...");
+
+ // Always disable Bed Level correction before probing...
+
+ #if HAS_LEVELING
+ const bool was_enabled = planner.leveling_active;
+ set_bed_leveling_enabled(false);
+ #endif
+
+ // Work with reasonable feedrates
+ remember_feedrate_scaling_off();
+
+ // Working variables
+ float mean = 0.0, // The average of all points so far, used to calculate deviation
+ sigma = 0.0, // Standard deviation of all points so far
+ min = 99999.9, // Smallest value sampled so far
+ max = -99999.9, // Largest value sampled so far
+ sample_set[n_samples]; // Storage for sampled values
+
+ auto dev_report = [](const bool verbose, const float &mean, const float &sigma, const float &min, const float &max, const bool final=false) {
+ if (verbose) {
+ SERIAL_ECHOPAIR_F("Mean: ", mean, 6);
+ if (!final) SERIAL_ECHOPAIR_F(" Sigma: ", sigma, 6);
+ SERIAL_ECHOPAIR_F(" Min: ", min, 3);
+ SERIAL_ECHOPAIR_F(" Max: ", max, 3);
+ SERIAL_ECHOPAIR_F(" Range: ", max-min, 3);
+ if (final) SERIAL_EOL();
+ }
+ if (final) {
+ SERIAL_ECHOLNPAIR_F("Standard Deviation: ", sigma, 6);
+ SERIAL_EOL();
+ }
+ };
+
+ // Move to the first point, deploy, and probe
+ const float t = probe.probe_at_point(test_position, raise_after, verbose_level);
+ bool probing_good = !isnan(t);
+
+ if (probing_good) {
+ randomSeed(millis());
+
+ float sample_sum = 0.0;
+
+ LOOP_L_N(n, n_samples) {
+ #if HAS_WIRED_LCD
+ // Display M48 progress in the status bar
+ ui.status_printf_P(0, PSTR(S_FMT ": %d/%d"), GET_TEXT(MSG_M48_POINT), int(n + 1), int(n_samples));
+ #endif
+
+ // When there are "legs" of movement move around the point before probing
+ if (n_legs) {
+
+ // Pick a random direction, starting angle, and radius
+ const int dir = (random(0, 10) > 5.0) ? -1 : 1; // clockwise or counter clockwise
+ float angle = random(0, 360);
+ const float radius = random(
+ #if ENABLED(DELTA)
+ int(0.1250000000 * (DELTA_PRINTABLE_RADIUS)),
+ int(0.3333333333 * (DELTA_PRINTABLE_RADIUS))
+ #else
+ int(5), int(0.125 * _MIN(X_BED_SIZE, Y_BED_SIZE))
+ #endif
+ );
+ if (verbose_level > 3) {
+ SERIAL_ECHOPAIR("Start radius:", radius, " angle:", angle, " dir:");
+ if (dir > 0) SERIAL_CHAR('C');
+ SERIAL_ECHOLNPGM("CW");
+ }
+
+ // Move from leg to leg in rapid succession
+ LOOP_L_N(l, n_legs - 1) {
+
+ // Move some distance around the perimeter
+ float delta_angle;
+ if (schizoid_flag) {
+ // The points of a 5 point star are 72 degrees apart.
+ // Skip a point and go to the next one on the star.
+ delta_angle = dir * 2.0 * 72.0;
+ }
+ else {
+ // Just move further along the perimeter.
+ delta_angle = dir * (float)random(25, 45);
+ }
+ angle += delta_angle;
+
+ // Trig functions work without clamping, but just to be safe...
+ while (angle > 360.0) angle -= 360.0;
+ while (angle < 0.0) angle += 360.0;
+
+ // Choose the next position as an offset to chosen test position
+ const xy_pos_t noz_pos = test_position - probe.offset_xy;
+ xy_pos_t next_pos = {
+ noz_pos.x + float(cos(RADIANS(angle))) * radius,
+ noz_pos.y + float(sin(RADIANS(angle))) * radius
+ };
+
+ #if ENABLED(DELTA)
+ // If the probe can't reach the point on a round bed...
+ // Simply scale the numbers to bring them closer to origin.
+ while (!probe.can_reach(next_pos)) {
+ next_pos *= 0.8f;
+ if (verbose_level > 3)
+ SERIAL_ECHOLNPAIR_P(PSTR("Moving inward: X"), next_pos.x, SP_Y_STR, next_pos.y);
+ }
+ #else
+ // For a rectangular bed just keep the probe in bounds
+ LIMIT(next_pos.x, X_MIN_POS, X_MAX_POS);
+ LIMIT(next_pos.y, Y_MIN_POS, Y_MAX_POS);
+ #endif
+
+ if (verbose_level > 3)
+ SERIAL_ECHOLNPAIR_P(PSTR("Going to: X"), next_pos.x, SP_Y_STR, next_pos.y);
+
+ do_blocking_move_to_xy(next_pos);
+ } // n_legs loop
+ } // n_legs
+
+ // Probe a single point
+ const float pz = probe.probe_at_point(test_position, raise_after, 0);
+
+ // Break the loop if the probe fails
+ probing_good = !isnan(pz);
+ if (!probing_good) break;
+
+ // Store the new sample
+ sample_set[n] = pz;
+
+ // Keep track of the largest and smallest samples
+ NOMORE(min, pz);
+ NOLESS(max, pz);
+
+ // Get the mean value of all samples thus far
+ sample_sum += pz;
+ mean = sample_sum / (n + 1);
+
+ // Calculate the standard deviation so far.
+ // The value after the last sample will be the final output.
+ float dev_sum = 0.0;
+ LOOP_LE_N(j, n) dev_sum += sq(sample_set[j] - mean);
+ sigma = SQRT(dev_sum / (n + 1));
+
+ if (verbose_level > 1) {
+ SERIAL_ECHO((int)(n + 1));
+ SERIAL_ECHOPAIR(" of ", (int)n_samples);
+ SERIAL_ECHOPAIR_F(": z: ", pz, 3);
+ SERIAL_CHAR(' ');
+ dev_report(verbose_level > 2, mean, sigma, min, max);
+ SERIAL_EOL();
+ }
+
+ } // n_samples loop
+ }
+
+ probe.stow();
+
+ if (probing_good) {
+ SERIAL_ECHOLNPGM("Finished!");
+ dev_report(verbose_level > 0, mean, sigma, min, max, true);
+
+ #if HAS_WIRED_LCD
+ // Display M48 results in the status bar
+ char sigma_str[8];
+ ui.status_printf_P(0, PSTR(S_FMT ": %s"), GET_TEXT(MSG_M48_DEVIATION), dtostrf(sigma, 2, 6, sigma_str));
+ #endif
+ }
+
+ restore_feedrate_and_scaling();
+
+ // Re-enable bed level correction if it had been on
+ TERN_(HAS_LEVELING, set_bed_leveling_enabled(was_enabled));
+
+ report_current_position();
+}
+
+#endif // Z_MIN_PROBE_REPEATABILITY_TEST
diff --git a/Marlin/src/gcode/calibrate/M665.cpp b/Marlin/src/gcode/calibrate/M665.cpp
new file mode 100644
index 0000000..557204c
--- /dev/null
+++ b/Marlin/src/gcode/calibrate/M665.cpp
@@ -0,0 +1,112 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../inc/MarlinConfig.h"
+
+#if IS_KINEMATIC
+
+#include "../gcode.h"
+#include "../../module/motion.h"
+
+#if ENABLED(DELTA)
+
+ #include "../../module/delta.h"
+ /**
+ * M665: Set delta configurations
+ *
+ * H = delta height
+ * L = diagonal rod
+ * R = delta radius
+ * S = segments per second
+ * X = Alpha (Tower 1) angle trim
+ * Y = Beta (Tower 2) angle trim
+ * Z = Gamma (Tower 3) angle trim
+ * A = Alpha (Tower 1) digonal rod trim
+ * B = Beta (Tower 2) digonal rod trim
+ * C = Gamma (Tower 3) digonal rod trim
+ */
+ void GcodeSuite::M665() {
+ if (parser.seen('H')) delta_height = parser.value_linear_units();
+ if (parser.seen('L')) delta_diagonal_rod = parser.value_linear_units();
+ if (parser.seen('R')) delta_radius = parser.value_linear_units();
+ if (parser.seen('S')) delta_segments_per_second = parser.value_float();
+ if (parser.seen('X')) delta_tower_angle_trim.a = parser.value_float();
+ if (parser.seen('Y')) delta_tower_angle_trim.b = parser.value_float();
+ if (parser.seen('Z')) delta_tower_angle_trim.c = parser.value_float();
+ if (parser.seen('A')) delta_diagonal_rod_trim.a = parser.value_float();
+ if (parser.seen('B')) delta_diagonal_rod_trim.b = parser.value_float();
+ if (parser.seen('C')) delta_diagonal_rod_trim.c = parser.value_float();
+ recalc_delta_settings();
+ }
+
+#elif IS_SCARA
+
+ #include "../../module/scara.h"
+
+ /**
+ * M665: Set SCARA settings
+ *
+ * Parameters:
+ *
+ * S[segments-per-second] - Segments-per-second
+ * P[theta-psi-offset] - Theta-Psi offset, added to the shoulder (A/X) angle
+ * T[theta-offset] - Theta offset, added to the elbow (B/Y) angle
+ * Z[z-offset] - Z offset, added to Z
+ *
+ * A, P, and X are all aliases for the shoulder angle
+ * B, T, and Y are all aliases for the elbow angle
+ */
+ void GcodeSuite::M665() {
+ if (parser.seenval('S')) delta_segments_per_second = parser.value_float();
+
+ #if HAS_SCARA_OFFSET
+
+ if (parser.seenval('Z')) scara_home_offset.z = parser.value_linear_units();
+
+ const bool hasA = parser.seenval('A'), hasP = parser.seenval('P'), hasX = parser.seenval('X');
+ const uint8_t sumAPX = hasA + hasP + hasX;
+ if (sumAPX) {
+ if (sumAPX == 1)
+ scara_home_offset.a = parser.value_float();
+ else {
+ SERIAL_ERROR_MSG("Only one of A, P, or X is allowed.");
+ return;
+ }
+ }
+
+ const bool hasB = parser.seenval('B'), hasT = parser.seenval('T'), hasY = parser.seenval('Y');
+ const uint8_t sumBTY = hasB + hasT + hasY;
+ if (sumBTY) {
+ if (sumBTY == 1)
+ scara_home_offset.b = parser.value_float();
+ else {
+ SERIAL_ERROR_MSG("Only one of B, T, or Y is allowed.");
+ return;
+ }
+ }
+
+ #endif // HAS_SCARA_OFFSET
+ }
+
+#endif
+
+#endif // IS_KINEMATIC
diff --git a/Marlin/src/gcode/calibrate/M666.cpp b/Marlin/src/gcode/calibrate/M666.cpp
new file mode 100644
index 0000000..e915aa8
--- /dev/null
+++ b/Marlin/src/gcode/calibrate/M666.cpp
@@ -0,0 +1,105 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../inc/MarlinConfig.h"
+
+#if ENABLED(DELTA) || HAS_EXTRA_ENDSTOPS
+
+#include "../gcode.h"
+
+#if ENABLED(DELTA)
+
+ #include "../../module/delta.h"
+ #include "../../module/motion.h"
+
+ #define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE)
+ #include "../../core/debug_out.h"
+
+ /**
+ * M666: Set delta endstop adjustment
+ */
+ void GcodeSuite::M666() {
+ DEBUG_SECTION(log_M666, "M666", DEBUGGING(LEVELING));
+ LOOP_XYZ(i) {
+ if (parser.seen(XYZ_CHAR(i))) {
+ const float v = parser.value_linear_units();
+ if (v * Z_HOME_DIR <= 0) delta_endstop_adj[i] = v;
+ if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("delta_endstop_adj[", XYZ_CHAR(i), "] = ", delta_endstop_adj[i]);
+ }
+ }
+ }
+
+#elif HAS_EXTRA_ENDSTOPS
+
+ #include "../../module/endstops.h"
+
+ /**
+ * M666: Set Dual Endstops offsets for X, Y, and/or Z.
+ * With no parameters report current offsets.
+ *
+ * For Triple / Quad Z Endstops:
+ * Set Z2 Only: M666 S2 Z
+ * Set Z3 Only: M666 S3 Z
+ * Set Z4 Only: M666 S4 Z
+ * Set All: M666 Z
+ */
+ void GcodeSuite::M666() {
+ #if ENABLED(X_DUAL_ENDSTOPS)
+ if (parser.seenval('X')) endstops.x2_endstop_adj = parser.value_linear_units();
+ #endif
+ #if ENABLED(Y_DUAL_ENDSTOPS)
+ if (parser.seenval('Y')) endstops.y2_endstop_adj = parser.value_linear_units();
+ #endif
+ #if ENABLED(Z_MULTI_ENDSTOPS)
+ if (parser.seenval('Z')) {
+ #if NUM_Z_STEPPER_DRIVERS >= 3
+ const float z_adj = parser.value_linear_units();
+ const int ind = parser.intval('S');
+ if (!ind || ind == 2) endstops.z2_endstop_adj = z_adj;
+ if (!ind || ind == 3) endstops.z3_endstop_adj = z_adj;
+ #if NUM_Z_STEPPER_DRIVERS >= 4
+ if (!ind || ind == 4) endstops.z4_endstop_adj = z_adj;
+ #endif
+ #else
+ endstops.z2_endstop_adj = parser.value_linear_units();
+ #endif
+ }
+ #endif
+ if (!parser.seen("XYZ")) {
+ SERIAL_ECHOPGM("Dual Endstop Adjustment (mm): ");
+ #if ENABLED(X_DUAL_ENDSTOPS)
+ SERIAL_ECHOPAIR(" X2:", endstops.x2_endstop_adj);
+ #endif
+ #if ENABLED(Y_DUAL_ENDSTOPS)
+ SERIAL_ECHOPAIR(" Y2:", endstops.y2_endstop_adj);
+ #endif
+ #if ENABLED(Z_MULTI_ENDSTOPS)
+ #define _ECHO_ZADJ(N) SERIAL_ECHOPAIR(" Z" STRINGIFY(N) ":", endstops.z##N##_endstop_adj);
+ REPEAT_S(2, INCREMENT(NUM_Z_STEPPER_DRIVERS), _ECHO_ZADJ)
+ #endif
+ SERIAL_EOL();
+ }
+ }
+
+#endif // HAS_EXTRA_ENDSTOPS
+
+#endif // DELTA || HAS_EXTRA_ENDSTOPS
diff --git a/Marlin/src/gcode/calibrate/M852.cpp b/Marlin/src/gcode/calibrate/M852.cpp
new file mode 100644
index 0000000..b60f417
--- /dev/null
+++ b/Marlin/src/gcode/calibrate/M852.cpp
@@ -0,0 +1,106 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../inc/MarlinConfig.h"
+
+#if ENABLED(SKEW_CORRECTION_GCODE)
+
+#include "../gcode.h"
+#include "../../module/planner.h"
+
+/**
+ * M852: Get or set the machine skew factors. Reports current values with no arguments.
+ *
+ * S[xy_factor] - Alias for 'I'
+ * I[xy_factor] - New XY skew factor
+ * J[xz_factor] - New XZ skew factor
+ * K[yz_factor] - New YZ skew factor
+ */
+void GcodeSuite::M852() {
+ uint8_t ijk = 0, badval = 0, setval = 0;
+
+ if (parser.seen('I') || parser.seen('S')) {
+ ++ijk;
+ const float value = parser.value_linear_units();
+ if (WITHIN(value, SKEW_FACTOR_MIN, SKEW_FACTOR_MAX)) {
+ if (planner.skew_factor.xy != value) {
+ planner.skew_factor.xy = value;
+ ++setval;
+ }
+ }
+ else
+ ++badval;
+ }
+
+ #if ENABLED(SKEW_CORRECTION_FOR_Z)
+
+ if (parser.seen('J')) {
+ ++ijk;
+ const float value = parser.value_linear_units();
+ if (WITHIN(value, SKEW_FACTOR_MIN, SKEW_FACTOR_MAX)) {
+ if (planner.skew_factor.xz != value) {
+ planner.skew_factor.xz = value;
+ ++setval;
+ }
+ }
+ else
+ ++badval;
+ }
+
+ if (parser.seen('K')) {
+ ++ijk;
+ const float value = parser.value_linear_units();
+ if (WITHIN(value, SKEW_FACTOR_MIN, SKEW_FACTOR_MAX)) {
+ if (planner.skew_factor.yz != value) {
+ planner.skew_factor.yz = value;
+ ++setval;
+ }
+ }
+ else
+ ++badval;
+ }
+
+ #endif
+
+ if (badval)
+ SERIAL_ECHOLNPGM(STR_SKEW_MIN " " STRINGIFY(SKEW_FACTOR_MIN) " " STR_SKEW_MAX " " STRINGIFY(SKEW_FACTOR_MAX));
+
+ // When skew is changed the current position changes
+ if (setval) {
+ set_current_from_steppers_for_axis(ALL_AXES);
+ sync_plan_position();
+ report_current_position();
+ }
+
+ if (!ijk) {
+ SERIAL_ECHO_START();
+ serialprintPGM(GET_TEXT(MSG_SKEW_FACTOR));
+ SERIAL_ECHOPAIR_F(" XY: ", planner.skew_factor.xy, 6);
+ #if ENABLED(SKEW_CORRECTION_FOR_Z)
+ SERIAL_ECHOPAIR_F(" XZ: ", planner.skew_factor.xz, 6);
+ SERIAL_ECHOPAIR_F(" YZ: ", planner.skew_factor.yz, 6);
+ #endif
+ SERIAL_EOL();
+ }
+}
+
+#endif // SKEW_CORRECTION_GCODE
diff --git a/Marlin/src/gcode/config/M200-M205.cpp b/Marlin/src/gcode/config/M200-M205.cpp
new file mode 100644
index 0000000..cb17fc4
--- /dev/null
+++ b/Marlin/src/gcode/config/M200-M205.cpp
@@ -0,0 +1,191 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../gcode.h"
+#include "../../MarlinCore.h"
+#include "../../module/planner.h"
+
+#if DISABLED(NO_VOLUMETRICS)
+
+ /**
+ * M200: Set filament diameter and set E axis units to cubic units
+ *
+ * T - Optional extruder number. Current extruder if omitted.
+ * D - Set filament diameter and enable. D0 disables volumetric.
+ * S - Turn volumetric ON or OFF.
+ * L - Volumetric extruder limit (in mm^3/sec). L0 disables the limit.
+ */
+ void GcodeSuite::M200() {
+
+ const int8_t target_extruder = get_target_extruder_from_command();
+ if (target_extruder < 0) return;
+
+ bool vol_enable = parser.volumetric_enabled,
+ can_enable = true;
+
+ if (parser.seenval('D')) {
+ const float dval = parser.value_linear_units();
+ if (dval) { // Set filament size for volumetric calculation
+ planner.set_filament_size(target_extruder, dval);
+ vol_enable = true; // Dn = enable for compatibility
+ }
+ else
+ can_enable = false; // D0 = disable for compatibility
+ }
+
+ // Enable or disable with S1 / S0
+ parser.volumetric_enabled = can_enable && parser.boolval('S', vol_enable);
+
+ #if ENABLED(VOLUMETRIC_EXTRUDER_LIMIT)
+ if (parser.seenval('L')) {
+ // Set volumetric limit (in mm^3/sec)
+ const float lval = parser.value_float();
+ if (WITHIN(lval, 0, 20))
+ planner.set_volumetric_extruder_limit(target_extruder, lval);
+ else
+ SERIAL_ECHOLNPGM("?L value out of range (0-20).");
+ }
+ #endif
+
+ planner.calculate_volumetric_multipliers();
+ }
+
+#endif // !NO_VOLUMETRICS
+
+/**
+ * M201: Set max acceleration in units/s^2 for print moves (M201 X1000 Y1000)
+ *
+ * With multiple extruders use T to specify which one.
+ */
+void GcodeSuite::M201() {
+
+ const int8_t target_extruder = get_target_extruder_from_command();
+ if (target_extruder < 0) return;
+
+ #ifdef XY_FREQUENCY_LIMIT
+ if (parser.seenval('F')) planner.set_frequency_limit(parser.value_byte());
+ if (parser.seenval('G')) planner.xy_freq_min_speed_factor = constrain(parser.value_float(), 1, 100) / 100;
+ #endif
+
+ LOOP_XYZE(i) {
+ if (parser.seen(axis_codes[i])) {
+ const uint8_t a = (i == E_AXIS ? uint8_t(E_AXIS_N(target_extruder)) : i);
+ planner.set_max_acceleration(a, parser.value_axis_units((AxisEnum)a));
+ }
+ }
+}
+
+/**
+ * M203: Set maximum feedrate that your machine can sustain (M203 X200 Y200 Z300 E10000) in units/sec
+ *
+ * With multiple extruders use T to specify which one.
+ */
+void GcodeSuite::M203() {
+
+ const int8_t target_extruder = get_target_extruder_from_command();
+ if (target_extruder < 0) return;
+
+ LOOP_XYZE(i)
+ if (parser.seen(axis_codes[i])) {
+ const uint8_t a = (i == E_AXIS ? uint8_t(E_AXIS_N(target_extruder)) : i);
+ planner.set_max_feedrate(a, parser.value_axis_units((AxisEnum)a));
+ }
+}
+
+/**
+ * M204: Set Accelerations in units/sec^2 (M204 P1200 R3000 T3000)
+ *
+ * P = Printing moves
+ * R = Retract only (no X, Y, Z) moves
+ * T = Travel (non printing) moves
+ */
+void GcodeSuite::M204() {
+ if (!parser.seen("PRST")) {
+ SERIAL_ECHOPAIR("Acceleration: P", planner.settings.acceleration);
+ SERIAL_ECHOPAIR(" R", planner.settings.retract_acceleration);
+ SERIAL_ECHOLNPAIR_P(SP_T_STR, planner.settings.travel_acceleration);
+ }
+ else {
+ //planner.synchronize();
+ // 'S' for legacy compatibility. Should NOT BE USED for new development
+ if (parser.seenval('S')) planner.settings.travel_acceleration = planner.settings.acceleration = parser.value_linear_units();
+ if (parser.seenval('P')) planner.settings.acceleration = parser.value_linear_units();
+ if (parser.seenval('R')) planner.settings.retract_acceleration = parser.value_linear_units();
+ if (parser.seenval('T')) planner.settings.travel_acceleration = parser.value_linear_units();
+ }
+}
+
+/**
+ * M205: Set Advanced Settings
+ *
+ * B = Min Segment Time (µs)
+ * S = Min Feed Rate (units/s)
+ * T = Min Travel Feed Rate (units/s)
+ * X = Max X Jerk (units/sec^2)
+ * Y = Max Y Jerk (units/sec^2)
+ * Z = Max Z Jerk (units/sec^2)
+ * E = Max E Jerk (units/sec^2)
+ * J = Junction Deviation (mm) (If not using CLASSIC_JERK)
+ */
+void GcodeSuite::M205() {
+ #if HAS_JUNCTION_DEVIATION
+ #define J_PARAM "J"
+ #else
+ #define J_PARAM
+ #endif
+ #if HAS_CLASSIC_JERK
+ #define XYZE_PARAM "XYZE"
+ #else
+ #define XYZE_PARAM
+ #endif
+ if (!parser.seen("BST" J_PARAM XYZE_PARAM)) return;
+
+ //planner.synchronize();
+ if (parser.seen('B')) planner.settings.min_segment_time_us = parser.value_ulong();
+ if (parser.seen('S')) planner.settings.min_feedrate_mm_s = parser.value_linear_units();
+ if (parser.seen('T')) planner.settings.min_travel_feedrate_mm_s = parser.value_linear_units();
+ #if HAS_JUNCTION_DEVIATION
+ if (parser.seen('J')) {
+ const float junc_dev = parser.value_linear_units();
+ if (WITHIN(junc_dev, 0.01f, 0.3f)) {
+ planner.junction_deviation_mm = junc_dev;
+ TERN_(LIN_ADVANCE, planner.recalculate_max_e_jerk());
+ }
+ else
+ SERIAL_ERROR_MSG("?J out of range (0.01 to 0.3)");
+ }
+ #endif
+ #if HAS_CLASSIC_JERK
+ if (parser.seen('X')) planner.set_max_jerk(X_AXIS, parser.value_linear_units());
+ if (parser.seen('Y')) planner.set_max_jerk(Y_AXIS, parser.value_linear_units());
+ if (parser.seen('Z')) {
+ planner.set_max_jerk(Z_AXIS, parser.value_linear_units());
+ #if HAS_MESH && DISABLED(LIMITED_JERK_EDITING)
+ if (planner.max_jerk.z <= 0.1f)
+ SERIAL_ECHOLNPGM("WARNING! Low Z Jerk may lead to unwanted pauses.");
+ #endif
+ }
+ #if HAS_CLASSIC_E_JERK
+ if (parser.seen('E')) planner.set_max_jerk(E_AXIS, parser.value_linear_units());
+ #endif
+ #endif
+}
diff --git a/Marlin/src/gcode/config/M217.cpp b/Marlin/src/gcode/config/M217.cpp
new file mode 100644
index 0000000..f2fefb5
--- /dev/null
+++ b/Marlin/src/gcode/config/M217.cpp
@@ -0,0 +1,171 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../inc/MarlinConfigPre.h"
+
+#if HAS_MULTI_EXTRUDER
+
+#include "../gcode.h"
+#include "../../module/tool_change.h"
+
+#if ENABLED(TOOLCHANGE_MIGRATION_FEATURE)
+ #include "../../module/motion.h"
+#endif
+
+#include "../../MarlinCore.h" // for SP_X_STR, etc.
+
+void M217_report(const bool eeprom=false) {
+
+ #if ENABLED(TOOLCHANGE_FILAMENT_SWAP)
+ serialprintPGM(eeprom ? PSTR(" M217") : PSTR("Toolchange:"));
+ SERIAL_ECHOPAIR(" S", LINEAR_UNIT(toolchange_settings.swap_length));
+ SERIAL_ECHOPAIR_P(SP_B_STR, LINEAR_UNIT(toolchange_settings.extra_resume),
+ SP_E_STR, LINEAR_UNIT(toolchange_settings.extra_prime),
+ SP_P_STR, LINEAR_UNIT(toolchange_settings.prime_speed));
+ SERIAL_ECHOPAIR(" R", LINEAR_UNIT(toolchange_settings.retract_speed),
+ " U", LINEAR_UNIT(toolchange_settings.unretract_speed),
+ " F", toolchange_settings.fan_speed,
+ " G", toolchange_settings.fan_time);
+
+ #if ENABLED(TOOLCHANGE_MIGRATION_FEATURE)
+ SERIAL_ECHOPAIR(" A", int(migration.automode));
+ SERIAL_ECHOPAIR(" L", LINEAR_UNIT(migration.last));
+ #endif
+
+ #if ENABLED(TOOLCHANGE_PARK)
+ SERIAL_ECHOPAIR(" W", LINEAR_UNIT(toolchange_settings.enable_park));
+ SERIAL_ECHOPAIR_P(SP_X_STR, LINEAR_UNIT(toolchange_settings.change_point.x));
+ SERIAL_ECHOPAIR_P(SP_Y_STR, LINEAR_UNIT(toolchange_settings.change_point.y));
+ #endif
+
+ #if ENABLED(TOOLCHANGE_FS_PRIME_FIRST_USED)
+ SERIAL_ECHOPAIR(" V", LINEAR_UNIT(enable_first_prime));
+ #endif
+
+ #else
+
+ UNUSED(eeprom);
+
+ #endif
+
+ SERIAL_ECHOPAIR_P(SP_Z_STR, LINEAR_UNIT(toolchange_settings.z_raise));
+ SERIAL_EOL();
+}
+
+/**
+ * M217 - Set SINGLENOZZLE toolchange parameters
+ *
+ * // Tool change command
+ * Q Prime active tool and exit
+ *
+ * // Tool change settings
+ * S[linear] Swap length
+ * B[linear] Extra Swap length
+ * E[linear] Prime length
+ * P[linear/m] Prime speed
+ * R[linear/m] Retract speed
+ * U[linear/m] UnRetract speed
+ * V[linear] 0/1 Enable auto prime first extruder used
+ * W[linear] 0/1 Enable park & Z Raise
+ * X[linear] Park X (Requires TOOLCHANGE_PARK)
+ * Y[linear] Park Y (Requires TOOLCHANGE_PARK)
+ * Z[linear] Z Raise
+ * F[linear] Fan Speed 0-255
+ * G[linear/s] Fan time
+ *
+ * Tool migration settings
+ * A[0|1] Enable auto-migration on runout
+ * L[index] Last extruder to use for auto-migration
+ *
+ * Tool migration command
+ * T[index] Migrate to next extruder or the given extruder
+ */
+void GcodeSuite::M217() {
+
+ #if ENABLED(TOOLCHANGE_FILAMENT_SWAP)
+
+ static constexpr float max_extrude = TERN(PREVENT_LENGTHY_EXTRUDE, EXTRUDE_MAXLENGTH, 500);
+
+ if (parser.seen('Q')) { tool_change_prime(); return; }
+
+ if (parser.seenval('S')) { const float v = parser.value_linear_units(); toolchange_settings.swap_length = constrain(v, 0, max_extrude); }
+ if (parser.seenval('B')) { const float v = parser.value_linear_units(); toolchange_settings.extra_resume = constrain(v, -10, 10); }
+ if (parser.seenval('E')) { const float v = parser.value_linear_units(); toolchange_settings.extra_prime = constrain(v, 0, max_extrude); }
+ if (parser.seenval('P')) { const int16_t v = parser.value_linear_units(); toolchange_settings.prime_speed = constrain(v, 10, 5400); }
+ if (parser.seenval('R')) { const int16_t v = parser.value_linear_units(); toolchange_settings.retract_speed = constrain(v, 10, 5400); }
+ if (parser.seenval('U')) { const int16_t v = parser.value_linear_units(); toolchange_settings.unretract_speed = constrain(v, 10, 5400); }
+ #if TOOLCHANGE_FS_FAN >= 0 && HAS_FAN
+ if (parser.seenval('F')) { const int16_t v = parser.value_linear_units(); toolchange_settings.fan_speed = constrain(v, 0, 255); }
+ if (parser.seenval('G')) { const int16_t v = parser.value_linear_units(); toolchange_settings.fan_time = constrain(v, 1, 30); }
+ #endif
+ #endif
+
+ #if ENABLED(TOOLCHANGE_FS_PRIME_FIRST_USED)
+ if (parser.seenval('V')) { enable_first_prime = parser.value_linear_units(); }
+ #endif
+
+ #if ENABLED(TOOLCHANGE_PARK)
+ if (parser.seenval('W')) { toolchange_settings.enable_park = parser.value_linear_units(); }
+ if (parser.seenval('X')) { const int16_t v = parser.value_linear_units(); toolchange_settings.change_point.x = constrain(v, X_MIN_POS, X_MAX_POS); }
+ if (parser.seenval('Y')) { const int16_t v = parser.value_linear_units(); toolchange_settings.change_point.y = constrain(v, Y_MIN_POS, Y_MAX_POS); }
+ #endif
+
+ if (parser.seenval('Z')) { toolchange_settings.z_raise = parser.value_linear_units(); }
+
+ #if ENABLED(TOOLCHANGE_MIGRATION_FEATURE)
+ migration.target = 0; // 0 = disabled
+
+ if (parser.seenval('L')) { // Last
+ const int16_t lval = parser.value_int();
+ if (WITHIN(lval, 0, EXTRUDERS - 1)) {
+ migration.last = lval;
+ migration.automode = (active_extruder < migration.last);
+ }
+ }
+
+ if (parser.seen('A')) // Auto on/off
+ migration.automode = parser.value_bool();
+
+ if (parser.seen('T')) { // Migrate now
+ if (parser.has_value()) {
+ const int16_t tval = parser.value_int();
+ if (WITHIN(tval, 0, EXTRUDERS - 1) && tval != active_extruder) {
+ migration.target = tval + 1;
+ extruder_migration();
+ migration.target = 0; // disable
+ return;
+ }
+ else
+ migration.target = 0; // disable
+ }
+ else {
+ extruder_migration();
+ return;
+ }
+ }
+
+ #endif
+
+ M217_report();
+}
+
+#endif // HAS_MULTI_EXTRUDER
diff --git a/Marlin/src/gcode/config/M218.cpp b/Marlin/src/gcode/config/M218.cpp
new file mode 100644
index 0000000..7701320
--- /dev/null
+++ b/Marlin/src/gcode/config/M218.cpp
@@ -0,0 +1,71 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../inc/MarlinConfig.h"
+
+#if HAS_HOTEND_OFFSET
+
+#include "../gcode.h"
+#include "../../module/motion.h"
+
+#if ENABLED(DELTA)
+ #include "../../module/planner.h"
+#endif
+
+/**
+ * M218 - set hotend offset (in linear units)
+ *
+ * T
+ * X
+ * Y
+ * Z
+ */
+void GcodeSuite::M218() {
+
+ const int8_t target_extruder = get_target_extruder_from_command();
+ if (target_extruder < 0) return;
+
+ if (parser.seenval('X')) hotend_offset[target_extruder].x = parser.value_linear_units();
+ if (parser.seenval('Y')) hotend_offset[target_extruder].y = parser.value_linear_units();
+ if (parser.seenval('Z')) hotend_offset[target_extruder].z = parser.value_linear_units();
+
+ if (!parser.seen("XYZ")) {
+ SERIAL_ECHO_START();
+ SERIAL_ECHOPGM(STR_HOTEND_OFFSET);
+ HOTEND_LOOP() {
+ SERIAL_CHAR(' ');
+ SERIAL_ECHO(hotend_offset[e].x);
+ SERIAL_CHAR(',');
+ SERIAL_ECHO(hotend_offset[e].y);
+ SERIAL_CHAR(',');
+ SERIAL_ECHO_F(hotend_offset[e].z, 3);
+ }
+ SERIAL_EOL();
+ }
+
+ #if ENABLED(DELTA)
+ if (target_extruder == active_extruder)
+ do_blocking_move_to_xy(current_position, planner.settings.max_feedrate_mm_s[X_AXIS]);
+ #endif
+}
+
+#endif // HAS_HOTEND_OFFSET
diff --git a/Marlin/src/gcode/config/M220.cpp b/Marlin/src/gcode/config/M220.cpp
new file mode 100644
index 0000000..75339f1
--- /dev/null
+++ b/Marlin/src/gcode/config/M220.cpp
@@ -0,0 +1,51 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../gcode.h"
+#include "../../module/motion.h"
+
+/**
+ * M220: Set speed percentage factor, aka "Feed Rate"
+ *
+ * Parameters
+ * S : Set the feed rate percentage factor
+ *
+ * Report the current speed percentage factor if no parameter is specified
+ *
+ * For MMU2 and MMU2S devices...
+ * B : Flag to back up the current factor
+ * R : Flag to restore the last-saved factor
+ */
+void GcodeSuite::M220() {
+
+ static int16_t backup_feedrate_percentage = 100;
+ if (parser.seen('B')) backup_feedrate_percentage = feedrate_percentage;
+ if (parser.seen('R')) feedrate_percentage = backup_feedrate_percentage;
+
+ if (parser.seenval('S')) feedrate_percentage = parser.value_int();
+
+ if (!parser.seen_any()) {
+ SERIAL_ECHOPAIR("FR:", feedrate_percentage);
+ SERIAL_CHAR('%');
+ SERIAL_EOL();
+ }
+}
diff --git a/Marlin/src/gcode/config/M221.cpp b/Marlin/src/gcode/config/M221.cpp
new file mode 100644
index 0000000..7ba22d1
--- /dev/null
+++ b/Marlin/src/gcode/config/M221.cpp
@@ -0,0 +1,47 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../gcode.h"
+#include "../../module/planner.h"
+
+#if EXTRUDERS
+
+/**
+ * M221: Set extrusion percentage (M221 T0 S95)
+ */
+void GcodeSuite::M221() {
+
+ const int8_t target_extruder = get_target_extruder_from_command();
+ if (target_extruder < 0) return;
+
+ if (parser.seenval('S'))
+ planner.set_flow(target_extruder, parser.value_int());
+ else {
+ SERIAL_ECHO_START();
+ SERIAL_CHAR('E', '0' + target_extruder);
+ SERIAL_ECHOPAIR(" Flow: ", planner.flow_percentage[target_extruder]);
+ SERIAL_CHAR('%');
+ SERIAL_EOL();
+ }
+}
+
+#endif // EXTRUDERS
diff --git a/Marlin/src/gcode/config/M281.cpp b/Marlin/src/gcode/config/M281.cpp
new file mode 100644
index 0000000..018ca1c
--- /dev/null
+++ b/Marlin/src/gcode/config/M281.cpp
@@ -0,0 +1,68 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+#include "../../inc/MarlinConfig.h"
+
+#if ENABLED(EDITABLE_SERVO_ANGLES)
+
+#include "../gcode.h"
+#include "../../module/servo.h"
+
+/**
+ * M281 - Edit / Report Servo Angles
+ *
+ * P - Servo to update
+ * L - Deploy Angle
+ * U - Stowed Angle
+ */
+void GcodeSuite::M281() {
+ if (!parser.seenval('P')) return;
+ const int servo_index = parser.value_int();
+ if (WITHIN(servo_index, 0, NUM_SERVOS - 1)) {
+ #if ENABLED(BLTOUCH)
+ if (servo_index == Z_PROBE_SERVO_NR) {
+ SERIAL_ERROR_MSG("BLTouch angles can't be changed.");
+ return;
+ }
+ #endif
+ bool angle_change = false;
+ if (parser.seen('L')) {
+ servo_angles[servo_index][0] = parser.value_int();
+ angle_change = true;
+ }
+ if (parser.seen('U')) {
+ servo_angles[servo_index][1] = parser.value_int();
+ angle_change = true;
+ }
+ if (!angle_change) {
+ SERIAL_ECHO_START();
+ SERIAL_ECHOLNPAIR(" Servo ", servo_index,
+ " L", servo_angles[servo_index][0],
+ " U", servo_angles[servo_index][1]);
+ }
+ }
+ else {
+ SERIAL_ERROR_START();
+ SERIAL_ECHOLNPAIR("Servo ", servo_index, " out of range");
+ }
+}
+
+#endif // EDITABLE_SERVO_ANGLES
diff --git a/Marlin/src/gcode/config/M301.cpp b/Marlin/src/gcode/config/M301.cpp
new file mode 100644
index 0000000..7b3f576
--- /dev/null
+++ b/Marlin/src/gcode/config/M301.cpp
@@ -0,0 +1,91 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../inc/MarlinConfig.h"
+
+#if ENABLED(PIDTEMP)
+
+#include "../gcode.h"
+#include "../../module/temperature.h"
+
+/**
+ * M301: Set PID parameters P I D (and optionally C, L)
+ *
+ * E[extruder] Default: 0
+ *
+ * P[float] Kp term
+ * I[float] Ki term (unscaled)
+ * D[float] Kd term (unscaled)
+ *
+ * With PID_EXTRUSION_SCALING:
+ *
+ * C[float] Kc term
+ * L[int] LPQ length
+ *
+ * With PID_FAN_SCALING:
+ *
+ * F[float] Kf term
+ */
+void GcodeSuite::M301() {
+
+ // multi-extruder PID patch: M301 updates or prints a single extruder's PID values
+ // default behavior (omitting E parameter) is to update for extruder 0 only
+ const uint8_t e = parser.byteval('E'); // extruder being updated
+
+ if (e < HOTENDS) { // catch bad input value
+ if (parser.seen('P')) PID_PARAM(Kp, e) = parser.value_float();
+ if (parser.seen('I')) PID_PARAM(Ki, e) = scalePID_i(parser.value_float());
+ if (parser.seen('D')) PID_PARAM(Kd, e) = scalePID_d(parser.value_float());
+ #if ENABLED(PID_EXTRUSION_SCALING)
+ if (parser.seen('C')) PID_PARAM(Kc, e) = parser.value_float();
+ if (parser.seenval('L')) thermalManager.lpq_len = parser.value_int();
+ NOMORE(thermalManager.lpq_len, LPQ_MAX_LEN);
+ NOLESS(thermalManager.lpq_len, 0);
+ #endif
+
+ #if ENABLED(PID_FAN_SCALING)
+ if (parser.seen('F')) PID_PARAM(Kf, e) = parser.value_float();
+ #endif
+
+ thermalManager.updatePID();
+
+ SERIAL_ECHO_START();
+ #if ENABLED(PID_PARAMS_PER_HOTEND)
+ SERIAL_ECHOPAIR(" e:", e); // specify extruder in serial output
+ #endif
+ SERIAL_ECHOPAIR(" p:", PID_PARAM(Kp, e),
+ " i:", unscalePID_i(PID_PARAM(Ki, e)),
+ " d:", unscalePID_d(PID_PARAM(Kd, e)));
+ #if ENABLED(PID_EXTRUSION_SCALING)
+ SERIAL_ECHOPAIR(" c:", PID_PARAM(Kc, e));
+ #endif
+ #if ENABLED(PID_FAN_SCALING)
+ SERIAL_ECHOPAIR(" f:", PID_PARAM(Kf, e));
+ #endif
+
+ SERIAL_EOL();
+ }
+ else
+ SERIAL_ERROR_MSG(STR_INVALID_EXTRUDER);
+}
+
+#endif // PIDTEMP
diff --git a/Marlin/src/gcode/config/M302.cpp b/Marlin/src/gcode/config/M302.cpp
new file mode 100644
index 0000000..afdc6c9
--- /dev/null
+++ b/Marlin/src/gcode/config/M302.cpp
@@ -0,0 +1,63 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../inc/MarlinConfig.h"
+
+#if ENABLED(PREVENT_COLD_EXTRUSION)
+
+#include "../gcode.h"
+#include "../../module/temperature.h"
+
+/**
+ * M302: Allow cold extrudes, or set the minimum extrude temperature
+ *
+ * S sets the minimum extrude temperature
+ * P enables (1) or disables (0) cold extrusion
+ *
+ * Examples:
+ *
+ * M302 ; report current cold extrusion state
+ * M302 P0 ; enable cold extrusion checking
+ * M302 P1 ; disable cold extrusion checking
+ * M302 S0 ; always allow extrusion (disables checking)
+ * M302 S170 ; only allow extrusion above 170
+ * M302 S170 P1 ; set min extrude temp to 170 but leave disabled
+ */
+void GcodeSuite::M302() {
+ const bool seen_S = parser.seen('S');
+ if (seen_S) {
+ thermalManager.extrude_min_temp = parser.value_celsius();
+ thermalManager.allow_cold_extrude = (thermalManager.extrude_min_temp == 0);
+ }
+
+ if (parser.seen('P'))
+ thermalManager.allow_cold_extrude = (thermalManager.extrude_min_temp == 0) || parser.value_bool();
+ else if (!seen_S) {
+ // Report current state
+ SERIAL_ECHO_START();
+ SERIAL_ECHOPGM("Cold extrudes are ");
+ serialprintPGM(thermalManager.allow_cold_extrude ? PSTR("en") : PSTR("dis"));
+ SERIAL_ECHOLNPAIR("abled (min temp ", thermalManager.extrude_min_temp, "C)");
+ }
+}
+
+#endif // PREVENT_COLD_EXTRUSION
diff --git a/Marlin/src/gcode/config/M304.cpp b/Marlin/src/gcode/config/M304.cpp
new file mode 100644
index 0000000..10739be
--- /dev/null
+++ b/Marlin/src/gcode/config/M304.cpp
@@ -0,0 +1,48 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../inc/MarlinConfig.h"
+
+#if ENABLED(PIDTEMPBED)
+
+#include "../gcode.h"
+#include "../../module/temperature.h"
+
+/**
+ * M304 - Set and/or Report the current Bed PID values
+ *
+ * P - Set the P value
+ * I - Set the I value
+ * D - Set the D value
+ */
+void GcodeSuite::M304() {
+ if (parser.seen('P')) thermalManager.temp_bed.pid.Kp = parser.value_float();
+ if (parser.seen('I')) thermalManager.temp_bed.pid.Ki = scalePID_i(parser.value_float());
+ if (parser.seen('D')) thermalManager.temp_bed.pid.Kd = scalePID_d(parser.value_float());
+
+ SERIAL_ECHO_START();
+ SERIAL_ECHOLNPAIR(" p:", thermalManager.temp_bed.pid.Kp,
+ " i:", unscalePID_i(thermalManager.temp_bed.pid.Ki),
+ " d:", unscalePID_d(thermalManager.temp_bed.pid.Kd));
+}
+
+#endif // PIDTEMPBED
diff --git a/Marlin/src/gcode/config/M305.cpp b/Marlin/src/gcode/config/M305.cpp
new file mode 100644
index 0000000..3e7206a
--- /dev/null
+++ b/Marlin/src/gcode/config/M305.cpp
@@ -0,0 +1,81 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../inc/MarlinConfig.h"
+
+#if HAS_USER_THERMISTORS
+
+#include "../gcode.h"
+#include "../../module/temperature.h"
+
+/**
+ * M305: Set (or report) custom thermistor parameters
+ *
+ * P[index] Thermistor table index
+ * R[ohms] Pullup resistor value
+ * T[ohms] Resistance at 25C
+ * B[beta] Thermistor "beta" value
+ * C[coeff] Steinhart-Hart Coefficient 'C'
+ *
+ * Format: M305 P[tbl_index] R[pullup_resistor_val] T[therm_25C_resistance] B[therm_beta] C[Steinhart_Hart_C_coeff]
+ *
+ * Examples: M305 P0 R4700 T100000 B3950 C0.0
+ * M305 P0 R4700
+ * M305 P0 T100000
+ * M305 P0 B3950
+ * M305 P0 C0.0
+ */
+void GcodeSuite::M305() {
+ const int8_t t_index = parser.intval('P', -1);
+ const bool do_set = parser.seen("BCRT");
+
+ // A valid P index is required
+ if (t_index >= (USER_THERMISTORS) || (do_set && t_index < 0)) {
+ SERIAL_ECHO_START();
+ SERIAL_ECHOLNPAIR("!Invalid index. (0 <= P <= ", int(USER_THERMISTORS - 1), ")");
+ }
+ else if (do_set) {
+ if (parser.seen('R')) // Pullup resistor value
+ if (!thermalManager.set_pull_up_res(t_index, parser.value_float()))
+ SERIAL_ECHO_MSG("!Invalid series resistance. (0 < R < 1000000)");
+
+ if (parser.seen('T')) // Resistance at 25C
+ if (!thermalManager.set_res25(t_index, parser.value_float()))
+ SERIAL_ECHO_MSG("!Invalid 25C resistance. (0 < T < 10000000)");
+
+ if (parser.seen('B')) // Beta value
+ if (!thermalManager.set_beta(t_index, parser.value_float()))
+ SERIAL_ECHO_MSG("!Invalid beta. (0 < B < 1000000)");
+
+ if (parser.seen('C')) // Steinhart-Hart C coefficient
+ if (!thermalManager.set_sh_coeff(t_index, parser.value_float()))
+ SERIAL_ECHO_MSG("!Invalid Steinhart-Hart C coeff. (-0.01 < C < +0.01)");
+ } // If not setting then report parameters
+ else if (t_index < 0) { // ...all user thermistors
+ LOOP_L_N(i, USER_THERMISTORS)
+ thermalManager.log_user_thermistor(i);
+ }
+ else // ...one user thermistor
+ thermalManager.log_user_thermistor(t_index);
+}
+
+#endif // HAS_USER_THERMISTORS
diff --git a/Marlin/src/gcode/config/M43.cpp b/Marlin/src/gcode/config/M43.cpp
new file mode 100644
index 0000000..005fdf0
--- /dev/null
+++ b/Marlin/src/gcode/config/M43.cpp
@@ -0,0 +1,386 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../inc/MarlinConfig.h"
+
+#if ENABLED(PINS_DEBUGGING)
+
+#include "../gcode.h"
+#include "../../MarlinCore.h" // for pin_is_protected
+#include "../../pins/pinsDebug.h"
+#include "../../module/endstops.h"
+
+#if HAS_Z_SERVO_PROBE
+ #include "../../module/probe.h"
+ #include "../../module/servo.h"
+#endif
+
+#if ENABLED(BLTOUCH)
+ #include "../../feature/bltouch.h"
+#endif
+
+#if ENABLED(HOST_PROMPT_SUPPORT)
+ #include "../../feature/host_actions.h"
+#endif
+
+#if ENABLED(EXTENSIBLE_UI)
+ #include "../../lcd/extui/ui_api.h"
+#endif
+
+#if HAS_RESUME_CONTINUE
+ #include "../../lcd/marlinui.h"
+#endif
+
+#ifndef GET_PIN_MAP_PIN_M43
+ #define GET_PIN_MAP_PIN_M43(Q) GET_PIN_MAP_PIN(Q)
+#endif
+
+inline void toggle_pins() {
+ const bool ignore_protection = parser.boolval('I');
+ const int repeat = parser.intval('R', 1),
+ start = PARSED_PIN_INDEX('S', 0),
+ end = PARSED_PIN_INDEX('L', NUM_DIGITAL_PINS - 1),
+ wait = parser.intval('W', 500);
+
+ LOOP_S_LE_N(i, start, end) {
+ pin_t pin = GET_PIN_MAP_PIN_M43(i);
+ if (!VALID_PIN(pin)) continue;
+ if (M43_NEVER_TOUCH(i) || (!ignore_protection && pin_is_protected(pin))) {
+ report_pin_state_extended(pin, ignore_protection, true, PSTR("Untouched "));
+ SERIAL_EOL();
+ }
+ else {
+ watchdog_refresh();
+ report_pin_state_extended(pin, ignore_protection, true, PSTR("Pulsing "));
+ #ifdef __STM32F1__
+ const auto prior_mode = _GET_MODE(i);
+ #else
+ const bool prior_mode = GET_PINMODE(pin);
+ #endif
+ #if AVR_AT90USB1286_FAMILY // Teensy IDEs don't know about these pins so must use FASTIO
+ if (pin == TEENSY_E2) {
+ SET_OUTPUT(TEENSY_E2);
+ for (int16_t j = 0; j < repeat; j++) {
+ WRITE(TEENSY_E2, LOW); safe_delay(wait);
+ WRITE(TEENSY_E2, HIGH); safe_delay(wait);
+ WRITE(TEENSY_E2, LOW); safe_delay(wait);
+ }
+ }
+ else if (pin == TEENSY_E3) {
+ SET_OUTPUT(TEENSY_E3);
+ for (int16_t j = 0; j < repeat; j++) {
+ WRITE(TEENSY_E3, LOW); safe_delay(wait);
+ WRITE(TEENSY_E3, HIGH); safe_delay(wait);
+ WRITE(TEENSY_E3, LOW); safe_delay(wait);
+ }
+ }
+ else
+ #endif
+ {
+ pinMode(pin, OUTPUT);
+ for (int16_t j = 0; j < repeat; j++) {
+ watchdog_refresh(); extDigitalWrite(pin, 0); safe_delay(wait);
+ watchdog_refresh(); extDigitalWrite(pin, 1); safe_delay(wait);
+ watchdog_refresh(); extDigitalWrite(pin, 0); safe_delay(wait);
+ watchdog_refresh();
+ }
+ }
+ #ifdef __STM32F1__
+ _SET_MODE(i, prior_mode);
+ #else
+ pinMode(pin, prior_mode);
+ #endif
+ }
+ SERIAL_EOL();
+ }
+ SERIAL_ECHOLNPGM("Done.");
+
+} // toggle_pins
+
+inline void servo_probe_test() {
+
+ #if !(NUM_SERVOS > 0 && HAS_SERVO_0)
+
+ SERIAL_ERROR_MSG("SERVO not set up.");
+
+ #elif !HAS_Z_SERVO_PROBE
+
+ SERIAL_ERROR_MSG("Z_PROBE_SERVO_NR not set up.");
+
+ #else // HAS_Z_SERVO_PROBE
+
+ const uint8_t probe_index = parser.byteval('P', Z_PROBE_SERVO_NR);
+
+ SERIAL_ECHOLNPAIR("Servo probe test\n"
+ ". using index: ", int(probe_index),
+ ", deploy angle: ", servo_angles[probe_index][0],
+ ", stow angle: ", servo_angles[probe_index][1]
+ );
+
+ bool deploy_state = false, stow_state;
+
+ #if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
+
+ #define PROBE_TEST_PIN Z_MIN_PIN
+ constexpr bool probe_inverting = Z_MIN_ENDSTOP_INVERTING;
+
+ SERIAL_ECHOLNPAIR(". Probe Z_MIN_PIN: ", int(PROBE_TEST_PIN));
+ SERIAL_ECHOPGM(". Z_MIN_ENDSTOP_INVERTING: ");
+
+ #else
+
+ #define PROBE_TEST_PIN Z_MIN_PROBE_PIN
+ constexpr bool probe_inverting = Z_MIN_PROBE_ENDSTOP_INVERTING;
+
+ SERIAL_ECHOLNPAIR(". Probe Z_MIN_PROBE_PIN: ", int(PROBE_TEST_PIN));
+ SERIAL_ECHOPGM( ". Z_MIN_PROBE_ENDSTOP_INVERTING: ");
+
+ #endif
+
+ serialprint_truefalse(probe_inverting);
+ SERIAL_EOL();
+
+ SET_INPUT_PULLUP(PROBE_TEST_PIN);
+
+ // First, check for a probe that recognizes an advanced BLTouch sequence.
+ // In addition to STOW and DEPLOY, it uses SW MODE (and RESET in the beginning)
+ // to see if this is one of the following: BLTOUCH Classic 1.2, 1.3, or
+ // BLTouch Smart 1.0, 2.0, 2.2, 3.0, 3.1. But only if the user has actually
+ // configured a BLTouch as being present. If the user has not configured this,
+ // the BLTouch will be detected in the last phase of these tests (see further on).
+ bool blt = false;
+ // This code will try to detect a BLTouch probe or clone
+ #if ENABLED(BLTOUCH)
+ SERIAL_ECHOLNPGM(". Check for BLTOUCH");
+ bltouch._reset();
+ bltouch._stow();
+ if (probe_inverting == READ(PROBE_TEST_PIN)) {
+ bltouch._set_SW_mode();
+ if (probe_inverting != READ(PROBE_TEST_PIN)) {
+ bltouch._deploy();
+ if (probe_inverting == READ(PROBE_TEST_PIN)) {
+ bltouch._stow();
+ SERIAL_ECHOLNPGM("= BLTouch Classic 1.2, 1.3, Smart 1.0, 2.0, 2.2, 3.0, 3.1 detected.");
+ // Check for a 3.1 by letting the user trigger it, later
+ blt = true;
+ }
+ }
+ }
+ #endif
+
+ // The following code is common to all kinds of servo probes.
+ // Since it could be a real servo or a BLTouch (any kind) or a clone,
+ // use only "common" functions - i.e. SERVO_MOVE. No bltouch.xxxx stuff.
+
+ // If it is already recognised as a being a BLTouch, no need for this test
+ if (!blt) {
+ // DEPLOY and STOW 4 times and see if the signal follows
+ // Then it is a mechanical switch
+ uint8_t i = 0;
+ SERIAL_ECHOLNPGM(". Deploy & stow 4 times");
+ do {
+ MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][0]); // Deploy
+ safe_delay(500);
+ deploy_state = READ(PROBE_TEST_PIN);
+ MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][1]); // Stow
+ safe_delay(500);
+ stow_state = READ(PROBE_TEST_PIN);
+ } while (++i < 4);
+
+ if (probe_inverting != deploy_state) SERIAL_ECHOLNPGM("WARNING: INVERTING setting probably backwards.");
+
+ if (deploy_state != stow_state) {
+ SERIAL_ECHOLNPGM("= Mechanical Switch detected");
+ if (deploy_state) {
+ SERIAL_ECHOLNPAIR(" DEPLOYED state: HIGH (logic 1)",
+ " STOWED (triggered) state: LOW (logic 0)");
+ }
+ else {
+ SERIAL_ECHOLNPAIR(" DEPLOYED state: LOW (logic 0)",
+ " STOWED (triggered) state: HIGH (logic 1)");
+ }
+ #if ENABLED(BLTOUCH)
+ SERIAL_ECHOLNPGM("FAIL: BLTOUCH enabled - Set up this device as a Servo Probe with INVERTING set to 'true'.");
+ #endif
+ return;
+ }
+ }
+
+ // Ask the user for a trigger event and measure the pulse width.
+ MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][0]); // Deploy
+ safe_delay(500);
+ SERIAL_ECHOLNPGM("** Please trigger probe within 30 sec **");
+ uint16_t probe_counter = 0;
+
+ // Wait 30 seconds for user to trigger probe
+ for (uint16_t j = 0; j < 500 * 30 && probe_counter == 0 ; j++) {
+ safe_delay(2);
+
+ if (0 == j % (500 * 1)) gcode.reset_stepper_timeout(); // Keep steppers powered
+
+ if (deploy_state != READ(PROBE_TEST_PIN)) { // probe triggered
+ for (probe_counter = 0; probe_counter < 15 && deploy_state != READ(PROBE_TEST_PIN); ++probe_counter) safe_delay(2);
+
+ SERIAL_ECHOPGM(". Pulse width");
+ if (probe_counter == 15)
+ SERIAL_ECHOLNPGM(": 30ms or more");
+ else
+ SERIAL_ECHOLNPAIR(" (+/- 4ms): ", probe_counter * 2);
+
+ if (probe_counter >= 4) {
+ if (probe_counter == 15) {
+ if (blt) SERIAL_ECHOPGM("= BLTouch V3.1");
+ else SERIAL_ECHOPGM("= Z Servo Probe");
+ }
+ else SERIAL_ECHOPGM("= BLTouch pre V3.1 (or compatible)");
+ SERIAL_ECHOLNPGM(" detected.");
+ }
+ else SERIAL_ECHOLNPGM("FAIL: Noise detected - please re-run test");
+
+ MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][1]); // Stow
+ return;
+ }
+ }
+
+ if (!probe_counter) SERIAL_ECHOLNPGM("FAIL: No trigger detected");
+
+ #endif // HAS_Z_SERVO_PROBE
+
+} // servo_probe_test
+
+/**
+ * M43: Pin debug - report pin state, watch pins, toggle pins and servo probe test/report
+ *
+ * M43 - report name and state of pin(s)
+ * P Pin to read or watch. If omitted, reads all pins.
+ * I Flag to ignore Marlin's pin protection.
+ *
+ * M43 W - Watch pins -reporting changes- until reset, click, or M108.
+ * P Pin to read or watch. If omitted, read/watch all pins.
+ * I Flag to ignore Marlin's pin protection.
+ *
+ * M43 E - Enable / disable background endstop monitoring
+ * - Machine continues to operate
+ * - Reports changes to endstops
+ * - Toggles LED_PIN when an endstop changes
+ * - Cannot reliably catch the 5mS pulse from BLTouch type probes
+ *
+ * M43 T - Toggle pin(s) and report which pin is being toggled
+ * S - Start Pin number. If not given, will default to 0
+ * L - End Pin number. If not given, will default to last pin defined for this board
+ * I - Flag to ignore Marlin's pin protection. Use with caution!!!!
+ * R - Repeat pulses on each pin this number of times before continueing to next pin
+ * W - Wait time (in miliseconds) between pulses. If not given will default to 500
+ *
+ * M43 S - Servo probe test
+ * P - Probe index (optional - defaults to 0
+ */
+void GcodeSuite::M43() {
+
+ // 'T' must be first. It uses 'S' and 'E' differently.
+ if (parser.seen('T')) return toggle_pins();
+
+ // 'E' Enable or disable endstop monitoring and return
+ if (parser.seen('E')) {
+ endstops.monitor_flag = parser.value_bool();
+ SERIAL_ECHOPGM("endstop monitor ");
+ serialprintPGM(endstops.monitor_flag ? PSTR("en") : PSTR("dis"));
+ SERIAL_ECHOLNPGM("abled");
+ return;
+ }
+
+ // 'S' Run servo probe test and return
+ if (parser.seen('S')) return servo_probe_test();
+
+ // 'P' Get the range of pins to test or watch
+ uint8_t first_pin = PARSED_PIN_INDEX('P', 0),
+ last_pin = parser.seenval('P') ? first_pin : NUMBER_PINS_TOTAL - 1;
+
+ if (first_pin > last_pin) return;
+
+ // 'I' to ignore protected pins
+ const bool ignore_protection = parser.boolval('I');
+
+ // 'W' Watch until click, M108, or reset
+ if (parser.boolval('W')) {
+ SERIAL_ECHOLNPGM("Watching pins");
+ #ifdef ARDUINO_ARCH_SAM
+ NOLESS(first_pin, 2); // Don't hijack the UART pins
+ #endif
+ uint8_t pin_state[last_pin - first_pin + 1];
+ LOOP_S_LE_N(i, first_pin, last_pin) {
+ pin_t pin = GET_PIN_MAP_PIN_M43(i);
+ if (!VALID_PIN(pin)) continue;
+ if (M43_NEVER_TOUCH(i) || (!ignore_protection && pin_is_protected(pin))) continue;
+ pinMode(pin, INPUT_PULLUP);
+ delay(1);
+ /*
+ if (IS_ANALOG(pin))
+ pin_state[pin - first_pin] = analogRead(DIGITAL_PIN_TO_ANALOG_PIN(pin)); // int16_t pin_state[...]
+ else
+ //*/
+ pin_state[i - first_pin] = extDigitalRead(pin);
+ }
+
+ #if HAS_RESUME_CONTINUE
+ KEEPALIVE_STATE(PAUSED_FOR_USER);
+ wait_for_user = true;
+ TERN_(HOST_PROMPT_SUPPORT, host_prompt_do(PROMPT_USER_CONTINUE, PSTR("M43 Wait Called"), CONTINUE_STR));
+ TERN_(EXTENSIBLE_UI, ExtUI::onUserConfirmRequired_P(PSTR("M43 Wait Called")));
+ #endif
+
+ for (;;) {
+ LOOP_S_LE_N(i, first_pin, last_pin) {
+ pin_t pin = GET_PIN_MAP_PIN_M43(i);
+ if (!VALID_PIN(pin)) continue;
+ if (M43_NEVER_TOUCH(i) || (!ignore_protection && pin_is_protected(pin))) continue;
+ const byte val =
+ /*
+ IS_ANALOG(pin)
+ ? analogRead(DIGITAL_PIN_TO_ANALOG_PIN(pin)) : // int16_t val
+ :
+ //*/
+ extDigitalRead(pin);
+ if (val != pin_state[i - first_pin]) {
+ report_pin_state_extended(pin, ignore_protection, false);
+ pin_state[i - first_pin] = val;
+ }
+ }
+
+ #if HAS_RESUME_CONTINUE
+ ui.update();
+ if (!wait_for_user) break;
+ #endif
+
+ safe_delay(200);
+ }
+ }
+ else {
+ // Report current state of selected pin(s)
+ LOOP_S_LE_N(i, first_pin, last_pin) {
+ pin_t pin = GET_PIN_MAP_PIN_M43(i);
+ if (VALID_PIN(pin)) report_pin_state_extended(pin, ignore_protection, true);
+ }
+ }
+}
+
+#endif // PINS_DEBUGGING
diff --git a/Marlin/src/gcode/config/M540.cpp b/Marlin/src/gcode/config/M540.cpp
new file mode 100644
index 0000000..54d52f3
--- /dev/null
+++ b/Marlin/src/gcode/config/M540.cpp
@@ -0,0 +1,40 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../inc/MarlinConfig.h"
+
+#if ENABLED(SD_ABORT_ON_ENDSTOP_HIT)
+
+#include "../gcode.h"
+#include "../../module/stepper.h"
+
+/**
+ * M540: Set whether SD card print should abort on endstop hit (M540 S<0|1>)
+ */
+void GcodeSuite::M540() {
+
+ if (parser.seen('S'))
+ planner.abort_on_endstop_hit = parser.value_bool();
+
+}
+
+#endif // SD_ABORT_ON_ENDSTOP_HIT
diff --git a/Marlin/src/gcode/config/M575.cpp b/Marlin/src/gcode/config/M575.cpp
new file mode 100644
index 0000000..44723b7
--- /dev/null
+++ b/Marlin/src/gcode/config/M575.cpp
@@ -0,0 +1,75 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../inc/MarlinConfig.h"
+
+#if ENABLED(BAUD_RATE_GCODE)
+
+#include "../gcode.h"
+
+/**
+ * M575 - Change serial baud rate
+ *
+ * P - Serial port index. Omit for all.
+ * B - Baud rate (bits per second)
+ */
+void GcodeSuite::M575() {
+ int32_t baud = parser.ulongval('B');
+ switch (baud) {
+ case 24:
+ case 96:
+ case 192:
+ case 384:
+ case 576:
+ case 1152: baud *= 100; break;
+ case 250:
+ case 500: baud *= 1000; break;
+ case 19: baud = 19200; break;
+ case 38: baud = 38400; break;
+ case 57: baud = 57600; break;
+ case 115: baud = 115200; break;
+ }
+ switch (baud) {
+ case 2400: case 9600: case 19200: case 38400: case 57600:
+ case 115200: case 250000: case 500000: case 1000000: {
+ const int8_t port = parser.intval('P', -99);
+ const bool set0 = (port == -99 || port == 0);
+ if (set0) SERIAL_ECHO_MSG(" Serial ", '0', " baud rate set to ", baud);
+ #if HAS_MULTI_SERIAL
+ const bool set1 = (port == -99 || port == 1);
+ if (set1) SERIAL_ECHO_MSG(" Serial ", '1', " baud rate set to ", baud);
+ #endif
+
+ SERIAL_FLUSH();
+
+ if (set0) { MYSERIAL0.end(); MYSERIAL0.begin(baud); }
+
+ #if HAS_MULTI_SERIAL
+ if (set1) { MYSERIAL1.end(); MYSERIAL1.begin(baud); }
+ #endif
+
+ } break;
+ default: SERIAL_ECHO_MSG("?(B)aud rate implausible.");
+ }
+}
+
+#endif // BAUD_RATE_GCODE
diff --git a/Marlin/src/gcode/config/M672.cpp b/Marlin/src/gcode/config/M672.cpp
new file mode 100644
index 0000000..af74230
--- /dev/null
+++ b/Marlin/src/gcode/config/M672.cpp
@@ -0,0 +1,98 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../inc/MarlinConfig.h"
+
+#if ENABLED(DUET_SMART_EFFECTOR) && PIN_EXISTS(SMART_EFFECTOR_MOD)
+
+#include "../gcode.h"
+#include "../../HAL/shared/Delay.h"
+#include "../parser.h"
+
+/**
+ * The Marlin format for the M672 command is different than shown in the Duet Smart Effector
+ * documentation https://duet3d.dozuki.com/Wiki/Smart_effector_and_carriage_adapters_for_delta_printer
+ *
+ * To set custom sensitivity:
+ * Duet: M672 S105:aaa:bbb
+ * Marlin: M672 Saaa
+ *
+ * (where aaa is the desired sensitivity and bbb is 255 - aaa).
+ *
+ * Revert sensitivity to factory settings:
+ * Duet: M672 S105:131:131
+ * Marlin: M672 R
+ */
+
+#define M672_PROGBYTE 105 // magic byte to start programming custom sensitivity
+#define M672_ERASEBYTE 131 // magic byte to clear custom sensitivity
+
+//
+// Smart Effector byte send protocol:
+//
+// 0 0 1 0 ... always 0010
+// b7 b6 b5 b4 ~b4 ... hi bits, NOT last bit
+// b3 b2 b1 b0 ~b0 ... lo bits, NOT last bit
+//
+void M672_send(uint8_t b) { // bit rate requirement: 1KHz +/- 30%
+ LOOP_L_N(bits, 14) {
+ switch (bits) {
+ default: { OUT_WRITE(SMART_EFFECTOR_MOD_PIN, !!(b & 0x80)); b <<= 1; break; } // send bit, shift next into place
+ case 7:
+ case 12: { OUT_WRITE(SMART_EFFECTOR_MOD_PIN, !!(b & 0x80)); break; } // send bit. no shift
+ case 8:
+ case 13: { OUT_WRITE(SMART_EFFECTOR_MOD_PIN, !(b & 0x80)); b <<= 1; break; } // send inverted previous bit
+ case 0: case 1: // 00
+ case 3: { OUT_WRITE(SMART_EFFECTOR_MOD_PIN, LOW); break; } // 0010
+ case 2: { OUT_WRITE(SMART_EFFECTOR_MOD_PIN, HIGH); break; } // 001
+ }
+ DELAY_US(1000);
+ }
+}
+
+/**
+ * M672 - Set/reset Duet Smart Effector sensitivity
+ *
+ * One of these is required:
+ * S - 0-255
+ * R - Flag to reset sensitivity to default
+ */
+void GcodeSuite::M672() {
+ if (parser.seen('R')) {
+ M672_send(M672_ERASEBYTE);
+ M672_send(M672_ERASEBYTE);
+ }
+ else if (parser.seenval('S')) {
+ const int8_t M672_sensitivity = parser.value_byte();
+ M672_send(M672_PROGBYTE);
+ M672_send(M672_sensitivity);
+ M672_send(255 - M672_sensitivity);
+ }
+ else {
+ SERIAL_ECHO_MSG("!'S' or 'R' parameter required.");
+ return;
+ }
+
+ OUT_WRITE(SMART_EFFECTOR_MOD_PIN, LOW); // Keep Smart Effector in NORMAL mode
+}
+
+#endif // DUET_SMART_EFFECTOR && SMART_EFFECTOR_MOD_PIN
diff --git a/Marlin/src/gcode/config/M92.cpp b/Marlin/src/gcode/config/M92.cpp
new file mode 100644
index 0000000..0a7d52b
--- /dev/null
+++ b/Marlin/src/gcode/config/M92.cpp
@@ -0,0 +1,114 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../gcode.h"
+#include "../../module/planner.h"
+
+void report_M92(const bool echo=true, const int8_t e=-1) {
+ if (echo) SERIAL_ECHO_START(); else SERIAL_CHAR(' ');
+ SERIAL_ECHOPAIR_P(PSTR(" M92 X"), LINEAR_UNIT(planner.settings.axis_steps_per_mm[X_AXIS]),
+ SP_Y_STR, LINEAR_UNIT(planner.settings.axis_steps_per_mm[Y_AXIS]),
+ SP_Z_STR, LINEAR_UNIT(planner.settings.axis_steps_per_mm[Z_AXIS]));
+ #if DISABLED(DISTINCT_E_FACTORS)
+ SERIAL_ECHOPAIR_P(SP_E_STR, VOLUMETRIC_UNIT(planner.settings.axis_steps_per_mm[E_AXIS]));
+ #endif
+ SERIAL_EOL();
+
+ #if ENABLED(DISTINCT_E_FACTORS)
+ LOOP_L_N(i, E_STEPPERS) {
+ if (e >= 0 && i != e) continue;
+ if (echo) SERIAL_ECHO_START(); else SERIAL_CHAR(' ');
+ SERIAL_ECHOLNPAIR_P(PSTR(" M92 T"), (int)i,
+ SP_E_STR, VOLUMETRIC_UNIT(planner.settings.axis_steps_per_mm[E_AXIS_N(i)]));
+ }
+ #endif
+
+ UNUSED_E(e);
+}
+
+/**
+ * M92: Set axis steps-per-unit for one or more axes, X, Y, Z, and E.
+ * (Follows the same syntax as G92)
+ *
+ * With multiple extruders use T to specify which one.
+ *
+ * If no argument is given print the current values.
+ *
+ * With MAGIC_NUMBERS_GCODE:
+ * Use 'H' and/or 'L' to get ideal layer-height information.
+ * 'H' specifies micro-steps to use. We guess if it's not supplied.
+ * 'L' specifies a desired layer height. Nearest good heights are shown.
+ */
+void GcodeSuite::M92() {
+
+ const int8_t target_extruder = get_target_extruder_from_command();
+ if (target_extruder < 0) return;
+
+ // No arguments? Show M92 report.
+ if (!parser.seen("XYZE"
+ #if ENABLED(MAGIC_NUMBERS_GCODE)
+ "HL"
+ #endif
+ )) return report_M92(true, target_extruder);
+
+ LOOP_XYZE(i) {
+ if (parser.seenval(axis_codes[i])) {
+ if (i == E_AXIS) {
+ const float value = parser.value_per_axis_units((AxisEnum)(E_AXIS_N(target_extruder)));
+ if (value < 20) {
+ float factor = planner.settings.axis_steps_per_mm[E_AXIS_N(target_extruder)] / value; // increase e constants if M92 E14 is given for netfab.
+ #if HAS_CLASSIC_JERK && HAS_CLASSIC_E_JERK
+ planner.max_jerk.e *= factor;
+ #endif
+ planner.settings.max_feedrate_mm_s[E_AXIS_N(target_extruder)] *= factor;
+ planner.max_acceleration_steps_per_s2[E_AXIS_N(target_extruder)] *= factor;
+ }
+ planner.settings.axis_steps_per_mm[E_AXIS_N(target_extruder)] = value;
+ }
+ else {
+ planner.settings.axis_steps_per_mm[i] = parser.value_per_axis_units((AxisEnum)i);
+ }
+ }
+ }
+ planner.refresh_positioning();
+
+ #if ENABLED(MAGIC_NUMBERS_GCODE)
+ #ifndef Z_MICROSTEPS
+ #define Z_MICROSTEPS 16
+ #endif
+ const float wanted = parser.floatval('L');
+ if (parser.seen('H') || wanted) {
+ const uint16_t argH = parser.ushortval('H'),
+ micro_steps = argH ?: Z_MICROSTEPS;
+ const float z_full_step_mm = micro_steps * planner.steps_to_mm[Z_AXIS];
+ SERIAL_ECHO_START();
+ SERIAL_ECHOPAIR("{ micro_steps:", micro_steps, ", z_full_step_mm:", z_full_step_mm);
+ if (wanted) {
+ const float best = uint16_t(wanted / z_full_step_mm) * z_full_step_mm;
+ SERIAL_ECHOPAIR(", best:[", best);
+ if (best != wanted) { SERIAL_CHAR(','); SERIAL_DECIMAL(best + z_full_step_mm); }
+ SERIAL_CHAR(']');
+ }
+ SERIAL_ECHOLNPGM(" }");
+ }
+ #endif
+}
diff --git a/Marlin/src/gcode/control/M108_M112_M410.cpp b/Marlin/src/gcode/control/M108_M112_M410.cpp
new file mode 100644
index 0000000..309c806
--- /dev/null
+++ b/Marlin/src/gcode/control/M108_M112_M410.cpp
@@ -0,0 +1,56 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../inc/MarlinConfig.h"
+
+#if DISABLED(EMERGENCY_PARSER)
+
+#include "../gcode.h"
+#include "../../MarlinCore.h" // for wait_for_heatup, kill, M112_KILL_STR
+#include "../../module/motion.h" // for quickstop_stepper
+
+/**
+ * M108: Stop the waiting for heaters in M109, M190, M303. Does not affect the target temperature.
+ */
+void GcodeSuite::M108() {
+ TERN_(HAS_RESUME_CONTINUE, wait_for_user = false);
+ wait_for_heatup = false;
+}
+
+/**
+ * M112: Full Shutdown
+ */
+void GcodeSuite::M112() {
+ kill(M112_KILL_STR, nullptr, true);
+}
+
+/**
+ * M410: Quickstop - Abort all planned moves
+ *
+ * This will stop the carriages mid-move, so most likely they
+ * will be out of sync with the stepper position after this.
+ */
+void GcodeSuite::M410() {
+ quickstop_stepper();
+}
+
+#endif // !EMERGENCY_PARSER
diff --git a/Marlin/src/gcode/control/M111.cpp b/Marlin/src/gcode/control/M111.cpp
new file mode 100644
index 0000000..38cb065
--- /dev/null
+++ b/Marlin/src/gcode/control/M111.cpp
@@ -0,0 +1,77 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../gcode.h"
+
+/**
+ * M111: Set the debug level
+ */
+void GcodeSuite::M111() {
+ if (parser.seen('S')) marlin_debug_flags = parser.byteval('S');
+
+ static PGMSTR(str_debug_1, STR_DEBUG_ECHO);
+ static PGMSTR(str_debug_2, STR_DEBUG_INFO);
+ static PGMSTR(str_debug_4, STR_DEBUG_ERRORS);
+ static PGMSTR(str_debug_8, STR_DEBUG_DRYRUN);
+ static PGMSTR(str_debug_16, STR_DEBUG_COMMUNICATION);
+ #if ENABLED(DEBUG_LEVELING_FEATURE)
+ static PGMSTR(str_debug_lvl, STR_DEBUG_LEVELING);
+ #endif
+
+ static PGM_P const debug_strings[] PROGMEM = {
+ str_debug_1, str_debug_2, str_debug_4, str_debug_8, str_debug_16,
+ TERN_(DEBUG_LEVELING_FEATURE, str_debug_lvl)
+ };
+
+ SERIAL_ECHO_START();
+ SERIAL_ECHOPGM(STR_DEBUG_PREFIX);
+ if (marlin_debug_flags) {
+ uint8_t comma = 0;
+ LOOP_L_N(i, COUNT(debug_strings)) {
+ if (TEST(marlin_debug_flags, i)) {
+ if (comma++) SERIAL_CHAR(',');
+ serialprintPGM((char*)pgm_read_ptr(&debug_strings[i]));
+ }
+ }
+ }
+ else {
+ SERIAL_ECHOPGM(STR_DEBUG_OFF);
+ #if !defined(__AVR__) || !defined(USBCON)
+ #if ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS)
+ SERIAL_ECHOPAIR("\nBuffer Overruns: ", MYSERIAL0.buffer_overruns());
+ #endif
+
+ #if ENABLED(SERIAL_STATS_RX_FRAMING_ERRORS)
+ SERIAL_ECHOPAIR("\nFraming Errors: ", MYSERIAL0.framing_errors());
+ #endif
+
+ #if ENABLED(SERIAL_STATS_DROPPED_RX)
+ SERIAL_ECHOPAIR("\nDropped bytes: ", MYSERIAL0.dropped());
+ #endif
+
+ #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
+ SERIAL_ECHOPAIR("\nMax RX Queue Size: ", MYSERIAL0.rxMaxEnqueued());
+ #endif
+ #endif // !__AVR__ || !USBCON
+ }
+ SERIAL_EOL();
+}
diff --git a/Marlin/src/gcode/control/M120_M121.cpp b/Marlin/src/gcode/control/M120_M121.cpp
new file mode 100644
index 0000000..570f2e9
--- /dev/null
+++ b/Marlin/src/gcode/control/M120_M121.cpp
@@ -0,0 +1,34 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../gcode.h"
+#include "../../module/endstops.h"
+
+/**
+ * M120: Enable endstops and set non-homing endstop state to "enabled"
+ */
+void GcodeSuite::M120() { endstops.enable_globally(true); }
+
+/**
+ * M121: Disable endstops and set non-homing endstop state to "disabled"
+ */
+void GcodeSuite::M121() { endstops.enable_globally(false); }
diff --git a/Marlin/src/gcode/control/M17_M18_M84.cpp b/Marlin/src/gcode/control/M17_M18_M84.cpp
new file mode 100644
index 0000000..b35b465
--- /dev/null
+++ b/Marlin/src/gcode/control/M17_M18_M84.cpp
@@ -0,0 +1,69 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../gcode.h"
+#include "../../MarlinCore.h" // for stepper_inactive_time, disable_e_steppers
+#include "../../lcd/marlinui.h"
+#include "../../module/stepper.h"
+
+#if ENABLED(AUTO_BED_LEVELING_UBL)
+ #include "../../feature/bedlevel/bedlevel.h"
+#endif
+
+/**
+ * M17: Enable stepper motors
+ */
+void GcodeSuite::M17() {
+ if (parser.seen("XYZE")) {
+ if (parser.seen('X')) ENABLE_AXIS_X();
+ if (parser.seen('Y')) ENABLE_AXIS_Y();
+ if (parser.seen('Z')) ENABLE_AXIS_Z();
+ if (TERN0(HAS_E_STEPPER_ENABLE, parser.seen('E'))) enable_e_steppers();
+ }
+ else {
+ LCD_MESSAGEPGM(MSG_NO_MOVE);
+ enable_all_steppers();
+ }
+}
+
+/**
+ * M18, M84: Disable stepper motors
+ */
+void GcodeSuite::M18_M84() {
+ if (parser.seenval('S')) {
+ reset_stepper_timeout();
+ stepper_inactive_time = parser.value_millis_from_seconds();
+ }
+ else {
+ if (parser.seen("XYZE")) {
+ planner.synchronize();
+ if (parser.seen('X')) DISABLE_AXIS_X();
+ if (parser.seen('Y')) DISABLE_AXIS_Y();
+ if (parser.seen('Z')) DISABLE_AXIS_Z();
+ if (TERN0(HAS_E_STEPPER_ENABLE, parser.seen('E'))) disable_e_steppers();
+ }
+ else
+ planner.finish_and_disable();
+
+ TERN_(AUTO_BED_LEVELING_UBL, ubl.steppers_were_disabled());
+ }
+}
diff --git a/Marlin/src/gcode/control/M211.cpp b/Marlin/src/gcode/control/M211.cpp
new file mode 100644
index 0000000..2049f1e
--- /dev/null
+++ b/Marlin/src/gcode/control/M211.cpp
@@ -0,0 +1,46 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../inc/MarlinConfigPre.h"
+
+#if HAS_SOFTWARE_ENDSTOPS
+
+#include "../gcode.h"
+#include "../../module/motion.h"
+
+/**
+ * M211: Enable, Disable, and/or Report software endstops
+ *
+ * Usage: M211 S1 to enable, M211 S0 to disable, M211 alone for report
+ */
+void GcodeSuite::M211() {
+ const xyz_pos_t l_soft_min = soft_endstop.min.asLogical(),
+ l_soft_max = soft_endstop.max.asLogical();
+ SERIAL_ECHO_START();
+ SERIAL_ECHOPGM(STR_SOFT_ENDSTOPS);
+ if (parser.seen('S')) soft_endstop._enabled = parser.value_bool();
+ serialprint_onoff(soft_endstop._enabled);
+ print_xyz(l_soft_min, PSTR(STR_SOFT_MIN), PSTR(" "));
+ print_xyz(l_soft_max, PSTR(STR_SOFT_MAX));
+}
+
+#endif
diff --git a/Marlin/src/gcode/control/M226.cpp b/Marlin/src/gcode/control/M226.cpp
new file mode 100644
index 0000000..63f022e
--- /dev/null
+++ b/Marlin/src/gcode/control/M226.cpp
@@ -0,0 +1,60 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../inc/MarlinConfig.h"
+
+#if ENABLED(DIRECT_PIN_CONTROL)
+
+#include "../gcode.h"
+#include "../../MarlinCore.h" // for pin_is_protected and idle()
+#include "../../module/stepper.h"
+
+void protected_pin_err();
+
+/**
+ * M226: Wait until the specified pin reaches the state required (M226 P S)
+ */
+void GcodeSuite::M226() {
+ if (parser.seen('P')) {
+ const int pin_number = PARSED_PIN_INDEX('P', 0),
+ pin_state = parser.intval('S', -1); // required pin state - default is inverted
+ const pin_t pin = GET_PIN_MAP_PIN(pin_number);
+
+ if (WITHIN(pin_state, -1, 1) && pin > -1) {
+ if (pin_is_protected(pin))
+ protected_pin_err();
+ else {
+ int target = LOW;
+ planner.synchronize();
+ pinMode(pin, INPUT);
+ switch (pin_state) {
+ case 1: target = HIGH; break;
+ case 0: target = LOW; break;
+ case -1: target = !extDigitalRead(pin); break;
+ }
+ while (int(extDigitalRead(pin)) != target) idle();
+ }
+ } // pin_state -1 0 1 && pin > -1
+ } // parser.seen('P')
+}
+
+#endif // DIRECT_PIN_CONTROL
diff --git a/Marlin/src/gcode/control/M280.cpp b/Marlin/src/gcode/control/M280.cpp
new file mode 100644
index 0000000..6ccbb7b
--- /dev/null
+++ b/Marlin/src/gcode/control/M280.cpp
@@ -0,0 +1,55 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../inc/MarlinConfig.h"
+
+#if HAS_SERVOS
+
+#include "../gcode.h"
+#include "../../module/servo.h"
+
+/**
+ * M280: Get or set servo position. P [S]
+ */
+void GcodeSuite::M280() {
+ if (!parser.seen('P')) return;
+ const int servo_index = parser.value_int();
+ if (WITHIN(servo_index, 0, NUM_SERVOS - 1)) {
+ if (parser.seen('S')) {
+ const int a = parser.value_int();
+ if (a == -1)
+ servo[servo_index].detach();
+ else
+ MOVE_SERVO(servo_index, a);
+ }
+ else {
+ SERIAL_ECHO_START();
+ SERIAL_ECHOLNPAIR(" Servo ", servo_index, ": ", servo[servo_index].read());
+ }
+ }
+ else {
+ SERIAL_ERROR_START();
+ SERIAL_ECHOLNPAIR("Servo ", servo_index, " out of range");
+ }
+}
+
+#endif // HAS_SERVOS
diff --git a/Marlin/src/gcode/control/M3-M5.cpp b/Marlin/src/gcode/control/M3-M5.cpp
new file mode 100644
index 0000000..711bb7e
--- /dev/null
+++ b/Marlin/src/gcode/control/M3-M5.cpp
@@ -0,0 +1,140 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../inc/MarlinConfig.h"
+
+#if HAS_CUTTER
+
+#include "../gcode.h"
+#include "../../feature/spindle_laser.h"
+#include "../../module/stepper.h"
+
+/**
+ * Laser:
+ * M3 - Laser ON/Power (Ramped power)
+ * M4 - Laser ON/Power (Continuous power)
+ *
+ * Spindle:
+ * M3 - Spindle ON (Clockwise)
+ * M4 - Spindle ON (Counter-clockwise)
+ *
+ * Parameters:
+ * S - Set power. S0 will turn the spindle/laser off, except in relative mode.
+ * O - Set power and OCR (oscillator count register)
+ *
+ * If no PWM pin is defined then M3/M4 just turns it on.
+ *
+ * At least 12.8KHz (50Hz * 256) is needed for Spindle PWM.
+ * Hardware PWM is required on AVR. ISRs are too slow.
+ *
+ * NOTE: WGM for timers 3, 4, and 5 must be either Mode 1 or Mode 5.
+ * No other settings give a PWM signal that goes from 0 to 5 volts.
+ *
+ * The system automatically sets WGM to Mode 1, so no special
+ * initialization is needed.
+ *
+ * WGM bits for timer 2 are automatically set by the system to
+ * Mode 1. This produces an acceptable 0 to 5 volt signal.
+ * No special initialization is needed.
+ *
+ * NOTE: A minimum PWM frequency of 50 Hz is needed. All prescaler
+ * factors for timers 2, 3, 4, and 5 are acceptable.
+ *
+ * SPINDLE_LASER_ENA_PIN needs an external pullup or it may power on
+ * the spindle/laser during power-up or when connecting to the host
+ * (usually goes through a reset which sets all I/O pins to tri-state)
+ *
+ * PWM duty cycle goes from 0 (off) to 255 (always on).
+ */
+void GcodeSuite::M3_M4(const bool is_M4) {
+ auto get_s_power = [] {
+ if (parser.seenval('S')) {
+ const float spwr = parser.value_float();
+ #if ENABLED(SPINDLE_SERVO)
+ cutter.unitPower = spwr;
+ #else
+ cutter.unitPower = TERN(SPINDLE_LASER_PWM,
+ cutter.power_to_range(cutter_power_t(round(spwr))),
+ spwr > 0 ? 255 : 0);
+ #endif
+ }
+ else
+ cutter.unitPower = cutter.cpwr_to_upwr(SPEED_POWER_STARTUP);
+ return cutter.unitPower;
+ };
+
+ #if ENABLED(LASER_POWER_INLINE)
+ if (parser.seen('I') == DISABLED(LASER_POWER_INLINE_INVERT)) {
+ // Laser power in inline mode
+ cutter.inline_direction(is_M4); // Should always be unused
+ #if ENABLED(SPINDLE_LASER_PWM)
+ if (parser.seen('O')) {
+ cutter.unitPower = cutter.power_to_range(parser.value_byte(), 0);
+ cutter.inline_ocr_power(cutter.unitPower); // The OCR is a value from 0 to 255 (uint8_t)
+ }
+ else
+ cutter.inline_power(cutter.upower_to_ocr(get_s_power()));
+ #else
+ cutter.set_inline_enabled(true);
+ #endif
+ return;
+ }
+ // Non-inline, standard case
+ cutter.inline_disable(); // Prevent future blocks re-setting the power
+ #endif
+
+ planner.synchronize(); // Wait for previous movement commands (G0/G0/G2/G3) to complete before changing power
+ cutter.set_reverse(is_M4);
+
+ #if ENABLED(SPINDLE_LASER_PWM)
+ if (parser.seenval('O')) {
+ cutter.unitPower = cutter.power_to_range(parser.value_byte(), 0);
+ cutter.set_ocr_power(cutter.unitPower); // The OCR is a value from 0 to 255 (uint8_t)
+ }
+ else
+ cutter.set_power(cutter.upower_to_ocr(get_s_power()));
+ #elif ENABLED(SPINDLE_SERVO)
+ cutter.set_power(get_s_power());
+ #else
+ cutter.set_enabled(true);
+ #endif
+ cutter.menuPower = cutter.unitPower;
+}
+
+/**
+ * M5 - Cutter OFF (when moves are complete)
+ */
+void GcodeSuite::M5() {
+ #if ENABLED(LASER_POWER_INLINE)
+ if (parser.seen('I') == DISABLED(LASER_POWER_INLINE_INVERT)) {
+ cutter.set_inline_enabled(false); // Laser power in inline mode
+ return;
+ }
+ // Non-inline, standard case
+ cutter.inline_disable(); // Prevent future blocks re-setting the power
+ #endif
+ planner.synchronize();
+ cutter.set_enabled(false);
+ cutter.menuPower = cutter.unitPower;
+}
+
+#endif // HAS_CUTTER
diff --git a/Marlin/src/gcode/control/M350_M351.cpp b/Marlin/src/gcode/control/M350_M351.cpp
new file mode 100644
index 0000000..463bd2a
--- /dev/null
+++ b/Marlin/src/gcode/control/M350_M351.cpp
@@ -0,0 +1,64 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../inc/MarlinConfig.h"
+
+#if HAS_MICROSTEPS
+
+#include "../gcode.h"
+#include "../../module/stepper.h"
+
+/**
+ * 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_XYZE(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());
+ 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.
+ */
+void GcodeSuite::M351() {
+ if (parser.seenval('S')) switch (parser.value_byte()) {
+ case 1:
+ LOOP_XYZE(i) if (parser.seenval(axis_codes[i])) stepper.microstep_ms(i, parser.value_byte(), -1, -1);
+ if (parser.seenval('B')) stepper.microstep_ms(4, parser.value_byte(), -1, -1);
+ break;
+ case 2:
+ LOOP_XYZE(i) if (parser.seenval(axis_codes[i])) stepper.microstep_ms(i, -1, parser.value_byte(), -1);
+ if (parser.seenval('B')) stepper.microstep_ms(4, -1, parser.value_byte(), -1);
+ break;
+ case 3:
+ LOOP_XYZE(i) if (parser.seenval(axis_codes[i])) stepper.microstep_ms(i, -1, -1, parser.value_byte());
+ if (parser.seenval('B')) stepper.microstep_ms(4, -1, -1, parser.value_byte());
+ break;
+ }
+ stepper.microstep_readings();
+}
+
+#endif // HAS_MICROSTEPS
diff --git a/Marlin/src/gcode/control/M380_M381.cpp b/Marlin/src/gcode/control/M380_M381.cpp
new file mode 100644
index 0000000..3f5b252
--- /dev/null
+++ b/Marlin/src/gcode/control/M380_M381.cpp
@@ -0,0 +1,56 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../inc/MarlinConfig.h"
+
+#if EITHER(EXT_SOLENOID, MANUAL_SOLENOID_CONTROL)
+
+#include "../gcode.h"
+#include "../../feature/solenoid.h"
+#include "../../module/motion.h"
+
+/**
+ * M380: Enable solenoid on the active extruder
+ *
+ * S to specify a solenoid (Requires MANUAL_SOLENOID_CONTROL)
+ */
+void GcodeSuite::M380() {
+ #if ENABLED(MANUAL_SOLENOID_CONTROL)
+ enable_solenoid(parser.intval('S', active_extruder));
+ #else
+ enable_solenoid_on_active_extruder();
+ #endif
+}
+
+/**
+ * M381: Disable all solenoids if EXT_SOLENOID
+ * Disable selected/active solenoid if MANUAL_SOLENOID_CONTROL
+ */
+void GcodeSuite::M381() {
+ #if ENABLED(MANUAL_SOLENOID_CONTROL)
+ disable_solenoid(parser.intval('S', active_extruder));
+ #else
+ disable_all_solenoids();
+ #endif
+}
+
+#endif // EXT_SOLENOID || MANUAL_SOLENOID_CONTROL
diff --git a/Marlin/src/gcode/control/M400.cpp b/Marlin/src/gcode/control/M400.cpp
new file mode 100644
index 0000000..9a5ad4e
--- /dev/null
+++ b/Marlin/src/gcode/control/M400.cpp
@@ -0,0 +1,33 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../gcode.h"
+#include "../../module/stepper.h"
+
+/**
+ * M400: Finish all moves
+ */
+void GcodeSuite::M400() {
+
+ planner.synchronize();
+
+}
diff --git a/Marlin/src/gcode/control/M42.cpp b/Marlin/src/gcode/control/M42.cpp
new file mode 100644
index 0000000..6ef8455
--- /dev/null
+++ b/Marlin/src/gcode/control/M42.cpp
@@ -0,0 +1,107 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../inc/MarlinConfig.h"
+
+#if ENABLED(DIRECT_PIN_CONTROL)
+
+#include "../gcode.h"
+#include "../../MarlinCore.h" // for pin_is_protected
+
+#if HAS_FAN
+ #include "../../module/temperature.h"
+#endif
+
+void protected_pin_err() {
+ SERIAL_ERROR_MSG(STR_ERR_PROTECTED_PIN);
+}
+
+/**
+ * M42: Change pin status via GCode
+ *
+ * P Pin number (LED if omitted)
+ * For LPC1768 specify pin P1_02 as M42 P102,
+ * P1_20 as M42 P120, etc.
+ *
+ * S Pin status from 0 - 255
+ * I Flag to ignore Marlin's pin protection
+ *
+ * M Pin mode: 0=INPUT 1=OUTPUT 2=INPUT_PULLUP 3=INPUT_PULLDOWN
+ */
+void GcodeSuite::M42() {
+ const int pin_index = PARSED_PIN_INDEX('P', GET_PIN_MAP_INDEX(LED_PIN));
+ if (pin_index < 0) return;
+
+ const pin_t pin = GET_PIN_MAP_PIN(pin_index);
+
+ if (!parser.boolval('I') && pin_is_protected(pin)) return protected_pin_err();
+
+ if (parser.seenval('M')) {
+ switch (parser.value_byte()) {
+ case 0: pinMode(pin, INPUT); break;
+ case 1: pinMode(pin, OUTPUT); break;
+ case 2: pinMode(pin, INPUT_PULLUP); break;
+ #ifdef INPUT_PULLDOWN
+ case 3: pinMode(pin, INPUT_PULLDOWN); break;
+ #endif
+ default: SERIAL_ECHOLNPGM("Invalid Pin Mode"); return;
+ }
+ }
+
+ if (!parser.seenval('S')) return;
+ const byte pin_status = parser.value_byte();
+
+ #if HAS_FAN
+ switch (pin) {
+ #if HAS_FAN0
+ case FAN0_PIN: thermalManager.fan_speed[0] = pin_status; return;
+ #endif
+ #if HAS_FAN1
+ case FAN1_PIN: thermalManager.fan_speed[1] = pin_status; return;
+ #endif
+ #if HAS_FAN2
+ case FAN2_PIN: thermalManager.fan_speed[2] = pin_status; return;
+ #endif
+ #if HAS_FAN3
+ case FAN3_PIN: thermalManager.fan_speed[3] = pin_status; return;
+ #endif
+ #if HAS_FAN4
+ case FAN4_PIN: thermalManager.fan_speed[4] = pin_status; return;
+ #endif
+ #if HAS_FAN5
+ case FAN5_PIN: thermalManager.fan_speed[5] = pin_status; return;
+ #endif
+ #if HAS_FAN6
+ case FAN6_PIN: thermalManager.fan_speed[6] = pin_status; return;
+ #endif
+ #if HAS_FAN7
+ case FAN7_PIN: thermalManager.fan_speed[7] = pin_status; return;
+ #endif
+ }
+ #endif
+
+ pinMode(pin, OUTPUT);
+ extDigitalWrite(pin, pin_status);
+ analogWrite(pin, pin_status);
+}
+
+#endif // DIRECT_PIN_CONTROL
diff --git a/Marlin/src/gcode/control/M605.cpp b/Marlin/src/gcode/control/M605.cpp
new file mode 100644
index 0000000..0d7a9f4
--- /dev/null
+++ b/Marlin/src/gcode/control/M605.cpp
@@ -0,0 +1,185 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../inc/MarlinConfig.h"
+
+#if HAS_DUPLICATION_MODE
+
+//#define DEBUG_DXC_MODE
+
+#include "../gcode.h"
+#include "../../module/motion.h"
+#include "../../module/stepper.h"
+#include "../../module/tool_change.h"
+#include "../../module/planner.h"
+
+#define DEBUG_OUT ENABLED(DEBUG_DXC_MODE)
+#include "../../core/debug_out.h"
+
+#if ENABLED(DUAL_X_CARRIAGE)
+
+ /**
+ * M605: Set dual x-carriage movement mode
+ *
+ * M605 S0 : (FULL_CONTROL) The slicer has full control over both X-carriages and can achieve optimal travel
+ * results as long as it supports dual X-carriages.
+ *
+ * M605 S1 : (AUTO_PARK) The firmware automatically parks and unparks the X-carriages on tool-change so that
+ * additional slicer support is not required.
+ *
+ * M605 S2 X R : (DUPLICATION) The firmware moves the second X-carriage and extruder in synchronization with
+ * the first X-carriage and extruder, to print 2 copies of the same object at the same time.
+ * Set the constant X-offset and temperature differential with M605 S2 X[offs] R[deg] and
+ * follow with "M605 S2" to initiate duplicated movement. For example, use "M605 S2 X100 R2" to
+ * make a copy 100mm to the right with E1 2° hotter than E0.
+ *
+ * M605 S3 : (MIRRORED) Formbot/Vivedino-inspired mirrored mode in which the second extruder duplicates
+ * the movement of the first except the second extruder is reversed in the X axis.
+ * The temperature differential and initial X offset must be set with "M605 S2 X[offs] R[deg]",
+ * then followed by "M605 S3" to initiate mirrored movement.
+ *
+ * M605 W : IDEX What? command.
+ *
+ * Note: the X axis should be homed after changing Dual X-carriage mode.
+ */
+ void GcodeSuite::M605() {
+ planner.synchronize();
+
+ if (parser.seen('S')) {
+ const DualXMode previous_mode = dual_x_carriage_mode;
+
+ dual_x_carriage_mode = (DualXMode)parser.value_byte();
+ idex_set_mirrored_mode(false);
+
+ if (dual_x_carriage_mode == DXC_MIRRORED_MODE) {
+ if (previous_mode != DXC_DUPLICATION_MODE) {
+ SERIAL_ECHOLNPGM("Printer must be in DXC_DUPLICATION_MODE prior to ");
+ SERIAL_ECHOLNPGM("specifying DXC_MIRRORED_MODE.");
+ dual_x_carriage_mode = DEFAULT_DUAL_X_CARRIAGE_MODE;
+ return;
+ }
+ idex_set_mirrored_mode(true);
+ float x_jog = current_position.x - .1;
+ for (uint8_t i = 2; --i;) {
+ planner.buffer_line(x_jog, current_position.y, current_position.z, current_position.e, feedrate_mm_s, 0);
+ x_jog += .1;
+ }
+ return;
+ }
+
+ switch (dual_x_carriage_mode) {
+ case DXC_FULL_CONTROL_MODE:
+ case DXC_AUTO_PARK_MODE:
+ break;
+ case DXC_DUPLICATION_MODE:
+ // Set the X offset, but no less than the safety gap
+ if (parser.seen('X')) duplicate_extruder_x_offset = _MAX(parser.value_linear_units(), (X2_MIN_POS) - (X1_MIN_POS));
+ if (parser.seen('R')) duplicate_extruder_temp_offset = parser.value_celsius_diff();
+ // Always switch back to tool 0
+ if (active_extruder != 0) tool_change(0);
+ break;
+ default:
+ dual_x_carriage_mode = DEFAULT_DUAL_X_CARRIAGE_MODE;
+ break;
+ }
+ idex_set_parked(false);
+ set_duplication_enabled(false);
+
+ #ifdef EVENT_GCODE_IDEX_AFTER_MODECHANGE
+ gcode.process_subcommands_now_P(PSTR(EVENT_GCODE_IDEX_AFTER_MODECHANGE));
+ #endif
+ }
+ else if (!parser.seen('W')) // if no S or W parameter, the DXC mode gets reset to the user's default
+ dual_x_carriage_mode = DEFAULT_DUAL_X_CARRIAGE_MODE;
+
+ #ifdef DEBUG_DXC_MODE
+
+ if (parser.seen('W')) {
+ DEBUG_ECHO_START();
+ DEBUG_ECHOPGM("Dual X Carriage Mode ");
+ switch (dual_x_carriage_mode) {
+ case DXC_FULL_CONTROL_MODE: DEBUG_ECHOPGM("FULL_CONTROL"); break;
+ case DXC_AUTO_PARK_MODE: DEBUG_ECHOPGM("AUTO_PARK"); break;
+ case DXC_DUPLICATION_MODE: DEBUG_ECHOPGM("DUPLICATION"); break;
+ case DXC_MIRRORED_MODE: DEBUG_ECHOPGM("MIRRORED"); break;
+ }
+ DEBUG_ECHOPAIR("\nActive Ext: ", int(active_extruder));
+ if (!active_extruder_parked) DEBUG_ECHOPGM(" NOT ");
+ DEBUG_ECHOPGM(" parked.");
+ DEBUG_ECHOPAIR("\nactive_extruder_x_pos: ", current_position.x);
+ DEBUG_ECHOPAIR("\ninactive_extruder_x: ", inactive_extruder_x);
+ DEBUG_ECHOPAIR("\nextruder_duplication_enabled: ", int(extruder_duplication_enabled));
+ DEBUG_ECHOPAIR("\nduplicate_extruder_x_offset: ", duplicate_extruder_x_offset);
+ DEBUG_ECHOPAIR("\nduplicate_extruder_temp_offset: ", duplicate_extruder_temp_offset);
+ DEBUG_ECHOPAIR("\ndelayed_move_time: ", delayed_move_time);
+ DEBUG_ECHOPAIR("\nX1 Home X: ", x_home_pos(0), "\nX1_MIN_POS=", int(X1_MIN_POS), "\nX1_MAX_POS=", int(X1_MAX_POS));
+ DEBUG_ECHOPAIR("\nX2 Home X: ", x_home_pos(1), "\nX2_MIN_POS=", int(X2_MIN_POS), "\nX2_MAX_POS=", int(X2_MAX_POS));
+ DEBUG_ECHOPAIR("\nX2_HOME_DIR=", int(X2_HOME_DIR), "\nX2_HOME_POS=", int(X2_HOME_POS));
+ DEBUG_ECHOPAIR("\nDEFAULT_DUAL_X_CARRIAGE_MODE=", STRINGIFY(DEFAULT_DUAL_X_CARRIAGE_MODE));
+ DEBUG_ECHOPAIR("\toolchange_settings.z_raise=", toolchange_settings.z_raise);
+ DEBUG_ECHOPAIR("\nDEFAULT_DUPLICATION_X_OFFSET=", int(DEFAULT_DUPLICATION_X_OFFSET));
+ DEBUG_EOL();
+
+ HOTEND_LOOP() {
+ DEBUG_ECHOPAIR_P(SP_T_STR, int(e));
+ LOOP_XYZ(a) DEBUG_ECHOPAIR(" hotend_offset[", int(e), "].", XYZ_CHAR(a) | 0x20, "=", hotend_offset[e][a]);
+ DEBUG_EOL();
+ }
+ DEBUG_EOL();
+ }
+ #endif // DEBUG_DXC_MODE
+ }
+
+#elif ENABLED(MULTI_NOZZLE_DUPLICATION)
+
+ /**
+ * M605: Set multi-nozzle duplication mode
+ *
+ * S2 - Enable duplication mode
+ * P[mask] - Bit-mask of nozzles to include in the duplication set.
+ * A value of 0 disables duplication.
+ * E[index] - Last nozzle index to include in the duplication set.
+ * A value of 0 disables duplication.
+ */
+ void GcodeSuite::M605() {
+ bool ena = false;
+ if (parser.seen("EPS")) {
+ planner.synchronize();
+ if (parser.seenval('P')) duplication_e_mask = parser.value_int(); // Set the mask directly
+ else if (parser.seenval('E')) duplication_e_mask = pow(2, parser.value_int() + 1) - 1; // Set the mask by E index
+ ena = (2 == parser.intval('S', extruder_duplication_enabled ? 2 : 0));
+ set_duplication_enabled(ena && (duplication_e_mask >= 3));
+ }
+ SERIAL_ECHO_START();
+ SERIAL_ECHOPGM(STR_DUPLICATION_MODE);
+ serialprint_onoff(extruder_duplication_enabled);
+ if (ena) {
+ SERIAL_ECHOPGM(" ( ");
+ HOTEND_LOOP() if (TEST(duplication_e_mask, e)) { SERIAL_ECHO(e); SERIAL_CHAR(' '); }
+ SERIAL_CHAR(')');
+ }
+ SERIAL_EOL();
+ }
+
+#endif // MULTI_NOZZLE_DUPLICATION
+
+#endif // HAS_DUPICATION_MODE
diff --git a/Marlin/src/gcode/control/M7-M9.cpp b/Marlin/src/gcode/control/M7-M9.cpp
new file mode 100644
index 0000000..a33e432
--- /dev/null
+++ b/Marlin/src/gcode/control/M7-M9.cpp
@@ -0,0 +1,63 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../inc/MarlinConfig.h"
+
+#if ENABLED(COOLANT_CONTROL)
+
+#include "../gcode.h"
+#include "../../module/planner.h"
+
+#if ENABLED(COOLANT_MIST)
+ /**
+ * M7: Mist Coolant On
+ */
+ void GcodeSuite::M7() {
+ planner.synchronize(); // Wait for move to arrive
+ WRITE(COOLANT_MIST_PIN, !(COOLANT_MIST_INVERT)); // Turn on Mist coolant
+ }
+#endif
+
+#if ENABLED(COOLANT_FLOOD)
+ /**
+ * M8: Flood Coolant On
+ */
+ void GcodeSuite::M8() {
+ planner.synchronize(); // Wait for move to arrive
+ WRITE(COOLANT_FLOOD_PIN, !(COOLANT_FLOOD_INVERT)); // Turn on Flood coolant
+ }
+#endif
+
+/**
+ * M9: Coolant OFF
+ */
+void GcodeSuite::M9() {
+ planner.synchronize(); // Wait for move to arrive
+ #if ENABLED(COOLANT_MIST)
+ WRITE(COOLANT_MIST_PIN, COOLANT_MIST_INVERT); // Turn off Mist coolant
+ #endif
+ #if ENABLED(COOLANT_FLOOD)
+ WRITE(COOLANT_FLOOD_PIN, COOLANT_FLOOD_INVERT); // Turn off Flood coolant
+ #endif
+}
+
+#endif // COOLANT_CONTROL
diff --git a/Marlin/src/gcode/control/M80_M81.cpp b/Marlin/src/gcode/control/M80_M81.cpp
new file mode 100644
index 0000000..394b06d
--- /dev/null
+++ b/Marlin/src/gcode/control/M80_M81.cpp
@@ -0,0 +1,113 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../gcode.h"
+
+#include "../../module/temperature.h"
+#include "../../module/planner.h" // for planner.finish_and_disable
+#include "../../module/printcounter.h" // for print_job_timer.stop
+#include "../../lcd/marlinui.h" // for LCD_MESSAGEPGM_P
+
+#include "../../inc/MarlinConfig.h"
+
+#if HAS_SUICIDE
+ #include "../../MarlinCore.h"
+#endif
+
+#if ENABLED(PSU_CONTROL)
+
+ #if ENABLED(AUTO_POWER_CONTROL)
+ #include "../../feature/power.h"
+ #else
+ void restore_stepper_drivers();
+ #endif
+
+ // Could be moved to a feature, but this is all the data
+ bool powersupply_on;
+
+ #if HAS_TRINAMIC_CONFIG
+ #include "../../feature/tmc_util.h"
+ #endif
+
+ /**
+ * M80 : Turn on the Power Supply
+ * M80 S : Report the current state and exit
+ */
+ void GcodeSuite::M80() {
+
+ // S: Report the current power supply state and exit
+ if (parser.seen('S')) {
+ serialprintPGM(powersupply_on ? PSTR("PS:1\n") : PSTR("PS:0\n"));
+ return;
+ }
+
+ PSU_ON();
+
+ /**
+ * If you have a switch on suicide pin, this is useful
+ * if you want to start another print with suicide feature after
+ * a print without suicide...
+ */
+ #if HAS_SUICIDE
+ OUT_WRITE(SUICIDE_PIN, !SUICIDE_PIN_INVERTING);
+ #endif
+
+ #if DISABLED(AUTO_POWER_CONTROL)
+ safe_delay(PSU_POWERUP_DELAY);
+ restore_stepper_drivers();
+ TERN_(HAS_TRINAMIC_CONFIG, safe_delay(PSU_POWERUP_DELAY));
+ #endif
+
+ TERN_(HAS_LCD_MENU, ui.reset_status());
+ }
+
+#endif // PSU_CONTROL
+
+/**
+ * M81: Turn off Power, including Power Supply, if there is one.
+ *
+ * This code should ALWAYS be available for FULL SHUTDOWN!
+ */
+void GcodeSuite::M81() {
+ thermalManager.disable_all_heaters();
+ planner.finish_and_disable();
+
+ print_job_timer.stop();
+
+ #if HAS_FAN
+ thermalManager.zero_fan_speeds();
+ #if ENABLED(PROBING_FANS_OFF)
+ thermalManager.fans_paused = false;
+ ZERO(thermalManager.saved_fan_speed);
+ #endif
+ #endif
+
+ safe_delay(1000); // Wait 1 second before switching off
+
+ #if HAS_SUICIDE
+ suicide();
+ #elif ENABLED(PSU_CONTROL)
+ PSU_OFF_SOON();
+ #endif
+
+ LCD_MESSAGEPGM_P(PSTR(MACHINE_NAME " " STR_OFF "."));
+}
diff --git a/Marlin/src/gcode/control/M85.cpp b/Marlin/src/gcode/control/M85.cpp
new file mode 100644
index 0000000..9c8c02c
--- /dev/null
+++ b/Marlin/src/gcode/control/M85.cpp
@@ -0,0 +1,35 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../gcode.h"
+
+/**
+ * M85: Set inactivity shutdown timer with parameter S. To disable set zero (default)
+ */
+void GcodeSuite::M85() {
+
+ if (parser.seen('S')) {
+ reset_stepper_timeout();
+ max_inactive_time = parser.value_millis_from_seconds();
+ }
+
+}
diff --git a/Marlin/src/gcode/control/M993_M994.cpp b/Marlin/src/gcode/control/M993_M994.cpp
new file mode 100644
index 0000000..ff9ff85
--- /dev/null
+++ b/Marlin/src/gcode/control/M993_M994.cpp
@@ -0,0 +1,88 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../inc/MarlinConfig.h"
+
+#if ALL(HAS_SPI_FLASH, SDSUPPORT, MARLIN_DEV_MODE)
+
+#include "../gcode.h"
+#include "../../sd/cardreader.h"
+#include "../../libs/W25Qxx.h"
+
+/**
+ * M993: Backup SPI Flash to SD
+ */
+void GcodeSuite::M993() {
+ if (!card.isMounted()) card.mount();
+
+ char fname[] = "spiflash.bin";
+ card.openFileWrite(fname);
+ if (!card.isFileOpen()) {
+ SERIAL_ECHOLNPAIR("Failed to open ", fname, " to write.");
+ return;
+ }
+
+ uint8_t buf[1024];
+ uint32_t addr = 0;
+ W25QXX.init(SPI_QUARTER_SPEED);
+ SERIAL_ECHOPGM("Save SPI Flash");
+ while (addr < SPI_FLASH_SIZE) {
+ W25QXX.SPI_FLASH_BufferRead(buf, addr, COUNT(buf));
+ addr += COUNT(buf);
+ card.write(buf, COUNT(buf));
+ if (addr % (COUNT(buf) * 10) == 0) SERIAL_CHAR('.');
+ }
+ SERIAL_ECHOLNPGM(" done");
+
+ card.closefile();
+}
+
+/**
+ * M994: Load a backup from SD to SPI Flash
+ */
+void GcodeSuite::M994() {
+ if (!card.isMounted()) card.mount();
+
+ char fname[] = "spiflash.bin";
+ card.openFileRead(fname);
+ if (!card.isFileOpen()) {
+ SERIAL_ECHOLNPAIR("Failed to open ", fname, " to read.");
+ return;
+ }
+
+ uint8_t buf[1024];
+ uint32_t addr = 0;
+ W25QXX.init(SPI_QUARTER_SPEED);
+ W25QXX.SPI_FLASH_BulkErase();
+ SERIAL_ECHOPGM("Load SPI Flash");
+ while (addr < SPI_FLASH_SIZE) {
+ card.read(buf, COUNT(buf));
+ W25QXX.SPI_FLASH_BufferWrite(buf, addr, COUNT(buf));
+ addr += COUNT(buf);
+ if (addr % (COUNT(buf) * 10) == 0) SERIAL_CHAR('.');
+ }
+ SERIAL_ECHOLNPGM(" done");
+
+ card.closefile();
+}
+
+#endif // HAS_SPI_FLASH && SDSUPPORT && MARLIN_DEV_MODE
diff --git a/Marlin/src/gcode/control/M997.cpp b/Marlin/src/gcode/control/M997.cpp
new file mode 100644
index 0000000..cdff96f
--- /dev/null
+++ b/Marlin/src/gcode/control/M997.cpp
@@ -0,0 +1,36 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../gcode.h"
+
+#if ENABLED(PLATFORM_M997_SUPPORT)
+
+/**
+ * M997: Perform in-application firmware update
+ */
+void GcodeSuite::M997() {
+
+ flashFirmware(parser.intval('S'));
+
+}
+
+#endif
diff --git a/Marlin/src/gcode/control/M999.cpp b/Marlin/src/gcode/control/M999.cpp
new file mode 100644
index 0000000..7487b4c
--- /dev/null
+++ b/Marlin/src/gcode/control/M999.cpp
@@ -0,0 +1,45 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../gcode.h"
+
+#include "../../lcd/marlinui.h" // for lcd_reset_alert_level
+#include "../../MarlinCore.h" // for marlin_state
+#include "../queue.h" // for flush_and_request_resend
+
+/**
+ * M999: Restart after being stopped
+ *
+ * Default behavior is to flush the serial buffer and request
+ * a resend to the host starting on the last N line received.
+ *
+ * Sending "M999 S1" will resume printing without flushing the
+ * existing command buffer.
+ */
+void GcodeSuite::M999() {
+ marlin_state = MF_RUNNING;
+ ui.reset_alert_level();
+
+ if (parser.boolval('S')) return;
+
+ queue.flush_and_request_resend();
+}
diff --git a/Marlin/src/gcode/control/T.cpp b/Marlin/src/gcode/control/T.cpp
new file mode 100644
index 0000000..3ce284f
--- /dev/null
+++ b/Marlin/src/gcode/control/T.cpp
@@ -0,0 +1,70 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../gcode.h"
+#include "../../module/tool_change.h"
+
+#if EITHER(HAS_MULTI_EXTRUDER, DEBUG_LEVELING_FEATURE)
+ #include "../../module/motion.h"
+#endif
+
+#if HAS_PRUSA_MMU2
+ #include "../../feature/mmu/mmu2.h"
+#endif
+
+#define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE)
+#include "../../core/debug_out.h"
+
+/**
+ * T0-T: Switch tool, usually switching extruders
+ *
+ * F[units/min] Set the movement feedrate
+ * S1 Don't move the tool in XY after change
+ *
+ * For PRUSA_MMU2(S) and SMUFF_EMU_MMU2(S)
+ * T[n] Gcode to extrude at least 38.10 mm at feedrate 19.02 mm/s must follow immediately to load to extruder wheels.
+ * T? Gcode to extrude shouldn't have to follow. Load to extruder wheels is done automatically.
+ * Tx Same as T?, but nozzle doesn't have to be preheated. Tc requires a preheated nozzle to finish filament load.
+ * Tc Load to nozzle after filament was prepared by Tc and nozzle is already heated.
+ */
+void GcodeSuite::T(const int8_t tool_index) {
+
+ DEBUG_SECTION(log_T, "T", DEBUGGING(LEVELING));
+ if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("...(", tool_index, ")");
+
+ // Count this command as movement / activity
+ reset_stepper_timeout();
+
+ #if HAS_PRUSA_MMU2
+ if (parser.string_arg) {
+ mmu2.tool_change(parser.string_arg); // Special commands T?/Tx/Tc
+ return;
+ }
+ #endif
+
+ tool_change(tool_index
+ #if HAS_MULTI_EXTRUDER
+ , TERN(PARKING_EXTRUDER, false, tool_index == active_extruder) // For PARKING_EXTRUDER motion is decided in tool_change()
+ || parser.boolval('S')
+ #endif
+ );
+}
diff --git a/Marlin/src/gcode/eeprom/M500-M504.cpp b/Marlin/src/gcode/eeprom/M500-M504.cpp
new file mode 100644
index 0000000..26c50a6
--- /dev/null
+++ b/Marlin/src/gcode/eeprom/M500-M504.cpp
@@ -0,0 +1,104 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../gcode.h"
+#include "../../module/settings.h"
+#include "../../core/serial.h"
+#include "../../inc/MarlinConfig.h"
+
+/**
+ * M500: Store settings in EEPROM
+ */
+void GcodeSuite::M500() {
+ (void)settings.save();
+}
+
+/**
+ * M501: Read settings from EEPROM
+ */
+void GcodeSuite::M501() {
+ (void)settings.load();
+}
+
+/**
+ * M502: Revert to default settings
+ */
+void GcodeSuite::M502() {
+ (void)settings.reset();
+}
+
+#if DISABLED(DISABLE_M503)
+
+ /**
+ * M503: print settings currently in memory
+ */
+ void GcodeSuite::M503() {
+ (void)settings.report(!parser.boolval('S', true));
+ }
+
+#endif // !DISABLE_M503
+
+#if ENABLED(EEPROM_SETTINGS)
+
+ #if ENABLED(MARLIN_DEV_MODE)
+ #include "../../libs/hex_print.h"
+ #endif
+
+ /**
+ * M504: Validate EEPROM Contents
+ */
+ void GcodeSuite::M504() {
+ #if ENABLED(MARLIN_DEV_MODE)
+ const bool dowrite = parser.seenval('W');
+ if (dowrite || parser.seenval('R')) {
+ uint8_t val = 0;
+ int addr = parser.value_ushort();
+ if (dowrite) {
+ val = parser.byteval('V');
+ persistentStore.write_data(addr, &val);
+ SERIAL_ECHOLNPAIR("Wrote address ", addr, " with ", int(val));
+ }
+ else {
+ if (parser.seenval('T')) {
+ const int endaddr = parser.value_ushort();
+ while (addr <= endaddr) {
+ persistentStore.read_data(addr, &val);
+ SERIAL_ECHOLNPAIR("0x", hex_word(addr), ":", hex_byte(val));
+ addr++;
+ safe_delay(10);
+ }
+ SERIAL_EOL();
+ }
+ else {
+ persistentStore.read_data(addr, &val);
+ SERIAL_ECHOLNPAIR("Read address ", addr, " and got ", int(val));
+ }
+ }
+ return;
+ }
+ #endif
+
+ if (settings.validate())
+ SERIAL_ECHO_MSG("EEPROM OK");
+ }
+
+#endif
diff --git a/Marlin/src/gcode/feature/L6470/M122.cpp b/Marlin/src/gcode/feature/L6470/M122.cpp
new file mode 100644
index 0000000..d2b7f73
--- /dev/null
+++ b/Marlin/src/gcode/feature/L6470/M122.cpp
@@ -0,0 +1,151 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if HAS_L64XX
+
+#include "../../gcode.h"
+#include "../../../libs/L64XX/L64XX_Marlin.h"
+#include "../../../module/stepper/indirection.h"
+
+void echo_yes_no(const bool yes);
+
+inline void L6470_say_status(const L64XX_axis_t axis) {
+ if (L64xxManager.spi_abort) return;
+ const L64XX_Marlin::L64XX_shadow_t &sh = L64xxManager.shadow;
+ L64xxManager.get_status(axis);
+ L64xxManager.say_axis(axis);
+ #if ENABLED(L6470_CHITCHAT)
+ char temp_buf[20];
+ sprintf_P(temp_buf, PSTR(" status: %4x "), sh.STATUS_AXIS_RAW);
+ SERIAL_ECHO(temp_buf);
+ print_bin(sh.STATUS_AXIS_RAW);
+ switch (sh.STATUS_AXIS_LAYOUT) {
+ case L6470_STATUS_LAYOUT: serialprintPGM(PSTR(" L6470")); break;
+ case L6474_STATUS_LAYOUT: serialprintPGM(PSTR(" L6474")); break;
+ case L6480_STATUS_LAYOUT: serialprintPGM(PSTR(" L6480/powerSTEP01")); break;
+ }
+ #endif
+ SERIAL_ECHOPGM("\n...OUTPUT: ");
+ serialprintPGM(sh.STATUS_AXIS & STATUS_HIZ ? PSTR("OFF") : PSTR("ON "));
+ SERIAL_ECHOPGM(" BUSY: "); echo_yes_no((sh.STATUS_AXIS & STATUS_BUSY) == 0);
+ SERIAL_ECHOPGM(" DIR: ");
+ serialprintPGM((((sh.STATUS_AXIS & STATUS_DIR) >> 4) ^ L64xxManager.index_to_dir[axis]) ? PSTR("FORWARD") : PSTR("REVERSE"));
+ if (sh.STATUS_AXIS_LAYOUT == L6480_STATUS_LAYOUT) {
+ SERIAL_ECHOPGM(" Last Command: ");
+ if (sh.STATUS_AXIS & sh.STATUS_AXIS_WRONG_CMD) SERIAL_ECHOPGM("VALID");
+ else SERIAL_ECHOPGM("ERROR");
+ SERIAL_ECHOPGM("\n...THERMAL: ");
+ switch ((sh.STATUS_AXIS & (sh.STATUS_AXIS_TH_SD | sh.STATUS_AXIS_TH_WRN)) >> 11) {
+ case 0: SERIAL_ECHOPGM("DEVICE SHUTDOWN"); break;
+ case 1: SERIAL_ECHOPGM("BRIDGE SHUTDOWN"); break;
+ case 2: SERIAL_ECHOPGM("WARNING "); break;
+ case 3: SERIAL_ECHOPGM("OK "); break;
+ }
+ }
+ else {
+ SERIAL_ECHOPGM(" Last Command: ");
+ if (!(sh.STATUS_AXIS & sh.STATUS_AXIS_WRONG_CMD)) SERIAL_ECHOPGM("IN");
+ SERIAL_ECHOPGM("VALID ");
+ serialprintPGM(sh.STATUS_AXIS & sh.STATUS_AXIS_NOTPERF_CMD ? PSTR("COMPLETED ") : PSTR("Not PERFORMED"));
+ SERIAL_ECHOPAIR("\n...THERMAL: ", !(sh.STATUS_AXIS & sh.STATUS_AXIS_TH_SD) ? "SHUTDOWN " : !(sh.STATUS_AXIS & sh.STATUS_AXIS_TH_WRN) ? "WARNING " : "OK ");
+ }
+ SERIAL_ECHOPGM(" OVERCURRENT:"); echo_yes_no((sh.STATUS_AXIS & sh.STATUS_AXIS_OCD) == 0);
+ if (sh.STATUS_AXIS_LAYOUT != L6474_STATUS_LAYOUT) {
+ SERIAL_ECHOPGM(" STALL:"); echo_yes_no((sh.STATUS_AXIS & sh.STATUS_AXIS_STEP_LOSS_A) == 0 || (sh.STATUS_AXIS & sh.STATUS_AXIS_STEP_LOSS_B) == 0);
+ SERIAL_ECHOPGM(" STEP-CLOCK MODE:"); echo_yes_no((sh.STATUS_AXIS & sh.STATUS_AXIS_SCK_MOD) != 0);
+ }
+ else {
+ SERIAL_ECHOPGM(" STALL: NA "
+ " STEP-CLOCK MODE: NA"
+ " UNDER VOLTAGE LOCKOUT: "); echo_yes_no((sh.STATUS_AXIS & sh.STATUS_AXIS_UVLO) == 0);
+ }
+ SERIAL_EOL();
+}
+
+/**
+ * M122: Debug L6470 drivers
+ */
+void GcodeSuite::M122() {
+ L64xxManager.pause_monitor(true); // Keep monitor_driver() from stealing status
+ L64xxManager.spi_active = true; // Tell set_directions() a series of SPI transfers is underway
+
+ //if (parser.seen('S'))
+ // tmc_set_report_interval(parser.value_bool());
+ //else
+
+ #if AXIS_IS_L64XX(X)
+ L6470_say_status(X);
+ #endif
+ #if AXIS_IS_L64XX(X2)
+ L6470_say_status(X2);
+ #endif
+ #if AXIS_IS_L64XX(Y)
+ L6470_say_status(Y);
+ #endif
+ #if AXIS_IS_L64XX(Y2)
+ L6470_say_status(Y2);
+ #endif
+ #if AXIS_IS_L64XX(Z)
+ L6470_say_status(Z);
+ #endif
+ #if AXIS_IS_L64XX(Z2)
+ L6470_say_status(Z2);
+ #endif
+ #if AXIS_IS_L64XX(Z3)
+ L6470_say_status(Z3);
+ #endif
+ #if AXIS_IS_L64XX(Z4)
+ L6470_say_status(Z4);
+ #endif
+ #if AXIS_IS_L64XX(E0)
+ L6470_say_status(E0);
+ #endif
+ #if AXIS_IS_L64XX(E1)
+ L6470_say_status(E1);
+ #endif
+ #if AXIS_IS_L64XX(E2)
+ L6470_say_status(E2);
+ #endif
+ #if AXIS_IS_L64XX(E3)
+ L6470_say_status(E3);
+ #endif
+ #if AXIS_IS_L64XX(E4)
+ L6470_say_status(E4);
+ #endif
+ #if AXIS_IS_L64XX(E5)
+ L6470_say_status(E5);
+ #endif
+ #if AXIS_IS_L64XX(E6)
+ L6470_say_status(E6);
+ #endif
+ #if AXIS_IS_L64XX(E7)
+ L6470_say_status(E7);
+ #endif
+
+ L64xxManager.spi_active = false; // done with all SPI transfers - clear handshake flags
+ L64xxManager.spi_abort = false;
+ L64xxManager.pause_monitor(false);
+}
+
+#endif // HAS_L64XX
diff --git a/Marlin/src/gcode/feature/L6470/M906.cpp b/Marlin/src/gcode/feature/L6470/M906.cpp
new file mode 100644
index 0000000..7bd446a
--- /dev/null
+++ b/Marlin/src/gcode/feature/L6470/M906.cpp
@@ -0,0 +1,370 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if HAS_L64XX
+
+#include "../../gcode.h"
+#include "../../../libs/L64XX/L64XX_Marlin.h"
+#include "../../../module/stepper/indirection.h"
+#include "../../../module/planner.h"
+
+#define DEBUG_OUT ENABLED(L6470_CHITCHAT)
+#include "../../../core/debug_out.h"
+
+/**
+ * M906: report or set KVAL_HOLD which sets the maximum effective voltage provided by the
+ * PWMs to the steppers
+ *
+ * On L6474 this sets the TVAL register (same address).
+ *
+ * I - select which driver(s) to change on multi-driver axis
+ * 0 - (default) all drivers on the axis or E0
+ * 1 - monitor only X, Y, Z or E1
+ * 2 - monitor only X2, Y2, Z2 or E2
+ * 3 - monitor only Z3 or E3
+ * 4 - monitor only Z4 or E4
+ * 5 - monitor only E5
+ * Xxxx, Yxxx, Zxxx, Exxx - axis to change (optional)
+ * L6474 - current in mA (4A max)
+ * All others - 0-255
+ */
+
+/**
+ * Sets KVAL_HOLD wich affects the current being driven through the stepper.
+ *
+ * L6470 is used in the STEP-CLOCK mode. KVAL_HOLD is the only KVAL_xxx
+ * that affects the effective voltage seen by the stepper.
+ */
+
+/**
+ * MACRO to fetch information on the items associated with current limiting
+ * and maximum voltage output.
+ *
+ * L6470 can be setup to shutdown if either current threshold is exceeded.
+ *
+ * L6470 output current can not be set directly. It is set indirectly by
+ * setting the maximum effective output voltage.
+ *
+ * Effective output voltage is set by PWM duty cycle.
+ *
+ * Maximum effective output voltage is affected by MANY variables. The main ones are:
+ * KVAL_HOLD
+ * KVAL_RUN
+ * KVAL_ACC
+ * KVAL_DEC
+ * Vs compensation (if enabled)
+ */
+void L64XX_report_current(L64XX &motor, const L64XX_axis_t axis) {
+
+ if (L64xxManager.spi_abort) return; // don't do anything if set_directions() has occurred
+
+ const L64XX_Marlin::L64XX_shadow_t &sh = L64xxManager.shadow;
+ const uint16_t status = L64xxManager.get_status(axis); //also populates shadow structure
+ const uint8_t OverCurrent_Threshold = uint8_t(motor.GetParam(L6470_OCD_TH));
+
+ auto say_axis_status = [](const L64XX_axis_t axis, const uint16_t status) {
+ L64xxManager.say_axis(axis);
+ #if ENABLED(L6470_CHITCHAT)
+ char tmp[10];
+ sprintf_P(tmp, PSTR("%4x "), status);
+ DEBUG_ECHOPAIR(" status: ", tmp);
+ print_bin(status);
+ #else
+ UNUSED(status);
+ #endif
+ SERIAL_EOL();
+ };
+
+ char temp_buf[10];
+
+ switch (sh.STATUS_AXIS_LAYOUT) {
+ case L6470_STATUS_LAYOUT: // L6470
+ case L6480_STATUS_LAYOUT: { // L6480 & powerstep01
+ const uint16_t Stall_Threshold = (uint8_t)motor.GetParam(L6470_STALL_TH),
+ motor_status = (status & (STATUS_MOT_STATUS)) >> 5,
+ L6470_ADC_out = motor.GetParam(L6470_ADC_OUT),
+ L6470_ADC_out_limited = constrain(L6470_ADC_out, 8, 24);
+ const float comp_coef = 1600.0f / L6470_ADC_out_limited;
+ const uint16_t MicroSteps = _BV(motor.GetParam(L6470_STEP_MODE) & 0x07);
+
+ say_axis_status(axis, sh.STATUS_AXIS_RAW);
+
+ SERIAL_ECHOPGM("...OverCurrent Threshold: ");
+ sprintf_P(temp_buf, PSTR("%2d ("), OverCurrent_Threshold);
+ SERIAL_ECHO(temp_buf);
+ SERIAL_ECHO((OverCurrent_Threshold + 1) * motor.OCD_CURRENT_CONSTANT_INV);
+ SERIAL_ECHOPGM(" mA)");
+ SERIAL_ECHOPGM(" Stall Threshold: ");
+ sprintf_P(temp_buf, PSTR("%2d ("), Stall_Threshold);
+ SERIAL_ECHO(temp_buf);
+ SERIAL_ECHO((Stall_Threshold + 1) * motor.STALL_CURRENT_CONSTANT_INV);
+ SERIAL_ECHOPGM(" mA)");
+ SERIAL_ECHOPGM(" Motor Status: ");
+ switch (motor_status) {
+ case 0: SERIAL_ECHOPGM("stopped"); break;
+ case 1: SERIAL_ECHOPGM("accelerating"); break;
+ case 2: SERIAL_ECHOPGM("decelerating"); break;
+ case 3: SERIAL_ECHOPGM("at constant speed"); break;
+ }
+ SERIAL_EOL();
+
+ SERIAL_ECHOPAIR("...MicroSteps: ", MicroSteps,
+ " ADC_OUT: ", L6470_ADC_out);
+ SERIAL_ECHOPGM(" Vs_compensation: ");
+ serialprintPGM((motor.GetParam(sh.L6470_AXIS_CONFIG) & CONFIG_EN_VSCOMP) ? PSTR("ENABLED ") : PSTR("DISABLED"));
+ SERIAL_ECHOLNPAIR(" Compensation coefficient: ~", comp_coef * 0.01f);
+
+ SERIAL_ECHOPAIR("...KVAL_HOLD: ", motor.GetParam(L6470_KVAL_HOLD),
+ " KVAL_RUN : ", motor.GetParam(L6470_KVAL_RUN),
+ " KVAL_ACC: ", motor.GetParam(L6470_KVAL_ACC),
+ " KVAL_DEC: ", motor.GetParam(L6470_KVAL_DEC),
+ " V motor max = ");
+ switch (motor_status) {
+ case 0: SERIAL_ECHO(motor.GetParam(L6470_KVAL_HOLD) * 100 / 256); SERIAL_ECHOPGM("% (KVAL_HOLD)"); break;
+ case 1: SERIAL_ECHO(motor.GetParam(L6470_KVAL_RUN) * 100 / 256); SERIAL_ECHOPGM("% (KVAL_RUN)"); break;
+ case 2: SERIAL_ECHO(motor.GetParam(L6470_KVAL_ACC) * 100 / 256); SERIAL_ECHOPGM("% (KVAL_ACC)"); break;
+ case 3: SERIAL_ECHO(motor.GetParam(L6470_KVAL_DEC) * 100 / 256); SERIAL_ECHOPGM("% (KVAL_HOLD)"); break;
+ }
+ SERIAL_EOL();
+
+ #if ENABLED(L6470_CHITCHAT)
+ DEBUG_ECHOPGM("...SLEW RATE: ");
+ switch (sh.STATUS_AXIS_LAYOUT) {
+ case L6470_STATUS_LAYOUT: {
+ switch ((motor.GetParam(sh.L6470_AXIS_CONFIG) & CONFIG_POW_SR) >> CONFIG_POW_SR_BIT) {
+ case 0: { DEBUG_ECHOLNPGM("320V/uS") ; break; }
+ case 1: { DEBUG_ECHOLNPGM("75V/uS") ; break; }
+ case 2: { DEBUG_ECHOLNPGM("110V/uS") ; break; }
+ case 3: { DEBUG_ECHOLNPGM("260V/uS") ; break; }
+ }
+ break;
+ }
+ case L6480_STATUS_LAYOUT: {
+ switch (motor.GetParam(L6470_GATECFG1) & CONFIG1_SR ) {
+ case CONFIG1_SR_220V_us: { DEBUG_ECHOLNPGM("220V/uS") ; break; }
+ case CONFIG1_SR_400V_us: { DEBUG_ECHOLNPGM("400V/uS") ; break; }
+ case CONFIG1_SR_520V_us: { DEBUG_ECHOLNPGM("520V/uS") ; break; }
+ case CONFIG1_SR_980V_us: { DEBUG_ECHOLNPGM("980V/uS") ; break; }
+ default: { DEBUG_ECHOLNPGM("unknown") ; break; }
+ }
+ }
+ }
+ #endif
+ SERIAL_EOL();
+ break;
+ }
+
+ case L6474_STATUS_LAYOUT: { // L6474
+ const uint16_t L6470_ADC_out = motor.GetParam(L6470_ADC_OUT) & 0x1F,
+ L6474_TVAL_val = motor.GetParam(L6474_TVAL) & 0x7F;
+
+ say_axis_status(axis, sh.STATUS_AXIS_RAW);
+
+ SERIAL_ECHOPGM("...OverCurrent Threshold: ");
+ sprintf_P(temp_buf, PSTR("%2d ("), OverCurrent_Threshold);
+ SERIAL_ECHO(temp_buf);
+ SERIAL_ECHO((OverCurrent_Threshold + 1) * motor.OCD_CURRENT_CONSTANT_INV);
+ SERIAL_ECHOPGM(" mA)");
+ SERIAL_ECHOPGM(" TVAL: ");
+ sprintf_P(temp_buf, PSTR("%2d ("), L6474_TVAL_val);
+ SERIAL_ECHO(temp_buf);
+ SERIAL_ECHO((L6474_TVAL_val + 1) * motor.STALL_CURRENT_CONSTANT_INV);
+ SERIAL_ECHOLNPGM(" mA) Motor Status: NA");
+
+ const uint16_t MicroSteps = _BV(motor.GetParam(L6470_STEP_MODE) & 0x07); //NOMORE(MicroSteps, 16);
+ SERIAL_ECHOPAIR("...MicroSteps: ", MicroSteps,
+ " ADC_OUT: ", L6470_ADC_out);
+
+ SERIAL_ECHOLNPGM(" Vs_compensation: NA\n");
+ SERIAL_ECHOLNPGM("...KVAL_HOLD: NA"
+ " KVAL_RUN : NA"
+ " KVAL_ACC: NA"
+ " KVAL_DEC: NA"
+ " V motor max = NA");
+
+ #if ENABLED(L6470_CHITCHAT)
+ DEBUG_ECHOPGM("...SLEW RATE: ");
+ switch ((motor.GetParam(sh.L6470_AXIS_CONFIG) & CONFIG_POW_SR) >> CONFIG_POW_SR_BIT) {
+ case 0: DEBUG_ECHOLNPGM("320V/uS") ; break;
+ case 1: DEBUG_ECHOLNPGM("75V/uS") ; break;
+ case 2: DEBUG_ECHOLNPGM("110V/uS") ; break;
+ case 3: DEBUG_ECHOLNPGM("260V/uS") ; break;
+ default: DEBUG_ECHOLNPAIR("slew rate: ", (motor.GetParam(sh.L6470_AXIS_CONFIG) & CONFIG_POW_SR) >> CONFIG_POW_SR_BIT); break;
+ }
+ #endif
+ SERIAL_EOL();
+ SERIAL_EOL();
+ break;
+ }
+ }
+}
+
+void GcodeSuite::M906() {
+
+ L64xxManager.pause_monitor(true); // Keep monitor_driver() from stealing status
+
+ #define L6470_SET_KVAL_HOLD(Q) (AXIS_IS_L64XX(Q) ? stepper##Q.setTVALCurrent(value) : stepper##Q.SetParam(L6470_KVAL_HOLD, uint8_t(value)))
+
+ DEBUG_ECHOLNPGM("M906");
+
+ uint8_t report_current = true;
+
+ #if HAS_L64XX
+ const uint8_t index = parser.byteval('I');
+ #endif
+
+ LOOP_XYZE(i) if (uint16_t value = parser.intval(axis_codes[i])) {
+
+ report_current = false;
+
+ if (planner.has_blocks_queued() || planner.cleaning_buffer_counter) {
+ SERIAL_ECHOLNPGM("Test aborted. Can't set KVAL_HOLD while steppers are moving.");
+ return;
+ }
+
+ switch (i) {
+ case X_AXIS:
+ #if AXIS_IS_L64XX(X)
+ if (index == 0) L6470_SET_KVAL_HOLD(X);
+ #endif
+ #if AXIS_IS_L64XX(X2)
+ if (index == 1) L6470_SET_KVAL_HOLD(X2);
+ #endif
+ break;
+ case Y_AXIS:
+ #if AXIS_IS_L64XX(Y)
+ if (index == 0) L6470_SET_KVAL_HOLD(Y);
+ #endif
+ #if AXIS_IS_L64XX(Y2)
+ if (index == 1) L6470_SET_KVAL_HOLD(Y2);
+ #endif
+ break;
+ case Z_AXIS:
+ #if AXIS_IS_L64XX(Z)
+ if (index == 0) L6470_SET_KVAL_HOLD(Z);
+ #endif
+ #if AXIS_IS_L64XX(Z2)
+ if (index == 1) L6470_SET_KVAL_HOLD(Z2);
+ #endif
+ #if AXIS_IS_L64XX(Z3)
+ if (index == 2) L6470_SET_KVAL_HOLD(Z3);
+ #endif
+ #if AXIS_DRIVER_TYPE_Z4(L6470)
+ if (index == 3) L6470_SET_KVAL_HOLD(Z4);
+ #endif
+ break;
+ case E_AXIS: {
+ const int8_t target_extruder = get_target_extruder_from_command();
+ if (target_extruder < 0) return;
+ switch (target_extruder) {
+ #if AXIS_IS_L64XX(E0)
+ case 0: L6470_SET_KVAL_HOLD(E0); break;
+ #endif
+ #if AXIS_IS_L64XX(E1)
+ case 1: L6470_SET_KVAL_HOLD(E1); break;
+ #endif
+ #if AXIS_IS_L64XX(E2)
+ case 2: L6470_SET_KVAL_HOLD(E2); break;
+ #endif
+ #if AXIS_IS_L64XX(E3)
+ case 3: L6470_SET_KVAL_HOLD(E3); break;
+ #endif
+ #if AXIS_IS_L64XX(E4)
+ case 4: L6470_SET_KVAL_HOLD(E4); break;
+ #endif
+ #if AXIS_IS_L64XX(E5)
+ case 5: L6470_SET_KVAL_HOLD(E5); break;
+ #endif
+ #if AXIS_IS_L64XX(E6)
+ case 6: L6470_SET_KVAL_HOLD(E6); break;
+ #endif
+ #if AXIS_IS_L64XX(E7)
+ case 7: L6470_SET_KVAL_HOLD(E7); break;
+ #endif
+ }
+ } break;
+ }
+ }
+
+ if (report_current) {
+ #define L64XX_REPORT_CURRENT(Q) L64XX_report_current(stepper##Q, Q)
+
+ L64xxManager.spi_active = true; // Tell set_directions() a series of SPI transfers is underway
+
+ #if AXIS_IS_L64XX(X)
+ L64XX_REPORT_CURRENT(X);
+ #endif
+ #if AXIS_IS_L64XX(X2)
+ L64XX_REPORT_CURRENT(X2);
+ #endif
+ #if AXIS_IS_L64XX(Y)
+ L64XX_REPORT_CURRENT(Y);
+ #endif
+ #if AXIS_IS_L64XX(Y2)
+ L64XX_REPORT_CURRENT(Y2);
+ #endif
+ #if AXIS_IS_L64XX(Z)
+ L64XX_REPORT_CURRENT(Z);
+ #endif
+ #if AXIS_IS_L64XX(Z2)
+ L64XX_REPORT_CURRENT(Z2);
+ #endif
+ #if AXIS_IS_L64XX(Z3)
+ L64XX_REPORT_CURRENT(Z3);
+ #endif
+ #if AXIS_IS_L64XX(Z4)
+ L64XX_REPORT_CURRENT(Z4);
+ #endif
+ #if AXIS_IS_L64XX(E0)
+ L64XX_REPORT_CURRENT(E0);
+ #endif
+ #if AXIS_IS_L64XX(E1)
+ L64XX_REPORT_CURRENT(E1);
+ #endif
+ #if AXIS_IS_L64XX(E2)
+ L64XX_REPORT_CURRENT(E2);
+ #endif
+ #if AXIS_IS_L64XX(E3)
+ L64XX_REPORT_CURRENT(E3);
+ #endif
+ #if AXIS_IS_L64XX(E4)
+ L64XX_REPORT_CURRENT(E4);
+ #endif
+ #if AXIS_IS_L64XX(E5)
+ L64XX_REPORT_CURRENT(E5);
+ #endif
+ #if AXIS_IS_L64XX(E6)
+ L64XX_REPORT_CURRENT(E6);
+ #endif
+ #if AXIS_IS_L64XX(E7)
+ L64XX_REPORT_CURRENT(E7);
+ #endif
+
+ L64xxManager.spi_active = false; // done with all SPI transfers - clear handshake flags
+ L64xxManager.spi_abort = false;
+ L64xxManager.pause_monitor(false);
+ }
+}
+
+#endif // HAS_L64XX
diff --git a/Marlin/src/gcode/feature/L6470/M916-918.cpp b/Marlin/src/gcode/feature/L6470/M916-918.cpp
new file mode 100644
index 0000000..8a1ea48
--- /dev/null
+++ b/Marlin/src/gcode/feature/L6470/M916-918.cpp
@@ -0,0 +1,651 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+//
+// NOTE: All tests assume each axis uses matching driver chips.
+//
+
+#include "../../../inc/MarlinConfig.h"
+
+#if HAS_L64XX
+
+#include "../../gcode.h"
+#include "../../../module/stepper/indirection.h"
+#include "../../../module/planner.h"
+#include "../../../libs/L64XX/L64XX_Marlin.h"
+
+#define DEBUG_OUT ENABLED(L6470_CHITCHAT)
+#include "../../../core/debug_out.h"
+
+/**
+ * M916: increase KVAL_HOLD until get thermal warning
+ * NOTE - on L6474 it is TVAL that is used
+ *
+ * J - select which driver(s) to monitor on multi-driver axis
+ * 0 - (default) monitor all drivers on the axis or E0
+ * 1 - monitor only X, Y, Z, E1
+ * 2 - monitor only X2, Y2, Z2, E2
+ * 3 - monitor only Z3, E3
+ * 4 - monitor only Z4, E4
+ *
+ * Xxxx, Yxxx, Zxxx, Exxx - axis to be monitored with displacement
+ * xxx (1-255) is distance moved on either side of current position
+ *
+ * F - feedrate
+ * optional - will use default max feedrate from configuration.h if not specified
+ *
+ * T - current (mA) setting for TVAL (0 - 4A in 31.25mA increments, rounds down) - L6474 only
+ * optional - will report current value from driver if not specified
+ *
+ * K - value for KVAL_HOLD (0 - 255) (ignored for L6474)
+ * optional - will report current value from driver if not specified
+ *
+ * D - time (in seconds) to run each setting of KVAL_HOLD/TVAL
+ * optional - defaults to zero (runs each setting once)
+ */
+
+/**
+ * This routine is also useful for determining the approximate KVAL_HOLD
+ * where the stepper stops losing steps. The sound will get noticeably quieter
+ * as it stops losing steps.
+ */
+
+void GcodeSuite::M916() {
+
+ DEBUG_ECHOLNPGM("M916");
+
+ L64xxManager.pause_monitor(true); // Keep monitor_driver() from stealing status
+
+ // Variables used by L64xxManager.get_user_input function - some may not be used
+ char axis_mon[3][3] = { {" "}, {" "}, {" "} }; // list of Axes to be monitored
+ L64XX_axis_t axis_index[3];
+ uint16_t axis_status[3];
+ uint8_t driver_count = 1;
+ float position_max;
+ float position_min;
+ float final_feedrate;
+ uint8_t kval_hold;
+ uint8_t OCD_TH_val = 0;
+ uint8_t STALL_TH_val = 0;
+ uint16_t over_current_threshold;
+ constexpr uint8_t over_current_flag = false; // M916 doesn't play with the overcurrent thresholds
+
+ #define DRIVER_TYPE_L6474(Q) AXIS_DRIVER_TYPE_##Q(L6474)
+
+ uint8_t j; // general purpose counter
+
+ if (L64xxManager.get_user_input(driver_count, axis_index, axis_mon, position_max, position_min, final_feedrate, kval_hold, over_current_flag, OCD_TH_val, STALL_TH_val, over_current_threshold))
+ return; // quit if invalid user input
+
+ DEBUG_ECHOLNPAIR("feedrate = ", final_feedrate);
+
+ planner.synchronize(); // wait for all current movement commands to complete
+
+ const L64XX_Marlin::L64XX_shadow_t &sh = L64xxManager.shadow;
+ for (j = 0; j < driver_count; j++)
+ L64xxManager.get_status(axis_index[j]); // clear out any pre-existing error flags
+
+ char temp_axis_string[] = " ";
+ temp_axis_string[0] = axis_mon[0][0]; // need to have a string for use within sprintf format section
+ char gcode_string[80];
+ uint16_t status_composite = 0;
+
+ uint16_t M91x_counter = kval_hold;
+ uint16_t M91x_counter_max;
+ if (sh.STATUS_AXIS_LAYOUT == L6474_STATUS_LAYOUT) {
+ M91x_counter_max = 128; // TVAL is 7 bits
+ LIMIT(M91x_counter, 0U, 127U);
+ }
+ else
+ M91x_counter_max = 256; // KVAL_HOLD is 8 bits
+
+ uint8_t M91x_delay_s = parser.byteval('D'); // get delay in seconds
+ millis_t M91x_delay_ms = SEC_TO_MS(M91x_delay_s * 60);
+ millis_t M91x_delay_end;
+
+ DEBUG_ECHOLNPGM(".\n.");
+
+ do {
+
+ if (sh.STATUS_AXIS_LAYOUT == L6474_STATUS_LAYOUT)
+ DEBUG_ECHOLNPAIR("TVAL current (mA) = ", (M91x_counter + 1) * sh.AXIS_STALL_CURRENT_CONSTANT_INV); // report TVAL current for this run
+ else
+ DEBUG_ECHOLNPAIR("kval_hold = ", M91x_counter); // report KVAL_HOLD for this run
+
+ for (j = 0; j < driver_count; j++)
+ L64xxManager.set_param(axis_index[j], L6470_KVAL_HOLD, M91x_counter); //set KVAL_HOLD or TVAL (same register address)
+
+ M91x_delay_end = millis() + M91x_delay_ms;
+ do {
+ // turn the motor(s) both directions
+ sprintf_P(gcode_string, PSTR("G0 %s%03d F%03d"), temp_axis_string, uint16_t(position_min), uint16_t(final_feedrate));
+ gcode.process_subcommands_now_P(gcode_string);
+
+ sprintf_P(gcode_string, PSTR("G0 %s%03d F%03d"), temp_axis_string, uint16_t(position_max), uint16_t(final_feedrate));
+ gcode.process_subcommands_now_P(gcode_string);
+
+ // get the status after the motors have stopped
+ planner.synchronize();
+
+ status_composite = 0; // clear out the old bits
+
+ for (j = 0; j < driver_count; j++) {
+ axis_status[j] = (~L64xxManager.get_status(axis_index[j])) & sh.L6470_ERROR_MASK; // bits of interest are all active low
+ status_composite |= axis_status[j] ;
+ }
+
+ if (status_composite) break;
+ } while (millis() < M91x_delay_end);
+
+ if (status_composite) break;
+
+ M91x_counter++;
+
+ } while (!(status_composite & (sh.STATUS_AXIS_TH_WRN | sh.STATUS_AXIS_TH_SD)) && (M91x_counter < M91x_counter_max));
+
+ DEBUG_ECHOLNPGM(".");
+
+ #if ENABLED(L6470_CHITCHAT)
+ if (status_composite) {
+ L64xxManager.error_status_decode(status_composite, axis_index[0],
+ sh.STATUS_AXIS_TH_SD, sh.STATUS_AXIS_TH_WRN,
+ sh.STATUS_AXIS_STEP_LOSS_A, sh.STATUS_AXIS_STEP_LOSS_B,
+ sh.STATUS_AXIS_OCD, sh.STATUS_AXIS_LAYOUT);
+ DEBUG_ECHOLNPGM(".");
+ }
+ #endif
+
+ if ((status_composite & (sh.STATUS_AXIS_TH_WRN | sh.STATUS_AXIS_TH_SD)))
+ DEBUG_ECHOLNPGM(".\n.\nTest completed normally - Thermal warning/shutdown has occurred");
+ else if (status_composite)
+ DEBUG_ECHOLNPGM(".\n.\nTest completed abnormally - non-thermal error has occured");
+ else
+ DEBUG_ECHOLNPGM(".\n.\nTest completed normally - Unable to get to thermal warning/shutdown");
+
+ L64xxManager.pause_monitor(false);
+}
+
+/**
+ * M917: Find minimum current thresholds
+ *
+ * Decrease OCD current until overcurrent error
+ * Increase OCD until overcurrent error goes away
+ * Decrease stall threshold until stall (not done on L6474)
+ * Increase stall until stall error goes away (not done on L6474)
+ *
+ * J - select which driver(s) to monitor on multi-driver axis
+ * 0 - (default) monitor all drivers on the axis or E0
+ * 1 - monitor only X, Y, Z, E1
+ * 2 - monitor only X2, Y2, Z2, E2
+ * Xxxx, Yxxx, Zxxx, Exxx - axis to be monitored with displacement
+ * xxx (1-255) is distance moved on either side of current position
+ *
+ * F - feedrate
+ * optional - will use default max feedrate from Configuration.h if not specified
+ *
+ * I - starting over-current threshold
+ * optional - will report current value from driver if not specified
+ * if there are multiple drivers on the axis then all will be set the same
+ *
+ * T - current (mA) setting for TVAL (0 - 4A in 31.25mA increments, rounds down) - L6474 only
+ * optional - will report current value from driver if not specified
+ *
+ * K - value for KVAL_HOLD (0 - 255) (ignored for L6474)
+ * optional - will report current value from driver if not specified
+ */
+void GcodeSuite::M917() {
+
+ DEBUG_ECHOLNPGM("M917");
+
+ L64xxManager.pause_monitor(true); // Keep monitor_driver() from stealing status
+
+ char axis_mon[3][3] = { {" "}, {" "}, {" "} }; // list of Axes to be monitored
+ L64XX_axis_t axis_index[3];
+ uint16_t axis_status[3];
+ uint8_t driver_count = 1;
+ float position_max;
+ float position_min;
+ float final_feedrate;
+ uint8_t kval_hold;
+ uint8_t OCD_TH_val = 0;
+ uint8_t STALL_TH_val = 0;
+ uint16_t over_current_threshold;
+ constexpr uint8_t over_current_flag = true;
+
+ uint8_t j; // general purpose counter
+
+ if (L64xxManager.get_user_input(driver_count, axis_index, axis_mon, position_max, position_min, final_feedrate, kval_hold, over_current_flag, OCD_TH_val, STALL_TH_val, over_current_threshold))
+ return; // quit if invalid user input
+
+ DEBUG_ECHOLNPAIR("feedrate = ", final_feedrate);
+
+ planner.synchronize(); // wait for all current movement commands to complete
+
+ const L64XX_Marlin::L64XX_shadow_t &sh = L64xxManager.shadow;
+ for (j = 0; j < driver_count; j++)
+ L64xxManager.get_status(axis_index[j]); // clear error flags
+ char temp_axis_string[] = " ";
+ temp_axis_string[0] = axis_mon[0][0]; // need a sprintf format string
+ char gcode_string[80];
+ uint16_t status_composite = 0;
+ uint8_t test_phase = 0; // 0 - decreasing OCD - exit when OCD warning occurs (ignore STALL)
+ // 1 - increasing OCD - exit when OCD warning stops (ignore STALL)
+ // 2 - OCD finalized - decreasing STALL - exit when STALL warning happens
+ // 3 - OCD finalized - increasing STALL - exit when STALL warning stop
+ // 4 - all testing completed
+ DEBUG_ECHOPAIR(".\n.\n.\nover_current threshold : ", (OCD_TH_val + 1) * 375); // first status display
+ DEBUG_ECHOPAIR(" (OCD_TH: : ", OCD_TH_val);
+ if (sh.STATUS_AXIS_LAYOUT != L6474_STATUS_LAYOUT) {
+ DEBUG_ECHOPAIR(") Stall threshold: ", (STALL_TH_val + 1) * 31.25);
+ DEBUG_ECHOPAIR(" (STALL_TH: ", STALL_TH_val);
+ }
+ DEBUG_ECHOLNPGM(")");
+
+ do {
+
+ if (sh.STATUS_AXIS_LAYOUT != L6474_STATUS_LAYOUT) DEBUG_ECHOPAIR("STALL threshold : ", (STALL_TH_val + 1) * 31.25);
+ DEBUG_ECHOLNPAIR(" OCD threshold : ", (OCD_TH_val + 1) * 375);
+
+ sprintf_P(gcode_string, PSTR("G0 %s%03d F%03d"), temp_axis_string, uint16_t(position_min), uint16_t(final_feedrate));
+ gcode.process_subcommands_now_P(gcode_string);
+
+ sprintf_P(gcode_string, PSTR("G0 %s%03d F%03d"), temp_axis_string, uint16_t(position_max), uint16_t(final_feedrate));
+ gcode.process_subcommands_now_P(gcode_string);
+
+ planner.synchronize();
+
+ status_composite = 0; // clear out the old bits
+
+ for (j = 0; j < driver_count; j++) {
+ axis_status[j] = (~L64xxManager.get_status(axis_index[j])) & sh.L6470_ERROR_MASK; // bits of interest are all active low
+ status_composite |= axis_status[j];
+ }
+
+ if (status_composite && (status_composite & sh.STATUS_AXIS_UVLO)) {
+ DEBUG_ECHOLNPGM("Test aborted (Undervoltage lockout active)");
+ #if ENABLED(L6470_CHITCHAT)
+ for (j = 0; j < driver_count; j++) {
+ if (j) DEBUG_ECHOPGM("...");
+ L64xxManager.error_status_decode(axis_status[j], axis_index[j],
+ sh.STATUS_AXIS_TH_SD, sh.STATUS_AXIS_TH_WRN,
+ sh.STATUS_AXIS_STEP_LOSS_A, sh.STATUS_AXIS_STEP_LOSS_B,
+ sh.STATUS_AXIS_OCD, sh.STATUS_AXIS_LAYOUT);
+ }
+ #endif
+ return;
+ }
+
+ if (status_composite & (sh.STATUS_AXIS_TH_WRN | sh.STATUS_AXIS_TH_SD)) {
+ DEBUG_ECHOLNPGM("thermal problem - waiting for chip(s) to cool down ");
+ uint16_t status_composite_temp = 0;
+ uint8_t k = 0;
+ do {
+ k++;
+ if (!(k % 4)) {
+ kval_hold *= 0.95;
+ DEBUG_EOL();
+ DEBUG_ECHOLNPAIR("Lowering KVAL_HOLD by about 5% to ", kval_hold);
+ for (j = 0; j < driver_count; j++)
+ L64xxManager.set_param(axis_index[j], L6470_KVAL_HOLD, kval_hold);
+ }
+ DEBUG_ECHOLNPGM(".");
+ gcode.reset_stepper_timeout(); // keep steppers powered
+ watchdog_refresh();
+ safe_delay(5000);
+ status_composite_temp = 0;
+ for (j = 0; j < driver_count; j++) {
+ axis_status[j] = (~L64xxManager.get_status(axis_index[j])) & sh.L6470_ERROR_MASK; // bits of interest are all active low
+ status_composite_temp |= axis_status[j];
+ }
+ }
+ while (status_composite_temp & (sh.STATUS_AXIS_TH_WRN | sh.STATUS_AXIS_TH_SD));
+ DEBUG_EOL();
+ }
+ if (status_composite & (sh.STATUS_AXIS_STEP_LOSS_A | sh.STATUS_AXIS_STEP_LOSS_B | sh.STATUS_AXIS_OCD)) {
+ switch (test_phase) {
+
+ case 0: {
+ if (status_composite & sh.STATUS_AXIS_OCD) {
+ // phase 0 with OCD warning - time to go to next phase
+ if (OCD_TH_val >= sh.AXIS_OCD_TH_MAX) {
+ OCD_TH_val = sh.AXIS_OCD_TH_MAX; // limit to max
+ test_phase = 2; // at highest value so skip phase 1
+ //DEBUG_ECHOLNPGM("LOGIC E0A OCD at highest - skip to 2");
+ DEBUG_ECHOLNPGM("OCD at highest - OCD finalized");
+ }
+ else {
+ OCD_TH_val++; // normal exit to next phase
+ test_phase = 1; // setup for first pass of phase 1
+ //DEBUG_ECHOLNPGM("LOGIC E0B - inc OCD & go to 1");
+ DEBUG_ECHOLNPGM("inc OCD");
+ }
+ }
+ else { // phase 0 without OCD warning - keep on decrementing if can
+ if (OCD_TH_val) {
+ OCD_TH_val--; // try lower value
+ //DEBUG_ECHOLNPGM("LOGIC E0C - dec OCD");
+ DEBUG_ECHOLNPGM("dec OCD");
+ }
+ else {
+ test_phase = 2; // at lowest value without warning so skip phase 1
+ //DEBUG_ECHOLNPGM("LOGIC E0D - OCD at latest - go to 2");
+ DEBUG_ECHOLNPGM("OCD finalized");
+ }
+ }
+ } break;
+
+ case 1: {
+ if (status_composite & sh.STATUS_AXIS_OCD) {
+ // phase 1 with OCD warning - increment if can
+ if (OCD_TH_val >= sh.AXIS_OCD_TH_MAX) {
+ OCD_TH_val = sh.AXIS_OCD_TH_MAX; // limit to max
+ test_phase = 2; // at highest value so go to next phase
+ //DEBUG_ECHOLNPGM("LOGIC E1A - OCD at max - go to 2");
+ DEBUG_ECHOLNPGM("OCD finalized");
+ }
+ else {
+ OCD_TH_val++; // try a higher value
+ //DEBUG_ECHOLNPGM("LOGIC E1B - inc OCD");
+ DEBUG_ECHOLNPGM("inc OCD");
+ }
+ }
+ else { // phase 1 without OCD warning - normal exit to phase 2
+ test_phase = 2;
+ //DEBUG_ECHOLNPGM("LOGIC E1C - no OCD warning - go to 1");
+ DEBUG_ECHOLNPGM("OCD finalized");
+ }
+ } break;
+
+ case 2: {
+ if (sh.STATUS_AXIS_LAYOUT == L6474_STATUS_LAYOUT) { // skip all STALL_TH steps if L6474
+ test_phase = 4;
+ break;
+ }
+ if (status_composite & (sh.STATUS_AXIS_STEP_LOSS_A | sh.STATUS_AXIS_STEP_LOSS_B)) {
+ // phase 2 with stall warning - time to go to next phase
+ if (STALL_TH_val >= 127) {
+ STALL_TH_val = 127; // limit to max
+ //DEBUG_ECHOLNPGM("LOGIC E2A - STALL warning, STALL at max, quit");
+ DEBUG_ECHOLNPGM("finished - STALL at maximum value but still have stall warning");
+ test_phase = 4;
+ }
+ else {
+ test_phase = 3; // normal exit to next phase (found failing value of STALL)
+ STALL_TH_val++; // setup for first pass of phase 3
+ //DEBUG_ECHOLNPGM("LOGIC E2B - INC - STALL warning, inc Stall, go to 3");
+ DEBUG_ECHOLNPGM("inc Stall");
+ }
+ }
+ else { // phase 2 without stall warning - decrement if can
+ if (STALL_TH_val) {
+ STALL_TH_val--; // try a lower value
+ //DEBUG_ECHOLNPGM("LOGIC E2C - no STALL, dec STALL");
+ DEBUG_ECHOLNPGM("dec STALL");
+ }
+ else {
+ DEBUG_ECHOLNPGM("finished - STALL at lowest value but still do NOT have stall warning");
+ test_phase = 4;
+ //DEBUG_ECHOLNPGM("LOGIC E2D - no STALL, at lowest so quit");
+ }
+ }
+ } break;
+
+ case 3: {
+ if (sh.STATUS_AXIS_LAYOUT == L6474_STATUS_LAYOUT) { // skip all STALL_TH steps if L6474
+ test_phase = 4;
+ break;
+ }
+ if (status_composite & (sh.STATUS_AXIS_STEP_LOSS_A | sh.STATUS_AXIS_STEP_LOSS_B)) {
+ // phase 3 with stall warning - increment if can
+ if (STALL_TH_val >= 127) {
+ STALL_TH_val = 127; // limit to max
+ DEBUG_ECHOLNPGM("finished - STALL at maximum value but still have stall warning");
+ test_phase = 4;
+ //DEBUG_ECHOLNPGM("LOGIC E3A - STALL, at max so quit");
+ }
+ else {
+ STALL_TH_val++; // still looking for passing value
+ //DEBUG_ECHOLNPGM("LOGIC E3B - STALL, inc stall");
+ DEBUG_ECHOLNPGM("inc stall");
+ }
+ }
+ else { //phase 3 without stall warning but have OCD warning
+ DEBUG_ECHOLNPGM("Hardware problem - OCD warning without STALL warning");
+ test_phase = 4;
+ //DEBUG_ECHOLNPGM("LOGIC E3C - not STALLED, hardware problem (quit)");
+ }
+ } break;
+
+ }
+
+ }
+ else {
+ switch (test_phase) {
+ case 0: { // phase 0 without OCD warning - keep on decrementing if can
+ if (OCD_TH_val) {
+ OCD_TH_val--; // try lower value
+ //DEBUG_ECHOLNPGM("LOGIC N0A - DEC OCD");
+ DEBUG_ECHOLNPGM("DEC OCD");
+ }
+ else {
+ test_phase = 2; // at lowest value without warning so skip phase 1
+ //DEBUG_ECHOLNPGM("LOGIC N0B - OCD at lowest (go to phase 2)");
+ DEBUG_ECHOLNPGM("OCD finalized");
+ }
+ } break;
+
+ case 1: //DEBUG_ECHOLNPGM("LOGIC N1 (go directly to 2)"); // phase 1 without OCD warning - drop directly to phase 2
+ DEBUG_ECHOLNPGM("OCD finalized");
+
+ case 2: { // phase 2 without stall warning - keep on decrementing if can
+ if (sh.STATUS_AXIS_LAYOUT == L6474_STATUS_LAYOUT) { // skip all STALL_TH steps if L6474
+ test_phase = 4;
+ break;
+ }
+ if (STALL_TH_val) {
+ STALL_TH_val--; // try a lower value (stay in phase 2)
+ //DEBUG_ECHOLNPGM("LOGIC N2B - dec STALL");
+ DEBUG_ECHOLNPGM("dec STALL");
+ }
+ else {
+ DEBUG_ECHOLNPGM("finished - STALL at lowest value but still no stall warning");
+ test_phase = 4;
+ //DEBUG_ECHOLNPGM("LOGIC N2C - STALL at lowest (quit)");
+ }
+ } break;
+
+ case 3: {
+ if (sh.STATUS_AXIS_LAYOUT == L6474_STATUS_LAYOUT) { // skip all STALL_TH steps if L6474
+ test_phase = 4;
+ break;
+ }
+ test_phase = 4;
+ //DEBUG_ECHOLNPGM("LOGIC N3 - finished!");
+ DEBUG_ECHOLNPGM("finished!");
+ } break; // phase 3 without any warnings - desired exit
+ } //
+ } // end of status checks
+
+ if (test_phase != 4) {
+ for (j = 0; j < driver_count; j++) { // update threshold(s)
+ L64xxManager.set_param(axis_index[j], L6470_OCD_TH, OCD_TH_val);
+ if (sh.STATUS_AXIS_LAYOUT != L6474_STATUS_LAYOUT) L64xxManager.set_param(axis_index[j], L6470_STALL_TH, STALL_TH_val);
+ if (L64xxManager.get_param(axis_index[j], L6470_OCD_TH) != OCD_TH_val) DEBUG_ECHOLNPGM("OCD mismatch");
+ if ((L64xxManager.get_param(axis_index[j], L6470_STALL_TH) != STALL_TH_val) && (sh.STATUS_AXIS_LAYOUT != L6474_STATUS_LAYOUT)) DEBUG_ECHOLNPGM("STALL mismatch");
+ }
+ }
+
+ } while (test_phase != 4);
+
+ DEBUG_ECHOLNPGM(".");
+ if (status_composite) {
+ #if ENABLED(L6470_CHITCHAT)
+ for (j = 0; j < driver_count; j++) {
+ if (j) DEBUG_ECHOPGM("...");
+ L64xxManager.error_status_decode(axis_status[j], axis_index[j],
+ sh.STATUS_AXIS_TH_SD, sh.STATUS_AXIS_TH_WRN,
+ sh.STATUS_AXIS_STEP_LOSS_A, sh.STATUS_AXIS_STEP_LOSS_B,
+ sh.STATUS_AXIS_OCD, sh.STATUS_AXIS_LAYOUT);
+ }
+ DEBUG_ECHOLNPGM(".");
+ #endif
+ DEBUG_ECHOLNPGM("Completed with errors");
+ }
+ else
+ DEBUG_ECHOLNPGM("Completed with no errors");
+ DEBUG_ECHOLNPGM(".");
+
+ L64xxManager.pause_monitor(false);
+}
+
+/**
+ * M918: increase speed until error or max feedrate achieved (as shown in configuration.h))
+ *
+ * J - select which driver(s) to monitor on multi-driver axis
+ * 0 - (default) monitor all drivers on the axis or E0
+ * 1 - monitor only X, Y, Z, E1
+ * 2 - monitor only X2, Y2, Z2, E2
+ * Xxxx, Yxxx, Zxxx, Exxx - axis to be monitored with displacement
+ * xxx (1-255) is distance moved on either side of current position
+ *
+ * I - over current threshold
+ * optional - will report current value from driver if not specified
+ *
+ * T - current (mA) setting for TVAL (0 - 4A in 31.25mA increments, rounds down) - L6474 only
+ * optional - will report current value from driver if not specified
+ *
+ * K - value for KVAL_HOLD (0 - 255) (ignored for L6474)
+ * optional - will report current value from driver if not specified
+ *
+ * M - value for microsteps (1 - 128) (optional)
+ * optional - will report current value from driver if not specified
+ */
+void GcodeSuite::M918() {
+
+ DEBUG_ECHOLNPGM("M918");
+
+ L64xxManager.pause_monitor(true); // Keep monitor_driver() from stealing status
+
+ char axis_mon[3][3] = { {" "}, {" "}, {" "} }; // list of Axes to be monitored
+ L64XX_axis_t axis_index[3];
+ uint16_t axis_status[3];
+ uint8_t driver_count = 1;
+ float position_max, position_min;
+ float final_feedrate;
+ uint8_t kval_hold;
+ uint8_t OCD_TH_val = 0;
+ uint8_t STALL_TH_val = 0;
+ uint16_t over_current_threshold;
+ constexpr uint8_t over_current_flag = true;
+
+ const L64XX_Marlin::L64XX_shadow_t &sh = L64xxManager.shadow;
+
+ uint8_t j; // general purpose counter
+
+ if (L64xxManager.get_user_input(driver_count, axis_index, axis_mon, position_max, position_min, final_feedrate, kval_hold, over_current_flag, OCD_TH_val, STALL_TH_val, over_current_threshold))
+ return; // quit if invalid user input
+
+ L64xxManager.get_status(axis_index[0]); // populate shadow array
+
+ uint8_t m_steps = parser.byteval('M');
+
+ if (m_steps != 0) {
+ LIMIT(m_steps, 1, sh.STATUS_AXIS_LAYOUT == L6474_STATUS_LAYOUT ? 16 : 128); // L6474
+
+ uint8_t stepVal;
+ for (stepVal = 0; stepVal < 8; stepVal++) { // convert to L64xx register value
+ if (m_steps == 1) break;
+ m_steps >>= 1;
+ }
+
+ if (sh.STATUS_AXIS_LAYOUT == L6474_STATUS_LAYOUT)
+ stepVal |= 0x98; // NO SYNC
+ else
+ stepVal |= (!SYNC_EN) | SYNC_SEL_1 | stepVal;
+
+ for (j = 0; j < driver_count; j++) {
+ L64xxManager.set_param(axis_index[j], dSPIN_HARD_HIZ, 0); // can't write STEP register if stepper being powered
+ // results in an extra NOOP being sent (data 00)
+ L64xxManager.set_param(axis_index[j], L6470_STEP_MODE, stepVal); // set microsteps
+ }
+ }
+ m_steps = L64xxManager.get_param(axis_index[0], L6470_STEP_MODE) & 0x07; // get microsteps
+
+ DEBUG_ECHOLNPAIR("Microsteps = ", _BV(m_steps));
+ DEBUG_ECHOLNPAIR("target (maximum) feedrate = ", final_feedrate);
+
+ const float feedrate_inc = final_feedrate / 10, // Start at 1/10 of max & go up by 1/10 per step
+ fr_limit = final_feedrate * 0.99f; // Rounding-safe comparison value
+ float current_feedrate = 0;
+
+ planner.synchronize(); // Wait for moves to complete
+
+ for (j = 0; j < driver_count; j++)
+ L64xxManager.get_status(axis_index[j]); // Clear error flags
+
+ char temp_axis_string[2] = " ";
+ temp_axis_string[0] = axis_mon[0][0]; // Need a sprintf format string
+ //temp_axis_string[1] = '\n';
+
+ char gcode_string[80];
+ uint16_t status_composite = 0;
+ DEBUG_ECHOLNPGM(".\n.\n."); // Make feedrate outputs easier to read
+
+ do {
+ current_feedrate += feedrate_inc;
+ DEBUG_ECHOLNPAIR("...feedrate = ", current_feedrate);
+
+ sprintf_P(gcode_string, PSTR("G0 %s%03d F%03d"), temp_axis_string, uint16_t(position_min), uint16_t(current_feedrate));
+ gcode.process_subcommands_now_P(gcode_string);
+
+ sprintf_P(gcode_string, PSTR("G0 %s%03d F%03d"), temp_axis_string, uint16_t(position_max), uint16_t(current_feedrate));
+ gcode.process_subcommands_now_P(gcode_string);
+
+ planner.synchronize();
+
+ for (j = 0; j < driver_count; j++) {
+ axis_status[j] = (~L64xxManager.get_status(axis_index[j])) & 0x0800; // Bits of interest are all active LOW
+ status_composite |= axis_status[j];
+ }
+ if (status_composite) break; // Break on any error
+ } while (current_feedrate < fr_limit);
+
+ DEBUG_ECHOPGM("Completed with ");
+ if (status_composite) {
+ DEBUG_ECHOLNPGM("errors");
+ #if ENABLED(L6470_CHITCHAT)
+ for (j = 0; j < driver_count; j++) {
+ if (j) DEBUG_ECHOPGM("...");
+ L64xxManager.error_status_decode(axis_status[j], axis_index[j],
+ sh.STATUS_AXIS_TH_SD, sh.STATUS_AXIS_TH_WRN,
+ sh.STATUS_AXIS_STEP_LOSS_A, sh.STATUS_AXIS_STEP_LOSS_B,
+ sh.STATUS_AXIS_OCD, sh.STATUS_AXIS_LAYOUT);
+ }
+ #endif
+ }
+ else
+ DEBUG_ECHOLNPGM("no errors");
+
+ L64xxManager.pause_monitor(false);
+}
+
+#endif // HAS_L64XX
diff --git a/Marlin/src/gcode/feature/advance/M900.cpp b/Marlin/src/gcode/feature/advance/M900.cpp
new file mode 100644
index 0000000..5c7155d
--- /dev/null
+++ b/Marlin/src/gcode/feature/advance/M900.cpp
@@ -0,0 +1,147 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if ENABLED(LIN_ADVANCE)
+
+#include "../../gcode.h"
+#include "../../../module/planner.h"
+#include "../../../module/stepper.h"
+
+#if ENABLED(EXTRA_LIN_ADVANCE_K)
+ float other_extruder_advance_K[EXTRUDERS];
+ uint8_t lin_adv_slot = 0;
+#endif
+
+/**
+ * M900: Get or Set Linear Advance K-factor
+ * T Which tool to address
+ * K Set current advance K factor (Slot 0).
+ * L Set secondary advance K factor (Slot 1). Requires EXTRA_LIN_ADVANCE_K.
+ * S<0/1> Activate slot 0 or 1. Requires EXTRA_LIN_ADVANCE_K.
+ */
+void GcodeSuite::M900() {
+
+ auto echo_value_oor = [](const char ltr, const bool ten=true) {
+ SERIAL_CHAR('?'); SERIAL_CHAR(ltr);
+ SERIAL_ECHOPGM(" value out of range");
+ if (ten) SERIAL_ECHOPGM(" (0-10)");
+ SERIAL_ECHOLNPGM(".");
+ };
+
+ #if EXTRUDERS < 2
+ constexpr uint8_t tool_index = 0;
+ #else
+ const uint8_t tool_index = parser.intval('T', active_extruder);
+ if (tool_index >= EXTRUDERS) {
+ echo_value_oor('T', false);
+ return;
+ }
+ #endif
+
+ float &kref = planner.extruder_advance_K[tool_index], newK = kref;
+ const float oldK = newK;
+
+ #if ENABLED(EXTRA_LIN_ADVANCE_K)
+
+ float &lref = other_extruder_advance_K[tool_index];
+
+ const bool old_slot = TEST(lin_adv_slot, tool_index), // The tool's current slot (0 or 1)
+ new_slot = parser.boolval('S', old_slot); // The passed slot (default = current)
+
+ // If a new slot is being selected swap the current and
+ // saved K values. Do here so K/L will apply correctly.
+ if (new_slot != old_slot) { // Not the same slot?
+ SET_BIT_TO(lin_adv_slot, tool_index, new_slot); // Update the slot for the tool
+ newK = lref; // Get new K value from backup
+ lref = oldK; // Save K to backup
+ }
+
+ // Set the main K value. Apply if the main slot is active.
+ if (parser.seenval('K')) {
+ const float K = parser.value_float();
+ if (!WITHIN(K, 0, 10)) echo_value_oor('K');
+ else if (new_slot) lref = K; // S1 Knn
+ else newK = K; // S0 Knn
+ }
+
+ // Set the extra K value. Apply if the extra slot is active.
+ if (parser.seenval('L')) {
+ const float L = parser.value_float();
+ if (!WITHIN(L, 0, 10)) echo_value_oor('L');
+ else if (!new_slot) lref = L; // S0 Lnn
+ else newK = L; // S1 Lnn
+ }
+
+ #else
+
+ if (parser.seenval('K')) {
+ const float K = parser.value_float();
+ if (WITHIN(K, 0, 10))
+ newK = K;
+ else
+ echo_value_oor('K');
+ }
+
+ #endif
+
+ if (newK != oldK) {
+ planner.synchronize();
+ kref = newK;
+ }
+
+ if (!parser.seen_any()) {
+
+ #if ENABLED(EXTRA_LIN_ADVANCE_K)
+
+ #if EXTRUDERS < 2
+ SERIAL_ECHOLNPAIR("Advance S", int(new_slot), " K", kref, "(S", int(!new_slot), " K", lref, ")");
+ #else
+ LOOP_L_N(i, EXTRUDERS) {
+ const bool slot = TEST(lin_adv_slot, i);
+ SERIAL_ECHOLNPAIR("Advance T", int(i), " S", int(slot), " K", planner.extruder_advance_K[i],
+ "(S", int(!slot), " K", other_extruder_advance_K[i], ")");
+ SERIAL_EOL();
+ }
+ #endif
+
+ #else
+
+ SERIAL_ECHO_START();
+ #if EXTRUDERS < 2
+ SERIAL_ECHOLNPAIR("Advance K=", planner.extruder_advance_K[0]);
+ #else
+ SERIAL_ECHOPGM("Advance K");
+ LOOP_L_N(i, EXTRUDERS) {
+ SERIAL_CHAR(' ', '0' + i, ':');
+ SERIAL_DECIMAL(planner.extruder_advance_K[i]);
+ }
+ SERIAL_EOL();
+ #endif
+
+ #endif
+ }
+
+}
+
+#endif // LIN_ADVANCE
diff --git a/Marlin/src/gcode/feature/baricuda/M126-M129.cpp b/Marlin/src/gcode/feature/baricuda/M126-M129.cpp
new file mode 100644
index 0000000..edeba0d
--- /dev/null
+++ b/Marlin/src/gcode/feature/baricuda/M126-M129.cpp
@@ -0,0 +1,58 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if ENABLED(BARICUDA)
+
+#include "../../gcode.h"
+#include "../../../feature/baricuda.h"
+
+#if HAS_HEATER_1
+
+ /**
+ * M126: Heater 1 valve open
+ */
+ void GcodeSuite::M126() { baricuda_valve_pressure = parser.byteval('S', 255); }
+
+ /**
+ * M127: Heater 1 valve close
+ */
+ void GcodeSuite::M127() { baricuda_valve_pressure = 0; }
+
+#endif // HAS_HEATER_1
+
+#if HAS_HEATER_2
+
+ /**
+ * M128: Heater 2 valve open
+ */
+ void GcodeSuite::M128() { baricuda_e_to_p_pressure = parser.byteval('S', 255); }
+
+ /**
+ * M129: Heater 2 valve close
+ */
+ void GcodeSuite::M129() { baricuda_e_to_p_pressure = 0; }
+
+#endif // HAS_HEATER_2
+
+#endif // BARICUDA
diff --git a/Marlin/src/gcode/feature/camera/M240.cpp b/Marlin/src/gcode/feature/camera/M240.cpp
new file mode 100644
index 0000000..fc350d8
--- /dev/null
+++ b/Marlin/src/gcode/feature/camera/M240.cpp
@@ -0,0 +1,204 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if ENABLED(PHOTO_GCODE)
+
+#include "../../gcode.h"
+#include "../../../module/motion.h" // for active_extruder and current_position
+
+#if PIN_EXISTS(CHDK)
+ millis_t chdk_timeout; // = 0
+#endif
+
+#if defined(PHOTO_POSITION) && PHOTO_DELAY_MS > 0
+ #include "../../../MarlinCore.h" // for idle()
+#endif
+
+#ifdef PHOTO_RETRACT_MM
+
+ #define _PHOTO_RETRACT_MM (PHOTO_RETRACT_MM + 0)
+
+ #include "../../../module/planner.h"
+ #include "../../../module/temperature.h"
+
+ #if ENABLED(ADVANCED_PAUSE_FEATURE)
+ #include "../../../feature/pause.h"
+ #endif
+
+ #ifdef PHOTO_RETRACT_MM
+ inline void e_move_m240(const float length, const feedRate_t &fr_mm_s) {
+ if (length && thermalManager.hotEnoughToExtrude(active_extruder))
+ unscaled_e_move(length, fr_mm_s);
+ }
+ #endif
+
+#endif
+
+#if PIN_EXISTS(PHOTOGRAPH)
+
+ FORCE_INLINE void set_photo_pin(const uint8_t state) {
+ constexpr uint32_t pulse_length = (
+ #ifdef PHOTO_PULSES_US
+ PHOTO_PULSE_DELAY_US
+ #else
+ 15 // 15.24 from _delay_ms(0.01524)
+ #endif
+ );
+ WRITE(PHOTOGRAPH_PIN, state);
+ delayMicroseconds(pulse_length);
+ }
+
+ FORCE_INLINE void tweak_photo_pin() { set_photo_pin(HIGH); set_photo_pin(LOW); }
+
+ #ifdef PHOTO_PULSES_US
+
+ inline void pulse_photo_pin(const uint32_t duration, const uint8_t state) {
+ if (state) {
+ for (const uint32_t stop = micros() + duration; micros() < stop;)
+ tweak_photo_pin();
+ }
+ else
+ delayMicroseconds(duration);
+ }
+
+ inline void spin_photo_pin() {
+ static constexpr uint32_t sequence[] = PHOTO_PULSES_US;
+ LOOP_L_N(i, COUNT(sequence))
+ pulse_photo_pin(sequence[i], !(i & 1));
+ }
+
+ #else
+
+ constexpr uint8_t NUM_PULSES = 16;
+ inline void spin_photo_pin() { for (uint8_t i = NUM_PULSES; i--;) tweak_photo_pin(); }
+
+ #endif
+#endif
+
+/**
+ * M240: Trigger a camera by...
+ *
+ * - CHDK : Emulate a Canon RC-1 with a configurable ON duration.
+ * https://captain-slow.dk/2014/03/09/3d-printing-timelapses/
+ * - PHOTOGRAPH_PIN : Pulse a digital pin 16 times.
+ * See https://www.doc-diy.net/photo/rc-1_hacked/
+ * - PHOTO_SWITCH_POSITION : Bump a physical switch with the X-carriage using a
+ * configured position, delay, and retract length.
+ *
+ * PHOTO_POSITION parameters:
+ * A - X offset to the return position
+ * B - Y offset to the return position
+ * F - Override the XY movement feedrate
+ * R - Retract/recover length (current units)
+ * S - Retract/recover feedrate (mm/m)
+ * X - Move to X before triggering the shutter
+ * Y - Move to Y before triggering the shutter
+ * Z - Raise Z by a distance before triggering the shutter
+ *
+ * PHOTO_SWITCH_POSITION parameters:
+ * D - Duration (ms) to hold down switch (Requires PHOTO_SWITCH_MS)
+ * P - Delay (ms) after triggering the shutter (Requires PHOTO_SWITCH_MS)
+ * I - Switch trigger position override X
+ * J - Switch trigger position override Y
+ */
+void GcodeSuite::M240() {
+
+ #ifdef PHOTO_POSITION
+
+ if (homing_needed_error()) return;
+
+ const xyz_pos_t old_pos = {
+ current_position.x + parser.linearval('A'),
+ current_position.y + parser.linearval('B'),
+ current_position.z
+ };
+
+ #ifdef PHOTO_RETRACT_MM
+ const float rval = parser.seenval('R') ? parser.value_linear_units() : _PHOTO_RETRACT_MM;
+ feedRate_t sval = (
+ #if ENABLED(ADVANCED_PAUSE_FEATURE)
+ PAUSE_PARK_RETRACT_FEEDRATE
+ #elif ENABLED(FWRETRACT)
+ RETRACT_FEEDRATE
+ #else
+ 45
+ #endif
+ );
+ if (parser.seenval('S')) sval = parser.value_feedrate();
+ e_move_m240(-rval, sval);
+ #endif
+
+ feedRate_t fr_mm_s = MMM_TO_MMS(parser.linearval('F'));
+ if (fr_mm_s) NOLESS(fr_mm_s, 10.0f);
+
+ constexpr xyz_pos_t photo_position = PHOTO_POSITION;
+ xyz_pos_t raw = {
+ parser.seenval('X') ? RAW_X_POSITION(parser.value_linear_units()) : photo_position.x,
+ parser.seenval('Y') ? RAW_Y_POSITION(parser.value_linear_units()) : photo_position.y,
+ (parser.seenval('Z') ? parser.value_linear_units() : photo_position.z) + current_position.z
+ };
+ apply_motion_limits(raw);
+ do_blocking_move_to(raw, fr_mm_s);
+
+ #ifdef PHOTO_SWITCH_POSITION
+ constexpr xy_pos_t photo_switch_position = PHOTO_SWITCH_POSITION;
+ const xy_pos_t sraw = {
+ parser.seenval('I') ? RAW_X_POSITION(parser.value_linear_units()) : photo_switch_position.x,
+ parser.seenval('J') ? RAW_Y_POSITION(parser.value_linear_units()) : photo_switch_position.y
+ };
+ do_blocking_move_to_xy(sraw, get_homing_bump_feedrate(X_AXIS));
+ #if PHOTO_SWITCH_MS > 0
+ safe_delay(parser.intval('D', PHOTO_SWITCH_MS));
+ #endif
+ do_blocking_move_to(raw);
+ #endif
+
+ #endif
+
+ #if PIN_EXISTS(CHDK)
+
+ OUT_WRITE(CHDK_PIN, HIGH);
+ chdk_timeout = millis() + parser.intval('D', PHOTO_SWITCH_MS);
+
+ #elif HAS_PHOTOGRAPH
+
+ spin_photo_pin();
+ delay(7.33);
+ spin_photo_pin();
+
+ #endif
+
+ #ifdef PHOTO_POSITION
+ #if PHOTO_DELAY_MS > 0
+ const millis_t timeout = millis() + parser.intval('P', PHOTO_DELAY_MS);
+ while (PENDING(millis(), timeout)) idle();
+ #endif
+ do_blocking_move_to(old_pos, fr_mm_s);
+ #ifdef PHOTO_RETRACT_MM
+ e_move_m240(rval, sval);
+ #endif
+ #endif
+}
+
+#endif // PHOTO_GCODE
diff --git a/Marlin/src/gcode/feature/cancel/M486.cpp b/Marlin/src/gcode/feature/cancel/M486.cpp
new file mode 100644
index 0000000..1f14ae0
--- /dev/null
+++ b/Marlin/src/gcode/feature/cancel/M486.cpp
@@ -0,0 +1,57 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if ENABLED(CANCEL_OBJECTS)
+
+#include "../../gcode.h"
+#include "../../../feature/cancel_object.h"
+
+/**
+ * M486: A simple interface to cancel objects
+ *
+ * T[count] : Reset objects and/or set the count
+ * S : Start an object with the given index
+ * P : Cancel the object with the given index
+ * U : Un-cancel object with the given index
+ * C : Cancel the current object (the last index given by S)
+ * S-1 : Start a non-object like a brim or purge tower that should always print
+ */
+void GcodeSuite::M486() {
+
+ if (parser.seen('T')) {
+ cancelable.reset();
+ cancelable.object_count = parser.intval('T', 1);
+ }
+
+ if (parser.seen('S'))
+ cancelable.set_active_object(parser.value_int());
+
+ if (parser.seen('C')) cancelable.cancel_active_object();
+
+ if (parser.seen('P')) cancelable.cancel_object(parser.value_int());
+
+ if (parser.seen('U')) cancelable.uncancel_object(parser.value_int());
+}
+
+#endif // CANCEL_OBJECTS
diff --git a/Marlin/src/gcode/feature/caselight/M355.cpp b/Marlin/src/gcode/feature/caselight/M355.cpp
new file mode 100644
index 0000000..12ae5cf
--- /dev/null
+++ b/Marlin/src/gcode/feature/caselight/M355.cpp
@@ -0,0 +1,73 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if ENABLED(CASE_LIGHT_ENABLE)
+
+#include "../../../feature/caselight.h"
+#include "../../gcode.h"
+
+/**
+ * M355: Turn case light on/off and set brightness
+ *
+ * P Set case light brightness (PWM pin required - ignored otherwise)
+ *
+ * S Set case light on/off
+ *
+ * When S turns on the light on a PWM pin then the current brightness level is used/restored
+ *
+ * M355 P200 S0 turns off the light & sets the brightness level
+ * M355 S1 turns on the light with a brightness of 200 (assuming a PWM pin)
+ */
+void GcodeSuite::M355() {
+ bool didset = false;
+ #if CASELIGHT_USES_BRIGHTNESS
+ if (parser.seenval('P')) {
+ didset = true;
+ caselight.brightness = parser.value_byte();
+ }
+ #endif
+ const bool sflag = parser.seenval('S');
+ if (sflag) {
+ didset = true;
+ caselight.on = parser.value_bool();
+ }
+ if (didset) caselight.update(sflag);
+
+ // Always report case light status
+ SERIAL_ECHO_START();
+ SERIAL_ECHOPGM("Case light: ");
+ if (!caselight.on)
+ SERIAL_ECHOLNPGM(STR_OFF);
+ else {
+ #if CASELIGHT_USES_BRIGHTNESS
+ if (PWM_PIN(CASE_LIGHT_PIN)) {
+ SERIAL_ECHOLN(int(caselight.brightness));
+ return;
+ }
+ #endif
+ SERIAL_ECHOLNPGM(STR_ON);
+ }
+}
+
+#endif // CASE_LIGHT_ENABLE
diff --git a/Marlin/src/gcode/feature/clean/G12.cpp b/Marlin/src/gcode/feature/clean/G12.cpp
new file mode 100644
index 0000000..216db5b
--- /dev/null
+++ b/Marlin/src/gcode/feature/clean/G12.cpp
@@ -0,0 +1,80 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if ENABLED(NOZZLE_CLEAN_FEATURE)
+
+#include "../../../libs/nozzle.h"
+
+#include "../../gcode.h"
+#include "../../parser.h"
+#include "../../../module/motion.h"
+
+#if HAS_LEVELING
+ #include "../../../module/planner.h"
+ #include "../../../feature/bedlevel/bedlevel.h"
+#endif
+
+/**
+ * G12: Clean the nozzle
+ *
+ * E : 0=Never or 1=Always apply the "software endstop" limits
+ * P0 S : Stroke cleaning with S strokes
+ * P1 Sn T : Zigzag cleaning with S repeats and T zigzags
+ * P2 Sn R : Circle cleaning with S repeats and R radius
+ */
+void GcodeSuite::G12() {
+ // Don't allow nozzle cleaning without homing first
+ if (homing_needed_error()) return;
+
+ #ifdef WIPE_SEQUENCE_COMMANDS
+ if (!parser.seen_any()) {
+ gcode.process_subcommands_now_P(PSTR(WIPE_SEQUENCE_COMMANDS));
+ return;
+ }
+ #endif
+
+ const uint8_t pattern = parser.ushortval('P', 0),
+ strokes = parser.ushortval('S', NOZZLE_CLEAN_STROKES),
+ objects = parser.ushortval('T', NOZZLE_CLEAN_TRIANGLES);
+ const float radius = parser.linearval('R', NOZZLE_CLEAN_CIRCLE_RADIUS);
+
+ const bool seenxyz = parser.seen("XYZ");
+ const uint8_t cleans = (!seenxyz || parser.boolval('X') ? _BV(X_AXIS) : 0)
+ | (!seenxyz || parser.boolval('Y') ? _BV(Y_AXIS) : 0)
+ | TERN(NOZZLE_CLEAN_NO_Z, 0, (!seenxyz || parser.boolval('Z') ? _BV(Z_AXIS) : 0))
+ ;
+
+ #if HAS_LEVELING
+ // Disable bed leveling if cleaning Z
+ TEMPORARY_BED_LEVELING_STATE(!TEST(cleans, Z_AXIS) && planner.leveling_active);
+ #endif
+
+ SET_SOFT_ENDSTOP_LOOSE(!parser.boolval('E'));
+
+ nozzle.clean(pattern, strokes, radius, objects, cleans);
+
+ SET_SOFT_ENDSTOP_LOOSE(false);
+}
+
+#endif // NOZZLE_CLEAN_FEATURE
diff --git a/Marlin/src/gcode/feature/controllerfan/M710.cpp b/Marlin/src/gcode/feature/controllerfan/M710.cpp
new file mode 100644
index 0000000..cc45073
--- /dev/null
+++ b/Marlin/src/gcode/feature/controllerfan/M710.cpp
@@ -0,0 +1,81 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfigPre.h"
+
+#if ENABLED(CONTROLLER_FAN_EDITABLE)
+
+#include "../../gcode.h"
+#include "../../../feature/controllerfan.h"
+
+void M710_report(const bool forReplay) {
+ if (!forReplay) { SERIAL_ECHOLNPGM("; Controller Fan"); SERIAL_ECHO_START(); }
+ SERIAL_ECHOLNPAIR(" M710"
+ " S", int(controllerFan.settings.active_speed),
+ " I", int(controllerFan.settings.idle_speed),
+ " A", int(controllerFan.settings.auto_mode),
+ " D", controllerFan.settings.duration,
+ " ; (", (int(controllerFan.settings.active_speed) * 100) / 255, "%"
+ " ", (int(controllerFan.settings.idle_speed) * 100) / 255, "%)"
+ );
+}
+
+/**
+ * M710: Set controller fan settings
+ *
+ * R : Reset to defaults
+ * S[0-255] : Fan speed when motors are active
+ * I[0-255] : Fan speed when motors are idle
+ * A[0|1] : Turn auto mode on or off
+ * D : Set auto mode idle duration
+ *
+ * Examples:
+ * M710 ; Report current Settings
+ * M710 R ; Reset SIAD to defaults
+ * M710 I64 ; Set controller fan Idle Speed to 25%
+ * M710 S255 ; Set controller fan Active Speed to 100%
+ * M710 S0 ; Set controller fan Active Speed to OFF
+ * M710 I255 A0 ; Set controller fan Idle Speed to 100% with Auto Mode OFF
+ * M710 I127 A1 S255 D160 ; Set controller fan idle speed 50%, AutoMode On, Fan speed 100%, duration to 160 Secs
+ */
+void GcodeSuite::M710() {
+
+ const bool seenR = parser.seen('R');
+ if (seenR) controllerFan.reset();
+
+ const bool seenS = parser.seenval('S');
+ if (seenS) controllerFan.settings.active_speed = parser.value_byte();
+
+ const bool seenI = parser.seenval('I');
+ if (seenI) controllerFan.settings.idle_speed = parser.value_byte();
+
+ const bool seenA = parser.seenval('A');
+ if (seenA) controllerFan.settings.auto_mode = parser.value_bool();
+
+ const bool seenD = parser.seenval('D');
+ if (seenD) controllerFan.settings.duration = parser.value_ushort();
+
+ if (!(seenR || seenS || seenI || seenA || seenD))
+ M710_report(false);
+}
+
+#endif // CONTROLLER_FAN_EDITABLE
diff --git a/Marlin/src/gcode/feature/digipot/M907-M910.cpp b/Marlin/src/gcode/feature/digipot/M907-M910.cpp
new file mode 100644
index 0000000..e463666
--- /dev/null
+++ b/Marlin/src/gcode/feature/digipot/M907-M910.cpp
@@ -0,0 +1,102 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if ANY(HAS_MOTOR_CURRENT_SPI, HAS_MOTOR_CURRENT_PWM, HAS_MOTOR_CURRENT_I2C, HAS_MOTOR_CURRENT_DAC)
+
+#include "../../gcode.h"
+
+#if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM
+ #include "../../../module/stepper.h"
+#endif
+
+#if HAS_MOTOR_CURRENT_I2C
+ #include "../../../feature/digipot/digipot.h"
+#endif
+
+#if ENABLED(HAS_MOTOR_CURRENT_DAC)
+ #include "../../../feature/dac/stepper_dac.h"
+#endif
+
+/**
+ * M907: Set digital trimpot motor current using axis codes X, Y, Z, E, B, S
+ */
+void GcodeSuite::M907() {
+ #if HAS_MOTOR_CURRENT_SPI
+
+ LOOP_XYZE(i) if (parser.seenval(axis_codes[i])) stepper.set_digipot_current(i, parser.value_int());
+ if (parser.seenval('B')) stepper.set_digipot_current(4, parser.value_int());
+ if (parser.seenval('S')) LOOP_LE_N(i, 4) stepper.set_digipot_current(i, parser.value_int());
+
+ #elif HAS_MOTOR_CURRENT_PWM
+
+ #if ANY_PIN(MOTOR_CURRENT_PWM_X, MOTOR_CURRENT_PWM_Y, MOTOR_CURRENT_PWM_XY)
+ if (parser.seenval('X') || parser.seenval('Y')) stepper.set_digipot_current(0, parser.value_int());
+ #endif
+ #if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
+ if (parser.seenval('Z')) stepper.set_digipot_current(1, parser.value_int());
+ #endif
+ #if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
+ if (parser.seenval('E')) stepper.set_digipot_current(2, parser.value_int());
+ #endif
+
+ #endif
+
+ #if HAS_MOTOR_CURRENT_I2C
+ // this one uses actual amps in floating point
+ LOOP_XYZE(i) if (parser.seenval(axis_codes[i])) digipot_i2c.set_current(i, parser.value_float());
+ // Additional extruders use B,C,D for channels 4,5,6.
+ // TODO: Change these parameters because 'E' is used. B?
+ for (uint8_t i = E_AXIS + 1; i < DIGIPOT_I2C_NUM_CHANNELS; i++)
+ if (parser.seenval('B' + i - (E_AXIS + 1))) digipot_i2c.set_current(i, parser.value_float());
+ #endif
+
+ #if ENABLED(HAS_MOTOR_CURRENT_DAC)
+ if (parser.seenval('S')) {
+ const float dac_percent = parser.value_float();
+ LOOP_LE_N(i, 4) stepper_dac.set_current_percent(i, dac_percent);
+ }
+ LOOP_XYZE(i) if (parser.seenval(axis_codes[i])) stepper_dac.set_current_percent(i, parser.value_float());
+ #endif
+}
+
+#if EITHER(HAS_MOTOR_CURRENT_SPI, HAS_MOTOR_CURRENT_DAC)
+
+ /**
+ * M908: Control digital trimpot directly (M908 P S)
+ */
+ void GcodeSuite::M908() {
+ TERN_(HAS_MOTOR_CURRENT_SPI, stepper.set_digipot_value_spi(parser.intval('P'), parser.intval('S')));
+ TERN_(HAS_MOTOR_CURRENT_DAC, stepper_dac.set_current_value(parser.byteval('P', -1), parser.ushortval('S', 0)));
+ }
+
+ #if ENABLED(HAS_MOTOR_CURRENT_DAC)
+
+ void GcodeSuite::M909() { stepper_dac.print_values(); }
+ void GcodeSuite::M910() { stepper_dac.commit_eeprom(); }
+
+ #endif // HAS_MOTOR_CURRENT_DAC
+
+#endif // HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_DAC
+
+#endif // HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM || HAS_MOTOR_CURRENT_I2C || HAS_MOTOR_CURRENT_DAC
diff --git a/Marlin/src/gcode/feature/filwidth/M404-M407.cpp b/Marlin/src/gcode/feature/filwidth/M404-M407.cpp
new file mode 100644
index 0000000..a70f7a6
--- /dev/null
+++ b/Marlin/src/gcode/feature/filwidth/M404-M407.cpp
@@ -0,0 +1,71 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if ENABLED(FILAMENT_WIDTH_SENSOR)
+
+#include "../../../feature/filwidth.h"
+#include "../../../module/planner.h"
+#include "../../../MarlinCore.h"
+#include "../../gcode.h"
+
+/**
+ * M404: Display or set (in current units) the nominal filament width (3mm, 1.75mm ) W<3.0>
+ */
+void GcodeSuite::M404() {
+ if (parser.seenval('W')) {
+ filwidth.nominal_mm = parser.value_linear_units();
+ planner.volumetric_area_nominal = CIRCLE_AREA(filwidth.nominal_mm * 0.5);
+ }
+ else
+ SERIAL_ECHOLNPAIR("Filament dia (nominal mm):", filwidth.nominal_mm);
+}
+
+/**
+ * M405: Turn on filament sensor for control
+ */
+void GcodeSuite::M405() {
+ // This is technically a linear measurement, but since it's quantized to centimeters and is a different
+ // unit than everything else, it uses parser.value_byte() instead of parser.value_linear_units().
+ if (parser.seenval('D'))
+ filwidth.set_delay_cm(parser.value_byte());
+
+ filwidth.enable(true);
+}
+
+/**
+ * M406: Turn off filament sensor for control
+ */
+void GcodeSuite::M406() {
+ filwidth.enable(false);
+ planner.calculate_volumetric_multipliers(); // Restore correct 'volumetric_multiplier' value
+}
+
+/**
+ * M407: Get measured filament diameter on serial output
+ */
+void GcodeSuite::M407() {
+ SERIAL_ECHOLNPAIR("Filament dia (measured mm):", filwidth.measured_mm);
+}
+
+#endif // FILAMENT_WIDTH_SENSOR
diff --git a/Marlin/src/gcode/feature/fwretract/G10_G11.cpp b/Marlin/src/gcode/feature/fwretract/G10_G11.cpp
new file mode 100644
index 0000000..219502f
--- /dev/null
+++ b/Marlin/src/gcode/feature/fwretract/G10_G11.cpp
@@ -0,0 +1,51 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if ENABLED(FWRETRACT)
+
+#include "../../../feature/fwretract.h"
+#include "../../gcode.h"
+#include "../../../module/motion.h"
+
+/**
+ * G10 - Retract filament according to settings of M207
+ * TODO: Handle 'G10 P' for tool settings and 'G10 L' for workspace settings
+ */
+void GcodeSuite::G10() {
+ #if HAS_MULTI_EXTRUDER
+ const bool rs = parser.boolval('S');
+ #endif
+ fwretract.retract(true
+ #if HAS_MULTI_EXTRUDER
+ , rs
+ #endif
+ );
+}
+
+/**
+ * G11 - Recover filament according to settings of M208
+ */
+void GcodeSuite::G11() { fwretract.retract(false); }
+
+#endif // FWRETRACT
diff --git a/Marlin/src/gcode/feature/fwretract/M207-M209.cpp b/Marlin/src/gcode/feature/fwretract/M207-M209.cpp
new file mode 100644
index 0000000..538f16c
--- /dev/null
+++ b/Marlin/src/gcode/feature/fwretract/M207-M209.cpp
@@ -0,0 +1,74 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if ENABLED(FWRETRACT)
+
+#include "../../../feature/fwretract.h"
+#include "../../gcode.h"
+
+/**
+ * M207: Set firmware retraction values
+ *
+ * S[+units] retract_length
+ * W[+units] swap_retract_length (multi-extruder)
+ * F[units/min] retract_feedrate_mm_s
+ * Z[units] retract_zraise
+ */
+void GcodeSuite::M207() {
+ if (parser.seen('S')) fwretract.settings.retract_length = parser.value_axis_units(E_AXIS);
+ if (parser.seen('F')) fwretract.settings.retract_feedrate_mm_s = MMM_TO_MMS(parser.value_axis_units(E_AXIS));
+ if (parser.seen('Z')) fwretract.settings.retract_zraise = parser.value_linear_units();
+ if (parser.seen('W')) fwretract.settings.swap_retract_length = parser.value_axis_units(E_AXIS);
+}
+
+/**
+ * M208: Set firmware un-retraction values
+ *
+ * S[+units] retract_recover_extra (in addition to M207 S*)
+ * W[+units] swap_retract_recover_extra (multi-extruder)
+ * F[units/min] retract_recover_feedrate_mm_s
+ * R[units/min] swap_retract_recover_feedrate_mm_s
+ */
+void GcodeSuite::M208() {
+ if (parser.seen('S')) fwretract.settings.retract_recover_extra = parser.value_axis_units(E_AXIS);
+ if (parser.seen('F')) fwretract.settings.retract_recover_feedrate_mm_s = MMM_TO_MMS(parser.value_axis_units(E_AXIS));
+ if (parser.seen('R')) fwretract.settings.swap_retract_recover_feedrate_mm_s = MMM_TO_MMS(parser.value_axis_units(E_AXIS));
+ if (parser.seen('W')) fwretract.settings.swap_retract_recover_extra = parser.value_axis_units(E_AXIS);
+}
+
+#if ENABLED(FWRETRACT_AUTORETRACT)
+
+ /**
+ * M209: Enable automatic retract (M209 S1)
+ * For slicers that don't support G10/11, reversed extrude-only
+ * moves will be classified as retraction.
+ */
+ void GcodeSuite::M209() {
+ if (MIN_AUTORETRACT <= MAX_AUTORETRACT && parser.seen('S'))
+ fwretract.enable_autoretract(parser.value_bool());
+ }
+
+#endif // FWRETRACT_AUTORETRACT
+
+#endif // FWRETRACT
diff --git a/Marlin/src/gcode/feature/i2c/M260_M261.cpp b/Marlin/src/gcode/feature/i2c/M260_M261.cpp
new file mode 100644
index 0000000..438d152
--- /dev/null
+++ b/Marlin/src/gcode/feature/i2c/M260_M261.cpp
@@ -0,0 +1,76 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if ENABLED(EXPERIMENTAL_I2CBUS)
+
+#include "../../gcode.h"
+
+#include "../../../feature/twibus.h"
+
+/**
+ * M260: Send data to a I2C slave device
+ *
+ * This is a PoC, the formatting and arguments for the GCODE will
+ * change to be more compatible, the current proposal is:
+ *
+ * M260 A ; Sets the I2C slave address the data will be sent to
+ *
+ * M260 B
+ * M260 B
+ * M260 B
+ *
+ * M260 S1 ; Send the buffered data and reset the buffer
+ * M260 R1 ; Reset the buffer without sending data
+ */
+void GcodeSuite::M260() {
+ // Set the target address
+ if (parser.seen('A')) i2c.address(parser.value_byte());
+
+ // Add a new byte to the buffer
+ if (parser.seen('B')) i2c.addbyte(parser.value_byte());
+
+ // Flush the buffer to the bus
+ if (parser.seen('S')) i2c.send();
+
+ // Reset and rewind the buffer
+ else if (parser.seen('R')) i2c.reset();
+}
+
+/**
+ * M261: Request X bytes from I2C slave device
+ *
+ * Usage: M261 A B
+ */
+void GcodeSuite::M261() {
+ if (parser.seen('A')) i2c.address(parser.value_byte());
+
+ uint8_t bytes = parser.byteval('B', 1);
+
+ if (i2c.addr && bytes && bytes <= TWIBUS_BUFFER_SIZE)
+ i2c.relay(bytes);
+ else
+ SERIAL_ERROR_MSG("Bad i2c request");
+}
+
+#endif
diff --git a/Marlin/src/gcode/feature/leds/M150.cpp b/Marlin/src/gcode/feature/leds/M150.cpp
new file mode 100644
index 0000000..cf09bf1
--- /dev/null
+++ b/Marlin/src/gcode/feature/leds/M150.cpp
@@ -0,0 +1,84 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if HAS_COLOR_LEDS
+
+#include "../../gcode.h"
+#include "../../../feature/leds/leds.h"
+
+/**
+ * M150: Set Status LED Color - Use R-U-B-W for R-G-B-W
+ * and Brightness - Use P (for NEOPIXEL only)
+ *
+ * Always sets all 3 or 4 components. If a component is left out, set to 0.
+ * If brightness is left out, no value changed
+ *
+ * With NEOPIXEL_LED:
+ * I Set the NeoPixel index to affect. Default: All
+ *
+ * With NEOPIXEL2_SEPARATE:
+ * S The NeoPixel strip to set. Default is index 0.
+ *
+ * Examples:
+ *
+ * M150 R255 ; Turn LED red
+ * M150 R255 U127 ; Turn LED orange (PWM only)
+ * M150 ; Turn LED off
+ * M150 R U B ; Turn LED white
+ * M150 W ; Turn LED white using a white LED
+ * M150 P127 ; Set LED 50% brightness
+ * M150 P ; Set LED full brightness
+ * M150 I1 R ; Set NEOPIXEL index 1 to red
+ * M150 S1 I1 R ; Set SEPARATE index 1 to red
+ */
+
+void GcodeSuite::M150() {
+ #if ENABLED(NEOPIXEL_LED)
+ const uint8_t index = parser.intval('I', -1);
+ #if ENABLED(NEOPIXEL2_SEPARATE)
+ const uint8_t unit = parser.intval('S'),
+ brightness = unit ? neo2.brightness() : neo.brightness();
+ *(unit ? &neo2.neoindex : &neo.neoindex) = index;
+ #else
+ const uint8_t brightness = neo.brightness();
+ neo.neoindex = index;
+ #endif
+ #endif
+
+ const LEDColor color = MakeLEDColor(
+ parser.seen('R') ? (parser.has_value() ? parser.value_byte() : 255) : 0,
+ parser.seen('U') ? (parser.has_value() ? parser.value_byte() : 255) : 0,
+ parser.seen('B') ? (parser.has_value() ? parser.value_byte() : 255) : 0,
+ parser.seen('W') ? (parser.has_value() ? parser.value_byte() : 255) : 0,
+ parser.seen('P') ? (parser.has_value() ? parser.value_byte() : 255) : brightness
+ );
+
+ #if ENABLED(NEOPIXEL2_SEPARATE)
+ if (unit == 1) { leds2.set_color(color); return; }
+ #endif
+
+ leds.set_color(color);
+}
+
+#endif // HAS_COLOR_LEDS
diff --git a/Marlin/src/gcode/feature/leds/M7219.cpp b/Marlin/src/gcode/feature/leds/M7219.cpp
new file mode 100644
index 0000000..a6ee711
--- /dev/null
+++ b/Marlin/src/gcode/feature/leds/M7219.cpp
@@ -0,0 +1,93 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfigPre.h"
+
+#if ENABLED(MAX7219_GCODE)
+
+#include "../../gcode.h"
+#include "../../../feature/max7219.h"
+
+/**
+ * M7219: Control the Max7219 LED matrix
+ *
+ * I - Initialize (clear) the matrix
+ * F - Fill the matrix (set all bits)
+ * P - Dump the led_line[] array values
+ * C - Set a column to the bitmask given by 'V' (Units 0-3 in portrait layout)
+ * R - Set a row to the bitmask given by 'V' (Units 0-3 in landscape layout)
+ * X - X index of an LED to set or toggle
+ * Y - Y index of an LED to set or toggle
+ * V - LED on/off state or row/column bitmask (8, 16, 24, or 32-bits)
+ * ('C' / 'R' can be used to update up to 4 units at once)
+ *
+ * Directly set a native matrix row to the 8-bit value 'V':
+ * D - Display line (0..7)
+ * U - Unit index (0..MAX7219_NUMBER_UNITS-1)
+ */
+void GcodeSuite::M7219() {
+ if (parser.seen('I')) {
+ max7219.register_setup();
+ max7219.clear();
+ }
+
+ if (parser.seen('F')) max7219.fill();
+
+ const uint32_t v = parser.ulongval('V');
+
+ if (parser.seenval('R')) {
+ const uint8_t r = parser.value_byte();
+ max7219.set_row(r, v);
+ }
+ else if (parser.seenval('C')) {
+ const uint8_t c = parser.value_byte();
+ max7219.set_column(c, v);
+ }
+ else if (parser.seenval('X') || parser.seenval('Y')) {
+ const uint8_t x = parser.byteval('X'), y = parser.byteval('Y');
+ if (parser.seenval('V'))
+ max7219.led_set(x, y, v > 0);
+ else
+ max7219.led_toggle(x, y);
+ }
+ else if (parser.seen('D')) {
+ const uint8_t uline = parser.value_byte() & 0x7,
+ line = uline + (parser.byteval('U') << 3);
+ if (line < MAX7219_LINES) {
+ max7219.led_line[line] = v;
+ return max7219.refresh_line(line);
+ }
+ }
+
+ if (parser.seen('P')) {
+ LOOP_L_N(r, MAX7219_LINES) {
+ SERIAL_ECHOPGM("led_line[");
+ if (r < 10) SERIAL_CHAR(' ');
+ SERIAL_ECHO(int(r));
+ SERIAL_ECHOPGM("]=");
+ for (uint8_t b = 8; b--;) SERIAL_CHAR('0' + TEST(max7219.led_line[r], b));
+ SERIAL_EOL();
+ }
+ }
+}
+
+#endif // MAX7219_GCODE
diff --git a/Marlin/src/gcode/feature/macro/M810-M819.cpp b/Marlin/src/gcode/feature/macro/M810-M819.cpp
new file mode 100644
index 0000000..7b9e1a1
--- /dev/null
+++ b/Marlin/src/gcode/feature/macro/M810-M819.cpp
@@ -0,0 +1,65 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if ENABLED(GCODE_MACROS)
+
+#include "../../gcode.h"
+#include "../../queue.h"
+#include "../../parser.h"
+
+char gcode_macros[GCODE_MACROS_SLOTS][GCODE_MACROS_SLOT_SIZE + 1] = {{ 0 }};
+
+/**
+ * M810_819: Set/execute a G-code macro.
+ *
+ * Usage:
+ * M810 |... Set Macro 0 to the given commands, separated by the pipe character
+ * M810 Execute Macro 0
+ */
+void GcodeSuite::M810_819() {
+ const uint8_t index = parser.codenum - 810;
+ if (index >= GCODE_MACROS_SLOTS) return;
+
+ const size_t len = strlen(parser.string_arg);
+
+ if (len) {
+ // Set a macro
+ if (len > GCODE_MACROS_SLOT_SIZE)
+ SERIAL_ERROR_MSG("Macro too long.");
+ else {
+ char c, *s = parser.string_arg, *d = gcode_macros[index];
+ do {
+ c = *s++;
+ *d++ = c == '|' ? '\n' : c;
+ } while (c);
+ }
+ }
+ else {
+ // Execute a macro
+ char * const cmd = gcode_macros[index];
+ if (strlen(cmd)) process_subcommands_now(cmd);
+ }
+}
+
+#endif // GCODE_MACROS
diff --git a/Marlin/src/gcode/feature/mixing/M163-M165.cpp b/Marlin/src/gcode/feature/mixing/M163-M165.cpp
new file mode 100644
index 0000000..a4cb64e
--- /dev/null
+++ b/Marlin/src/gcode/feature/mixing/M163-M165.cpp
@@ -0,0 +1,101 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if ENABLED(MIXING_EXTRUDER)
+
+#include "../../gcode.h"
+#include "../../../feature/mixing.h"
+
+/**
+ * M163: Set a single mix factor for a mixing extruder
+ * This is called "weight" by some systems.
+ * Must be followed by M164 to normalize and commit them.
+ *
+ * S[index] The channel index to set
+ * P[float] The mix value
+ */
+void GcodeSuite::M163() {
+ const int mix_index = parser.intval('S');
+ if (mix_index < MIXING_STEPPERS)
+ mixer.set_collector(mix_index, parser.floatval('P'));
+}
+
+/**
+ * M164: Normalize and commit the mix.
+ *
+ * S[index] The virtual tool to store
+ * If 'S' is omitted update the active virtual tool.
+ */
+void GcodeSuite::M164() {
+ #if MIXING_VIRTUAL_TOOLS > 1
+ const int tool_index = parser.intval('S', -1);
+ #else
+ constexpr int tool_index = 0;
+ #endif
+ if (tool_index >= 0) {
+ if (tool_index < MIXING_VIRTUAL_TOOLS)
+ mixer.normalize(tool_index);
+ }
+ else
+ mixer.normalize();
+}
+
+#if ENABLED(DIRECT_MIXING_IN_G1)
+
+ /**
+ * M165: Set multiple mix factors for a mixing extruder.
+ * Omitted factors will be set to 0.
+ * The mix is normalized and stored in the current virtual tool.
+ *
+ * A[factor] Mix factor for extruder stepper 1
+ * B[factor] Mix factor for extruder stepper 2
+ * C[factor] Mix factor for extruder stepper 3
+ * D[factor] Mix factor for extruder stepper 4
+ * H[factor] Mix factor for extruder stepper 5
+ * I[factor] Mix factor for extruder stepper 6
+ */
+ void GcodeSuite::M165() {
+ // Get mixing parameters from the GCode
+ // The total "must" be 1.0 (but it will be normalized)
+ // If no mix factors are given, the old mix is preserved
+ const char mixing_codes[] = { LIST_N(MIXING_STEPPERS, 'A', 'B', 'C', 'D', 'H', 'I') };
+ uint8_t mix_bits = 0;
+ MIXER_STEPPER_LOOP(i) {
+ if (parser.seenval(mixing_codes[i])) {
+ SBI(mix_bits, i);
+ mixer.set_collector(i, parser.value_float());
+ }
+ }
+ // If any mixing factors were included, clear the rest
+ // If none were included, preserve the last mix
+ if (mix_bits) {
+ MIXER_STEPPER_LOOP(i)
+ if (!TEST(mix_bits, i)) mixer.set_collector(i, 0.0f);
+ mixer.normalize();
+ }
+ }
+
+#endif // DIRECT_MIXING_IN_G1
+
+#endif // MIXING_EXTRUDER
diff --git a/Marlin/src/gcode/feature/mixing/M166.cpp b/Marlin/src/gcode/feature/mixing/M166.cpp
new file mode 100644
index 0000000..9e071a4
--- /dev/null
+++ b/Marlin/src/gcode/feature/mixing/M166.cpp
@@ -0,0 +1,103 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if ENABLED(GRADIENT_MIX)
+
+#include "../../gcode.h"
+#include "../../../module/motion.h"
+#include "../../../module/planner.h"
+#include "../../../feature/mixing.h"
+
+inline void echo_mix() {
+ SERIAL_ECHOPAIR(" (", int(mixer.mix[0]), "%|", int(mixer.mix[1]), "%)");
+}
+
+inline void echo_zt(const int t, const float &z) {
+ mixer.update_mix_from_vtool(t);
+ SERIAL_ECHOPAIR_P(SP_Z_STR, z, SP_T_STR, t);
+ echo_mix();
+}
+
+/**
+ * M166: Set a simple gradient mix for a two-component mixer
+ * based on the Geeetech A10M implementation by Jone Liu.
+ *
+ * S[bool] - Enable / disable gradients
+ * A[float] - Starting Z for the gradient
+ * Z[float] - Ending Z for the gradient. (Must be greater than the starting Z.)
+ * I[index] - V-Tool to use as the starting mix.
+ * J[index] - V-Tool to use as the ending mix.
+ *
+ * T[index] - A V-Tool index to use as an alias for the Gradient (Requires GRADIENT_VTOOL)
+ * T with no index clears the setting. Note: This can match the I or J value.
+ *
+ * Example: M166 S1 A0 Z20 I0 J1
+ */
+void GcodeSuite::M166() {
+ if (parser.seenval('A')) mixer.gradient.start_z = parser.value_float();
+ if (parser.seenval('Z')) mixer.gradient.end_z = parser.value_float();
+ if (parser.seenval('I')) mixer.gradient.start_vtool = (uint8_t)constrain(parser.value_int(), 0, MIXING_VIRTUAL_TOOLS);
+ if (parser.seenval('J')) mixer.gradient.end_vtool = (uint8_t)constrain(parser.value_int(), 0, MIXING_VIRTUAL_TOOLS);
+
+ #if ENABLED(GRADIENT_VTOOL)
+ if (parser.seen('T')) mixer.gradient.vtool_index = parser.byteval('T', -1);
+ #endif
+
+ if (parser.seen('S')) mixer.gradient.enabled = parser.value_bool();
+
+ mixer.refresh_gradient();
+
+ SERIAL_ECHOPGM("Gradient Mix ");
+ serialprint_onoff(mixer.gradient.enabled);
+ if (mixer.gradient.enabled) {
+
+ #if ENABLED(GRADIENT_VTOOL)
+ if (mixer.gradient.vtool_index >= 0) {
+ SERIAL_ECHOPAIR(" (T", int(mixer.gradient.vtool_index));
+ SERIAL_CHAR(')');
+ }
+ #endif
+
+ SERIAL_ECHOPGM(" ; Start");
+ echo_zt(mixer.gradient.start_vtool, mixer.gradient.start_z);
+
+ SERIAL_ECHOPGM(" ; End");
+ echo_zt(mixer.gradient.end_vtool, mixer.gradient.end_z);
+
+ mixer.update_mix_from_gradient();
+
+ SERIAL_ECHOPGM(" ; Current Z");
+ #if ENABLED(DELTA)
+ get_cartesian_from_steppers();
+ SERIAL_ECHO(cartes.z);
+ #else
+ SERIAL_ECHO(planner.get_axis_position_mm(Z_AXIS));
+ #endif
+ echo_mix();
+ }
+
+ SERIAL_EOL();
+}
+
+#endif // GRADIENT_MIX
diff --git a/Marlin/src/gcode/feature/network/M552-M554.cpp b/Marlin/src/gcode/feature/network/M552-M554.cpp
new file mode 100644
index 0000000..6ea15fe
--- /dev/null
+++ b/Marlin/src/gcode/feature/network/M552-M554.cpp
@@ -0,0 +1,126 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfigPre.h"
+
+#if HAS_ETHERNET
+
+#include "../../../feature/ethernet.h"
+#include "../../../core/serial.h"
+#include "../../gcode.h"
+
+void say_ethernet() { SERIAL_ECHOPGM(" Ethernet "); }
+
+void ETH0_report() {
+ say_ethernet();
+ SERIAL_ECHO_TERNARY(ethernet.hardware_enabled, "port ", "en", "dis", "abled.\n");
+ if (ethernet.hardware_enabled) {
+ say_ethernet();
+ SERIAL_ECHO_TERNARY(ethernet.have_telnet_client, "client ", "en", "dis", "abled.\n");
+ }
+ else
+ SERIAL_ECHOLNPGM("Send 'M552 S1' to enable.");
+}
+
+void MAC_report() {
+ uint8_t mac[6];
+ if (ethernet.hardware_enabled) {
+ Ethernet.MACAddress(mac);
+ SERIAL_ECHOPGM(" MAC: ");
+ LOOP_L_N(i, 6) {
+ if (mac[i] < 16) SERIAL_CHAR('0');
+ SERIAL_PRINT(mac[i], HEX);
+ if (i < 5) SERIAL_CHAR(':');
+ }
+ }
+ SERIAL_EOL();
+}
+
+// Display current values when the link is active,
+// otherwise show the stored values
+void ip_report(const uint16_t cmd, PGM_P const post, const IPAddress &ipo) {
+ SERIAL_CHAR('M'); SERIAL_ECHO(cmd); SERIAL_CHAR(' ');
+ LOOP_L_N(i, 4) {
+ SERIAL_ECHO(ipo[i]);
+ if (i < 3) SERIAL_CHAR('.');
+ }
+ SERIAL_ECHOPGM(" ; ");
+ SERIAL_ECHOPGM_P(post);
+ SERIAL_EOL();
+}
+void M552_report() {
+ ip_report(552, PSTR("ip address"), Ethernet.linkStatus() == LinkON ? Ethernet.localIP() : ethernet.ip);
+}
+void M553_report() {
+ ip_report(553, PSTR("subnet mask"), Ethernet.linkStatus() == LinkON ? Ethernet.subnetMask() : ethernet.subnet);
+}
+void M554_report() {
+ ip_report(554, PSTR("gateway"), Ethernet.linkStatus() == LinkON ? Ethernet.gatewayIP() : ethernet.gateway);
+}
+
+/**
+ * M552: Set IP address, enable/disable network interface
+ *
+ * S0 : disable networking
+ * S1 : enable networking
+ * S-1 : reset network interface
+ *
+ * Pnnn : Set IP address, 0.0.0.0 means acquire an IP address using DHCP
+ */
+void GcodeSuite::M552() {
+ const bool seenP = parser.seenval('P');
+ if (seenP) ethernet.ip.fromString(parser.value_string());
+
+ const bool seenS = parser.seenval('S');
+ if (seenS) {
+ switch (parser.value_int()) {
+ case -1:
+ if (ethernet.telnetClient) ethernet.telnetClient.stop();
+ ethernet.init();
+ break;
+ case 0: ethernet.hardware_enabled = false; break;
+ case 1: ethernet.hardware_enabled = true; break;
+ default: break;
+ }
+ }
+ const bool nopar = !seenS && !seenP;
+ if (nopar || seenS) ETH0_report();
+ if (nopar || seenP) M552_report();
+}
+
+/**
+ * M553 Pnnn - Set netmask
+ */
+void GcodeSuite::M553() {
+ if (parser.seenval('P')) ethernet.subnet.fromString(parser.value_string());
+ M553_report();
+}
+
+/**
+ * M554 Pnnn - Set Gateway
+ */
+void GcodeSuite::M554() {
+ if (parser.seenval('P')) ethernet.gateway.fromString(parser.value_string());
+ M554_report();
+}
+
+#endif // HAS_ETHERNET
diff --git a/Marlin/src/gcode/feature/password/M510-M512.cpp b/Marlin/src/gcode/feature/password/M510-M512.cpp
new file mode 100644
index 0000000..eeb9b1d
--- /dev/null
+++ b/Marlin/src/gcode/feature/password/M510-M512.cpp
@@ -0,0 +1,83 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfigPre.h"
+
+#if ENABLED(PASSWORD_FEATURE)
+
+#include "../../../feature/password/password.h"
+#include "../../../core/serial.h"
+#include "../../gcode.h"
+
+//
+// M510: Lock Printer
+//
+void GcodeSuite::M510() {
+ password.lock_machine();
+}
+
+//
+// M511: Unlock Printer
+//
+#if ENABLED(PASSWORD_UNLOCK_GCODE)
+
+ void GcodeSuite::M511() {
+ if (password.is_locked) {
+ password.value_entry = parser.ulongval('P');
+ password.authentication_check();
+ }
+ }
+
+#endif // PASSWORD_UNLOCK_GCODE
+
+//
+// M512: Set/Change/Remove Password
+//
+#if ENABLED(PASSWORD_CHANGE_GCODE)
+
+ void GcodeSuite::M512() {
+ if (password.is_set && parser.ulongval('P') != password.value) {
+ SERIAL_ECHOLNPGM(STR_WRONG_PASSWORD);
+ return;
+ }
+
+ if (parser.seenval('S')) {
+ password.value_entry = parser.ulongval('S');
+
+ if (password.value_entry < CAT(1e, PASSWORD_LENGTH)) {
+ password.is_set = true;
+ password.value = password.value_entry;
+ SERIAL_ECHOLNPAIR(STR_PASSWORD_SET, password.value); // TODO: Update password.string
+ }
+ else
+ SERIAL_ECHOLNPGM(STR_PASSWORD_TOO_LONG);
+ }
+ else {
+ password.is_set = false;
+ SERIAL_ECHOLNPGM(STR_PASSWORD_REMOVED);
+ }
+ SERIAL_ECHOLNPGM(STR_REMINDER_SAVE_SETTINGS);
+ }
+
+#endif // PASSWORD_CHANGE_GCODE
+
+#endif // PASSWORD_FEATURE
diff --git a/Marlin/src/gcode/feature/pause/G27.cpp b/Marlin/src/gcode/feature/pause/G27.cpp
new file mode 100644
index 0000000..3ce618d
--- /dev/null
+++ b/Marlin/src/gcode/feature/pause/G27.cpp
@@ -0,0 +1,41 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+
+#include "../../../inc/MarlinConfig.h"
+
+#if ENABLED(NOZZLE_PARK_FEATURE)
+
+#include "../../gcode.h"
+#include "../../../libs/nozzle.h"
+#include "../../../module/motion.h"
+
+/**
+ * G27: Park the nozzle
+ */
+void GcodeSuite::G27() {
+ // Don't allow nozzle parking without homing first
+ if (homing_needed_error()) return;
+ nozzle.park(parser.ushortval('P'));
+}
+
+#endif // NOZZLE_PARK_FEATURE
diff --git a/Marlin/src/gcode/feature/pause/G60.cpp b/Marlin/src/gcode/feature/pause/G60.cpp
new file mode 100644
index 0000000..6f695b9
--- /dev/null
+++ b/Marlin/src/gcode/feature/pause/G60.cpp
@@ -0,0 +1,58 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if SAVED_POSITIONS
+
+#include "../../gcode.h"
+#include "../../../module/motion.h"
+
+#define DEBUG_OUT ENABLED(SAVED_POSITIONS_DEBUG)
+#include "../../../core/debug_out.h"
+
+/**
+ * G60: Save current position
+ *
+ * S - Memory slot # (0-based) to save into (default 0)
+ */
+void GcodeSuite::G60() {
+ const uint8_t slot = parser.byteval('S');
+
+ if (slot >= SAVED_POSITIONS) {
+ SERIAL_ERROR_MSG(STR_INVALID_POS_SLOT STRINGIFY(SAVED_POSITIONS));
+ return;
+ }
+
+ stored_position[slot] = current_position;
+ SBI(saved_slots[slot >> 3], slot & 0x07);
+
+ #if ENABLED(SAVED_POSITIONS_DEBUG)
+ const xyze_pos_t &pos = stored_position[slot];
+ DEBUG_ECHOPAIR_F(STR_SAVED_POS " S", slot);
+ DEBUG_ECHOPAIR_F(" : X", pos.x);
+ DEBUG_ECHOPAIR_F_P(SP_Y_STR, pos.y);
+ DEBUG_ECHOLNPAIR_F_P(SP_Z_STR, pos.z);
+ #endif
+}
+
+#endif // SAVED_POSITIONS
diff --git a/Marlin/src/gcode/feature/pause/G61.cpp b/Marlin/src/gcode/feature/pause/G61.cpp
new file mode 100644
index 0000000..5d89af0
--- /dev/null
+++ b/Marlin/src/gcode/feature/pause/G61.cpp
@@ -0,0 +1,73 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if SAVED_POSITIONS
+
+#include "../../../module/planner.h"
+#include "../../gcode.h"
+#include "../../../module/motion.h"
+
+/**
+ * G61: Return to saved position
+ *
+ * F - Feedrate (optional) for the move back.
+ * S - Slot # (0-based) to restore from (default 0).
+ * X Y Z - Axes to restore. At least one is required.
+ */
+void GcodeSuite::G61(void) {
+
+ const uint8_t slot = parser.byteval('S');
+
+ #if SAVED_POSITIONS < 256
+ if (slot >= SAVED_POSITIONS) {
+ SERIAL_ERROR_MSG(STR_INVALID_POS_SLOT STRINGIFY(SAVED_POSITIONS));
+ return;
+ }
+ #endif
+
+ // No saved position? No axes being restored?
+ if (!TEST(saved_slots[slot >> 3], slot & 0x07) || !parser.seen("XYZ")) return;
+
+ SERIAL_ECHOPAIR(STR_RESTORING_POS " S", int(slot));
+ LOOP_XYZ(i) {
+ destination[i] = parser.seen(XYZ_CHAR(i))
+ ? stored_position[slot][i] + parser.value_axis_units((AxisEnum)i)
+ : current_position[i];
+ SERIAL_CHAR(' ', XYZ_CHAR(i));
+ SERIAL_ECHO_F(destination[i]);
+ }
+ SERIAL_EOL();
+
+ // Apply any given feedrate over 0.0
+ feedRate_t saved_feedrate = feedrate_mm_s;
+ const float fr = parser.linearval('F');
+ if (fr > 0.0) feedrate_mm_s = MMM_TO_MMS(fr);
+
+ // Move to the saved position
+ prepare_line_to_destination();
+
+ feedrate_mm_s = saved_feedrate;
+}
+
+#endif // SAVED_POSITIONS
diff --git a/Marlin/src/gcode/feature/pause/M125.cpp b/Marlin/src/gcode/feature/pause/M125.cpp
new file mode 100644
index 0000000..9391b86
--- /dev/null
+++ b/Marlin/src/gcode/feature/pause/M125.cpp
@@ -0,0 +1,90 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if ENABLED(PARK_HEAD_ON_PAUSE)
+
+#include "../../gcode.h"
+#include "../../parser.h"
+#include "../../../feature/pause.h"
+#include "../../../lcd/marlinui.h"
+#include "../../../module/motion.h"
+#include "../../../module/printcounter.h"
+#include "../../../sd/cardreader.h"
+
+#if ENABLED(POWER_LOSS_RECOVERY)
+ #include "../../../feature/powerloss.h"
+#endif
+
+/**
+ * M125: Store current position and move to parking position.
+ * Called on pause (by M25) to prevent material leaking onto the
+ * object. On resume (M24) the head will be moved back and the
+ * print will resume.
+ *
+ * When not actively SD printing, M125 simply moves to the park
+ * position and waits, resuming with a button click or M108.
+ * Without PARK_HEAD_ON_PAUSE the M125 command does nothing.
+ *
+ * L = Override retract Length
+ * X = Override park position X
+ * Y = Override park position Y
+ * Z = Override Z raise
+ *
+ * With an LCD menu:
+ * P = Always show a prompt and await a response
+ */
+void GcodeSuite::M125() {
+ // Initial retract before move to filament change position
+ const float retract = -ABS(parser.seen('L') ? parser.value_axis_units(E_AXIS) : (PAUSE_PARK_RETRACT_LENGTH));
+
+ xyz_pos_t park_point = NOZZLE_PARK_POINT;
+
+ // Move XY axes to filament change position or given position
+ if (parser.seenval('X')) park_point.x = RAW_X_POSITION(parser.linearval('X'));
+ if (parser.seenval('Y')) park_point.y = RAW_X_POSITION(parser.linearval('Y'));
+
+ // Lift Z axis
+ if (parser.seenval('Z')) park_point.z = parser.linearval('Z');
+
+ #if HAS_HOTEND_OFFSET && NONE(DUAL_X_CARRIAGE, DELTA)
+ park_point += hotend_offset[active_extruder];
+ #endif
+
+ const bool sd_printing = TERN0(SDSUPPORT, IS_SD_PRINTING());
+
+ ui.pause_show_message(PAUSE_MESSAGE_PARKING, PAUSE_MODE_PAUSE_PRINT);
+
+ // If possible, show an LCD prompt with the 'P' flag
+ const bool show_lcd = TERN0(HAS_LCD_MENU, parser.boolval('P'));
+
+ if (pause_print(retract, park_point, 0, show_lcd)) {
+ TERN_(POWER_LOSS_RECOVERY, if (recovery.enabled) recovery.save(true));
+ if (ENABLED(EXTENSIBLE_UI) || !sd_printing || show_lcd) {
+ wait_for_confirmation(false, 0);
+ resume_print(0, 0, -retract, 0);
+ }
+ }
+}
+
+#endif // PARK_HEAD_ON_PAUSE
diff --git a/Marlin/src/gcode/feature/pause/M600.cpp b/Marlin/src/gcode/feature/pause/M600.cpp
new file mode 100644
index 0000000..1c282f2
--- /dev/null
+++ b/Marlin/src/gcode/feature/pause/M600.cpp
@@ -0,0 +1,172 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if ENABLED(ADVANCED_PAUSE_FEATURE)
+
+#include "../../gcode.h"
+#include "../../../feature/pause.h"
+#include "../../../module/motion.h"
+#include "../../../module/printcounter.h"
+#include "../../../lcd/marlinui.h"
+
+#if HAS_MULTI_EXTRUDER
+ #include "../../../module/tool_change.h"
+#endif
+
+#if ENABLED(MMU2_MENUS)
+ #include "../../../lcd/menu/menu_mmu2.h"
+#endif
+
+#if ENABLED(MIXING_EXTRUDER)
+ #include "../../../feature/mixing.h"
+#endif
+
+#if HAS_FILAMENT_SENSOR
+ #include "../../../feature/runout.h"
+#endif
+
+/**
+ * M600: Pause for filament change
+ *
+ * E[distance] - Retract the filament this far
+ * Z[distance] - Move the Z axis by this distance
+ * X[position] - Move to this X position, with Y
+ * Y[position] - Move to this Y position, with X
+ * U[distance] - Retract distance for removal (manual reload)
+ * L[distance] - Extrude distance for insertion (manual reload)
+ * B[count] - Number of times to beep, -1 for indefinite (if equipped with a buzzer)
+ * T[toolhead] - Select extruder for filament change
+ * R[temp] - Resume temperature (in current units)
+ *
+ * Default values are used for omitted arguments.
+ */
+void GcodeSuite::M600() {
+
+ #if ENABLED(MIXING_EXTRUDER)
+ const int8_t target_e_stepper = get_target_e_stepper_from_command();
+ if (target_e_stepper < 0) return;
+
+ const uint8_t old_mixing_tool = mixer.get_current_vtool();
+ mixer.T(MIXER_DIRECT_SET_TOOL);
+
+ MIXER_STEPPER_LOOP(i) mixer.set_collector(i, i == uint8_t(target_e_stepper) ? 1.0 : 0.0);
+ mixer.normalize();
+
+ const int8_t target_extruder = active_extruder;
+ #else
+ const int8_t target_extruder = get_target_extruder_from_command();
+ if (target_extruder < 0) return;
+ #endif
+
+ #if ENABLED(DUAL_X_CARRIAGE)
+ int8_t DXC_ext = target_extruder;
+ if (!parser.seen('T')) { // If no tool index is specified, M600 was (probably) sent in response to filament runout.
+ // In this case, for duplicating modes set DXC_ext to the extruder that ran out.
+ #if HAS_FILAMENT_SENSOR && NUM_RUNOUT_SENSORS > 1
+ if (idex_is_duplicating())
+ DXC_ext = (READ(FIL_RUNOUT2_PIN) == FIL_RUNOUT2_STATE) ? 1 : 0;
+ #else
+ DXC_ext = active_extruder;
+ #endif
+ }
+ #endif
+
+ // Show initial "wait for start" message
+ #if DISABLED(MMU2_MENUS)
+ ui.pause_show_message(PAUSE_MESSAGE_CHANGING, PAUSE_MODE_PAUSE_PRINT, target_extruder);
+ #endif
+
+ #if ENABLED(HOME_BEFORE_FILAMENT_CHANGE)
+ // If needed, home before parking for filament change
+ if (!all_axes_trusted()) home_all_axes(true);
+ #endif
+
+ #if HAS_MULTI_EXTRUDER
+ // Change toolhead if specified
+ const uint8_t active_extruder_before_filament_change = active_extruder;
+ if (active_extruder != target_extruder && TERN1(DUAL_X_CARRIAGE, !idex_is_duplicating()))
+ tool_change(target_extruder, false);
+ #endif
+
+ // Initial retract before move to filament change position
+ const float retract = -ABS(parser.seen('E') ? parser.value_axis_units(E_AXIS) : (PAUSE_PARK_RETRACT_LENGTH));
+
+ xyz_pos_t park_point NOZZLE_PARK_POINT;
+
+ // Lift Z axis
+ if (parser.seenval('Z')) park_point.z = parser.linearval('Z');
+
+ // Move XY axes to filament change position or given position
+ if (parser.seenval('X')) park_point.x = parser.linearval('X');
+ if (parser.seenval('Y')) park_point.y = parser.linearval('Y');
+
+ #if HAS_HOTEND_OFFSET && NONE(DUAL_X_CARRIAGE, DELTA)
+ park_point += hotend_offset[active_extruder];
+ #endif
+
+ #if ENABLED(MMU2_MENUS)
+ // For MMU2 reset retract and load/unload values so they don't mess with MMU filament handling
+ constexpr float unload_length = 0.5f,
+ slow_load_length = 0.0f,
+ fast_load_length = 0.0f;
+ #else
+ // Unload filament
+ const float unload_length = -ABS(parser.seen('U') ? parser.value_axis_units(E_AXIS)
+ : fc_settings[active_extruder].unload_length);
+
+ // Slow load filament
+ constexpr float slow_load_length = FILAMENT_CHANGE_SLOW_LOAD_LENGTH;
+
+ // Fast load filament
+ const float fast_load_length = ABS(parser.seen('L') ? parser.value_axis_units(E_AXIS)
+ : fc_settings[active_extruder].load_length);
+ #endif
+
+ const int beep_count = parser.intval('B', -1
+ #ifdef FILAMENT_CHANGE_ALERT_BEEPS
+ + 1 + FILAMENT_CHANGE_ALERT_BEEPS
+ #endif
+ );
+
+ if (pause_print(retract, park_point, unload_length, true DXC_PASS)) {
+ #if ENABLED(MMU2_MENUS)
+ mmu2_M600();
+ resume_print(slow_load_length, fast_load_length, 0, beep_count DXC_PASS);
+ #else
+ wait_for_confirmation(true, beep_count DXC_PASS);
+ resume_print(slow_load_length, fast_load_length, ADVANCED_PAUSE_PURGE_LENGTH,
+ beep_count, (parser.seenval('R') ? parser.value_celsius() : 0) DXC_PASS);
+ #endif
+ }
+
+ #if HAS_MULTI_EXTRUDER
+ // Restore toolhead if it was changed
+ if (active_extruder_before_filament_change != active_extruder)
+ tool_change(active_extruder_before_filament_change, false);
+ #endif
+
+ TERN_(MIXING_EXTRUDER, mixer.T(old_mixing_tool)); // Restore original mixing tool
+}
+
+#endif // ADVANCED_PAUSE_FEATURE
diff --git a/Marlin/src/gcode/feature/pause/M603.cpp b/Marlin/src/gcode/feature/pause/M603.cpp
new file mode 100644
index 0000000..9c3b774
--- /dev/null
+++ b/Marlin/src/gcode/feature/pause/M603.cpp
@@ -0,0 +1,65 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if ENABLED(ADVANCED_PAUSE_FEATURE)
+
+#include "../../gcode.h"
+#include "../../../feature/pause.h"
+#include "../../../module/motion.h"
+#include "../../../module/printcounter.h"
+
+#if HAS_MULTI_EXTRUDER
+ #include "../../../module/tool_change.h"
+#endif
+
+/**
+ * M603: Configure filament change
+ *
+ * T[toolhead] - Select extruder to configure, active extruder if not specified
+ * U[distance] - Retract distance for removal, for the specified extruder
+ * L[distance] - Extrude distance for insertion, for the specified extruder
+ */
+void GcodeSuite::M603() {
+
+ const int8_t target_extruder = get_target_extruder_from_command();
+ if (target_extruder < 0) return;
+
+ // Unload length
+ if (parser.seen('U')) {
+ fc_settings[target_extruder].unload_length = ABS(parser.value_axis_units(E_AXIS));
+ #if ENABLED(PREVENT_LENGTHY_EXTRUDE)
+ NOMORE(fc_settings[target_extruder].unload_length, EXTRUDE_MAXLENGTH);
+ #endif
+ }
+
+ // Load length
+ if (parser.seen('L')) {
+ fc_settings[target_extruder].load_length = ABS(parser.value_axis_units(E_AXIS));
+ #if ENABLED(PREVENT_LENGTHY_EXTRUDE)
+ NOMORE(fc_settings[target_extruder].load_length, EXTRUDE_MAXLENGTH);
+ #endif
+ }
+}
+
+#endif // ADVANCED_PAUSE_FEATURE
diff --git a/Marlin/src/gcode/feature/pause/M701_M702.cpp b/Marlin/src/gcode/feature/pause/M701_M702.cpp
new file mode 100644
index 0000000..9a2b774
--- /dev/null
+++ b/Marlin/src/gcode/feature/pause/M701_M702.cpp
@@ -0,0 +1,235 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfigPre.h"
+
+#if ENABLED(FILAMENT_LOAD_UNLOAD_GCODES)
+
+#include "../../gcode.h"
+#include "../../../MarlinCore.h"
+#include "../../../module/motion.h"
+#include "../../../module/temperature.h"
+#include "../../../feature/pause.h"
+#include "../../../lcd/marlinui.h"
+
+#if HAS_MULTI_EXTRUDER
+ #include "../../../module/tool_change.h"
+#endif
+
+#if HAS_PRUSA_MMU2
+ #include "../../../feature/mmu/mmu2.h"
+#endif
+
+#if ENABLED(MIXING_EXTRUDER)
+ #include "../../../feature/mixing.h"
+#endif
+
+/**
+ * M701: Load filament
+ *
+ * T - Extruder number. Required for mixing extruder.
+ * For non-mixing, current extruder if omitted.
+ * Z - Move the Z axis by this distance
+ * L - Extrude distance for insertion (positive value) (manual reload)
+ *
+ * Default values are used for omitted arguments.
+ */
+void GcodeSuite::M701() {
+ xyz_pos_t park_point = NOZZLE_PARK_POINT;
+
+ // Don't raise Z if the machine isn't homed
+ if (TERN0(NO_MOTION_BEFORE_HOMING, axes_should_home())) park_point.z = 0;
+
+ #if ENABLED(MIXING_EXTRUDER)
+ const int8_t target_e_stepper = get_target_e_stepper_from_command();
+ if (target_e_stepper < 0) return;
+
+ const uint8_t old_mixing_tool = mixer.get_current_vtool();
+ mixer.T(MIXER_DIRECT_SET_TOOL);
+
+ MIXER_STEPPER_LOOP(i) mixer.set_collector(i, (i == (uint8_t)target_e_stepper) ? 1.0 : 0.0);
+ mixer.normalize();
+
+ const int8_t target_extruder = active_extruder;
+ #else
+ const int8_t target_extruder = get_target_extruder_from_command();
+ if (target_extruder < 0) return;
+ #endif
+
+ // Z axis lift
+ if (parser.seenval('Z')) park_point.z = parser.linearval('Z');
+
+ // Show initial "wait for load" message
+ ui.pause_show_message(PAUSE_MESSAGE_LOAD, PAUSE_MODE_LOAD_FILAMENT, target_extruder);
+
+ #if HAS_MULTI_EXTRUDER && (HAS_PRUSA_MMU1 || !HAS_MMU)
+ // Change toolhead if specified
+ uint8_t active_extruder_before_filament_change = active_extruder;
+ if (active_extruder != target_extruder)
+ tool_change(target_extruder, false);
+ #endif
+
+ // Lift Z axis
+ if (park_point.z > 0)
+ do_blocking_move_to_z(_MIN(current_position.z + park_point.z, Z_MAX_POS), feedRate_t(NOZZLE_PARK_Z_FEEDRATE));
+
+ // Load filament
+ #if HAS_PRUSA_MMU2
+ mmu2.load_filament_to_nozzle(target_extruder);
+ #else
+ constexpr float purge_length = ADVANCED_PAUSE_PURGE_LENGTH,
+ slow_load_length = FILAMENT_CHANGE_SLOW_LOAD_LENGTH;
+ const float fast_load_length = ABS(parser.seen('L') ? parser.value_axis_units(E_AXIS)
+ : fc_settings[active_extruder].load_length);
+ load_filament(
+ slow_load_length, fast_load_length, purge_length,
+ FILAMENT_CHANGE_ALERT_BEEPS,
+ true, // show_lcd
+ thermalManager.still_heating(target_extruder), // pause_for_user
+ PAUSE_MODE_LOAD_FILAMENT // pause_mode
+ #if ENABLED(DUAL_X_CARRIAGE)
+ , target_extruder // Dual X target
+ #endif
+ );
+ #endif
+
+ // Restore Z axis
+ if (park_point.z > 0)
+ do_blocking_move_to_z(_MAX(current_position.z - park_point.z, 0), feedRate_t(NOZZLE_PARK_Z_FEEDRATE));
+
+ #if HAS_MULTI_EXTRUDER && (HAS_PRUSA_MMU1 || !HAS_MMU)
+ // Restore toolhead if it was changed
+ if (active_extruder_before_filament_change != active_extruder)
+ tool_change(active_extruder_before_filament_change, false);
+ #endif
+
+ TERN_(MIXING_EXTRUDER, mixer.T(old_mixing_tool)); // Restore original mixing tool
+
+ // Show status screen
+ ui.pause_show_message(PAUSE_MESSAGE_STATUS);
+}
+
+/**
+ * M702: Unload filament
+ *
+ * T - Extruder number. Required for mixing extruder.
+ * For non-mixing, if omitted, current extruder
+ * (or ALL extruders with FILAMENT_UNLOAD_ALL_EXTRUDERS).
+ * Z - Move the Z axis by this distance
+ * U - Retract distance for removal (manual reload)
+ *
+ * Default values are used for omitted arguments.
+ */
+void GcodeSuite::M702() {
+ xyz_pos_t park_point = NOZZLE_PARK_POINT;
+
+ // Don't raise Z if the machine isn't homed
+ if (TERN0(NO_MOTION_BEFORE_HOMING, axes_should_home())) park_point.z = 0;
+
+ #if ENABLED(MIXING_EXTRUDER)
+ const uint8_t old_mixing_tool = mixer.get_current_vtool();
+
+ #if ENABLED(FILAMENT_UNLOAD_ALL_EXTRUDERS)
+ float mix_multiplier = 1.0;
+ const bool seenT = parser.seenval('T');
+ if (!seenT) {
+ mixer.T(MIXER_AUTORETRACT_TOOL);
+ mix_multiplier = MIXING_STEPPERS;
+ }
+ #else
+ constexpr bool seenT = true;
+ #endif
+
+ if (seenT) {
+ const int8_t target_e_stepper = get_target_e_stepper_from_command();
+ if (target_e_stepper < 0) return;
+ mixer.T(MIXER_DIRECT_SET_TOOL);
+ MIXER_STEPPER_LOOP(i) mixer.set_collector(i, (i == (uint8_t)target_e_stepper) ? 1.0 : 0.0);
+ mixer.normalize();
+ }
+
+ const int8_t target_extruder = active_extruder;
+ #else
+ const int8_t target_extruder = get_target_extruder_from_command();
+ if (target_extruder < 0) return;
+ #endif
+
+ // Z axis lift
+ if (parser.seenval('Z')) park_point.z = parser.linearval('Z');
+
+ // Show initial "wait for unload" message
+ ui.pause_show_message(PAUSE_MESSAGE_UNLOAD, PAUSE_MODE_UNLOAD_FILAMENT, target_extruder);
+
+ #if HAS_MULTI_EXTRUDER && (HAS_PRUSA_MMU1 || !HAS_MMU)
+ // Change toolhead if specified
+ uint8_t active_extruder_before_filament_change = active_extruder;
+ if (active_extruder != target_extruder)
+ tool_change(target_extruder, false);
+ #endif
+
+ // Lift Z axis
+ if (park_point.z > 0)
+ do_blocking_move_to_z(_MIN(current_position.z + park_point.z, Z_MAX_POS), feedRate_t(NOZZLE_PARK_Z_FEEDRATE));
+
+ // Unload filament
+ #if HAS_PRUSA_MMU2
+ mmu2.unload();
+ #else
+ #if BOTH(HAS_MULTI_EXTRUDER, FILAMENT_UNLOAD_ALL_EXTRUDERS)
+ if (!parser.seenval('T')) {
+ HOTEND_LOOP() {
+ if (e != active_extruder) tool_change(e, false);
+ unload_filament(-fc_settings[e].unload_length, true, PAUSE_MODE_UNLOAD_FILAMENT);
+ }
+ }
+ else
+ #endif
+ {
+ // Unload length
+ const float unload_length = -ABS(parser.seen('U') ? parser.value_axis_units(E_AXIS)
+ : fc_settings[target_extruder].unload_length);
+
+ unload_filament(unload_length, true, PAUSE_MODE_UNLOAD_FILAMENT
+ #if ALL(FILAMENT_UNLOAD_ALL_EXTRUDERS, MIXING_EXTRUDER)
+ , mix_multiplier
+ #endif
+ );
+ }
+ #endif
+
+ // Restore Z axis
+ if (park_point.z > 0)
+ do_blocking_move_to_z(_MAX(current_position.z - park_point.z, 0), feedRate_t(NOZZLE_PARK_Z_FEEDRATE));
+
+ #if HAS_MULTI_EXTRUDER && (HAS_PRUSA_MMU1 || !HAS_MMU)
+ // Restore toolhead if it was changed
+ if (active_extruder_before_filament_change != active_extruder)
+ tool_change(active_extruder_before_filament_change, false);
+ #endif
+
+ TERN_(MIXING_EXTRUDER, mixer.T(old_mixing_tool)); // Restore original mixing tool
+
+ // Show status screen
+ ui.pause_show_message(PAUSE_MESSAGE_STATUS);
+}
+
+#endif // ADVANCED_PAUSE_FEATURE
diff --git a/Marlin/src/gcode/feature/power_monitor/M430.cpp b/Marlin/src/gcode/feature/power_monitor/M430.cpp
new file mode 100644
index 0000000..9559404
--- /dev/null
+++ b/Marlin/src/gcode/feature/power_monitor/M430.cpp
@@ -0,0 +1,70 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if HAS_POWER_MONITOR
+
+#include "../../../feature/power_monitor.h"
+#include "../../../MarlinCore.h"
+#include "../../gcode.h"
+
+/**
+ * M430: Enable/disable current LCD display
+ * With no parameters report the system current draw (in Amps)
+ *
+ * I[bool] - Set Display of current on the LCD
+ * V[bool] - Set Display of voltage on the LCD
+ * W[bool] - Set Display of power on the LCD
+ */
+void GcodeSuite::M430() {
+ bool do_report = true;
+ #if HAS_WIRED_LCD
+ #if ENABLED(POWER_MONITOR_CURRENT)
+ if (parser.seen('I')) { power_monitor.set_current_display(parser.value_bool()); do_report = false; }
+ #endif
+ #if HAS_POWER_MONITOR_VREF
+ if (parser.seen('V')) { power_monitor.set_voltage_display(parser.value_bool()); do_report = false; }
+ #endif
+ #if HAS_POWER_MONITOR_WATTS
+ if (parser.seen('W')) { power_monitor.set_power_display(parser.value_bool()); do_report = false; }
+ #endif
+ #endif
+ if (do_report) {
+ SERIAL_ECHOLNPAIR(
+ #if ENABLED(POWER_MONITOR_CURRENT)
+ "Current: ", power_monitor.getAmps(), "A"
+ #if HAS_POWER_MONITOR_VREF
+ " "
+ #endif
+ #endif
+ #if HAS_POWER_MONITOR_VREF
+ "Voltage: ", power_monitor.getVolts(), "V"
+ #endif
+ #if HAS_POWER_MONITOR_WATTS
+ " Power: ", power_monitor.getPower(), "W"
+ #endif
+ );
+ }
+}
+
+#endif // HAS_POWER_MONITOR
diff --git a/Marlin/src/gcode/feature/powerloss/M1000.cpp b/Marlin/src/gcode/feature/powerloss/M1000.cpp
new file mode 100644
index 0000000..14c9253
--- /dev/null
+++ b/Marlin/src/gcode/feature/powerloss/M1000.cpp
@@ -0,0 +1,89 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if ENABLED(POWER_LOSS_RECOVERY)
+
+#include "../../gcode.h"
+#include "../../../feature/powerloss.h"
+#include "../../../module/motion.h"
+#include "../../../lcd/marlinui.h"
+#if ENABLED(EXTENSIBLE_UI)
+ #include "../../../lcd/extui/ui_api.h"
+#endif
+
+#define DEBUG_OUT ENABLED(DEBUG_POWER_LOSS_RECOVERY)
+#include "../../../core/debug_out.h"
+
+void menu_job_recovery();
+
+inline void plr_error(PGM_P const prefix) {
+ #if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
+ DEBUG_ECHO_START();
+ serialprintPGM(prefix);
+ DEBUG_ECHOLNPGM(" Job Recovery Data");
+ #else
+ UNUSED(prefix);
+ #endif
+}
+
+#if HAS_LCD_MENU
+ void lcd_power_loss_recovery_cancel();
+#endif
+
+/**
+ * M1000: Resume from power-loss (undocumented)
+ * - With 'S' go to the Resume/Cancel menu
+ * - With no parameters, run recovery commands
+ */
+void GcodeSuite::M1000() {
+
+ if (recovery.valid()) {
+ if (parser.seen('S')) {
+ #if HAS_LCD_MENU
+ ui.goto_screen(menu_job_recovery);
+ #elif ENABLED(DWIN_CREALITY_LCD)
+ recovery.dwin_flag = true;
+ #elif ENABLED(EXTENSIBLE_UI)
+ ExtUI::onPowerLossResume();
+ #else
+ SERIAL_ECHO_MSG("Resume requires LCD.");
+ #endif
+ }
+ else if (parser.seen('C')) {
+ #if HAS_LCD_MENU
+ lcd_power_loss_recovery_cancel();
+ #else
+ recovery.cancel();
+ #endif
+ TERN_(EXTENSIBLE_UI, ExtUI::onPrintTimerStopped());
+ }
+ else
+ recovery.resume();
+ }
+ else
+ plr_error(recovery.info.valid_head ? PSTR("No") : PSTR("Invalid"));
+
+}
+
+#endif // POWER_LOSS_RECOVERY
diff --git a/Marlin/src/gcode/feature/powerloss/M413.cpp b/Marlin/src/gcode/feature/powerloss/M413.cpp
new file mode 100644
index 0000000..64573e5
--- /dev/null
+++ b/Marlin/src/gcode/feature/powerloss/M413.cpp
@@ -0,0 +1,62 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if ENABLED(POWER_LOSS_RECOVERY)
+
+#include "../../gcode.h"
+#include "../../../feature/powerloss.h"
+#include "../../../module/motion.h"
+#include "../../../lcd/marlinui.h"
+
+/**
+ * M413: Enable / Disable power-loss recovery
+ *
+ * Parameters
+ * S[bool] - Flag to enable / disable.
+ * If omitted, report current state.
+ */
+void GcodeSuite::M413() {
+
+ if (parser.seen('S'))
+ recovery.enable(parser.value_bool());
+ else {
+ SERIAL_ECHO_START();
+ SERIAL_ECHOPGM("Power-loss recovery ");
+ serialprintln_onoff(recovery.enabled);
+ }
+
+ #if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
+ if (parser.seen("RL")) recovery.load();
+ if (parser.seen('W')) recovery.save(true);
+ if (parser.seen('P')) recovery.purge();
+ if (parser.seen('D')) recovery.debug(PSTR("M413"));
+ #if PIN_EXISTS(POWER_LOSS)
+ if (parser.seen('O')) recovery._outage();
+ #endif
+ if (parser.seen('E')) serialprintPGM(recovery.exists() ? PSTR("PLR Exists\n") : PSTR("No PLR\n"));
+ if (parser.seen('V')) serialprintPGM(recovery.valid() ? PSTR("Valid\n") : PSTR("Invalid\n"));
+ #endif
+}
+
+#endif // POWER_LOSS_RECOVERY
diff --git a/Marlin/src/gcode/feature/prusa_MMU2/M403.cpp b/Marlin/src/gcode/feature/prusa_MMU2/M403.cpp
new file mode 100644
index 0000000..31d0763
--- /dev/null
+++ b/Marlin/src/gcode/feature/prusa_MMU2/M403.cpp
@@ -0,0 +1,49 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfigPre.h"
+
+#if HAS_PRUSA_MMU2
+
+#include "../../gcode.h"
+#include "../../../feature/mmu/mmu2.h"
+
+/**
+ * M403: Set filament type for MMU2
+ *
+ * Valid filament type values:
+ *
+ * 0 Default
+ * 1 Flexible
+ * 2 PVA
+ */
+void GcodeSuite::M403() {
+ int8_t index = parser.intval('E', -1),
+ type = parser.intval('F', -1);
+
+ if (WITHIN(index, 0, 4) && WITHIN(type, 0, 2))
+ mmu2.set_filament_type(index, type);
+ else
+ SERIAL_ECHO_MSG("M403 - bad arguments.");
+}
+
+#endif // HAS_PRUSA_MMU2
diff --git a/Marlin/src/gcode/feature/runout/M412.cpp b/Marlin/src/gcode/feature/runout/M412.cpp
new file mode 100644
index 0000000..130f9c8
--- /dev/null
+++ b/Marlin/src/gcode/feature/runout/M412.cpp
@@ -0,0 +1,64 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if HAS_FILAMENT_SENSOR
+
+#include "../../gcode.h"
+#include "../../../feature/runout.h"
+
+/**
+ * M412: Enable / Disable filament runout detection
+ *
+ * Parameters
+ * R : Reset the runout sensor
+ * S : Reset and enable/disable the runout sensor
+ * H : Enable/disable host handling of filament runout
+ * D : Extra distance to continue after runout is triggered
+ */
+void GcodeSuite::M412() {
+ if (parser.seen("RS"
+ TERN_(HAS_FILAMENT_RUNOUT_DISTANCE, "D")
+ TERN_(HOST_ACTION_COMMANDS, "H")
+ )) {
+ #if ENABLED(HOST_ACTION_COMMANDS)
+ if (parser.seen('H')) runout.host_handling = parser.value_bool();
+ #endif
+ const bool seenR = parser.seen('R'), seenS = parser.seen('S');
+ if (seenR || seenS) runout.reset();
+ if (seenS) runout.enabled = parser.value_bool();
+ #if HAS_FILAMENT_RUNOUT_DISTANCE
+ if (parser.seen('D')) runout.set_runout_distance(parser.value_linear_units());
+ #endif
+ }
+ else {
+ SERIAL_ECHO_START();
+ SERIAL_ECHOPGM("Filament runout ");
+ serialprintln_onoff(runout.enabled);
+ #if HAS_FILAMENT_RUNOUT_DISTANCE
+ SERIAL_ECHOLNPAIR("Filament runout distance (mm): ", runout.runout_distance());
+ #endif
+ }
+}
+
+#endif // HAS_FILAMENT_SENSOR
diff --git a/Marlin/src/gcode/feature/trinamic/M122.cpp b/Marlin/src/gcode/feature/trinamic/M122.cpp
new file mode 100644
index 0000000..46e4365
--- /dev/null
+++ b/Marlin/src/gcode/feature/trinamic/M122.cpp
@@ -0,0 +1,60 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if HAS_TRINAMIC_CONFIG
+
+#include "../../gcode.h"
+#include "../../../feature/tmc_util.h"
+#include "../../../module/stepper/indirection.h"
+
+/**
+ * M122: Debug TMC drivers
+ */
+void GcodeSuite::M122() {
+ xyze_bool_t print_axis = { false, false, false, false };
+ bool print_all = true;
+ LOOP_XYZE(i) if (parser.seen(axis_codes[i])) { print_axis[i] = true; print_all = false; }
+
+ if (print_all) LOOP_XYZE(i) print_axis[i] = true;
+
+ if (parser.boolval('I')) restore_stepper_drivers();
+
+ #if ENABLED(TMC_DEBUG)
+ #if ENABLED(MONITOR_DRIVER_STATUS)
+ uint16_t interval = MONITOR_DRIVER_STATUS_INTERVAL_MS;
+ if (parser.seen('S') && !parser.value_bool()) interval = 0;
+ if (parser.seenval('P')) NOMORE(interval, parser.value_ushort());
+ tmc_set_report_interval(interval);
+ #endif
+
+ if (parser.seen('V'))
+ tmc_get_registers(print_axis.x, print_axis.y, print_axis.z, print_axis.e);
+ else
+ tmc_report_all(print_axis.x, print_axis.y, print_axis.z, print_axis.e);
+ #endif
+
+ test_tmc_connection(print_axis.x, print_axis.y, print_axis.z, print_axis.e);
+}
+
+#endif // HAS_TRINAMIC_CONFIG
diff --git a/Marlin/src/gcode/feature/trinamic/M569.cpp b/Marlin/src/gcode/feature/trinamic/M569.cpp
new file mode 100644
index 0000000..6b379f1
--- /dev/null
+++ b/Marlin/src/gcode/feature/trinamic/M569.cpp
@@ -0,0 +1,186 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if HAS_STEALTHCHOP
+
+#include "../../gcode.h"
+#include "../../../feature/tmc_util.h"
+#include "../../../module/stepper/indirection.h"
+
+template
+void tmc_say_stealth_status(TMC &st) {
+ st.printLabel();
+ SERIAL_ECHOPGM(" driver mode:\t");
+ serialprintPGM(st.get_stealthChop() ? PSTR("stealthChop") : PSTR("spreadCycle"));
+ SERIAL_EOL();
+}
+template
+void tmc_set_stealthChop(TMC &st, const bool enable) {
+ st.stored.stealthChop_enabled = enable;
+ st.refresh_stepping_mode();
+}
+
+static void set_stealth_status(const bool enable, const int8_t target_extruder) {
+ #define TMC_SET_STEALTH(Q) tmc_set_stealthChop(stepper##Q, enable)
+
+ #if AXIS_HAS_STEALTHCHOP(X) || AXIS_HAS_STEALTHCHOP(X2) \
+ || AXIS_HAS_STEALTHCHOP(Y) || AXIS_HAS_STEALTHCHOP(Y2) \
+ || AXIS_HAS_STEALTHCHOP(Z) || AXIS_HAS_STEALTHCHOP(Z2) \
+ || AXIS_HAS_STEALTHCHOP(Z3) || AXIS_HAS_STEALTHCHOP(Z4)
+ const uint8_t index = parser.byteval('I');
+ #endif
+
+ LOOP_XYZE(i) if (parser.seen(axis_codes[i])) {
+ switch (i) {
+ case X_AXIS:
+ #if AXIS_HAS_STEALTHCHOP(X)
+ if (index == 0) TMC_SET_STEALTH(X);
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(X2)
+ if (index == 1) TMC_SET_STEALTH(X2);
+ #endif
+ break;
+ case Y_AXIS:
+ #if AXIS_HAS_STEALTHCHOP(Y)
+ if (index == 0) TMC_SET_STEALTH(Y);
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(Y2)
+ if (index == 1) TMC_SET_STEALTH(Y2);
+ #endif
+ break;
+ case Z_AXIS:
+ #if AXIS_HAS_STEALTHCHOP(Z)
+ if (index == 0) TMC_SET_STEALTH(Z);
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(Z2)
+ if (index == 1) TMC_SET_STEALTH(Z2);
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(Z3)
+ if (index == 2) TMC_SET_STEALTH(Z3);
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(Z4)
+ if (index == 3) TMC_SET_STEALTH(Z4);
+ #endif
+ break;
+ case E_AXIS: {
+ if (target_extruder < 0) return;
+ switch (target_extruder) {
+ #if AXIS_HAS_STEALTHCHOP(E0)
+ case 0: TMC_SET_STEALTH(E0); break;
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(E1)
+ case 1: TMC_SET_STEALTH(E1); break;
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(E2)
+ case 2: TMC_SET_STEALTH(E2); break;
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(E3)
+ case 3: TMC_SET_STEALTH(E3); break;
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(E4)
+ case 4: TMC_SET_STEALTH(E4); break;
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(E5)
+ case 5: TMC_SET_STEALTH(E5); break;
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(E6)
+ case 6: TMC_SET_STEALTH(E6); break;
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(E7)
+ case 7: TMC_SET_STEALTH(E7); break;
+ #endif
+ }
+ } break;
+ }
+ }
+}
+
+static void say_stealth_status() {
+ #define TMC_SAY_STEALTH_STATUS(Q) tmc_say_stealth_status(stepper##Q)
+
+ #if AXIS_HAS_STEALTHCHOP(X)
+ TMC_SAY_STEALTH_STATUS(X);
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(X2)
+ TMC_SAY_STEALTH_STATUS(X2);
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(Y)
+ TMC_SAY_STEALTH_STATUS(Y);
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(Y2)
+ TMC_SAY_STEALTH_STATUS(Y2);
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(Z)
+ TMC_SAY_STEALTH_STATUS(Z);
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(Z2)
+ TMC_SAY_STEALTH_STATUS(Z2);
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(Z3)
+ TMC_SAY_STEALTH_STATUS(Z3);
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(Z4)
+ TMC_SAY_STEALTH_STATUS(Z4);
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(E0)
+ TMC_SAY_STEALTH_STATUS(E0);
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(E1)
+ TMC_SAY_STEALTH_STATUS(E1);
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(E2)
+ TMC_SAY_STEALTH_STATUS(E2);
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(E3)
+ TMC_SAY_STEALTH_STATUS(E3);
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(E4)
+ TMC_SAY_STEALTH_STATUS(E4);
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(E5)
+ TMC_SAY_STEALTH_STATUS(E5);
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(E6)
+ TMC_SAY_STEALTH_STATUS(E6);
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(E7)
+ TMC_SAY_STEALTH_STATUS(E7);
+ #endif
+}
+
+/**
+ * M569: Enable stealthChop on an axis
+ *
+ * S[1|0] to enable or disable
+ * XYZE to target an axis
+ * No arguments reports the stealthChop status of all capable drivers.
+ */
+void GcodeSuite::M569() {
+ if (parser.seen('S'))
+ set_stealth_status(parser.value_bool(), get_target_extruder_from_command());
+ else
+ say_stealth_status();
+}
+
+#endif // HAS_STEALTHCHOP
diff --git a/Marlin/src/gcode/feature/trinamic/M906.cpp b/Marlin/src/gcode/feature/trinamic/M906.cpp
new file mode 100644
index 0000000..e834ebd
--- /dev/null
+++ b/Marlin/src/gcode/feature/trinamic/M906.cpp
@@ -0,0 +1,173 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if HAS_TRINAMIC_CONFIG
+
+#include "../../gcode.h"
+#include "../../../feature/tmc_util.h"
+#include "../../../module/stepper/indirection.h"
+
+/**
+ * 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; 3 for Z4.)
+ * T[index] - Extruder index (Zero-based. Omit for E0 only.)
+ *
+ * With no parameters report driver currents.
+ */
+void GcodeSuite::M906() {
+ #define TMC_SAY_CURRENT(Q) tmc_print_current(stepper##Q)
+ #define TMC_SET_CURRENT(Q) stepper##Q.rms_current(value)
+
+ 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)
+ const uint8_t index = parser.byteval('I');
+ #endif
+
+ LOOP_XYZE(i) if (uint16_t value = parser.intval(axis_codes[i])) {
+ report = false;
+ switch (i) {
+ case X_AXIS:
+ #if AXIS_IS_TMC(X)
+ if (index == 0) TMC_SET_CURRENT(X);
+ #endif
+ #if AXIS_IS_TMC(X2)
+ if (index == 1) TMC_SET_CURRENT(X2);
+ #endif
+ break;
+ case Y_AXIS:
+ #if AXIS_IS_TMC(Y)
+ if (index == 0) TMC_SET_CURRENT(Y);
+ #endif
+ #if AXIS_IS_TMC(Y2)
+ if (index == 1) TMC_SET_CURRENT(Y2);
+ #endif
+ break;
+ case Z_AXIS:
+ #if AXIS_IS_TMC(Z)
+ if (index == 0) TMC_SET_CURRENT(Z);
+ #endif
+ #if AXIS_IS_TMC(Z2)
+ if (index == 1) TMC_SET_CURRENT(Z2);
+ #endif
+ #if AXIS_IS_TMC(Z3)
+ if (index == 2) TMC_SET_CURRENT(Z3);
+ #endif
+ #if AXIS_IS_TMC(Z4)
+ if (index == 3) TMC_SET_CURRENT(Z4);
+ #endif
+ break;
+ case E_AXIS: {
+ const int8_t target_extruder = get_target_extruder_from_command();
+ if (target_extruder < 0) return;
+ switch (target_extruder) {
+ #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
+ }
+ } break;
+ }
+ }
+
+ if (report) {
+ #if AXIS_IS_TMC(X)
+ TMC_SAY_CURRENT(X);
+ #endif
+ #if AXIS_IS_TMC(X2)
+ TMC_SAY_CURRENT(X2);
+ #endif
+ #if AXIS_IS_TMC(Y)
+ TMC_SAY_CURRENT(Y);
+ #endif
+ #if AXIS_IS_TMC(Y2)
+ TMC_SAY_CURRENT(Y2);
+ #endif
+ #if AXIS_IS_TMC(Z)
+ TMC_SAY_CURRENT(Z);
+ #endif
+ #if AXIS_IS_TMC(Z2)
+ TMC_SAY_CURRENT(Z2);
+ #endif
+ #if AXIS_IS_TMC(Z3)
+ TMC_SAY_CURRENT(Z3);
+ #endif
+ #if AXIS_IS_TMC(Z4)
+ TMC_SAY_CURRENT(Z4);
+ #endif
+ #if AXIS_IS_TMC(E0)
+ TMC_SAY_CURRENT(E0);
+ #endif
+ #if AXIS_IS_TMC(E1)
+ TMC_SAY_CURRENT(E1);
+ #endif
+ #if AXIS_IS_TMC(E2)
+ TMC_SAY_CURRENT(E2);
+ #endif
+ #if AXIS_IS_TMC(E3)
+ TMC_SAY_CURRENT(E3);
+ #endif
+ #if AXIS_IS_TMC(E4)
+ TMC_SAY_CURRENT(E4);
+ #endif
+ #if AXIS_IS_TMC(E5)
+ TMC_SAY_CURRENT(E5);
+ #endif
+ #if AXIS_IS_TMC(E6)
+ TMC_SAY_CURRENT(E6);
+ #endif
+ #if AXIS_IS_TMC(E7)
+ TMC_SAY_CURRENT(E7);
+ #endif
+ }
+}
+
+#endif // HAS_TRINAMIC_CONFIG
diff --git a/Marlin/src/gcode/feature/trinamic/M911-M914.cpp b/Marlin/src/gcode/feature/trinamic/M911-M914.cpp
new file mode 100644
index 0000000..8c840db
--- /dev/null
+++ b/Marlin/src/gcode/feature/trinamic/M911-M914.cpp
@@ -0,0 +1,429 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if HAS_TRINAMIC_CONFIG
+
+#include "../../gcode.h"
+#include "../../../feature/tmc_util.h"
+#include "../../../module/stepper/indirection.h"
+#include "../../../module/planner.h"
+#include "../../queue.h"
+
+#if ENABLED(MONITOR_DRIVER_STATUS)
+
+ #define M91x_USE(ST) (AXIS_DRIVER_TYPE(ST, TMC2130) || AXIS_DRIVER_TYPE(ST, TMC2160) || AXIS_DRIVER_TYPE(ST, TMC2208) || AXIS_DRIVER_TYPE(ST, TMC2209) || AXIS_DRIVER_TYPE(ST, TMC2660) || AXIS_DRIVER_TYPE(ST, TMC5130) || AXIS_DRIVER_TYPE(ST, TMC5160))
+ #define M91x_USE_E(N) (E_STEPPERS > N && M91x_USE(E##N))
+
+ #define M91x_SOME_X (M91x_USE(X) || M91x_USE(X2))
+ #define M91x_SOME_Y (M91x_USE(Y) || M91x_USE(Y2))
+ #define M91x_SOME_Z (M91x_USE(Z) || M91x_USE(Z2) || M91x_USE(Z3) || M91x_USE(Z4))
+ #define M91x_SOME_E (M91x_USE_E(0) || M91x_USE_E(1) || M91x_USE_E(2) || M91x_USE_E(3) || M91x_USE_E(4) || M91x_USE_E(5) || M91x_USE_E(6) || M91x_USE_E(7))
+
+ #if !M91x_SOME_X && !M91x_SOME_Y && !M91x_SOME_Z && !M91x_SOME_E
+ #error "MONITOR_DRIVER_STATUS requires at least one TMC2130, 2160, 2208, 2209, 2660, 5130, or 5160."
+ #endif
+
+ /**
+ * M911: Report TMC stepper driver overtemperature pre-warn flag
+ * This flag is held by the library, persisting until cleared by M912
+ */
+ void GcodeSuite::M911() {
+ #if M91x_USE(X)
+ tmc_report_otpw(stepperX);
+ #endif
+ #if M91x_USE(X2)
+ tmc_report_otpw(stepperX2);
+ #endif
+ #if M91x_USE(Y)
+ tmc_report_otpw(stepperY);
+ #endif
+ #if M91x_USE(Y2)
+ tmc_report_otpw(stepperY2);
+ #endif
+ #if M91x_USE(Z)
+ tmc_report_otpw(stepperZ);
+ #endif
+ #if M91x_USE(Z2)
+ tmc_report_otpw(stepperZ2);
+ #endif
+ #if M91x_USE(Z3)
+ tmc_report_otpw(stepperZ3);
+ #endif
+ #if M91x_USE(Z4)
+ tmc_report_otpw(stepperZ4);
+ #endif
+ #if M91x_USE_E(0)
+ tmc_report_otpw(stepperE0);
+ #endif
+ #if M91x_USE_E(1)
+ tmc_report_otpw(stepperE1);
+ #endif
+ #if M91x_USE_E(2)
+ tmc_report_otpw(stepperE2);
+ #endif
+ #if M91x_USE_E(3)
+ tmc_report_otpw(stepperE3);
+ #endif
+ #if M91x_USE_E(4)
+ tmc_report_otpw(stepperE4);
+ #endif
+ #if M91x_USE_E(5)
+ tmc_report_otpw(stepperE5);
+ #endif
+ #if M91x_USE_E(6)
+ tmc_report_otpw(stepperE6);
+ #endif
+ #if M91x_USE_E(7)
+ tmc_report_otpw(stepperE7);
+ #endif
+ }
+
+ /**
+ * M912: Clear TMC stepper driver overtemperature pre-warn flag held by the library
+ * Specify one or more axes with X, Y, Z, X1, Y1, Z1, X2, Y2, Z2, Z3, Z4 and E[index].
+ * If no axes are given, clear all.
+ *
+ * Examples:
+ * M912 X ; clear X and X2
+ * M912 X1 ; clear X1 only
+ * M912 X2 ; clear X2 only
+ * M912 X E ; clear X, X2, and all E
+ * M912 E1 ; clear E1 only
+ */
+ void GcodeSuite::M912() {
+ #if M91x_SOME_X
+ const bool hasX = parser.seen(axis_codes.x);
+ #else
+ constexpr bool hasX = false;
+ #endif
+
+ #if M91x_SOME_Y
+ const bool hasY = parser.seen(axis_codes.y);
+ #else
+ constexpr bool hasY = false;
+ #endif
+
+ #if M91x_SOME_Z
+ const bool hasZ = parser.seen(axis_codes.z);
+ #else
+ constexpr bool hasZ = false;
+ #endif
+
+ #if M91x_SOME_E
+ const bool hasE = parser.seen(axis_codes.e);
+ #else
+ constexpr bool hasE = false;
+ #endif
+
+ const bool hasNone = !hasX && !hasY && !hasZ && !hasE;
+
+ #if M91x_SOME_X
+ const int8_t xval = int8_t(parser.byteval(axis_codes.x, 0xFF));
+ #if M91x_USE(X)
+ if (hasNone || xval == 1 || (hasX && xval < 0)) tmc_clear_otpw(stepperX);
+ #endif
+ #if M91x_USE(X2)
+ if (hasNone || xval == 2 || (hasX && xval < 0)) tmc_clear_otpw(stepperX2);
+ #endif
+ #endif
+
+ #if M91x_SOME_Y
+ const int8_t yval = int8_t(parser.byteval(axis_codes.y, 0xFF));
+ #if M91x_USE(Y)
+ if (hasNone || yval == 1 || (hasY && yval < 0)) tmc_clear_otpw(stepperY);
+ #endif
+ #if M91x_USE(Y2)
+ if (hasNone || yval == 2 || (hasY && yval < 0)) tmc_clear_otpw(stepperY2);
+ #endif
+ #endif
+
+ #if M91x_SOME_Z
+ const int8_t zval = int8_t(parser.byteval(axis_codes.z, 0xFF));
+ #if M91x_USE(Z)
+ if (hasNone || zval == 1 || (hasZ && zval < 0)) tmc_clear_otpw(stepperZ);
+ #endif
+ #if M91x_USE(Z2)
+ if (hasNone || zval == 2 || (hasZ && zval < 0)) tmc_clear_otpw(stepperZ2);
+ #endif
+ #if M91x_USE(Z3)
+ if (hasNone || zval == 3 || (hasZ && zval < 0)) tmc_clear_otpw(stepperZ3);
+ #endif
+ #if M91x_USE(Z4)
+ if (hasNone || zval == 4 || (hasZ && zval < 0)) tmc_clear_otpw(stepperZ4);
+ #endif
+ #endif
+
+ #if M91x_SOME_E
+ const int8_t eval = int8_t(parser.byteval(axis_codes.e, 0xFF));
+ #if M91x_USE_E(0)
+ if (hasNone || eval == 0 || (hasE && eval < 0)) tmc_clear_otpw(stepperE0);
+ #endif
+ #if M91x_USE_E(1)
+ if (hasNone || eval == 1 || (hasE && eval < 0)) tmc_clear_otpw(stepperE1);
+ #endif
+ #if M91x_USE_E(2)
+ if (hasNone || eval == 2 || (hasE && eval < 0)) tmc_clear_otpw(stepperE2);
+ #endif
+ #if M91x_USE_E(3)
+ if (hasNone || eval == 3 || (hasE && eval < 0)) tmc_clear_otpw(stepperE3);
+ #endif
+ #if M91x_USE_E(4)
+ if (hasNone || eval == 4 || (hasE && eval < 0)) tmc_clear_otpw(stepperE4);
+ #endif
+ #if M91x_USE_E(5)
+ if (hasNone || eval == 5 || (hasE && eval < 0)) tmc_clear_otpw(stepperE5);
+ #endif
+ #if M91x_USE_E(6)
+ if (hasNone || eval == 6 || (hasE && eval < 0)) tmc_clear_otpw(stepperE6);
+ #endif
+ #if M91x_USE_E(7)
+ if (hasNone || eval == 7 || (hasE && eval < 0)) tmc_clear_otpw(stepperE7);
+ #endif
+ #endif
+ }
+
+#endif // MONITOR_DRIVER_STATUS
+
+/**
+ * M913: Set HYBRID_THRESHOLD speed.
+ */
+#if ENABLED(HYBRID_THRESHOLD)
+ void GcodeSuite::M913() {
+ #define TMC_SAY_PWMTHRS(A,Q) tmc_print_pwmthrs(stepper##Q)
+ #define TMC_SET_PWMTHRS(A,Q) stepper##Q.set_pwm_thrs(value)
+ #define TMC_SAY_PWMTHRS_E(E) tmc_print_pwmthrs(stepperE##E)
+ #define TMC_SET_PWMTHRS_E(E) stepperE##E.set_pwm_thrs(value)
+
+ 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)
+ const uint8_t index = parser.byteval('I');
+ #endif
+ LOOP_XYZE(i) if (int32_t value = parser.longval(axis_codes[i])) {
+ report = false;
+ switch (i) {
+ case X_AXIS:
+ #if AXIS_HAS_STEALTHCHOP(X)
+ if (index < 2) TMC_SET_PWMTHRS(X,X);
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(X2)
+ if (!(index & 1)) TMC_SET_PWMTHRS(X,X2);
+ #endif
+ break;
+ case Y_AXIS:
+ #if AXIS_HAS_STEALTHCHOP(Y)
+ if (index < 2) TMC_SET_PWMTHRS(Y,Y);
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(Y2)
+ if (!(index & 1)) TMC_SET_PWMTHRS(Y,Y2);
+ #endif
+ break;
+ case Z_AXIS:
+ #if AXIS_HAS_STEALTHCHOP(Z)
+ if (index < 2) TMC_SET_PWMTHRS(Z,Z);
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(Z2)
+ if (index == 0 || index == 2) TMC_SET_PWMTHRS(Z,Z2);
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(Z3)
+ if (index == 0 || index == 3) TMC_SET_PWMTHRS(Z,Z3);
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(Z4)
+ if (index == 0 || index == 4) TMC_SET_PWMTHRS(Z,Z4);
+ #endif
+ break;
+ case E_AXIS: {
+ #if E_STEPPERS
+ const int8_t target_extruder = get_target_extruder_from_command();
+ if (target_extruder < 0) return;
+ switch (target_extruder) {
+ #if AXIS_HAS_STEALTHCHOP(E0)
+ case 0: TMC_SET_PWMTHRS_E(0); break;
+ #endif
+ #if E_STEPPERS > 1 && AXIS_HAS_STEALTHCHOP(E1)
+ case 1: TMC_SET_PWMTHRS_E(1); break;
+ #endif
+ #if E_STEPPERS > 2 && AXIS_HAS_STEALTHCHOP(E2)
+ case 2: TMC_SET_PWMTHRS_E(2); break;
+ #endif
+ #if E_STEPPERS > 3 && AXIS_HAS_STEALTHCHOP(E3)
+ case 3: TMC_SET_PWMTHRS_E(3); break;
+ #endif
+ #if E_STEPPERS > 4 && AXIS_HAS_STEALTHCHOP(E4)
+ case 4: TMC_SET_PWMTHRS_E(4); break;
+ #endif
+ #if E_STEPPERS > 5 && AXIS_HAS_STEALTHCHOP(E5)
+ case 5: TMC_SET_PWMTHRS_E(5); break;
+ #endif
+ #if E_STEPPERS > 6 && AXIS_HAS_STEALTHCHOP(E6)
+ case 6: TMC_SET_PWMTHRS_E(6); break;
+ #endif
+ #if E_STEPPERS > 7 && AXIS_HAS_STEALTHCHOP(E7)
+ case 7: TMC_SET_PWMTHRS_E(7); break;
+ #endif
+ }
+ #endif // E_STEPPERS
+ } break;
+ }
+ }
+
+ if (report) {
+ #if AXIS_HAS_STEALTHCHOP(X)
+ TMC_SAY_PWMTHRS(X,X);
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(X2)
+ TMC_SAY_PWMTHRS(X,X2);
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(Y)
+ TMC_SAY_PWMTHRS(Y,Y);
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(Y2)
+ TMC_SAY_PWMTHRS(Y,Y2);
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(Z)
+ TMC_SAY_PWMTHRS(Z,Z);
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(Z2)
+ TMC_SAY_PWMTHRS(Z,Z2);
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(Z3)
+ TMC_SAY_PWMTHRS(Z,Z3);
+ #endif
+ #if AXIS_HAS_STEALTHCHOP(Z4)
+ TMC_SAY_PWMTHRS(Z,Z4);
+ #endif
+ #if E_STEPPERS && AXIS_HAS_STEALTHCHOP(E0)
+ TMC_SAY_PWMTHRS_E(0);
+ #endif
+ #if E_STEPPERS > 1 && AXIS_HAS_STEALTHCHOP(E1)
+ TMC_SAY_PWMTHRS_E(1);
+ #endif
+ #if E_STEPPERS > 2 && AXIS_HAS_STEALTHCHOP(E2)
+ TMC_SAY_PWMTHRS_E(2);
+ #endif
+ #if E_STEPPERS > 3 && AXIS_HAS_STEALTHCHOP(E3)
+ TMC_SAY_PWMTHRS_E(3);
+ #endif
+ #if E_STEPPERS > 4 && AXIS_HAS_STEALTHCHOP(E4)
+ TMC_SAY_PWMTHRS_E(4);
+ #endif
+ #if E_STEPPERS > 5 && AXIS_HAS_STEALTHCHOP(E5)
+ TMC_SAY_PWMTHRS_E(5);
+ #endif
+ #if E_STEPPERS > 6 && AXIS_HAS_STEALTHCHOP(E6)
+ TMC_SAY_PWMTHRS_E(6);
+ #endif
+ #if E_STEPPERS > 7 && AXIS_HAS_STEALTHCHOP(E7)
+ TMC_SAY_PWMTHRS_E(7);
+ #endif
+ }
+ }
+#endif // HYBRID_THRESHOLD
+
+/**
+ * M914: Set StallGuard sensitivity.
+ */
+#if USE_SENSORLESS
+ void GcodeSuite::M914() {
+
+ bool report = true;
+ const uint8_t index = parser.byteval('I');
+ LOOP_XYZ(i) if (parser.seen(XYZ_CHAR(i))) {
+ const int16_t value = parser.value_int();
+ report = false;
+ switch (i) {
+ #if X_SENSORLESS
+ case X_AXIS:
+ #if AXIS_HAS_STALLGUARD(X)
+ if (index < 2) stepperX.homing_threshold(value);
+ #endif
+ #if AXIS_HAS_STALLGUARD(X2)
+ if (!(index & 1)) stepperX2.homing_threshold(value);
+ #endif
+ break;
+ #endif
+ #if Y_SENSORLESS
+ case Y_AXIS:
+ #if AXIS_HAS_STALLGUARD(Y)
+ if (index < 2) stepperY.homing_threshold(value);
+ #endif
+ #if AXIS_HAS_STALLGUARD(Y2)
+ if (!(index & 1)) stepperY2.homing_threshold(value);
+ #endif
+ break;
+ #endif
+ #if Z_SENSORLESS
+ case Z_AXIS:
+ #if AXIS_HAS_STALLGUARD(Z)
+ if (index < 2) stepperZ.homing_threshold(value);
+ #endif
+ #if AXIS_HAS_STALLGUARD(Z2)
+ if (index == 0 || index == 2) stepperZ2.homing_threshold(value);
+ #endif
+ #if AXIS_HAS_STALLGUARD(Z3)
+ if (index == 0 || index == 3) stepperZ3.homing_threshold(value);
+ #endif
+ #if AXIS_HAS_STALLGUARD(Z4)
+ if (index == 0 || index == 4) stepperZ4.homing_threshold(value);
+ #endif
+ break;
+ #endif
+ }
+ }
+
+ if (report) {
+ #if X_SENSORLESS
+ #if AXIS_HAS_STALLGUARD(X)
+ tmc_print_sgt(stepperX);
+ #endif
+ #if AXIS_HAS_STALLGUARD(X2)
+ tmc_print_sgt(stepperX2);
+ #endif
+ #endif
+ #if Y_SENSORLESS
+ #if AXIS_HAS_STALLGUARD(Y)
+ tmc_print_sgt(stepperY);
+ #endif
+ #if AXIS_HAS_STALLGUARD(Y2)
+ tmc_print_sgt(stepperY2);
+ #endif
+ #endif
+ #if Z_SENSORLESS
+ #if AXIS_HAS_STALLGUARD(Z)
+ tmc_print_sgt(stepperZ);
+ #endif
+ #if AXIS_HAS_STALLGUARD(Z2)
+ tmc_print_sgt(stepperZ2);
+ #endif
+ #if AXIS_HAS_STALLGUARD(Z3)
+ tmc_print_sgt(stepperZ3);
+ #endif
+ #if AXIS_HAS_STALLGUARD(Z4)
+ tmc_print_sgt(stepperZ4);
+ #endif
+ #endif
+ }
+ }
+#endif // USE_SENSORLESS
+
+#endif // HAS_TRINAMIC_CONFIG
diff --git a/Marlin/src/gcode/gcode.cpp b/Marlin/src/gcode/gcode.cpp
new file mode 100644
index 0000000..f917318
--- /dev/null
+++ b/Marlin/src/gcode/gcode.cpp
@@ -0,0 +1,1084 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+/**
+ * gcode.cpp - Temporary container for all gcode handlers
+ * Most will migrate to classes, by feature.
+ */
+
+#include "gcode.h"
+GcodeSuite gcode;
+
+#if ENABLED(WIFI_CUSTOM_COMMAND)
+ extern bool wifi_custom_command(char * const command_ptr);
+#endif
+
+#include "parser.h"
+#include "queue.h"
+#include "../module/motion.h"
+
+#if ENABLED(PRINTCOUNTER)
+ #include "../module/printcounter.h"
+#endif
+
+#if ENABLED(HOST_ACTION_COMMANDS)
+ #include "../feature/host_actions.h"
+#endif
+
+#if ENABLED(POWER_LOSS_RECOVERY)
+ #include "../sd/cardreader.h"
+ #include "../feature/powerloss.h"
+#endif
+
+#if ENABLED(CANCEL_OBJECTS)
+ #include "../feature/cancel_object.h"
+#endif
+
+#if ENABLED(LASER_MOVE_POWER)
+ #include "../feature/spindle_laser.h"
+#endif
+
+#if ENABLED(PASSWORD_FEATURE)
+ #include "../feature/password/password.h"
+#endif
+
+#include "../MarlinCore.h" // for idle, kill
+
+// Inactivity shutdown
+millis_t GcodeSuite::previous_move_ms = 0,
+ GcodeSuite::max_inactive_time = 0,
+ GcodeSuite::stepper_inactive_time = SEC_TO_MS(DEFAULT_STEPPER_DEACTIVE_TIME);
+
+// Relative motion mode for each logical axis
+static constexpr xyze_bool_t ar_init = AXIS_RELATIVE_MODES;
+uint8_t GcodeSuite::axis_relative = (
+ (ar_init.x ? _BV(REL_X) : 0)
+ | (ar_init.y ? _BV(REL_Y) : 0)
+ | (ar_init.z ? _BV(REL_Z) : 0)
+ | (ar_init.e ? _BV(REL_E) : 0)
+);
+
+#if EITHER(HAS_AUTO_REPORTING, HOST_KEEPALIVE_FEATURE)
+ bool GcodeSuite::autoreport_paused; // = false
+#endif
+
+#if ENABLED(HOST_KEEPALIVE_FEATURE)
+ GcodeSuite::MarlinBusyState GcodeSuite::busy_state = NOT_BUSY;
+ uint8_t GcodeSuite::host_keepalive_interval = DEFAULT_KEEPALIVE_INTERVAL;
+#endif
+
+#if ENABLED(CNC_WORKSPACE_PLANES)
+ GcodeSuite::WorkspacePlane GcodeSuite::workspace_plane = PLANE_XY;
+#endif
+
+#if ENABLED(CNC_COORDINATE_SYSTEMS)
+ int8_t GcodeSuite::active_coordinate_system = -1; // machine space
+ xyz_pos_t GcodeSuite::coordinate_system[MAX_COORDINATE_SYSTEMS];
+#endif
+
+/**
+ * Get the target extruder from the T parameter or the active_extruder
+ * Return -1 if the T parameter is out of range
+ */
+int8_t GcodeSuite::get_target_extruder_from_command() {
+ if (parser.seenval('T')) {
+ const int8_t e = parser.value_byte();
+ if (e < EXTRUDERS) return e;
+ SERIAL_ECHO_START();
+ SERIAL_CHAR('M'); SERIAL_ECHO(parser.codenum);
+ SERIAL_ECHOLNPAIR(" " STR_INVALID_EXTRUDER " ", int(e));
+ return -1;
+ }
+ return active_extruder;
+}
+
+/**
+ * Get the target e stepper from the T parameter
+ * Return -1 if the T parameter is out of range or unspecified
+ */
+int8_t GcodeSuite::get_target_e_stepper_from_command() {
+ const int8_t e = parser.intval('T', -1);
+ if (WITHIN(e, 0, E_STEPPERS - 1)) return e;
+
+ SERIAL_ECHO_START();
+ SERIAL_CHAR('M'); SERIAL_ECHO(parser.codenum);
+ if (e == -1)
+ SERIAL_ECHOLNPGM(" " STR_E_STEPPER_NOT_SPECIFIED);
+ else
+ SERIAL_ECHOLNPAIR(" " STR_INVALID_E_STEPPER " ", int(e));
+ return -1;
+}
+
+/**
+ * Set XYZE destination and feedrate from the current GCode command
+ *
+ * - Set destination from included axis codes
+ * - Set to current for missing axis codes
+ * - Set the feedrate, if included
+ */
+void GcodeSuite::get_destination_from_command() {
+ xyze_bool_t seen = { false, false, false, false };
+
+ #if ENABLED(CANCEL_OBJECTS)
+ const bool &skip_move = cancelable.skipping;
+ #else
+ constexpr bool skip_move = false;
+ #endif
+
+ // Get new XYZ position, whether absolute or relative
+ LOOP_XYZ(i) {
+ if ( (seen[i] = parser.seenval(XYZ_CHAR(i))) ) {
+ const float v = parser.value_axis_units((AxisEnum)i);
+ if (skip_move)
+ destination[i] = current_position[i];
+ else
+ destination[i] = axis_is_relative(AxisEnum(i)) ? current_position[i] + v : LOGICAL_TO_NATIVE(v, i);
+ }
+ else
+ destination[i] = current_position[i];
+ }
+
+ // Get new E position, whether absolute or relative
+ if ( (seen.e = parser.seenval('E')) ) {
+ const float v = parser.value_axis_units(E_AXIS);
+ destination.e = axis_is_relative(E_AXIS) ? current_position.e + v : v;
+ }
+ else
+ destination.e = current_position.e;
+
+ #if ENABLED(POWER_LOSS_RECOVERY) && !PIN_EXISTS(POWER_LOSS)
+ // Only update power loss recovery on moves with E
+ if (recovery.enabled && IS_SD_PRINTING() && seen.e && (seen.x || seen.y))
+ recovery.save();
+ #endif
+
+ if (parser.linearval('F') > 0)
+ feedrate_mm_s = parser.value_feedrate();
+
+ #if ENABLED(PRINTCOUNTER)
+ if (!DEBUGGING(DRYRUN) && !skip_move)
+ print_job_timer.incFilamentUsed(destination.e - current_position.e);
+ #endif
+
+ // Get ABCDHI mixing factors
+ #if BOTH(MIXING_EXTRUDER, DIRECT_MIXING_IN_G1)
+ M165();
+ #endif
+
+ #if ENABLED(LASER_MOVE_POWER)
+ // Set the laser power in the planner to configure this move
+ if (parser.seen('S')) {
+ const float spwr = parser.value_float();
+ cutter.inline_power(TERN(SPINDLE_LASER_PWM, cutter.power_to_range(cutter_power_t(round(spwr))), spwr > 0 ? 255 : 0));
+ }
+ else if (ENABLED(LASER_MOVE_G0_OFF) && parser.codenum == 0) // G0
+ cutter.set_inline_enabled(false);
+ #endif
+}
+
+/**
+ * Dwell waits immediately. It does not synchronize. Use M400 instead of G4
+ */
+void GcodeSuite::dwell(millis_t time) {
+ time += millis();
+ while (PENDING(millis(), time)) idle();
+}
+
+/**
+ * When G29_RETRY_AND_RECOVER is enabled, call G29() in
+ * a loop with recovery and retry handling.
+ */
+#if BOTH(HAS_LEVELING, G29_RETRY_AND_RECOVER)
+
+ void GcodeSuite::event_probe_recover() {
+ TERN_(HOST_PROMPT_SUPPORT, host_prompt_do(PROMPT_INFO, PSTR("G29 Retrying"), DISMISS_STR));
+ #ifdef ACTION_ON_G29_RECOVER
+ host_action(PSTR(ACTION_ON_G29_RECOVER));
+ #endif
+ #ifdef G29_RECOVER_COMMANDS
+ process_subcommands_now_P(PSTR(G29_RECOVER_COMMANDS));
+ #endif
+ }
+
+ void GcodeSuite::event_probe_failure() {
+ #ifdef ACTION_ON_G29_FAILURE
+ host_action(PSTR(ACTION_ON_G29_FAILURE));
+ #endif
+ #ifdef G29_FAILURE_COMMANDS
+ process_subcommands_now_P(PSTR(G29_FAILURE_COMMANDS));
+ #endif
+ #if ENABLED(G29_HALT_ON_FAILURE)
+ #ifdef ACTION_ON_CANCEL
+ host_action_cancel();
+ #endif
+ kill(GET_TEXT(MSG_LCD_PROBING_FAILED));
+ #endif
+ }
+
+ #ifndef G29_MAX_RETRIES
+ #define G29_MAX_RETRIES 0
+ #endif
+
+ void GcodeSuite::G29_with_retry() {
+ uint8_t retries = G29_MAX_RETRIES;
+ while (G29()) { // G29 should return true for failed probes ONLY
+ if (retries) {
+ event_probe_recover();
+ --retries;
+ }
+ else {
+ event_probe_failure();
+ return;
+ }
+ }
+
+ TERN_(HOST_PROMPT_SUPPORT, host_action_prompt_end());
+
+ #ifdef G29_SUCCESS_COMMANDS
+ process_subcommands_now_P(PSTR(G29_SUCCESS_COMMANDS));
+ #endif
+ }
+
+#endif // HAS_LEVELING && G29_RETRY_AND_RECOVER
+
+//
+// Placeholders for non-migrated codes
+//
+#if ENABLED(M100_FREE_MEMORY_WATCHER)
+ extern void M100_dump_routine(PGM_P const title, const char * const start, const char * const end);
+#endif
+
+/**
+ * Process the parsed command and dispatch it to its handler
+ */
+void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
+ KEEPALIVE_STATE(IN_HANDLER);
+
+ /**
+ * Block all Gcodes except M511 Unlock Printer, if printer is locked
+ * Will still block Gcodes if M511 is disabled, in which case the printer should be unlocked via LCD Menu
+ */
+ #if ENABLED(PASSWORD_FEATURE)
+ if (password.is_locked && !parser.is_command('M', 511)) {
+ SERIAL_ECHO_MSG(STR_PRINTER_LOCKED);
+ if (!no_ok) queue.ok_to_send();
+ return;
+ }
+ #endif
+
+ // Handle a known G, M, or T
+ switch (parser.command_letter) {
+ case 'G': switch (parser.codenum) {
+
+ case 0: case 1: // G0: Fast Move, G1: Linear Move
+ G0_G1(TERN_(HAS_FAST_MOVES, parser.codenum == 0)); break;
+
+ #if ENABLED(ARC_SUPPORT) && DISABLED(SCARA)
+ case 2: case 3: G2_G3(parser.codenum == 2); break; // G2: CW ARC, G3: CCW ARC
+ #endif
+
+ case 4: G4(); break; // G4: Dwell
+
+ #if ENABLED(BEZIER_CURVE_SUPPORT)
+ case 5: G5(); break; // G5: Cubic B_spline
+ #endif
+
+ #if ENABLED(DIRECT_STEPPING)
+ case 6: G6(); break; // G6: Direct Stepper Move
+ #endif
+
+ #if ENABLED(FWRETRACT)
+ case 10: G10(); break; // G10: Retract / Swap Retract
+ case 11: G11(); break; // G11: Recover / Swap Recover
+ #endif
+
+ #if ENABLED(NOZZLE_CLEAN_FEATURE)
+ case 12: G12(); break; // G12: Nozzle Clean
+ #endif
+
+ #if ENABLED(CNC_WORKSPACE_PLANES)
+ case 17: G17(); break; // G17: Select Plane XY
+ case 18: G18(); break; // G18: Select Plane ZX
+ case 19: G19(); break; // G19: Select Plane YZ
+ #endif
+
+ #if ENABLED(INCH_MODE_SUPPORT)
+ case 20: G20(); break; // G20: Inch Mode
+ case 21: G21(); break; // G21: MM Mode
+ #else
+ case 21: NOOP; break; // No error on unknown G21
+ #endif
+
+ #if ENABLED(G26_MESH_VALIDATION)
+ case 26: G26(); break; // G26: Mesh Validation Pattern generation
+ #endif
+
+ #if ENABLED(NOZZLE_PARK_FEATURE)
+ case 27: G27(); break; // G27: Nozzle Park
+ #endif
+
+ case 28: G28(); break; // G28: Home one or more axes
+
+ #if HAS_LEVELING
+ case 29: // G29: Bed leveling calibration
+ TERN(G29_RETRY_AND_RECOVER, G29_with_retry, G29)();
+ break;
+ #endif
+
+ #if HAS_BED_PROBE
+ case 30: G30(); break; // G30: Single Z probe
+ #if ENABLED(Z_PROBE_SLED)
+ case 31: G31(); break; // G31: dock the sled
+ case 32: G32(); break; // G32: undock the sled
+ #endif
+ #endif
+
+ #if ENABLED(DELTA_AUTO_CALIBRATION)
+ case 33: G33(); break; // G33: Delta Auto-Calibration
+ #endif
+
+ #if ANY(Z_MULTI_ENDSTOPS, Z_STEPPER_AUTO_ALIGN, MECHANICAL_GANTRY_CALIBRATION)
+ case 34: G34(); break; // G34: Z Stepper automatic alignment using probe
+ #endif
+
+ #if ENABLED(ASSISTED_TRAMMING)
+ case 35: G35(); break; // G35: Read four bed corners to help adjust bed screws
+ #endif
+
+ #if ENABLED(G38_PROBE_TARGET)
+ case 38: // G38.2, G38.3: Probe towards target
+ if (WITHIN(parser.subcode, 2, TERN(G38_PROBE_AWAY, 5, 3)))
+ G38(parser.subcode); // G38.4, G38.5: Probe away from target
+ break;
+ #endif
+
+ #if ENABLED(CNC_COORDINATE_SYSTEMS)
+ case 53: G53(); break; // G53: (prefix) Apply native workspace
+ case 54: G54(); break; // G54: Switch to Workspace 1
+ case 55: G55(); break; // G55: Switch to Workspace 2
+ case 56: G56(); break; // G56: Switch to Workspace 3
+ case 57: G57(); break; // G57: Switch to Workspace 4
+ case 58: G58(); break; // G58: Switch to Workspace 5
+ case 59: G59(); break; // G59.0 - G59.3: Switch to Workspace 6-9
+ #endif
+
+ #if SAVED_POSITIONS
+ case 60: G60(); break; // G60: save current position
+ case 61: G61(); break; // G61: Apply/restore saved coordinates.
+ #endif
+
+ #if ENABLED(PROBE_TEMP_COMPENSATION)
+ case 76: G76(); break; // G76: Calibrate first layer compensation values
+ #endif
+
+ #if ENABLED(GCODE_MOTION_MODES)
+ case 80: G80(); break; // G80: Reset the current motion mode
+ #endif
+
+ case 90: set_relative_mode(false); break; // G90: Absolute Mode
+ case 91: set_relative_mode(true); break; // G91: Relative Mode
+
+ case 92: G92(); break; // G92: Set current axis position(s)
+
+ #if HAS_MESH
+ case 42: G42(); break; // G42: Coordinated move to a mesh point
+ #endif
+
+ #if ENABLED(CALIBRATION_GCODE)
+ case 425: G425(); break; // G425: Perform calibration with calibration cube
+ #endif
+
+ #if ENABLED(DEBUG_GCODE_PARSER)
+ case 800: parser.debug(); break; // G800: GCode Parser Test for G
+ #endif
+
+ default: parser.unknown_command_warning(); break;
+ }
+ break;
+
+ case 'M': switch (parser.codenum) {
+
+ #if HAS_RESUME_CONTINUE
+ case 0: // M0: Unconditional stop - Wait for user button press on LCD
+ case 1: M0_M1(); break; // M1: Conditional stop - Wait for user button press on LCD
+ #endif
+
+ #if HAS_CUTTER
+ case 3: M3_M4(false); break; // M3: Turn ON Laser | Spindle (clockwise), set Power | Speed
+ case 4: M3_M4(true ); break; // M4: Turn ON Laser | Spindle (counter-clockwise), set Power | Speed
+ case 5: M5(); break; // M5: Turn OFF Laser | Spindle
+ #endif
+
+ #if ENABLED(COOLANT_CONTROL)
+ #if ENABLED(COOLANT_MIST)
+ case 7: M7(); break; // M7: Mist coolant ON
+ #endif
+ #if ENABLED(COOLANT_FLOOD)
+ case 8: M8(); break; // M8: Flood coolant ON
+ #endif
+ case 9: M9(); break; // M9: Coolant OFF
+ #endif
+
+ #if ENABLED(EXTERNAL_CLOSED_LOOP_CONTROLLER)
+ case 12: M12(); break; // M12: Synchronize and optionally force a CLC set
+ #endif
+
+ #if ENABLED(EXPECTED_PRINTER_CHECK)
+ case 16: M16(); break; // M16: Expected printer check
+ #endif
+
+ case 17: M17(); break; // M17: Enable all stepper motors
+
+ #if ENABLED(SDSUPPORT)
+ case 20: M20(); break; // M20: List SD card
+ case 21: M21(); break; // M21: Init SD card
+ case 22: M22(); break; // M22: Release SD card
+ case 23: M23(); break; // M23: Select file
+ case 24: M24(); break; // M24: Start SD print
+ case 25: M25(); break; // M25: Pause SD print
+ case 26: M26(); break; // M26: Set SD index
+ case 27: M27(); break; // M27: Get SD status
+ case 28: M28(); break; // M28: Start SD write
+ case 29: M29(); break; // M29: Stop SD write
+ case 30: M30(); break; // M30 Delete File
+
+ #if HAS_MEDIA_SUBCALLS
+ case 32: M32(); break; // M32: Select file and start SD print
+ #endif
+
+ #if ENABLED(LONG_FILENAME_HOST_SUPPORT)
+ case 33: M33(); break; // M33: Get the long full path to a file or folder
+ #endif
+
+ #if BOTH(SDCARD_SORT_ALPHA, SDSORT_GCODE)
+ case 34: M34(); break; // M34: Set SD card sorting options
+ #endif
+
+ case 928: M928(); break; // M928: Start SD write
+ #endif // SDSUPPORT
+
+ case 31: M31(); break; // M31: Report time since the start of SD print or last M109
+
+ #if ENABLED(DIRECT_PIN_CONTROL)
+ case 42: M42(); break; // M42: Change pin state
+ #endif
+
+ #if ENABLED(PINS_DEBUGGING)
+ case 43: M43(); break; // M43: Read pin state
+ #endif
+
+ #if ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST)
+ case 48: M48(); break; // M48: Z probe repeatability test
+ #endif
+
+ #if ENABLED(LCD_SET_PROGRESS_MANUALLY)
+ case 73: M73(); break; // M73: Set progress percentage (for display on LCD)
+ #endif
+
+ case 75: M75(); break; // M75: Start print timer
+ case 76: M76(); break; // M76: Pause print timer
+ case 77: M77(); break; // M77: Stop print timer
+
+ #if ENABLED(PRINTCOUNTER)
+ case 78: M78(); break; // M78: Show print statistics
+ #endif
+
+ #if ENABLED(M100_FREE_MEMORY_WATCHER)
+ case 100: M100(); break; // M100: Free Memory Report
+ #endif
+
+ #if EXTRUDERS
+ case 104: M104(); break; // M104: Set hot end temperature
+ case 109: M109(); break; // M109: Wait for hotend temperature to reach target
+ #endif
+
+ case 105: M105(); return; // M105: Report Temperatures (and say "ok")
+
+ #if HAS_FAN
+ case 106: M106(); break; // M106: Fan On
+ case 107: M107(); break; // M107: Fan Off
+ #endif
+
+ case 110: M110(); break; // M110: Set Current Line Number
+ case 111: M111(); break; // M111: Set debug level
+
+ #if DISABLED(EMERGENCY_PARSER)
+ case 108: M108(); break; // M108: Cancel Waiting
+ case 112: M112(); break; // M112: Full Shutdown
+ case 410: M410(); break; // M410: Quickstop - Abort all the planned moves.
+ TERN_(HOST_PROMPT_SUPPORT, case 876:) // M876: Handle Host prompt responses
+ #else
+ case 108: case 112: case 410:
+ TERN_(HOST_PROMPT_SUPPORT, case 876:)
+ break;
+ #endif
+
+ #if ENABLED(HOST_KEEPALIVE_FEATURE)
+ case 113: M113(); break; // M113: Set Host Keepalive interval
+ #endif
+
+ #if HAS_HEATED_BED
+ case 140: M140(); break; // M140: Set bed temperature
+ case 190: M190(); break; // M190: Wait for bed temperature to reach target
+ #endif
+
+ #if HAS_HEATED_CHAMBER
+ case 141: M141(); break; // M141: Set chamber temperature
+ case 191: M191(); break; // M191: Wait for chamber temperature to reach target
+ #endif
+
+ #if BOTH(AUTO_REPORT_TEMPERATURES, HAS_TEMP_SENSOR)
+ case 155: M155(); break; // M155: Set temperature auto-report interval
+ #endif
+
+ #if ENABLED(PARK_HEAD_ON_PAUSE)
+ case 125: M125(); break; // M125: Store current position and move to filament change position
+ #endif
+
+ #if ENABLED(BARICUDA)
+ // PWM for HEATER_1_PIN
+ #if HAS_HEATER_1
+ case 126: M126(); break; // M126: valve open
+ case 127: M127(); break; // M127: valve closed
+ #endif
+
+ // PWM for HEATER_2_PIN
+ #if HAS_HEATER_2
+ case 128: M128(); break; // M128: valve open
+ case 129: M129(); break; // M129: valve closed
+ #endif
+ #endif // BARICUDA
+
+ #if ENABLED(PSU_CONTROL)
+ case 80: M80(); break; // M80: Turn on Power Supply
+ #endif
+ case 81: M81(); break; // M81: Turn off Power, including Power Supply, if possible
+
+ case 82: M82(); break; // M82: Set E axis normal mode (same as other axes)
+ case 83: M83(); break; // M83: Set E axis relative mode
+ case 18: case 84: M18_M84(); break; // M18/M84: Disable Steppers / Set Timeout
+ case 85: M85(); break; // M85: Set inactivity stepper shutdown timeout
+ case 92: M92(); break; // M92: Set the steps-per-unit for one or more axes
+ case 114: M114(); break; // M114: Report current position
+ case 115: M115(); break; // M115: Report capabilities
+ case 117: M117(); break; // M117: Set LCD message text, if possible
+ case 118: M118(); break; // M118: Display a message in the host console
+ case 119: M119(); break; // M119: Report endstop states
+ case 120: M120(); break; // M120: Enable endstops
+ case 121: M121(); break; // M121: Disable endstops
+
+ #if PREHEAT_COUNT
+ case 145: M145(); break; // M145: Set material heatup parameters
+ #endif
+
+ #if ENABLED(TEMPERATURE_UNITS_SUPPORT)
+ case 149: M149(); break; // M149: Set temperature units
+ #endif
+
+ #if HAS_COLOR_LEDS
+ case 150: M150(); break; // M150: Set Status LED Color
+ #endif
+
+ #if ENABLED(MIXING_EXTRUDER)
+ case 163: M163(); break; // M163: Set a component weight for mixing extruder
+ case 164: M164(); break; // M164: Save current mix as a virtual extruder
+ #if ENABLED(DIRECT_MIXING_IN_G1)
+ case 165: M165(); break; // M165: Set multiple mix weights
+ #endif
+ #if ENABLED(GRADIENT_MIX)
+ case 166: M166(); break; // M166: Set Gradient Mix
+ #endif
+ #endif
+
+ #if DISABLED(NO_VOLUMETRICS)
+ case 200: M200(); break; // M200: Set filament diameter, E to cubic units
+ #endif
+
+ case 201: M201(); break; // M201: Set max acceleration for print moves (units/s^2)
+
+ #if 0
+ case 202: M202(); break; // M202: Not used for Sprinter/grbl gen6
+ #endif
+
+ case 203: M203(); break; // M203: Set max feedrate (units/sec)
+ case 204: M204(); break; // M204: Set acceleration
+ case 205: M205(); break; // M205: Set advanced settings
+
+ #if HAS_M206_COMMAND
+ case 206: M206(); break; // M206: Set home offsets
+ #endif
+
+ #if ENABLED(FWRETRACT)
+ case 207: M207(); break; // M207: Set Retract Length, Feedrate, and Z lift
+ case 208: M208(); break; // M208: Set Recover (unretract) Additional Length and Feedrate
+ #if ENABLED(FWRETRACT_AUTORETRACT)
+ case 209:
+ if (MIN_AUTORETRACT <= MAX_AUTORETRACT) M209(); // M209: Turn Automatic Retract Detection on/off
+ break;
+ #endif
+ #endif
+
+ #if HAS_SOFTWARE_ENDSTOPS
+ case 211: M211(); break; // M211: Enable, Disable, and/or Report software endstops
+ #endif
+
+ #if HAS_MULTI_EXTRUDER
+ case 217: M217(); break; // M217: Set filament swap parameters
+ #endif
+
+ #if HAS_HOTEND_OFFSET
+ case 218: M218(); break; // M218: Set a tool offset
+ #endif
+
+ case 220: M220(); break; // M220: Set Feedrate Percentage: S ("FR" on your LCD)
+
+ #if EXTRUDERS
+ case 221: M221(); break; // M221: Set Flow Percentage
+ #endif
+
+ #if ENABLED(DIRECT_PIN_CONTROL)
+ case 226: M226(); break; // M226: Wait until a pin reaches a state
+ #endif
+
+ #if HAS_SERVOS
+ case 280: M280(); break; // M280: Set servo position absolute
+ #if ENABLED(EDITABLE_SERVO_ANGLES)
+ case 281: M281(); break; // M281: Set servo angles
+ #endif
+ #endif
+
+ #if ENABLED(BABYSTEPPING)
+ case 290: M290(); break; // M290: Babystepping
+ #endif
+
+ #if HAS_BUZZER
+ case 300: M300(); break; // M300: Play beep tone
+ #endif
+
+ #if ENABLED(PIDTEMP)
+ case 301: M301(); break; // M301: Set hotend PID parameters
+ #endif
+
+ #if ENABLED(PIDTEMPBED)
+ case 304: M304(); break; // M304: Set bed PID parameters
+ #endif
+
+ #if ENABLED(PHOTO_GCODE)
+ case 240: M240(); break; // M240: Trigger a camera
+ #endif
+
+ #if HAS_LCD_CONTRAST
+ case 250: M250(); break; // M250: Set LCD contrast
+ #endif
+
+ #if ENABLED(EXPERIMENTAL_I2CBUS)
+ case 260: M260(); break; // M260: Send data to an i2c slave
+ case 261: M261(); break; // M261: Request data from an i2c slave
+ #endif
+
+ #if ENABLED(PREVENT_COLD_EXTRUSION)
+ case 302: M302(); break; // M302: Allow cold extrudes (set the minimum extrude temperature)
+ #endif
+
+ #if HAS_PID_HEATING
+ case 303: M303(); break; // M303: PID autotune
+ #endif
+
+ #if HAS_USER_THERMISTORS
+ case 305: M305(); break; // M305: Set user thermistor parameters
+ #endif
+
+ #if ENABLED(REPETIER_GCODE_M360)
+ case 360: M360(); break; // M360: Firmware settings
+ #endif
+
+ #if ENABLED(MORGAN_SCARA)
+ case 360: if (M360()) return; break; // M360: SCARA Theta pos1
+ case 361: if (M361()) return; break; // M361: SCARA Theta pos2
+ case 362: if (M362()) return; break; // M362: SCARA Psi pos1
+ case 363: if (M363()) return; break; // M363: SCARA Psi pos2
+ case 364: if (M364()) return; break; // M364: SCARA Psi pos3 (90 deg to Theta)
+ #endif
+
+ #if EITHER(EXT_SOLENOID, MANUAL_SOLENOID_CONTROL)
+ case 380: M380(); break; // M380: Activate solenoid on active (or specified) extruder
+ case 381: M381(); break; // M381: Disable all solenoids or, if MANUAL_SOLENOID_CONTROL, active (or specified) solenoid
+ #endif
+
+ case 400: M400(); break; // M400: Finish all moves
+
+ #if HAS_BED_PROBE
+ case 401: M401(); break; // M401: Deploy probe
+ case 402: M402(); break; // M402: Stow probe
+ #endif
+
+ #if HAS_PRUSA_MMU2
+ case 403: M403(); break;
+ #endif
+
+ #if ENABLED(FILAMENT_WIDTH_SENSOR)
+ case 404: M404(); break; // M404: Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or display nominal filament width
+ case 405: M405(); break; // M405: Turn on filament sensor for control
+ case 406: M406(); break; // M406: Turn off filament sensor for control
+ case 407: M407(); break; // M407: Display measured filament diameter
+ #endif
+
+ #if HAS_FILAMENT_SENSOR
+ case 412: M412(); break; // M412: Enable/Disable filament runout detection
+ #endif
+
+ #if HAS_MULTI_LANGUAGE
+ case 414: M414(); break; // M414: Select multi language menu
+ #endif
+
+ #if HAS_LEVELING
+ case 420: M420(); break; // M420: Enable/Disable Bed Leveling
+ #endif
+
+ #if HAS_MESH
+ case 421: M421(); break; // M421: Set a Mesh Bed Leveling Z coordinate
+ #endif
+
+ #if ENABLED(BACKLASH_GCODE)
+ case 425: M425(); break; // M425: Tune backlash compensation
+ #endif
+
+ #if HAS_M206_COMMAND
+ case 428: M428(); break; // M428: Apply current_position to home_offset
+ #endif
+
+ #if HAS_POWER_MONITOR
+ case 430: M430(); break; // M430: Read the system current (A), voltage (V), and power (W)
+ #endif
+
+ #if ENABLED(CANCEL_OBJECTS)
+ case 486: M486(); break; // M486: Identify and cancel objects
+ #endif
+
+ case 500: M500(); break; // M500: Store settings in EEPROM
+ case 501: M501(); break; // M501: Read settings from EEPROM
+ case 502: M502(); break; // M502: Revert to default settings
+ #if DISABLED(DISABLE_M503)
+ case 503: M503(); break; // M503: print settings currently in memory
+ #endif
+ #if ENABLED(EEPROM_SETTINGS)
+ case 504: M504(); break; // M504: Validate EEPROM contents
+ #endif
+
+ #if ENABLED(PASSWORD_FEATURE)
+ case 510: M510(); break; // M510: Lock Printer
+ #if ENABLED(PASSWORD_UNLOCK_GCODE)
+ case 511: M511(); break; // M511: Unlock Printer
+ #endif
+ #if ENABLED(PASSWORD_CHANGE_GCODE)
+ case 512: M512(); break; // M512: Set/Change/Remove Password
+ #endif
+ #endif
+
+ #if ENABLED(SDSUPPORT)
+ case 524: M524(); break; // M524: Abort the current SD print job
+ #endif
+
+ #if ENABLED(SD_ABORT_ON_ENDSTOP_HIT)
+ case 540: M540(); break; // M540: Set abort on endstop hit for SD printing
+ #endif
+
+ #if HAS_ETHERNET
+ case 552: M552(); break; // M552: Set IP address
+ case 553: M553(); break; // M553: Set gateway
+ case 554: M554(); break; // M554: Set netmask
+ #endif
+
+ #if ENABLED(BAUD_RATE_GCODE)
+ case 575: M575(); break; // M575: Set serial baudrate
+ #endif
+
+ #if ENABLED(ADVANCED_PAUSE_FEATURE)
+ case 600: M600(); break; // M600: Pause for Filament Change
+ case 603: M603(); break; // M603: Configure Filament Change
+ #endif
+
+ #if HAS_DUPLICATION_MODE
+ case 605: M605(); break; // M605: Set Dual X Carriage movement mode
+ #endif
+
+ #if ENABLED(DELTA)
+ case 665: M665(); break; // M665: Set delta configurations
+ #endif
+
+ #if ENABLED(DELTA) || HAS_EXTRA_ENDSTOPS
+ case 666: M666(); break; // M666: Set delta or multiple endstop adjustment
+ #endif
+
+ #if ENABLED(DUET_SMART_EFFECTOR) && PIN_EXISTS(SMART_EFFECTOR_MOD)
+ case 672: M672(); break; // M672: Set/clear Duet Smart Effector sensitivity
+ #endif
+
+ #if ENABLED(FILAMENT_LOAD_UNLOAD_GCODES)
+ case 701: M701(); break; // M701: Load Filament
+ case 702: M702(); break; // M702: Unload Filament
+ #endif
+
+ #if ENABLED(CONTROLLER_FAN_EDITABLE)
+ case 710: M710(); break; // M710: Set Controller Fan settings
+ #endif
+
+ #if ENABLED(GCODE_MACROS)
+ case 810: case 811: case 812: case 813: case 814:
+ case 815: case 816: case 817: case 818: case 819:
+ M810_819(); break; // M810-M819: Define/execute G-code macro
+ #endif
+
+ #if HAS_BED_PROBE
+ case 851: M851(); break; // M851: Set Z Probe Z Offset
+ #endif
+
+ #if ENABLED(SKEW_CORRECTION_GCODE)
+ case 852: M852(); break; // M852: Set Skew factors
+ #endif
+
+ #if ENABLED(PROBE_TEMP_COMPENSATION)
+ case 192: M192(); break; // M192: Wait for probe temp
+ case 871: M871(); break; // M871: Print/reset/clear first layer temperature offset values
+ #endif
+
+ #if ENABLED(LIN_ADVANCE)
+ case 900: M900(); break; // M900: Set advance K factor.
+ #endif
+
+ #if ANY(HAS_MOTOR_CURRENT_SPI, HAS_MOTOR_CURRENT_PWM, HAS_MOTOR_CURRENT_I2C, HAS_MOTOR_CURRENT_DAC)
+ case 907: M907(); break; // M907: Set digital trimpot motor current using axis codes.
+ #if EITHER(HAS_MOTOR_CURRENT_SPI, HAS_MOTOR_CURRENT_DAC)
+ case 908: M908(); break; // M908: Control digital trimpot directly.
+ #if ENABLED(HAS_MOTOR_CURRENT_DAC)
+ case 909: M909(); break; // M909: Print digipot/DAC current value
+ case 910: M910(); break; // M910: Commit digipot/DAC value to external EEPROM
+ #endif
+ #endif
+ #endif
+
+ #if HAS_TRINAMIC_CONFIG
+ case 122: M122(); break; // M122: Report driver configuration and status
+ case 906: M906(); break; // M906: Set motor current in milliamps using axis codes X, Y, Z, E
+ #if HAS_STEALTHCHOP
+ case 569: M569(); break; // M569: Enable stealthChop on an axis.
+ #endif
+ #if ENABLED(MONITOR_DRIVER_STATUS)
+ case 911: M911(); break; // M911: Report TMC2130 prewarn triggered flags
+ case 912: M912(); break; // M912: Clear TMC2130 prewarn triggered flags
+ #endif
+ #if ENABLED(HYBRID_THRESHOLD)
+ case 913: M913(); break; // M913: Set HYBRID_THRESHOLD speed.
+ #endif
+ #if USE_SENSORLESS
+ case 914: M914(); break; // M914: Set StallGuard sensitivity.
+ #endif
+ #endif
+
+ #if HAS_L64XX
+ case 122: M122(); break; // M122: Report status
+ case 906: M906(); break; // M906: Set or get motor drive level
+ case 916: M916(); break; // M916: L6470 tuning: Increase drive level until thermal warning
+ case 917: M917(); break; // M917: L6470 tuning: Find minimum current thresholds
+ case 918: M918(); break; // M918: L6470 tuning: Increase speed until max or error
+ #endif
+
+ #if HAS_MICROSTEPS
+ case 350: M350(); break; // M350: Set microstepping mode. Warning: Steps per unit remains unchanged. S code sets stepping mode for all drivers.
+ case 351: M351(); break; // M351: Toggle MS1 MS2 pins directly, S# determines MS1 or MS2, X# sets the pin high/low.
+ #endif
+
+ #if ENABLED(CASE_LIGHT_ENABLE)
+ case 355: M355(); break; // M355: Set case light brightness
+ #endif
+
+ #if ENABLED(DEBUG_GCODE_PARSER)
+ case 800: parser.debug(); break; // M800: GCode Parser Test for M
+ #endif
+
+ #if ENABLED(GCODE_REPEAT_MARKERS)
+ case 808: M808(); break; // M808: Set / Goto repeat markers
+ #endif
+
+ #if ENABLED(I2C_POSITION_ENCODERS)
+ case 860: M860(); break; // M860: Report encoder module position
+ case 861: M861(); break; // M861: Report encoder module status
+ case 862: M862(); break; // M862: Perform axis test
+ case 863: M863(); break; // M863: Calibrate steps/mm
+ case 864: M864(); break; // M864: Change module address
+ case 865: M865(); break; // M865: Check module firmware version
+ case 866: M866(); break; // M866: Report axis error count
+ case 867: M867(); break; // M867: Toggle error correction
+ case 868: M868(); break; // M868: Set error correction threshold
+ case 869: M869(); break; // M869: Report axis error
+ #endif
+
+ #if ENABLED(MAGNETIC_PARKING_EXTRUDER)
+ case 951: M951(); break; // M951: Set Magnetic Parking Extruder parameters
+ #endif
+
+ #if ENABLED(Z_STEPPER_AUTO_ALIGN)
+ case 422: M422(); break; // M422: Set Z Stepper automatic alignment position using probe
+ #endif
+
+ #if ALL(HAS_SPI_FLASH, SDSUPPORT, MARLIN_DEV_MODE)
+ case 993: M993(); break; // M993: Backup SPI Flash to SD
+ case 994: M994(); break; // M994: Load a Backup from SD to SPI Flash
+ #endif
+
+ #if ENABLED(TOUCH_SCREEN_CALIBRATION)
+ case 995: M995(); break; // M995: Touch screen calibration for TFT display
+ #endif
+
+ #if ENABLED(PLATFORM_M997_SUPPORT)
+ case 997: M997(); break; // M997: Perform in-application firmware update
+ #endif
+
+ case 999: M999(); break; // M999: Restart after being Stopped
+
+ #if ENABLED(POWER_LOSS_RECOVERY)
+ case 413: M413(); break; // M413: Enable/disable/query Power-Loss Recovery
+ case 1000: M1000(); break; // M1000: [INTERNAL] Resume from power-loss
+ #endif
+
+ #if ENABLED(SDSUPPORT)
+ case 1001: M1001(); break; // M1001: [INTERNAL] Handle SD completion
+ #endif
+
+ #if ENABLED(MAX7219_GCODE)
+ case 7219: M7219(); break; // M7219: Set LEDs, columns, and rows
+ #endif
+
+ default: parser.unknown_command_warning(); break;
+ }
+ break;
+
+ case 'T': T(parser.codenum); break; // Tn: Tool Change
+
+ #if ENABLED(MARLIN_DEV_MODE)
+ case 'D': D(parser.codenum); break; // Dn: Debug codes
+ #endif
+
+ default:
+ #if ENABLED(WIFI_CUSTOM_COMMAND)
+ if (wifi_custom_command(parser.command_ptr)) break;
+ #endif
+ parser.unknown_command_warning();
+ }
+
+ if (!no_ok) queue.ok_to_send();
+
+ SERIAL_OUT(msgDone); // Call the msgDone serial hook to signal command processing done
+}
+
+/**
+ * Process a single command and dispatch it to its handler
+ * This is called from the main loop()
+ */
+void GcodeSuite::process_next_command() {
+ char * const current_command = queue.command_buffer[queue.index_r];
+
+ PORT_REDIRECT(SERIAL_PORTMASK(queue.port[queue.index_r]));
+
+ #if ENABLED(POWER_LOSS_RECOVERY)
+ recovery.queue_index_r = queue.index_r;
+ #endif
+
+ if (DEBUGGING(ECHO)) {
+ SERIAL_ECHO_START();
+ SERIAL_ECHOLN(current_command);
+ #if ENABLED(M100_FREE_MEMORY_DUMPER)
+ SERIAL_ECHOPAIR("slot:", queue.index_r);
+ M100_dump_routine(PSTR(" Command Queue:"), &queue.command_buffer[0][0], &queue.command_buffer[BUFSIZE - 1][MAX_CMD_SIZE - 1]);
+ #endif
+ }
+
+ // Parse the next command in the queue
+ parser.parse(current_command);
+ process_parsed_command();
+}
+
+/**
+ * Run a series of commands, bypassing the command queue to allow
+ * G-code "macros" to be called from within other G-code handlers.
+ */
+
+void GcodeSuite::process_subcommands_now_P(PGM_P pgcode) {
+ char * const saved_cmd = parser.command_ptr; // Save the parser state
+ for (;;) {
+ PGM_P const delim = strchr_P(pgcode, '\n'); // Get address of next newline
+ const size_t len = delim ? delim - pgcode : strlen_P(pgcode); // Get the command length
+ char cmd[len + 1]; // Allocate a stack buffer
+ strncpy_P(cmd, pgcode, len); // Copy the command to the stack
+ cmd[len] = '\0'; // End with a nul
+ parser.parse(cmd); // Parse the command
+ process_parsed_command(true); // Process it
+ if (!delim) break; // Last command?
+ pgcode = delim + 1; // Get the next command
+ }
+ parser.parse(saved_cmd); // Restore the parser state
+}
+
+void GcodeSuite::process_subcommands_now(char * gcode) {
+ char * const saved_cmd = parser.command_ptr; // Save the parser state
+ for (;;) {
+ char * const delim = strchr(gcode, '\n'); // Get address of next newline
+ if (delim) *delim = '\0'; // Replace with nul
+ parser.parse(gcode); // Parse the current command
+ if (delim) *delim = '\n'; // Put back the newline
+ process_parsed_command(true); // Process it
+ if (!delim) break; // Last command?
+ gcode = delim + 1; // Get the next command
+ }
+ parser.parse(saved_cmd); // Restore the parser state
+}
+
+#if ENABLED(HOST_KEEPALIVE_FEATURE)
+
+ /**
+ * Output a "busy" message at regular intervals
+ * while the machine is not accepting commands.
+ */
+ void GcodeSuite::host_keepalive() {
+ const millis_t ms = millis();
+ static millis_t next_busy_signal_ms = 0;
+ if (!autoreport_paused && host_keepalive_interval && busy_state != NOT_BUSY) {
+ if (PENDING(ms, next_busy_signal_ms)) return;
+ switch (busy_state) {
+ case IN_HANDLER:
+ case IN_PROCESS:
+ SERIAL_ECHO_MSG(STR_BUSY_PROCESSING);
+ break;
+ case PAUSED_FOR_USER:
+ SERIAL_ECHO_MSG(STR_BUSY_PAUSED_FOR_USER);
+ break;
+ case PAUSED_FOR_INPUT:
+ SERIAL_ECHO_MSG(STR_BUSY_PAUSED_FOR_INPUT);
+ break;
+ default:
+ break;
+ }
+ }
+ next_busy_signal_ms = ms + SEC_TO_MS(host_keepalive_interval);
+ }
+
+#endif // HOST_KEEPALIVE_FEATURE
diff --git a/Marlin/src/gcode/gcode.h b/Marlin/src/gcode/gcode.h
new file mode 100644
index 0000000..7fd8d69
--- /dev/null
+++ b/Marlin/src/gcode/gcode.h
@@ -0,0 +1,906 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+#pragma once
+
+/**
+ * gcode.h - Temporary container for all gcode handlers
+ */
+
+/**
+ * -----------------
+ * G-Codes in Marlin
+ * -----------------
+ *
+ * Helpful G-code references:
+ * - https://marlinfw.org/meta/gcode
+ * - https://reprap.org/wiki/G-code
+ * - https://linuxcnc.org/docs/html/gcode.html
+ *
+ * Help to document Marlin's G-codes online:
+ * - https://github.com/MarlinFirmware/MarlinDocumentation
+ *
+ * -----------------
+ *
+ * "G" Codes
+ *
+ * G0 -> G1
+ * G1 - Coordinated Movement X Y Z E
+ * G2 - CW ARC
+ * G3 - CCW ARC
+ * G4 - Dwell S or P
+ * G5 - Cubic B-spline with XYZE destination and IJPQ offsets
+ * G10 - Retract filament according to settings of M207 (Requires FWRETRACT)
+ * G11 - Retract recover filament according to settings of M208 (Requires FWRETRACT)
+ * G12 - Clean tool (Requires NOZZLE_CLEAN_FEATURE)
+ * G17 - Select Plane XY (Requires CNC_WORKSPACE_PLANES)
+ * G18 - Select Plane ZX (Requires CNC_WORKSPACE_PLANES)
+ * G19 - Select Plane YZ (Requires CNC_WORKSPACE_PLANES)
+ * G20 - Set input units to inches (Requires INCH_MODE_SUPPORT)
+ * G21 - Set input units to millimeters (Requires INCH_MODE_SUPPORT)
+ * G26 - Mesh Validation Pattern (Requires G26_MESH_VALIDATION)
+ * G27 - Park Nozzle (Requires NOZZLE_PARK_FEATURE)
+ * G28 - Home one or more axes
+ * G29 - Start or continue the bed leveling probe procedure (Requires bed leveling)
+ * G30 - Single Z probe, probes bed at X Y location (defaults to current XY location)
+ * G31 - Dock sled (Z_PROBE_SLED only)
+ * G32 - Undock sled (Z_PROBE_SLED only)
+ * G33 - Delta Auto-Calibration (Requires DELTA_AUTO_CALIBRATION)
+ * G34 - Z Stepper automatic alignment using probe: I T A (Requires Z_STEPPER_AUTO_ALIGN)
+ * G35 - Read bed corners to help adjust bed screws: T (Requires ASSISTED_TRAMMING)
+ * G38 - Probe in any direction using the Z_MIN_PROBE (Requires G38_PROBE_TARGET)
+ * G42 - Coordinated move to a mesh point (Requires MESH_BED_LEVELING, AUTO_BED_LEVELING_BLINEAR, or AUTO_BED_LEVELING_UBL)
+ * G60 - Save current position. (Requires SAVED_POSITIONS)
+ * G61 - Apply/restore saved coordinates. (Requires SAVED_POSITIONS)
+ * G76 - Calibrate first layer temperature offsets. (Requires PROBE_TEMP_COMPENSATION)
+ * G80 - Cancel current motion mode (Requires GCODE_MOTION_MODES)
+ * G90 - Use Absolute Coordinates
+ * G91 - Use Relative Coordinates
+ * G92 - Set current position to coordinates given
+ *
+ * "M" Codes
+ *
+ * M0 - Unconditional stop - Wait for user to press a button on the LCD (Only if ULTRA_LCD is enabled)
+ * M1 -> M0
+ * M3 - Turn ON Laser | Spindle (clockwise), set Power | Speed. (Requires SPINDLE_FEATURE or LASER_FEATURE)
+ * M4 - Turn ON Laser | Spindle (counter-clockwise), set Power | Speed. (Requires SPINDLE_FEATURE or LASER_FEATURE)
+ * M5 - Turn OFF Laser | Spindle. (Requires SPINDLE_FEATURE or LASER_FEATURE)
+ * M7 - Turn mist coolant ON. (Requires COOLANT_CONTROL)
+ * M8 - Turn flood coolant ON. (Requires COOLANT_CONTROL)
+ * M9 - Turn coolant OFF. (Requires COOLANT_CONTROL)
+ * M12 - Set up closed loop control system. (Requires EXTERNAL_CLOSED_LOOP_CONTROLLER)
+ * M16 - Expected printer check. (Requires EXPECTED_PRINTER_CHECK)
+ * M17 - Enable/Power all stepper motors
+ * M18 - Disable all stepper motors; same as M84
+ * M20 - List SD card. (Requires SDSUPPORT)
+ * M21 - Init SD card. (Requires SDSUPPORT)
+ * M22 - Release SD card. (Requires SDSUPPORT)
+ * M23 - Select SD file: "M23 /path/file.gco". (Requires SDSUPPORT)
+ * M24 - Start/resume SD print. (Requires SDSUPPORT)
+ * M25 - Pause SD print. (Requires SDSUPPORT)
+ * M26 - Set SD position in bytes: "M26 S12345". (Requires SDSUPPORT)
+ * M27 - Report SD print status. (Requires SDSUPPORT)
+ * OR, with 'S' set the SD status auto-report interval. (Requires AUTO_REPORT_SD_STATUS)
+ * OR, with 'C' get the current filename.
+ * M28 - Start SD write: "M28 /path/file.gco". (Requires SDSUPPORT)
+ * M29 - Stop SD write. (Requires SDSUPPORT)
+ * M30 - Delete file from SD: "M30 /path/file.gco"
+ * M31 - Report time since last M109 or SD card start to serial.
+ * M32 - Select file and start SD print: "M32 [S] !/path/file.gco#". (Requires SDSUPPORT)
+ * Use P to run other files as sub-programs: "M32 P !filename#"
+ * The '#' is necessary when calling from within sd files, as it stops buffer prereading
+ * M33 - Get the longname version of a path. (Requires LONG_FILENAME_HOST_SUPPORT)
+ * M34 - Set SD Card sorting options. (Requires SDCARD_SORT_ALPHA)
+ * M42 - Change pin status via gcode: M42 P S. LED pin assumed if P is omitted. (Requires DIRECT_PIN_CONTROL)
+ * M43 - Display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins
+ * M48 - Measure Z Probe repeatability: M48 P X Y V E L S. (Requires Z_MIN_PROBE_REPEATABILITY_TEST)
+ * M73 - Set the progress percentage. (Requires LCD_SET_PROGRESS_MANUALLY)
+ * M75 - Start the print job timer.
+ * M76 - Pause the print job timer.
+ * M77 - Stop the print job timer.
+ * M78 - Show statistical information about the print jobs. (Requires PRINTCOUNTER)
+ * M80 - Turn on Power Supply. (Requires PSU_CONTROL)
+ * M81 - Turn off Power Supply. (Requires PSU_CONTROL)
+ * M82 - Set E codes absolute (default).
+ * M83 - Set E codes relative while in Absolute (G90) mode.
+ * M84 - Disable steppers until next move, or use S to specify an idle
+ * duration after which steppers should turn off. S0 disables the timeout.
+ * M85 - Set inactivity shutdown timer with parameter S. To disable set zero (default)
+ * M92 - Set planner.settings.axis_steps_per_mm for one or more axes.
+ * M100 - Watch Free Memory (for debugging) (Requires M100_FREE_MEMORY_WATCHER)
+ * M104 - Set extruder target temp.
+ * M105 - Report current temperatures.
+ * M106 - Set print fan speed.
+ * M107 - Print fan off.
+ * M108 - Break out of heating loops (M109, M190, M303). With no controller, breaks out of M0/M1. (Requires EMERGENCY_PARSER)
+ * M109 - S Wait for extruder current temp to reach target temp. ** Wait only when heating! **
+ * R Wait for extruder current temp to reach target temp. ** Wait for heating or cooling. **
+ * If AUTOTEMP is enabled, S B F. Exit autotemp by any M109 without F
+ * M110 - Set the current line number. (Used by host printing)
+ * M111 - Set debug flags: "M111 S". See flag bits defined in enum.h.
+ * M112 - Full Shutdown.
+ * M113 - Get or set the timeout interval for Host Keepalive "busy" messages. (Requires HOST_KEEPALIVE_FEATURE)
+ * M114 - Report current position.
+ * M115 - Report capabilities. (Extended capabilities requires EXTENDED_CAPABILITIES_REPORT)
+ * M117 - Display a message on the controller screen. (Requires an LCD)
+ * M118 - Display a message in the host console.
+ * M119 - Report endstops status.
+ * M120 - Enable endstops detection.
+ * M121 - Disable endstops detection.
+ * M122 - Debug stepper (Requires at least one _DRIVER_TYPE defined as TMC2130/2160/5130/5160/2208/2209/2660 or L6470)
+ * M125 - Save current position and move to filament change position. (Requires PARK_HEAD_ON_PAUSE)
+ * M126 - Solenoid Air Valve Open. (Requires BARICUDA)
+ * M127 - Solenoid Air Valve Closed. (Requires BARICUDA)
+ * M128 - EtoP Open. (Requires BARICUDA)
+ * M129 - EtoP Closed. (Requires BARICUDA)
+ * M140 - Set bed target temp. S
+ * M141 - Set heated chamber target temp. S (Requires a chamber heater)
+ * M145 - Set heatup values for materials on the LCD. H B F for S (0=PLA, 1=ABS)
+ * M149 - Set temperature units. (Requires TEMPERATURE_UNITS_SUPPORT)
+ * M150 - Set Status LED Color as R U B W P. Values 0-255. (Requires BLINKM, RGB_LED, RGBW_LED, NEOPIXEL_LED, PCA9533, or PCA9632).
+ * M155 - Auto-report temperatures with interval of S. (Requires AUTO_REPORT_TEMPERATURES)
+ * M163 - Set a single proportion for a mixing extruder. (Requires MIXING_EXTRUDER)
+ * M164 - Commit the mix and save to a virtual tool (current, or as specified by 'S'). (Requires MIXING_EXTRUDER)
+ * M165 - Set the mix for the mixing extruder (and current virtual tool) with parameters ABCDHI. (Requires MIXING_EXTRUDER and DIRECT_MIXING_IN_G1)
+ * M166 - Set the Gradient Mix for the mixing extruder. (Requires GRADIENT_MIX)
+ * M190 - S Wait for bed current temp to reach target temp. ** Wait only when heating! **
+ * R Wait for bed current temp to reach target temp. ** Wait for heating or cooling. **
+ * M200 - Set filament diameter, D, setting E axis units to cubic. (Use S0 to revert to linear units.)
+ * M201 - Set max acceleration in units/s^2 for print moves: "M201 X Y Z E"
+ * M202 - Set max acceleration in units/s^2 for travel moves: "M202 X Y Z E" ** UNUSED IN MARLIN! **
+ * M203 - Set maximum feedrate: "M203 X Y Z E" in units/sec.
+ * M204 - Set default acceleration in units/sec^2: P R T
+ * M205 - Set advanced settings. Current units apply:
+ S T minimum speeds
+ B
+ X, Y, Z, E
+ * M206 - Set additional homing offset. (Disabled by NO_WORKSPACE_OFFSETS or DELTA)
+ * M207 - Set Retract Length: S, Feedrate: F, and Z lift: Z. (Requires FWRETRACT)
+ * M208 - Set Recover (unretract) Additional (!) Length: S and Feedrate: F. (Requires FWRETRACT)
+ * M209 - Turn Automatic Retract Detection on/off: S<0|1> (For slicers that don't support G10/11). (Requires FWRETRACT_AUTORETRACT)
+ Every normal extrude-only move will be classified as retract depending on the direction.
+ * M211 - Enable, Disable, and/or Report software endstops: S<0|1> (Requires MIN_SOFTWARE_ENDSTOPS or MAX_SOFTWARE_ENDSTOPS)
+ * M217 - Set filament swap parameters: "M217 S P R". (Requires SINGLENOZZLE)
+ * M218 - Set/get a tool offset: "M218 T X Y". (Requires 2 or more extruders)
+ * M220 - Set Feedrate Percentage: "M220 S" (i.e., "FR" on the LCD)
+ * Use "M220 B" to back up the Feedrate Percentage and "M220 R" to restore it. (Requires an MMU_MODEL version 2 or 2S)
+ * M221 - Set Flow Percentage: "M221 S"
+ * M226 - Wait until a pin is in a given state: "M226 P S" (Requires DIRECT_PIN_CONTROL)
+ * M240 - Trigger a camera to take a photograph. (Requires PHOTO_GCODE)
+ * M250 - Set LCD contrast: "M250 C" (0-63). (Requires LCD support)
+ * M260 - i2c Send Data (Requires EXPERIMENTAL_I2CBUS)
+ * M261 - i2c Request Data (Requires EXPERIMENTAL_I2CBUS)
+ * M280 - Set servo position absolute: "M280 P S". (Requires servos)
+ * M281 - Set servo min|max position: "M281 P L U". (Requires EDITABLE_SERVO_ANGLES)
+ * M290 - Babystepping (Requires BABYSTEPPING)
+ * M300 - Play beep sound S P
+ * M301 - Set PID parameters P I and D. (Requires PIDTEMP)
+ * M302 - Allow cold extrudes, or set the minimum extrude S. (Requires PREVENT_COLD_EXTRUSION)
+ * M303 - PID relay autotune S sets the target temperature. Default 150C. (Requires PIDTEMP)
+ * M304 - Set bed PID parameters P I and D. (Requires PIDTEMPBED)
+ * M305 - Set user thermistor parameters R T and P. (Requires TEMP_SENSOR_x 1000)
+ * M350 - Set microstepping mode. (Requires digital microstepping pins.)
+ * M351 - Toggle MS1 MS2 pins directly. (Requires digital microstepping pins.)
+ * M355 - Set Case Light on/off and set brightness. (Requires CASE_LIGHT_PIN)
+ * M380 - Activate solenoid on active extruder. (Requires EXT_SOLENOID)
+ * M381 - Disable all solenoids. (Requires EXT_SOLENOID)
+ * M400 - Finish all moves.
+ * M401 - Deploy and activate Z probe. (Requires a probe)
+ * M402 - Deactivate and stow Z probe. (Requires a probe)
+ * M403 - Set filament type for PRUSA MMU2
+ * M404 - Display or set the Nominal Filament Width: "W". (Requires FILAMENT_WIDTH_SENSOR)
+ * M405 - Enable Filament Sensor flow control. "M405 D". (Requires FILAMENT_WIDTH_SENSOR)
+ * M406 - Disable Filament Sensor flow control. (Requires FILAMENT_WIDTH_SENSOR)
+ * M407 - Display measured filament diameter in millimeters. (Requires FILAMENT_WIDTH_SENSOR)
+ * M410 - Quickstop. Abort all planned moves.
+ * M412 - Enable / Disable Filament Runout Detection. (Requires FILAMENT_RUNOUT_SENSOR)
+ * M413 - Enable / Disable Power-Loss Recovery. (Requires POWER_LOSS_RECOVERY)
+ * M414 - Set language by index. (Requires LCD_LANGUAGE_2...)
+ * M420 - Enable/Disable Leveling (with current values) S1=enable S0=disable (Requires MESH_BED_LEVELING or ABL)
+ * M421 - Set a single Z coordinate in the Mesh Leveling grid. X Y Z (Requires MESH_BED_LEVELING, AUTO_BED_LEVELING_BILINEAR, or AUTO_BED_LEVELING_UBL)
+ * M422 - Set Z Stepper automatic alignment position using probe. X Y A (Requires Z_STEPPER_AUTO_ALIGN)
+ * M425 - Enable/Disable and tune backlash correction. (Requires BACKLASH_COMPENSATION and BACKLASH_GCODE)
+ * M428 - Set the home_offset based on the current_position. Nearest edge applies. (Disabled by NO_WORKSPACE_OFFSETS or DELTA)
+ * M430 - Read the system current, voltage, and power (Requires POWER_MONITOR_CURRENT, POWER_MONITOR_VOLTAGE, or POWER_MONITOR_FIXED_VOLTAGE)
+ * M486 - Identify and cancel objects. (Requires CANCEL_OBJECTS)
+ * M500 - Store parameters in EEPROM. (Requires EEPROM_SETTINGS)
+ * M501 - Restore parameters from EEPROM. (Requires EEPROM_SETTINGS)
+ * M502 - Revert to the default "factory settings". ** Does not write them to EEPROM! **
+ * M503 - Print the current settings (in memory): "M503 S". S0 specifies compact output.
+ * M504 - Validate EEPROM contents. (Requires EEPROM_SETTINGS)
+ * M510 - Lock Printer
+ * M511 - Unlock Printer
+ * M512 - Set/Change/Remove Password
+ * M524 - Abort the current SD print job started with M24. (Requires SDSUPPORT)
+ * M540 - Enable/disable SD card abort on endstop hit: "M540 S". (Requires SD_ABORT_ON_ENDSTOP_HIT)
+ * M552 - Get or set IP address. Enable/disable network interface. (Requires enabled Ethernet port)
+ * M553 - Get or set IP netmask. (Requires enabled Ethernet port)
+ * M554 - Get or set IP gateway. (Requires enabled Ethernet port)
+ * M569 - Enable stealthChop on an axis. (Requires at least one _DRIVER_TYPE to be TMC2130/2160/2208/2209/5130/5160)
+ * M600 - Pause for filament change: "M600 X Y Z E L". (Requires ADVANCED_PAUSE_FEATURE)
+ * M603 - Configure filament change: "M603 T U L