32
32
33
33
#include " wiring_private.h"
34
34
35
- static volatile voidFuncPtr intFunc [EXTERNAL_NUM_INTERRUPTS ];
35
+ static volatile voidFuncPtrParam intFunc[EXTERNAL_NUM_INTERRUPTS];
36
+ static void * args[EXTERNAL_NUM_INTERRUPTS];
36
37
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 ) {
38
39
39
40
/* Get bit position and check pin validity */
40
41
uint8_t bit_pos = digitalPinToBitPosition (pin);
@@ -46,24 +47,27 @@ void attachInterrupt(uint8_t pin, void (*userFunc)(void), PinStatus mode) {
46
47
/* Check interrupt number and apply function pointer to correct array index */
47
48
if (interruptNum < EXTERNAL_NUM_INTERRUPTS) {
48
49
intFunc[interruptNum] = userFunc;
50
+ args[interruptNum] = params;
49
51
50
52
// Configure the interrupt mode (trigger on low input, any change, rising
51
53
// edge, or falling edge). The mode constants were chosen to correspond
52
54
// to the configuration bits in the hardware register, so we simply apply
53
55
// the setting in the pin control register
54
56
57
+ int isc_mode;
58
+
55
59
switch (mode) {
56
60
case CHANGE:
57
- mode = PORT_ISC_BOTHEDGES_gc ;
61
+ isc_mode = PORT_ISC_BOTHEDGES_gc;
58
62
break ;
59
63
case FALLING:
60
- mode = PORT_ISC_FALLING_gc ;
64
+ isc_mode = PORT_ISC_FALLING_gc;
61
65
break ;
62
66
case RISING:
63
- mode = PORT_ISC_RISING_gc ;
67
+ isc_mode = PORT_ISC_RISING_gc;
64
68
break ;
65
69
case LOW:
66
- mode = PORT_ISC_LEVEL_gc ;
70
+ isc_mode = PORT_ISC_LEVEL_gc;
67
71
break ;
68
72
default :
69
73
// AVR doesn't support level triggered interrupts
@@ -80,10 +84,14 @@ void attachInterrupt(uint8_t pin, void (*userFunc)(void), PinStatus mode) {
80
84
*pin_ctrl_reg &= ~(PORT_ISC_gm);
81
85
82
86
/* Apply ISC setting */
83
- * pin_ctrl_reg |= mode ;
87
+ *pin_ctrl_reg |= isc_mode ;
84
88
}
85
89
}
86
90
91
+ void attachInterrupt (uint8_t pin, void (*userFunc)(void ), PinStatus mode) {
92
+ attachInterruptParam (pin, (voidFuncPtrParam)userFunc, mode, NULL );
93
+ }
94
+
87
95
void detachInterrupt (uint8_t pin) {
88
96
/* Get bit position and check pin validity */
89
97
uint8_t bit_pos = digitalPinToBitPosition (pin);
@@ -127,7 +135,7 @@ static void port_interrupt_handler(uint8_t port) {
127
135
if (intFunc[interrupt_num] != 0 ){
128
136
129
137
/* Call function */
130
- intFunc [interrupt_num ]();
138
+ intFunc[interrupt_num](args[interrupt_num] );
131
139
}
132
140
}
133
141
bit_pos++;
0 commit comments