diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 75ab781a7e25735d79277dc57a59e52ce0134e67..5b15c3f3f79ba2c30449aded6316e3b30695cd28 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -445,6 +445,9 @@ #define Z_MAX_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop. #define Z_MIN_PROBE_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop. +// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE. +// Then the function testing the endstops will only be called, if the state of one of the endstops changed. +//#define ENDSTOP_INTERRUPTS_FEATURE //============================================================================= //============================== Movement Settings ============================ diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 5473f5387d4a279d6cb0b38c8a1126b0b9b08110..862f7dfc51da1de82119a3b6907824c5a06a0554 100755 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -89,6 +89,9 @@ #include "twibus.h" #endif +#if ENABLED(ENDSTOP_INTERRUPTS_FEATURE) + #include "endstop_interrupts.h" +#endif /** * Look here for descriptions of G-codes: * - http://linuxcnc.org/handbook/gcode/g-code.html @@ -10000,6 +10003,10 @@ void setup() { i2c.onReceive(i2c_on_receive); i2c.onRequest(i2c_on_request); #endif + + #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE) + setup_enstop_interrupts(); + #endif } /** diff --git a/Marlin/endstop_interrupts.h b/Marlin/endstop_interrupts.h new file mode 100644 index 0000000000000000000000000000000000000000..db8691d19215b6ca88d6bcba376314d65294cc4d --- /dev/null +++ b/Marlin/endstop_interrupts.h @@ -0,0 +1,211 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (C) 2016 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 <http://www.gnu.org/licenses/>. + * + */ + +/** + * Endstop interrupts + * Without endstop interrups the stepper-ISR must always test all endstops when interested in their states (endstops.update()). + * Most time the test will result in finding out nothing has changed. + * With endstop interrupts endstops.update() is called only when we know that at least one endstop has changed its state. + * + * This can work only if all __used__ endstop pins can provide ether an 'external interrupt' or a 'pin change interrupt'. + * You can find out about pins issuing interrupts by running 'pin_interrupt_test.ino' (Marlin\buildroot\share\pin_interrupt_test\pin_interrupt_test.ino) + */ + + #ifndef _ENDSTOP_INTERRUPTS_H_ + #define _ENDSTOP_INTERRUPTS_H_ + + /** + * Patch for pins_arduino.h (...\Arduino\hardware\arduino\avr\variants\mega\pins_arduino.h) + * + * These macros for the Arduino MEGA do not include the two connected pins on Port J (D13, D14). + * So we extend them here because this are the normal pins for Y_MIN and Y_MAX on RAMPS. + * There are more PCI enabled processor pins on Port J, but they are not connected to Arduino MEGA. + */ + #if defined(ARDUINO_AVR_MEGA2560) || defined(ARDUINO_AVR_MEGA) + #undef digitalPinToPCICR + #define digitalPinToPCICR(p) ( (((p) >= 10) && ((p) <= 15)) || \ + (((p) >= 50) && ((p) <= 53)) || \ + (((p) >= 62) && ((p) <= 69)) ? (&PCICR) : ((uint8_t *)0) ) + #undef digitalPinToPCICRbit + #define digitalPinToPCICRbit(p) ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? 0 : \ + ( (((p) >= 14) && ((p) <= 15)) ? 1 : \ + ( (((p) >= 62) && ((p) <= 69)) ? 2 : \ + 0 ) ) ) + #undef digitalPinToPCMSK + #define digitalPinToPCMSK(p) ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? (&PCMSK0) : \ + ( (((p) >= 14) && ((p) <= 15)) ? (&PCMSK1) : \ + ( (((p) >= 62) && ((p) <= 69)) ? (&PCMSK2) : \ + ((uint8_t *)0) ) ) ) + #undef digitalPinToPCMSKbit + #define digitalPinToPCMSKbit(p) ( (((p) >= 10) && ((p) <= 13)) ? ((p) - 6) : \ + ( ((p) == 14) ? 2 : \ + ( ((p) == 15) ? 1 : \ + ( ((p) == 50) ? 3 : \ + ( ((p) == 51) ? 2 : \ + ( ((p) == 52) ? 1 : \ + ( ((p) == 53) ? 0 : \ + ( (((p) >= 62) && ((p) <= 69)) ? ((p) - 62) : \ + 0 ) ) ) ) ) ) ) ) + #endif + + 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. + + // Install Pin change interrupt for a pin, can be called multiple times + void pciSetup(byte pin) { + *digitalPinToPCMSK(pin) |= bit (digitalPinToPCMSKbit(pin)); // enable pin + PCIFR |= bit (digitalPinToPCICRbit(pin)); // clear any outstanding interrupt + PCICR |= bit (digitalPinToPCICRbit(pin)); // enable interrupt for the group + } + + // This is what is really done inside the interrupts. + 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. + } + + // Use one Routine to handle each group + // One ISR for all EXT-Interrupts + void endstop_ISR(void) { + endstop_ISR_worker(); + } + + #ifdef PCINT0_vect + ISR(PCINT0_vect) { // handle pin change interrupt + endstop_ISR_worker(); + } + #endif + + #ifdef PCINT1_vect + ISR(PCINT1_vect) { // handle pin change interrupt + endstop_ISR_worker(); + } + #endif + + #ifdef PCINT2_vect + ISR(PCINT2_vect) { // handle pin change interrupt + endstop_ISR_worker(); + } + #endif + + #ifdef PCINT3_vect + ISR(PCINT3_vect) { // handle pin change interrupt + endstop_ISR_worker(); + } + #endif + + void setup_enstop_interrupts( void ) { + + #if HAS_X_MAX + #if (digitalPinToInterrupt(X_MAX_PIN) != NOT_AN_INTERRUPT) // if pin has an external interrupt + attachInterrupt(digitalPinToInterrupt(X_MAX_PIN), endstop_ISR, CHANGE); // assign it + #else + // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration! + static_assert(digitalPinToPCICR(X_MAX_PIN) != NULL, "ENDSTOP_INTERRUPT_ERROR"); // if pin has no pin change interrupt - error + pciSetup(X_MAX_PIN); // assign it + #endif + #endif + + #if HAS_X_MIN + #if (digitalPinToInterrupt(X_MIN_PIN) != NOT_AN_INTERRUPT) + attachInterrupt(digitalPinToInterrupt(X_MIN_PIN), endstop_ISR, CHANGE); + #else + // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration! + static_assert(digitalPinToPCICR(X_MIN_PIN) != NULL, "ENDSTOP_INTERRUPT_ERROR"); + pciSetup(X_MIN_PIN); + #endif + #endif + + #if HAS_Y_MAX + #if (digitalPinToInterrupt(Y_MAX_PIN) != NOT_AN_INTERRUPT) + attachInterrupt(digitalPinToInterrupt(Y_MAX_PIN), endstop_ISR, CHANGE); + #else + // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration! + static_assert(digitalPinToPCICR(Y_MAX_PIN) != NULL, "ENDSTOP_INTERRUPT_ERROR"); + pciSetup(Y_MAX_PIN); + #endif + #endif + + #if HAS_Y_MIN + #if (digitalPinToInterrupt(Y_MIN_PIN) != NOT_AN_INTERRUPT) + attachInterrupt(digitalPinToInterrupt(Y_MIN_PIN), endstop_ISR, CHANGE); + #else + // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration! + static_assert(digitalPinToPCICR(Y_MIN_PIN) != NULL, "ENDSTOP_INTERRUPT_ERROR"); + pciSetup(Y_MIN_PIN); + #endif + #endif + + #if HAS_Z_MAX + #if (digitalPinToInterrupt(Z_MAX_PIN) != NOT_AN_INTERRUPT) + attachInterrupt(digitalPinToInterrupt(Z_MAX_PIN), endstop_ISR, CHANGE); + #else + // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration! + static_assert(digitalPinToPCICR(Z_MAX_PIN) != NULL, "ENDSTOP_INTERRUPT_ERROR"); + pciSetup(Z_MAX_PIN); + #endif + #endif + + #if HAS_Z_MIN + #if (digitalPinToInterrupt(Z_MIN_PIN) != NOT_AN_INTERRUPT) + attachInterrupt(digitalPinToInterrupt(Z_MIN_PIN), endstop_ISR, CHANGE); + #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, "ENDSTOP_INTERRUPT_ERROR"); + pciSetup(Z_MIN_PIN); + #endif + #endif + + #if HAS_Z2_MAX + #if (digitalPinToInterrupt(Z2_MAX_PIN) != NOT_AN_INTERRUPT) + attachInterrupt(digitalPinToInterrupt(Z2_MAX_PIN), endstop_ISR, CHANGE); + #else + // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration! + static_assert(digitalPinToPCICR(Z2_MAX_PIN) != NULL, "ENDSTOP_INTERRUPT_ERROR"); + pciSetup(Z2_MAX_PIN); + #endif + #endif + + #if HAS_Z2_MIN + #if (digitalPinToInterrupt(Z2_MIN_PIN) != NOT_AN_INTERRUPT) + attachInterrupt(digitalPinToInterrupt(Z2_MIN_PIN), endstop_ISR, CHANGE); + #else + // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration! + static_assert(digitalPinToPCICR(Z2_MIN_PIN) != NULL, "ENDSTOP_INTERRUPT_ERROR"); + pciSetup(Z2_MIN_PIN); + #endif + #endif + + #if HAS_Z_MIN_PROBE_PIN + #if (digitalPinToInterrupt(Z_MIN_PROBE_PIN) != NOT_AN_INTERRUPT) + attachInterrupt(digitalPinToInterrupt(Z_MIN_PROBE_PIN), endstop_ISR, CHANGE); + #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, "ENDSTOP_INTERRUPT_ERROR"); + pciSetup(Z_MIN_PROBE_PIN); + #endif + #endif + + // When we arive here without error each pin has ether a EXT-interrupt or a PCI. + } + + +#endif //_ENDSTOP_INTERRUPTS_H_ diff --git a/Marlin/example_configurations/Cartesio/Configuration.h b/Marlin/example_configurations/Cartesio/Configuration.h index 634afc7ddbcddc365efbff7345f9056f590291e9..b25931b58e02898b3862b2a89dcd254516da45df 100644 --- a/Marlin/example_configurations/Cartesio/Configuration.h +++ b/Marlin/example_configurations/Cartesio/Configuration.h @@ -445,6 +445,9 @@ #define Z_MAX_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop. #define Z_MIN_PROBE_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop. +// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE. +// Then the function testing the endstops will only be called, if the state of one of the endstops changed. +//#define ENDSTOP_INTERRUPTS_FEATURE //============================================================================= //============================== Movement Settings ============================ diff --git a/Marlin/example_configurations/Felix/Configuration.h b/Marlin/example_configurations/Felix/Configuration.h index f59173cba8ee41f61effb8121fd995e1560aa77b..f11ec8a80aca9004f2f6901693938d8402ce1bda 100644 --- a/Marlin/example_configurations/Felix/Configuration.h +++ b/Marlin/example_configurations/Felix/Configuration.h @@ -427,6 +427,9 @@ #define Z_MAX_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop. #define Z_MIN_PROBE_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop. +// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE. +// Then the function testing the endstops will only be called, if the state of one of the endstops changed. +//#define ENDSTOP_INTERRUPTS_FEATURE //============================================================================= //============================== Movement Settings ============================ diff --git a/Marlin/example_configurations/Felix/DUAL/Configuration.h b/Marlin/example_configurations/Felix/DUAL/Configuration.h index af0af94278d0b2888037a84854549fe2cc96c0c6..5f65aa52fff2a9ec73bef31e3289aaaee151c51f 100644 --- a/Marlin/example_configurations/Felix/DUAL/Configuration.h +++ b/Marlin/example_configurations/Felix/DUAL/Configuration.h @@ -427,6 +427,9 @@ #define Z_MAX_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop. #define Z_MIN_PROBE_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop. +// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE. +// Then the function testing the endstops will only be called, if the state of one of the endstops changed. +//#define ENDSTOP_INTERRUPTS_FEATURE //============================================================================= //============================== Movement Settings ============================ diff --git a/Marlin/example_configurations/Hephestos/Configuration.h b/Marlin/example_configurations/Hephestos/Configuration.h index 2d5f51997dd1911a9cec01a8dfbdcd42bd5d1a96..d2cce0106d799fcf70da97f1a66e0e7582b7855d 100644 --- a/Marlin/example_configurations/Hephestos/Configuration.h +++ b/Marlin/example_configurations/Hephestos/Configuration.h @@ -437,6 +437,9 @@ #define Z_MAX_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop. #define Z_MIN_PROBE_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop. +// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE. +// Then the function testing the endstops will only be called, if the state of one of the endstops changed. +//#define ENDSTOP_INTERRUPTS_FEATURE //============================================================================= //============================== Movement Settings ============================ diff --git a/Marlin/example_configurations/Hephestos_2/Configuration.h b/Marlin/example_configurations/Hephestos_2/Configuration.h index 162a2628b65b5cba28f600be3059449d13b5b1e4..7a352d802a458dbcd012e238f3cd022de3a28e98 100644 --- a/Marlin/example_configurations/Hephestos_2/Configuration.h +++ b/Marlin/example_configurations/Hephestos_2/Configuration.h @@ -439,6 +439,9 @@ #define Z_MAX_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop. #define Z_MIN_PROBE_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop. +// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE. +// Then the function testing the endstops will only be called, if the state of one of the endstops changed. +//#define ENDSTOP_INTERRUPTS_FEATURE //============================================================================= //============================== Movement Settings ============================ diff --git a/Marlin/example_configurations/K8200/Configuration.h b/Marlin/example_configurations/K8200/Configuration.h index 9f8b54d07b9b1b876c69e7d5fa98160ac023e87e..fb2adee3e8a48599723e081e9c6db372911ac6ee 100644 --- a/Marlin/example_configurations/K8200/Configuration.h +++ b/Marlin/example_configurations/K8200/Configuration.h @@ -462,6 +462,9 @@ #define Z_MAX_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop. #define Z_MIN_PROBE_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop. +// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE. +// Then the function testing the endstops will only be called, if the state of one of the endstops changed. +//#define ENDSTOP_INTERRUPTS_FEATURE //============================================================================= //============================== Movement Settings ============================ diff --git a/Marlin/example_configurations/K8400/Configuration.h b/Marlin/example_configurations/K8400/Configuration.h index 8b52c085c21eee19fb7c0d26fdde25916b50eeb7..4ea9328f083c8dae40715219c32c2fd615df7a74 100644 --- a/Marlin/example_configurations/K8400/Configuration.h +++ b/Marlin/example_configurations/K8400/Configuration.h @@ -445,6 +445,9 @@ #define Z_MAX_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop. #define Z_MIN_PROBE_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop. +// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE. +// Then the function testing the endstops will only be called, if the state of one of the endstops changed. +//#define ENDSTOP_INTERRUPTS_FEATURE //============================================================================= //============================== Movement Settings ============================ diff --git a/Marlin/example_configurations/K8400/Dual-head/Configuration.h b/Marlin/example_configurations/K8400/Dual-head/Configuration.h index 79fcf4726aab30d0d8a7fcdb78a0ce9227ee3e35..b290503f5a5988b0fbfdcaee479439f6b39d3dba 100644 --- a/Marlin/example_configurations/K8400/Dual-head/Configuration.h +++ b/Marlin/example_configurations/K8400/Dual-head/Configuration.h @@ -445,6 +445,9 @@ #define Z_MAX_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop. #define Z_MIN_PROBE_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop. +// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE. +// Then the function testing the endstops will only be called, if the state of one of the endstops changed. +//#define ENDSTOP_INTERRUPTS_FEATURE //============================================================================= //============================== Movement Settings ============================ diff --git a/Marlin/example_configurations/RepRapWorld/Megatronics/Configuration.h b/Marlin/example_configurations/RepRapWorld/Megatronics/Configuration.h index 14de17911c45836958ed1bbb8e16809bfb8c7786..c8f4ac97aa8917ecc48d31cf8de1e9d7002ac746 100644 --- a/Marlin/example_configurations/RepRapWorld/Megatronics/Configuration.h +++ b/Marlin/example_configurations/RepRapWorld/Megatronics/Configuration.h @@ -445,6 +445,9 @@ #define Z_MAX_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop. #define Z_MIN_PROBE_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop. +// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE. +// Then the function testing the endstops will only be called, if the state of one of the endstops changed. +//#define ENDSTOP_INTERRUPTS_FEATURE //============================================================================= //============================== Movement Settings ============================ diff --git a/Marlin/example_configurations/RigidBot/Configuration.h b/Marlin/example_configurations/RigidBot/Configuration.h index fb329ca09e25eca5f30ddc817ff679f98ce1a748..f6c0dc1ee2396e490ee09ad861a5a108a54d085a 100644 --- a/Marlin/example_configurations/RigidBot/Configuration.h +++ b/Marlin/example_configurations/RigidBot/Configuration.h @@ -442,6 +442,9 @@ #define Z_MAX_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop. #define Z_MIN_PROBE_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop. +// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE. +// Then the function testing the endstops will only be called, if the state of one of the endstops changed. +//#define ENDSTOP_INTERRUPTS_FEATURE //============================================================================= //============================== Movement Settings ============================ diff --git a/Marlin/example_configurations/SCARA/Configuration.h b/Marlin/example_configurations/SCARA/Configuration.h index ec244874fecf3140b7c8f07807cf71ac003e95b3..c2c0e6a8b80f30b738ea7edfda50f9c8994c9748 100644 --- a/Marlin/example_configurations/SCARA/Configuration.h +++ b/Marlin/example_configurations/SCARA/Configuration.h @@ -460,6 +460,9 @@ #define Z_MAX_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop. #define Z_MIN_PROBE_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop. +// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE. +// Then the function testing the endstops will only be called, if the state of one of the endstops changed. +//#define ENDSTOP_INTERRUPTS_FEATURE //============================================================================= //============================== Movement Settings ============================ diff --git a/Marlin/example_configurations/TAZ4/Configuration.h b/Marlin/example_configurations/TAZ4/Configuration.h index 92a9c033dc2c084f1e602368c8ada92338016db9..d7f6aefc74cd5c57a178da492b1c868478c8cdcd 100644 --- a/Marlin/example_configurations/TAZ4/Configuration.h +++ b/Marlin/example_configurations/TAZ4/Configuration.h @@ -466,6 +466,9 @@ #define Z_MAX_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop. #define Z_MIN_PROBE_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop. +// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE. +// Then the function testing the endstops will only be called, if the state of one of the endstops changed. +//#define ENDSTOP_INTERRUPTS_FEATURE //============================================================================= //============================== Movement Settings ============================ diff --git a/Marlin/example_configurations/WITBOX/Configuration.h b/Marlin/example_configurations/WITBOX/Configuration.h index 60d79d52f2381a74c90daebf56626c9dc52b6ed7..0d933e805abc5eab6c94628ad1f2eef18c0babd5 100644 --- a/Marlin/example_configurations/WITBOX/Configuration.h +++ b/Marlin/example_configurations/WITBOX/Configuration.h @@ -437,6 +437,9 @@ #define Z_MAX_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop. #define Z_MIN_PROBE_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop. +// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE. +// Then the function testing the endstops will only be called, if the state of one of the endstops changed. +//#define ENDSTOP_INTERRUPTS_FEATURE //============================================================================= //============================== Movement Settings ============================ diff --git a/Marlin/example_configurations/adafruit/ST7565/Configuration.h b/Marlin/example_configurations/adafruit/ST7565/Configuration.h index fdd8d79ea6c6461fb3d4b48c1623d2499923e16b..3e9da7b7940ef0285d5613d0591c07c37f0a92ba 100644 --- a/Marlin/example_configurations/adafruit/ST7565/Configuration.h +++ b/Marlin/example_configurations/adafruit/ST7565/Configuration.h @@ -445,6 +445,9 @@ #define Z_MAX_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop. #define Z_MIN_PROBE_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop. +// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE. +// Then the function testing the endstops will only be called, if the state of one of the endstops changed. +//#define ENDSTOP_INTERRUPTS_FEATURE //============================================================================= //============================== Movement Settings ============================ diff --git a/Marlin/example_configurations/delta/biv2.5/Configuration.h b/Marlin/example_configurations/delta/biv2.5/Configuration.h index f6a1b8cdd3ac26f9bb88d2f3843c39c69e5049b4..e939c4b72815b073dcf903a127fc8b2b2b8b3468 100644 --- a/Marlin/example_configurations/delta/biv2.5/Configuration.h +++ b/Marlin/example_configurations/delta/biv2.5/Configuration.h @@ -489,6 +489,9 @@ #define Z_MAX_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop. #define Z_MIN_PROBE_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop. +// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE. +// Then the function testing the endstops will only be called, if the state of one of the endstops changed. +//#define ENDSTOP_INTERRUPTS_FEATURE //============================================================================= //============================== Movement Settings ============================ diff --git a/Marlin/example_configurations/delta/generic/Configuration.h b/Marlin/example_configurations/delta/generic/Configuration.h index 6dd1b8191dfae53e33963cd3bf05b316cfdebcde..107ccb65d2f553983c7af52c9e9ec1906f315d6b 100644 --- a/Marlin/example_configurations/delta/generic/Configuration.h +++ b/Marlin/example_configurations/delta/generic/Configuration.h @@ -489,6 +489,9 @@ #define Z_MAX_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop. #define Z_MIN_PROBE_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop. +// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE. +// Then the function testing the endstops will only be called, if the state of one of the endstops changed. +//#define ENDSTOP_INTERRUPTS_FEATURE //============================================================================= //============================== Movement Settings ============================ diff --git a/Marlin/example_configurations/delta/kossel_mini/Configuration.h b/Marlin/example_configurations/delta/kossel_mini/Configuration.h index 057320b31a624b14235724dc51167266679193ed..cf2d63b7a40ebf322a9f2e975c493b4140bb76b4 100644 --- a/Marlin/example_configurations/delta/kossel_mini/Configuration.h +++ b/Marlin/example_configurations/delta/kossel_mini/Configuration.h @@ -489,6 +489,9 @@ #define Z_MAX_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop. #define Z_MIN_PROBE_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop. +// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE. +// Then the function testing the endstops will only be called, if the state of one of the endstops changed. +//#define ENDSTOP_INTERRUPTS_FEATURE //============================================================================= //============================== Movement Settings ============================ diff --git a/Marlin/example_configurations/delta/kossel_pro/Configuration.h b/Marlin/example_configurations/delta/kossel_pro/Configuration.h index 2cd160adc642504507e09c753bcf7f0a23088059..233ce8b1b86b5bea871a27e54fc18344ea1cd62a 100644 --- a/Marlin/example_configurations/delta/kossel_pro/Configuration.h +++ b/Marlin/example_configurations/delta/kossel_pro/Configuration.h @@ -478,6 +478,9 @@ #define Z_MAX_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop. #define Z_MIN_PROBE_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop. +// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE. +// Then the function testing the endstops will only be called, if the state of one of the endstops changed. +//#define ENDSTOP_INTERRUPTS_FEATURE //============================================================================= //============================== Movement Settings ============================ diff --git a/Marlin/example_configurations/delta/kossel_xl/Configuration.h b/Marlin/example_configurations/delta/kossel_xl/Configuration.h index 679fa5564f529965e3ffed432f9113ae096ce3bd..c6ca06f4e54cba250605d3de2dd5526adba51793 100644 --- a/Marlin/example_configurations/delta/kossel_xl/Configuration.h +++ b/Marlin/example_configurations/delta/kossel_xl/Configuration.h @@ -487,6 +487,9 @@ #define Z_MAX_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop. #define Z_MIN_PROBE_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop. +// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE. +// Then the function testing the endstops will only be called, if the state of one of the endstops changed. +//#define ENDSTOP_INTERRUPTS_FEATURE //============================================================================= //============================== Movement Settings ============================ diff --git a/Marlin/example_configurations/makibox/Configuration.h b/Marlin/example_configurations/makibox/Configuration.h index 802c9bbbc5ae676c949e83011a74457bc944feb0..5f5ad1d8a30ca5874f54c57a9aadc9eb28b0ef4a 100644 --- a/Marlin/example_configurations/makibox/Configuration.h +++ b/Marlin/example_configurations/makibox/Configuration.h @@ -448,6 +448,9 @@ #define Z_MAX_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop. #define Z_MIN_PROBE_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop. +// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE. +// Then the function testing the endstops will only be called, if the state of one of the endstops changed. +//#define ENDSTOP_INTERRUPTS_FEATURE //============================================================================= //============================== Movement Settings ============================ diff --git a/Marlin/example_configurations/tvrrug/Round2/Configuration.h b/Marlin/example_configurations/tvrrug/Round2/Configuration.h index 75bbded7fa7c0f23bdc96ef64ccddd9db9e1d75c..03bb14b5bf720086e93470c5fdbcb88ae50538fd 100644 --- a/Marlin/example_configurations/tvrrug/Round2/Configuration.h +++ b/Marlin/example_configurations/tvrrug/Round2/Configuration.h @@ -435,6 +435,9 @@ #define Z_MAX_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop. #define Z_MIN_PROBE_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop. +// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE. +// Then the function testing the endstops will only be called, if the state of one of the endstops changed. +//#define ENDSTOP_INTERRUPTS_FEATURE //============================================================================= //============================== Movement Settings ============================ diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index dd35990a56415cd88383bc20f2add096d51378b2..9f712faad8b90085668daedae5a99737158a5b1f 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -310,6 +310,10 @@ void Stepper::set_directions() { #endif // !ADVANCE && !LIN_ADVANCE } +#if ENABLED(ENDSTOP_INTERRUPTS_FEATURE) + extern volatile uint8_t e_hit; +#endif + /** * Stepper Driver Interrupt * @@ -378,7 +382,15 @@ void Stepper::isr() { #if HAS_BED_PROBE || endstops.z_probe_enabled #endif - ) endstops.update(); + ) + #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE) + if(e_hit) { + #endif + endstops.update(); + #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE) + e_hit--; + } + #endif // Take multiple steps per interrupt (For high speed moves) bool all_steps_done = false; diff --git a/buildroot/share/pin_interrupt_test/pin_interrupt_test.ino b/buildroot/share/pin_interrupt_test/pin_interrupt_test.ino new file mode 100644 index 0000000000000000000000000000000000000000..8650a3d1329816afb740dcb53cf002105fb5b8ac --- /dev/null +++ b/buildroot/share/pin_interrupt_test/pin_interrupt_test.ino @@ -0,0 +1,32 @@ +// Search pins uasable for endstop-interupts +// Compile with the same settings you'd use with Marlin. + +#if defined(ARDUINO_AVR_MEGA2560) || defined(ARDUINO_AVR_MEGA) + #undef digitalPinToPCICR + #define digitalPinToPCICR(p) ( (((p) >= 10) && ((p) <= 15)) || \ + (((p) >= 50) && ((p) <= 53)) || \ + (((p) >= 62) && ((p) <= 69)) ? (&PCICR) : ((uint8_t *)0) ) +#endif + +void setup() { + Serial.begin(9600); + Serial.println("PINs causing interrups are:"); + for(int i=2; i<NUM_DIGITAL_PINS; i++){ + if( digitalPinToPCICR(i) != NULL || (int)digitalPinToInterrupt(i) != -1 ) { + for (int j= 0; j<NUM_ANALOG_INPUTS; j++){ + if(analogInputToDigitalPin(j) == i) { + Serial.print("A"); + Serial.print(j); + Serial.print(" = "); + } + } + Serial.print("D"); + Serial.println(i); + } + } + Serial.println("Arduino pin numbering!"); +} + +void loop() { + // put your main code here, to run repeatedly: +}