@@ -91,18 +91,14 @@ void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode)
91
91
uint32_t current = 0 ;
92
92
93
93
// Check if we already have this interrupt
94
- int id = -1 ;
95
- for (uint32_t i = 0 ; i < nints ; i ++ ) {
96
- if (ISRlist [i ] == in ) id = in ;
94
+ for (current = 0 ; current < nints ; current ++ ) {
95
+ if (ISRlist [current ] == in ) {
96
+ break ;
97
+ }
97
98
}
98
-
99
- if (id == -1 ) {
99
+ if (current == nints ) {
100
100
// Need to make a new entry
101
- current = nints ;
102
101
nints ++ ;
103
- } else {
104
- // We already have an entry for this pin
105
- current = id ;
106
102
}
107
103
ISRlist [current ] = in ; // List with nr of interrupt in order of when they were attached
108
104
ISRcallback [current ] = callback ; // List of callback adresses
@@ -163,16 +159,18 @@ void detachInterrupt(uint32_t pin)
163
159
EIC -> WAKEUP .reg &= ~(1 << in );
164
160
165
161
// Remove callback from the ISR list
166
- int id = -1 ;
167
- for (uint32_t i = 0 ; i < nints ; i ++ ) {
168
- if (ISRlist [i ] == in ) id = in ;
162
+ uint32_t current ;
163
+ for (current = 0 ; current < nints ; current ++ ) {
164
+ if (ISRlist [current ] == in ) {
165
+ break ;
166
+ }
169
167
}
170
- if (id == -1 ) return ; // We didn't have it
168
+ if (current == nints ) return ; // We didn't have it
171
169
172
170
// Shift the reminder down
173
- for (uint32_t i = id ; i < nints - 1 ; i ++ ) {
174
- ISRlist [i ] = ISRlist [i + 1 ];
175
- ISRcallback [i ] = ISRcallback [i + 1 ];
171
+ for (; current < nints - 1 ; current ++ ) {
172
+ ISRlist [current ] = ISRlist [current + 1 ];
173
+ ISRcallback [current ] = ISRcallback [current + 1 ];
176
174
}
177
175
nints -- ;
178
176
}
0 commit comments