Skip to content

Commit df16dab

Browse files
committed
Refactor digitalPinToInterrupt macro
This way the behaviour matches SAMD core (both attachInterrupt(pin) and attachInterrupt(digitalPinToInterrupt(pin) can be used. Fixes #18
1 parent 3dd10f4 commit df16dab

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

cores/arduino/Arduino.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ bool isDoubleBondedActive(uint8_t pin);
125125
#define portToPortStruct(port) ( (port < NUM_TOTAL_PORTS) ? ((PORT_t *)&PORTA + port) : NULL)
126126
#define digitalPinToPortStruct(pin) ( (pin < NUM_TOTAL_PINS) ? ((PORT_t *)&PORTA + digitalPinToPort(pin)) : NULL)
127127
#define getPINnCTRLregister(port, bit_pos) ( ((port != NULL) && (bit_pos < NOT_A_PIN)) ? ((volatile uint8_t *)&(port->PIN0CTRL) + bit_pos) : NULL )
128-
#define digitalPinToInterrupt(p) ( digitalPinToPort(p) * 8 + digitalPinToBitPosition(p) )
128+
#define digitalPinToInterrupt(P) (P)
129129

130130
#define portOutputRegister(P) ( (volatile uint8_t *)( &portToPortStruct(P)->OUT ) )
131131
#define portInputRegister(P) ( (volatile uint8_t *)( &portToPortStruct(P)->IN ) )

cores/arduino/WInterrupts.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void attachInterrupt(uint8_t pin, void (*userFunc)(void), PinStatus mode) {
4141
if(bit_pos == NOT_A_PIN) return;
4242

4343
/* Get interrupt number from pin */
44-
uint8_t interruptNum = digitalPinToInterrupt(pin);
44+
uint8_t interruptNum = (digitalPinToPort(pin) * 8) + bit_pos;
4545

4646
/* Check interrupt number and apply function pointer to correct array index */
4747
if(interruptNum < EXTERNAL_NUM_INTERRUPTS) {
@@ -90,7 +90,7 @@ void detachInterrupt(uint8_t pin) {
9090
if(bit_pos == NOT_A_PIN) return;
9191

9292
/* Get interrupt number from pin */
93-
uint8_t interruptNum = digitalPinToInterrupt(pin);
93+
uint8_t interruptNum = (digitalPinToPort(pin) * 8) + bit_pos;
9494

9595
if(interruptNum < EXTERNAL_NUM_INTERRUPTS) {
9696
// Disable the interrupt.

0 commit comments

Comments
 (0)