Add and apply WITHIN macro
This commit is contained in:
@@ -35,8 +35,10 @@
|
||||
* (Located in Marlin/buildroot/share/pin_interrupt_test/pin_interrupt_test.ino)
|
||||
*/
|
||||
|
||||
#ifndef _ENDSTOP_INTERRUPTS_H_
|
||||
#define _ENDSTOP_INTERRUPTS_H_
|
||||
#ifndef _ENDSTOP_INTERRUPTS_H_
|
||||
#define _ENDSTOP_INTERRUPTS_H_
|
||||
|
||||
#include "macros.h"
|
||||
|
||||
/**
|
||||
* Patch for pins_arduino.h (...\Arduino\hardware\arduino\avr\variants\mega\pins_arduino.h)
|
||||
@@ -47,39 +49,37 @@
|
||||
*/
|
||||
#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) )
|
||||
#define digitalPinToPCICR(p) ( WITHIN(p, 10, 15) || \
|
||||
WITHIN(p, 50, 53) || \
|
||||
WITHIN(p, 62, 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 ) ) )
|
||||
#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) ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? (&PCMSK0) : \
|
||||
( (((p) >= 14) && ((p) <= 15)) ? (&PCMSK1) : \
|
||||
( (((p) >= 62) && ((p) <= 69)) ? (&PCMSK2) : \
|
||||
((uint8_t *)0) ) ) )
|
||||
#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) ( (((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 ) ) ) ) ) ) ) )
|
||||
#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
|
||||
|
||||
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.
|
||||
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(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
|
||||
SBI(*digitalPinToPCMSK(pin), digitalPinToPCMSKbit(pin)); // enable pin
|
||||
SBI(PCIFR, digitalPinToPCICRbit(pin)); // clear any outstanding interrupt
|
||||
SBI(PCICR, digitalPinToPCICRbit(pin)); // enable interrupt for the group
|
||||
}
|
||||
|
||||
// This is what is really done inside the interrupts.
|
||||
|
Reference in New Issue
Block a user