Skip to content

Commit ebd14de

Browse files
committed
Port attachInterruptParams
1 parent a39f0d3 commit ebd14de

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

Diff for: cores/arduino/WInterrupts.c renamed to cores/arduino/WInterrupts.cpp

+16-8
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@
3232

3333
#include "wiring_private.h"
3434

35-
static volatile voidFuncPtr intFunc[EXTERNAL_NUM_INTERRUPTS];
35+
static volatile voidFuncPtrParam intFunc[EXTERNAL_NUM_INTERRUPTS];
36+
static void* args[EXTERNAL_NUM_INTERRUPTS];
3637

37-
void attachInterrupt(uint8_t pin, void (*userFunc)(void), PinStatus mode) {
38+
void attachInterruptParam(pin_size_t pin, void (*userFunc)(void*), PinStatus mode, void* params) {
3839

3940
/* Get bit position and check pin validity */
4041
uint8_t bit_pos = digitalPinToBitPosition(pin);
@@ -46,24 +47,27 @@ void attachInterrupt(uint8_t pin, void (*userFunc)(void), PinStatus mode) {
4647
/* Check interrupt number and apply function pointer to correct array index */
4748
if(interruptNum < EXTERNAL_NUM_INTERRUPTS) {
4849
intFunc[interruptNum] = userFunc;
50+
args[interruptNum] = params;
4951

5052
// Configure the interrupt mode (trigger on low input, any change, rising
5153
// edge, or falling edge). The mode constants were chosen to correspond
5254
// to the configuration bits in the hardware register, so we simply apply
5355
// the setting in the pin control register
5456

57+
int isc_mode;
58+
5559
switch (mode) {
5660
case CHANGE:
57-
mode = PORT_ISC_BOTHEDGES_gc;
61+
isc_mode = PORT_ISC_BOTHEDGES_gc;
5862
break;
5963
case FALLING:
60-
mode = PORT_ISC_FALLING_gc;
64+
isc_mode = PORT_ISC_FALLING_gc;
6165
break;
6266
case RISING:
63-
mode = PORT_ISC_RISING_gc;
67+
isc_mode = PORT_ISC_RISING_gc;
6468
break;
6569
case LOW:
66-
mode = PORT_ISC_LEVEL_gc;
70+
isc_mode = PORT_ISC_LEVEL_gc;
6771
break;
6872
default:
6973
// AVR doesn't support level triggered interrupts
@@ -80,10 +84,14 @@ void attachInterrupt(uint8_t pin, void (*userFunc)(void), PinStatus mode) {
8084
*pin_ctrl_reg &= ~(PORT_ISC_gm);
8185

8286
/* Apply ISC setting */
83-
*pin_ctrl_reg |= mode;
87+
*pin_ctrl_reg |= isc_mode;
8488
}
8589
}
8690

91+
void attachInterrupt(uint8_t pin, void (*userFunc)(void), PinStatus mode) {
92+
attachInterruptParam(pin, (voidFuncPtrParam)userFunc, mode, NULL);
93+
}
94+
8795
void detachInterrupt(uint8_t pin) {
8896
/* Get bit position and check pin validity */
8997
uint8_t bit_pos = digitalPinToBitPosition(pin);
@@ -127,7 +135,7 @@ static void port_interrupt_handler(uint8_t port) {
127135
if(intFunc[interrupt_num] != 0){
128136

129137
/* Call function */
130-
intFunc[interrupt_num]();
138+
intFunc[interrupt_num](args[interrupt_num]);
131139
}
132140
}
133141
bit_pos++;

0 commit comments

Comments
 (0)