From 7fcc605595f777e00c377372f9a4e7c09d232a2a Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 24 Nov 2025 17:06:42 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20Relocate=20?= =?UTF-8?q?G38=20data?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/MarlinCore.cpp | 5 ----- Marlin/src/MarlinCore.h | 5 ----- Marlin/src/gcode/probe/G38.cpp | 10 ++++++---- Marlin/src/module/endstops.cpp | 6 +++--- Marlin/src/module/endstops.h | 8 ++++++++ 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index cb81efc4bb..b6a47ec744 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -164,11 +164,6 @@ CardReader card; #endif -#if ENABLED(G38_PROBE_TARGET) - uint8_t G38_move; // = 0 - bool G38_did_trigger; // = false -#endif - #if ENABLED(DELTA) #include "module/delta.h" #elif ENABLED(POLARGRAPH) diff --git a/Marlin/src/MarlinCore.h b/Marlin/src/MarlinCore.h index ecab0e3630..6f27b9998e 100644 --- a/Marlin/src/MarlinCore.h +++ b/Marlin/src/MarlinCore.h @@ -33,11 +33,6 @@ void stop(); void idle(const bool no_stepper_sleep=false); inline void idle_no_sleep() { idle(true); } -#if ENABLED(G38_PROBE_TARGET) - extern uint8_t G38_move; // Flag to tell the ISR that G38 is in progress, and the type - extern bool G38_did_trigger; // Flag from the ISR to indicate the endstop changed -#endif - void kill(FSTR_P const lcd_error=nullptr, FSTR_P const lcd_component=nullptr, const bool steppers_off=false); void minkill(const bool steppers_off=false); diff --git a/Marlin/src/gcode/probe/G38.cpp b/Marlin/src/gcode/probe/G38.cpp index d57eb9b59e..34cab07ed6 100644 --- a/Marlin/src/gcode/probe/G38.cpp +++ b/Marlin/src/gcode/probe/G38.cpp @@ -31,12 +31,14 @@ #include "../../module/planner.h" #include "../../module/probe.h" +probe_target_t G38_move{0}; + inline void G38_single_probe(const uint8_t move_value) { endstops.enable(true); - G38_move = move_value; + G38_move.type = move_value; prepare_line_to_destination(); planner.synchronize(); - G38_move = 0; + G38_move.type = 0; endstops.hit_on_purpose(); set_current_from_steppers_for_axis(ALL_AXES_ENUM); sync_plan_position(); @@ -64,12 +66,12 @@ inline bool G38_run_probe() { constexpr uint8_t move_value = 1; #endif - G38_did_trigger = false; + G38_move.triggered = false; // Move until destination reached or target hit G38_single_probe(move_value); - if (G38_did_trigger) { + if (G38_move.triggered) { G38_pass_fail = true; diff --git a/Marlin/src/module/endstops.cpp b/Marlin/src/module/endstops.cpp index 20b3b8b1d2..31b877b642 100644 --- a/Marlin/src/module/endstops.cpp +++ b/Marlin/src/module/endstops.cpp @@ -473,7 +473,7 @@ void Endstops::update() { #if ENABLED(G38_PROBE_TARGET) // For G38 moves check the probe's pin for ALL movement - if (G38_move) UPDATE_LIVE_STATE(Z, TERN(USE_Z_MIN_PROBE, MIN_PROBE, MIN)); + if (G38_move.type) UPDATE_LIVE_STATE(Z, TERN(USE_Z_MIN_PROBE, MIN_PROBE, MIN)); #endif #if ENABLED(CALIBRATION_GCODE) @@ -723,8 +723,8 @@ void Endstops::update() { #if ENABLED(G38_PROBE_TARGET) // For G38 moves check the probe's pin for ALL movement - if (G38_move && TEST_ENDSTOP(Z_MIN_PROBE) == TERN1(G38_PROBE_AWAY, (G38_move < 4))) { - G38_did_trigger = true; + if (G38_move.type && TEST_ENDSTOP(Z_MIN_PROBE) == TERN1(G38_PROBE_AWAY, (G38_move.type < 4))) { + G38_move.triggered = true; #define _G38_SET(Q) | (AXIS_IS_MOVING(Q) << _AXIS(Q)) #define _G38_RESP(Q) if (moving[_AXIS(Q)]) { _ENDSTOP_HIT(Q, ENDSTOP); planner.endstop_triggered(_AXIS(Q)); } const Flags moving = { uvalue_t(NUM_AXES)(0 MAIN_AXIS_MAP(_G38_SET)) }; diff --git a/Marlin/src/module/endstops.h b/Marlin/src/module/endstops.h index 4d7a444bc4..17715de1da 100644 --- a/Marlin/src/module/endstops.h +++ b/Marlin/src/module/endstops.h @@ -313,3 +313,11 @@ class TemporaryGlobalEndstopsState { } ~TemporaryGlobalEndstopsState() { endstops.enable_globally(saved); } }; + +#if ENABLED(G38_PROBE_TARGET) + typedef struct ProbeTarget { + uint8_t type; // Flag to tell the ISR the type of G38 in progress; 0 for NONE. + bool triggered; // Flag from the ISR to indicate the endstop changed + } probe_target_t; + extern probe_target_t G38_move; +#endif