@@ -91,18 +91,14 @@ void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode)
9191 uint32_t current = 0 ;
9292
9393 // 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+ }
9798 }
98-
99- if (id == -1 ) {
99+ if (current == nints ) {
100100 // Need to make a new entry
101- current = nints ;
102101 nints ++ ;
103- } else {
104- // We already have an entry for this pin
105- current = id ;
106102 }
107103 ISRlist [current ] = in ; // List with nr of interrupt in order of when they were attached
108104 ISRcallback [current ] = callback ; // List of callback adresses
@@ -163,16 +159,18 @@ void detachInterrupt(uint32_t pin)
163159 EIC -> WAKEUP .reg &= ~(1 << in );
164160
165161 // 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+ }
169167 }
170- if (id == -1 ) return ; // We didn't have it
168+ if (current == nints ) return ; // We didn't have it
171169
172170 // 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 ];
176174 }
177175 nints -- ;
178176}
0 commit comments