diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index baa8c2f..f0b94ab --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1985,8 +1985,14 @@ static void clean_up_after_endstop_or_probe_move() { #define STOW_PROBE() set_probe_deployed(false) #if ENABLED(BLTOUCH) + #if DISABLED(ENDSTOP_INTERRUPTS_FEATURE) + bool blTouchDeployed = false; + #endif FORCE_INLINE void set_bltouch_deployed(const bool &deploy) { servo[Z_ENDSTOP_SERVO_NR].move(deploy ? BLTOUCH_DEPLOY : BLTOUCH_STOW); + #if DISABLED(ENDSTOP_INTERRUPTS_FEATURE) + blTouchDeployed = deploy; + #endif #if ENABLED(DEBUG_LEVELING_FEATURE) if (DEBUGGING(LEVELING)) { SERIAL_ECHOPAIR("set_bltouch_deployed(", deploy); @@ -10097,6 +10103,14 @@ void idle( host_keepalive(); + #if DISABLED(ENDSTOP_INTERRUPTS_FEATURE) + #if ENABLED(BLTOUCH) + if (blTouchDeployed) { + endstops.update(); + } + #endif + #endif + #if ENABLED(AUTO_REPORT_TEMPERATURES) && (HAS_TEMP_HOTEND || HAS_TEMP_BED) auto_report_temperatures(); #endif diff --git a/Marlin/endstop_interrupts.h b/Marlin/endstop_interrupts.h index 495a758..58d6d5a 100644 --- a/Marlin/endstop_interrupts.h +++ b/Marlin/endstop_interrupts.h @@ -75,6 +75,11 @@ volatile uint8_t e_hit = 0; // Different from 0 when the endstops shall be tested in detail. // Must be reset to 0 by the test function when the tests are finished. +#if ENABLED(BLTOUCH) + volatile uint8_t bl_hit = 0; // Different from 0 when the endstops shall be tested in detail. + // Must be reset to 0 by the test function when the tests are finished. +#endif + // Install Pin change interrupt for a pin. Can be called multiple times. void pciSetup(byte pin) { *digitalPinToPCMSK(pin) |= bit (digitalPinToPCMSKbit(pin)); // enable pin @@ -87,6 +92,15 @@ FORCE_INLINE void endstop_ISR_worker( void ) { e_hit = 2; // Because the detection of a e-stop hit has a 1 step debouncer it has to be called at least twice. } +#if ENABLED(BLTOUCH) + FORCE_INLINE void endstop_ISR_worker_bltouch( void ) { + bl_hit = 1; + } + + // Use one Routine to handle bltouch + void endstop_ISR_bltouch(void) { endstop_ISR_worker_bltouch(); } +#endif + // Use one Routine to handle each group // One ISR for all EXT-Interrupts void endstop_ISR(void) { endstop_ISR_worker(); } @@ -162,7 +176,11 @@ void setup_endstop_interrupts( void ) { #if HAS_Z_MIN #if (digitalPinToInterrupt(Z_MIN_PIN) != NOT_AN_INTERRUPT) - attachInterrupt(digitalPinToInterrupt(Z_MIN_PIN), endstop_ISR, CHANGE); + #if ENABLED(BLTOUCH) + attachInterrupt(digitalPinToInterrupt(Z_MIN_PIN), endstop_ISR_bltouch, RISING); + #else + attachInterrupt(digitalPinToInterrupt(Z_MIN_PIN), endstop_ISR, CHANGE); + #endif #else // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration! static_assert(digitalPinToPCICR(Z_MIN_PIN) != NULL, "Z_MIN_PIN is not interrupt-capable"); @@ -192,7 +210,11 @@ void setup_endstop_interrupts( void ) { #if HAS_Z_MIN_PROBE_PIN #if (digitalPinToInterrupt(Z_MIN_PROBE_PIN) != NOT_AN_INTERRUPT) - attachInterrupt(digitalPinToInterrupt(Z_MIN_PROBE_PIN), endstop_ISR, CHANGE); + #if ENABLED(BLTOUCH) + attachInterrupt(digitalPinToInterrupt(Z_MIN_PROBE_PIN), endstop_ISR_bltouch, RISING); + #else + attachInterrupt(digitalPinToInterrupt(Z_MIN_PROBE_PIN), endstop_ISR, CHANGE); + #endif #else // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration! static_assert(digitalPinToPCICR(Z_MIN_PROBE_PIN) != NULL, "Z_MIN_PROBE_PIN is not interrupt-capable"); diff --git a/Marlin/endstops.cpp b/Marlin/endstops.cpp index 653e075..01b9414 100644 --- a/Marlin/endstops.cpp +++ b/Marlin/endstops.cpp @@ -348,6 +348,7 @@ void Endstops::update() { #else // !Z_DUAL_ENDSTOPS + #if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) if (z_probe_enabled) UPDATE_ENDSTOP(Z, MIN); #else diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index 82289a5..7a94cf9 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -312,6 +312,9 @@ void Stepper::set_directions() { #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE) extern volatile uint8_t e_hit; + #if ENABLED(BLTOUCH) + extern volatile uint8_t bl_hit; + #endif #endif /** @@ -413,13 +416,43 @@ void Stepper::isr() { #endif ) #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE) - && e_hit + && (e_hit + #if ENABLED(BLTOUCH) + || bl_hit + #endif + ) #endif ) { endstops.update(); #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE) - e_hit--; + #if ENABLED(BLTOUCH) + if (bl_hit) { + #if ENABLED(DEBUG_LEVELING_FEATURE) + if (DEBUGGING(LEVELING)) { + SERIAL_ECHOPAIR("stepper.ISR() bl_hit(", bl_hit); + SERIAL_CHAR(')'); + SERIAL_EOL; + } + #endif + if (motor_direction(Z_AXIS)) { + endstop_triggered(Z_AXIS); + bl_hit--; + } + } + if (e_hit) { + #if ENABLED(DEBUG_LEVELING_FEATURE) + if (DEBUGGING(LEVELING)) { + SERIAL_ECHOPAIR("e_hit(", e_hit); + SERIAL_CHAR(')'); + SERIAL_EOL; + } + #endif + e_hit--; + } + #else + e_hit--; + #endif #endif } @@ -1122,6 +1155,14 @@ void Stepper::endstop_triggered(AxisEnum axis) { #endif // !COREXY && !COREXZ && !COREYZ + #if ENABLED(DEBUG_LEVELING_FEATURE) + if (DEBUGGING(LEVELING)) { + SERIAL_ECHOPAIR("endstop_triggered(", axis); + SERIAL_CHAR(')'); + SERIAL_EOL; + } + #endif + kill_current_block(); }