From 12ee7e45f1170d6648d193c7a95cbc5d8cac9217 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 7 Feb 2026 19:20:18 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Misc.=20endstop-related=20tweaks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/feature/backlash.cpp | 8 ++--- Marlin/src/feature/backlash.h | 2 +- Marlin/src/gcode/calibrate/M425.cpp | 16 +++++----- Marlin/src/module/endstops.cpp | 41 +++++++++++++++++++------- Marlin/src/module/ft_motion.cpp | 2 +- Marlin/src/module/ft_motion/stepping.h | 7 ++--- Marlin/src/module/planner.cpp | 2 +- Marlin/src/module/planner.h | 2 +- 8 files changed, 49 insertions(+), 31 deletions(-) diff --git a/Marlin/src/feature/backlash.cpp b/Marlin/src/feature/backlash.cpp index 3b9d78cb2e..2de0aa00ef 100644 --- a/Marlin/src/feature/backlash.cpp +++ b/Marlin/src/feature/backlash.cpp @@ -29,7 +29,7 @@ #include "../module/motion.h" #include "../module/planner.h" -AxisBits Backlash::last_direction_bits; +AxisBits Backlash::last_direction; xyz_long_t Backlash::residual_error{0}; #ifdef BACKLASH_DISTANCE_MM @@ -64,7 +64,7 @@ Backlash backlash; */ void Backlash::add_correction_steps(const xyze_long_t &dist, const AxisBits dm, block_t * const block) { - AxisBits changed_dir = last_direction_bits ^ dm; + AxisBits changed_dir = last_direction ^ dm; // Ignore direction change unless steps are taken in that direction #if DISABLED(CORE_BACKLASH) || ANY(MARKFORGED_XY, MARKFORGED_YX) if (!dist.a) changed_dir.x = false; @@ -83,7 +83,7 @@ void Backlash::add_correction_steps(const xyze_long_t &dist, const AxisBits dm, if (!(dist.b - dist.c)) changed_dir.z = false; if (!dist.a) changed_dir.x = false; #endif - last_direction_bits ^= changed_dir; + last_direction ^= changed_dir; if (!correction && !residual_error) return; @@ -167,7 +167,7 @@ void Backlash::add_correction_steps(const xyze_long_t &dist, const AxisBits dm, int32_t Backlash::get_applied_steps(const AxisEnum axis) { if (axis >= NUM_AXES) return 0; - const bool forward = last_direction_bits[axis]; + const bool forward = last_direction[axis]; const int32_t residual_error_axis = residual_error[axis]; diff --git a/Marlin/src/feature/backlash.h b/Marlin/src/feature/backlash.h index b4790cb161..39c55ea21c 100644 --- a/Marlin/src/feature/backlash.h +++ b/Marlin/src/feature/backlash.h @@ -29,7 +29,7 @@ public: static constexpr uint8_t all_on = 0xFF, all_off = 0x00; private: - static AxisBits last_direction_bits; + static AxisBits last_direction; static xyz_long_t residual_error; #if ENABLED(BACKLASH_GCODE) diff --git a/Marlin/src/gcode/calibrate/M425.cpp b/Marlin/src/gcode/calibrate/M425.cpp index 5dab92a307..d95bfcd7e5 100644 --- a/Marlin/src/gcode/calibrate/M425.cpp +++ b/Marlin/src/gcode/calibrate/M425.cpp @@ -32,14 +32,14 @@ /** * M425: Enable and tune backlash correction. * - * F Enable/disable/fade-out backlash correction (0.0 to 1.0) - * S Distance over which backlash correction is spread - * X Set the backlash distance on X (0 to disable) - * Y ... on Y - * Z ... on Z - * X If a backlash measurement was done on X, copy that value - * Y ... on Y - * Z ... on Z + * F Enable/disable/fade-out backlash correction (0.0 to 1.0) + * S Distance over which backlash correction is spread + * X Set the backlash distance on X (0 to disable) + * Y ... on Y + * Z ... 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. */ diff --git a/Marlin/src/module/endstops.cpp b/Marlin/src/module/endstops.cpp index 5b7be5d00c..323a31e320 100644 --- a/Marlin/src/module/endstops.cpp +++ b/Marlin/src/module/endstops.cpp @@ -77,17 +77,6 @@ bool Endstops::enabled, Endstops::enabled_globally; // Initialized by settings.l volatile Endstops::endstop_mask_t Endstops::hit_state; Endstops::endstop_mask_t Endstops::live_state = 0; -#if ENABLED(BD_SENSOR) - bool Endstops::bdp_state; // = false - #if HOMING_Z_WITH_PROBE - #define READ_ENDSTOP(P) ((P == TERN(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN, Z_MIN_PIN, Z_MIN_PROBE_PIN)) ? bdp_state : READ(P)) - #else - #define READ_ENDSTOP(P) READ(P) - #endif -#else - #define READ_ENDSTOP(P) READ(P) -#endif - #if ENDSTOP_NOISE_THRESHOLD Endstops::endstop_mask_t Endstops::validated_live_state; uint8_t Endstops::endstop_poll_count; @@ -97,11 +86,34 @@ Endstops::endstop_mask_t Endstops::live_state = 0; volatile bool Endstops::z_probe_enabled = false; #endif +// +// Standard Endstop READ +// +#define READ_ENDSTOP(P) READ(P) + +// +// Bed Distance Sensor +// +#if ENABLED(BD_SENSOR) + bool Endstops::bdp_state; // = false + #if HOMING_Z_WITH_PROBE + #undef READ_ENDSTOP + #define READ_ENDSTOP(P) ((P == TERN(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN, Z_MIN_PIN, Z_MIN_PROBE_PIN)) ? bdp_state : READ(P)) + #endif +#endif + +// +// Calibration Probe +// #if ENABLED(CALIBRATION_GCODE) volatile bool Endstops::calibration_probe_enabled = false; volatile bool Endstops::calibration_stop_state; #endif +// +// Multi-Endstop Alignment +// + // Initialized by settings.load #if ENABLED(X_DUAL_ENDSTOPS) float Endstops::x2_endstop_adj; @@ -119,9 +131,16 @@ Endstops::endstop_mask_t Endstops::live_state = 0; #endif #endif +// +// SPI Endstops +// #if ENABLED(SPI_ENDSTOPS) Endstops::tmc_spi_homing_t Endstops::tmc_spi_homing; // = 0 #endif + +// +// StallGuard Debounce +// #if ENABLED(IMPROVE_HOMING_RELIABILITY) millis_t sg_guard_period; // = 0 #endif diff --git a/Marlin/src/module/ft_motion.cpp b/Marlin/src/module/ft_motion.cpp index d2876404e0..e59536f434 100644 --- a/Marlin/src/module/ft_motion.cpp +++ b/Marlin/src/module/ft_motion.cpp @@ -409,7 +409,7 @@ bool FTMotion::plan_next_block() { const float totalLength = current_block->millimeters; startPos = endPos_prevBlock; - const xyze_pos_t& moveDist = current_block->dist_mm; + const xyze_pos_t &moveDist = current_block->distance_mm; ratio = moveDist / totalLength; // Plan the trajectory using the trajectory generator diff --git a/Marlin/src/module/ft_motion/stepping.h b/Marlin/src/module/ft_motion/stepping.h index 636945ac06..e389e56c3c 100644 --- a/Marlin/src/module/ft_motion/stepping.h +++ b/Marlin/src/module/ft_motion/stepping.h @@ -67,8 +67,7 @@ typedef struct Stepping { // ISR part // - AxisBits dir_bits; - AxisBits step_bits; + AxisBits dir_bits, step_bits; xyze_ulong_t axis_interval_fp{ LOGICAL_AXIS_LIST_1(FTM_NEVER) }; xyze_ulong_t ticks_left_per_axis_fp{ LOGICAL_AXIS_LIST_1(FTM_NEVER) }; @@ -78,7 +77,7 @@ typedef struct Stepping { // generating the next step pulse. The call is inexpensive: // - no heap, no locks – pure arithmetic on pre-computed data FORCE_INLINE uint32_t advance_until_step() { - step_bits = 0; + step_bits.reset(); uint32_t ticks_to_wait_fp = 0; for (;;) { @@ -140,7 +139,7 @@ typedef struct Stepping { } FORCE_INLINE void reset() { - step_bits = 0; + step_bits.reset(); axis_interval_fp = FTM_NEVER; ticks_left_per_axis_fp = FTM_NEVER; ticks_left_in_frame_fp = 0; diff --git a/Marlin/src/module/planner.cpp b/Marlin/src/module/planner.cpp index 4ed9d9c0cd..2d1e5dd219 100644 --- a/Marlin/src/module/planner.cpp +++ b/Marlin/src/module/planner.cpp @@ -2060,7 +2060,7 @@ bool Planner::_populate_block( TERN_(BACKLASH_COMPENSATION, backlash.add_correction_steps(dist, dm, block)); } - TERN_(FT_MOTION, block->dist_mm = dist_mm); // Store the distance for all axes in mm for this block + TERN_(FT_MOTION, block->distance_mm = dist_mm); // Store the distance for all axes in mm for this block TERN_(HAS_EXTRUDERS, block->steps.e = esteps); diff --git a/Marlin/src/module/planner.h b/Marlin/src/module/planner.h index cdcf553698..02150451b6 100644 --- a/Marlin/src/module/planner.h +++ b/Marlin/src/module/planner.h @@ -262,7 +262,7 @@ typedef struct PlannerBlock { AxisBits direction_bits; // Direction bits set for this block, where 1 is negative motion #if ENABLED(FT_MOTION) - xyze_pos_t dist_mm; // The distance traveled in mm along each axis + xyze_pos_t distance_mm; // The distance traveled in mm along each axis #endif #if ANY(SMOOTH_LIN_ADVANCE, FTM_HAS_LIN_ADVANCE)