123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- #ifndef _ENDSTOP_INTERRUPTS_H_
- #define _ENDSTOP_INTERRUPTS_H_
- #include "macros.h"
- void endstop_ISR(void) { endstops.update(); }
- #if defined(ARDUINO_AVR_MEGA2560) || defined(ARDUINO_AVR_MEGA)
- #undef digitalPinToPCICR
- #define digitalPinToPCICR(p) ( WITHIN(p, 10, 15) || \
- WITHIN(p, 50, 53) || \
- WITHIN(p, 62, 69) ? &PCICR : (uint8_t*)0 )
- #undef digitalPinToPCICRbit
- #define digitalPinToPCICRbit(p) ( WITHIN(p, 10, 13) || WITHIN(p, 50, 53) ? 0 : \
- WITHIN(p, 14, 15) ? 1 : \
- WITHIN(p, 62, 69) ? 2 : \
- 0 )
- #undef digitalPinToPCMSK
- #define digitalPinToPCMSK(p) ( WITHIN(p, 10, 13) || WITHIN(p, 50, 53) ? &PCMSK0 : \
- WITHIN(p, 14, 15) ? &PCMSK1 : \
- WITHIN(p, 62, 69) ? &PCMSK2 : \
- (uint8_t *)0 )
- #undef digitalPinToPCMSKbit
- #define digitalPinToPCMSKbit(p) ( WITHIN(p, 10, 13) ? ((p) - 6) : \
- (p) == 14 || (p) == 51 ? 2 : \
- (p) == 15 || (p) == 52 ? 1 : \
- (p) == 50 ? 3 : \
- (p) == 53 ? 0 : \
- WITHIN(p, 62, 69) ? ((p) - 62) : \
- 0 )
- #endif
- void pciSetup(const int8_t pin) {
- SBI(*digitalPinToPCMSK(pin), digitalPinToPCMSKbit(pin));
- SBI(PCIFR, digitalPinToPCICRbit(pin));
- SBI(PCICR, digitalPinToPCICRbit(pin));
- }
- #ifdef PCINT0_vect
- ISR(PCINT0_vect) { endstop_ISR(); }
- #endif
- #ifdef PCINT1_vect
- ISR(PCINT1_vect) { endstop_ISR(); }
- #endif
- #ifdef PCINT2_vect
- ISR(PCINT2_vect) { endstop_ISR(); }
- #endif
- #ifdef PCINT3_vect
- ISR(PCINT3_vect) { endstop_ISR(); }
- #endif
- void setup_endstop_interrupts( void ) {
- #if HAS_X_MAX
- #if digitalPinToInterrupt(X_MAX_PIN) != NOT_AN_INTERRUPT
- attachInterrupt(digitalPinToInterrupt(X_MAX_PIN), endstop_ISR, CHANGE);
- #else
-
- static_assert(digitalPinToPCICR(X_MAX_PIN) != NULL, "X_MAX_PIN is not interrupt-capable");
- pciSetup(X_MAX_PIN);
- #endif
- #endif
- #if HAS_X_MIN
- #if digitalPinToInterrupt(X_MIN_PIN) != NOT_AN_INTERRUPT
- attachInterrupt(digitalPinToInterrupt(X_MIN_PIN), endstop_ISR, CHANGE);
- #else
-
- static_assert(digitalPinToPCICR(X_MIN_PIN) != NULL, "X_MIN_PIN is not interrupt-capable");
- 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
-
- static_assert(digitalPinToPCICR(Y_MAX_PIN) != NULL, "Y_MAX_PIN is not interrupt-capable");
- 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
-
- static_assert(digitalPinToPCICR(Y_MIN_PIN) != NULL, "Y_MIN_PIN is not interrupt-capable");
- 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
-
- static_assert(digitalPinToPCICR(Z_MAX_PIN) != NULL, "Z_MAX_PIN is not interrupt-capable");
- 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
-
- static_assert(digitalPinToPCICR(Z_MIN_PIN) != NULL, "Z_MIN_PIN is not interrupt-capable");
- pciSetup(Z_MIN_PIN);
- #endif
- #endif
- #if HAS_X2_MAX
- #if (digitalPinToInterrupt(X2_MAX_PIN) != NOT_AN_INTERRUPT)
- attachInterrupt(digitalPinToInterrupt(X2_MAX_PIN), endstop_ISR, CHANGE);
- #else
-
- static_assert(digitalPinToPCICR(X2_MAX_PIN) != NULL, "X2_MAX_PIN is not interrupt-capable");
- pciSetup(X2_MAX_PIN);
- #endif
- #endif
- #if HAS_X2_MIN
- #if (digitalPinToInterrupt(X2_MIN_PIN) != NOT_AN_INTERRUPT)
- attachInterrupt(digitalPinToInterrupt(X2_MIN_PIN), endstop_ISR, CHANGE);
- #else
-
- static_assert(digitalPinToPCICR(X2_MIN_PIN) != NULL, "X2_MIN_PIN is not interrupt-capable");
- pciSetup(X2_MIN_PIN);
- #endif
- #endif
- #if HAS_Y2_MAX
- #if (digitalPinToInterrupt(Y2_MAX_PIN) != NOT_AN_INTERRUPT)
- attachInterrupt(digitalPinToInterrupt(Y2_MAX_PIN), endstop_ISR, CHANGE);
- #else
-
- static_assert(digitalPinToPCICR(Y2_MAX_PIN) != NULL, "Y2_MAX_PIN is not interrupt-capable");
- pciSetup(Y2_MAX_PIN);
- #endif
- #endif
- #if HAS_Y2_MIN
- #if (digitalPinToInterrupt(Y2_MIN_PIN) != NOT_AN_INTERRUPT)
- attachInterrupt(digitalPinToInterrupt(Y2_MIN_PIN), endstop_ISR, CHANGE);
- #else
-
- static_assert(digitalPinToPCICR(Y2_MIN_PIN) != NULL, "Y2_MIN_PIN is not interrupt-capable");
- pciSetup(Y2_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
-
- static_assert(digitalPinToPCICR(Z2_MAX_PIN) != NULL, "Z2_MAX_PIN is not interrupt-capable");
- 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
-
- static_assert(digitalPinToPCICR(Z2_MIN_PIN) != NULL, "Z2_MIN_PIN is not interrupt-capable");
- 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
-
- static_assert(digitalPinToPCICR(Z_MIN_PROBE_PIN) != NULL, "Z_MIN_PROBE_PIN is not interrupt-capable");
- pciSetup(Z_MIN_PROBE_PIN);
- #endif
- #endif
-
- }
- #endif
|