Fix interrupt-based endstop detection
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
* Endstop Interrupts
|
||||
*
|
||||
* Without endstop interrupts the endstop pins must be polled continually in
|
||||
* the stepper-ISR via endstops.update(), most of the time finding no change.
|
||||
* the temperature-ISR via endstops.update(), most of the time finding no change.
|
||||
* With this feature endstops.update() is called only when we know that at
|
||||
* least one endstop has changed state, saving valuable CPU cycles.
|
||||
*
|
||||
@@ -40,6 +40,9 @@
|
||||
|
||||
#include "macros.h"
|
||||
|
||||
// One ISR for all EXT-Interrupts
|
||||
void endstop_ISR(void) { endstops.check_possible_change(); }
|
||||
|
||||
/**
|
||||
* Patch for pins_arduino.h (...\Arduino\hardware\arduino\avr\variants\mega\pins_arduino.h)
|
||||
*
|
||||
@@ -72,8 +75,6 @@
|
||||
0 )
|
||||
#endif
|
||||
|
||||
volatile uint8_t e_hit = 0; // Different from 0 when the endstops should be tested in detail.
|
||||
// Must be reset to 0 by the test function when finished.
|
||||
|
||||
// Install Pin change interrupt for a pin. Can be called multiple times.
|
||||
void pciSetup(const int8_t pin) {
|
||||
@@ -82,30 +83,22 @@ void pciSetup(const int8_t pin) {
|
||||
SBI(PCICR, 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(); }
|
||||
|
||||
// Handlers for pin change interrupts
|
||||
#ifdef PCINT0_vect
|
||||
ISR(PCINT0_vect) { endstop_ISR_worker(); }
|
||||
ISR(PCINT0_vect) { endstop_ISR(); }
|
||||
#endif
|
||||
|
||||
#ifdef PCINT1_vect
|
||||
ISR(PCINT1_vect) { endstop_ISR_worker(); }
|
||||
ISR(PCINT1_vect) { endstop_ISR(); }
|
||||
#endif
|
||||
|
||||
#ifdef PCINT2_vect
|
||||
ISR(PCINT2_vect) { endstop_ISR_worker(); }
|
||||
ISR(PCINT2_vect) { endstop_ISR(); }
|
||||
#endif
|
||||
|
||||
#ifdef PCINT3_vect
|
||||
ISR(PCINT3_vect) { endstop_ISR_worker(); }
|
||||
ISR(PCINT3_vect) { endstop_ISR(); }
|
||||
#endif
|
||||
|
||||
void setup_endstop_interrupts( void ) {
|
||||
|
||||
Reference in New Issue
Block a user