Skip to content

Commit 0155fab

Browse files
committed
Revise style on interrupt handler functions
1 parent ead32ea commit 0155fab

File tree

1 file changed

+12
-38
lines changed

1 file changed

+12
-38
lines changed

ports/stm32f4/common-hal/pulseio/PulseIn.c

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ static pulseio_pulsein_obj_t* _objs[STM32_GPIO_PORT_SIZE];
4343
static void assign_EXTI_Interrupt(pulseio_pulsein_obj_t* self, uint8_t num);
4444

4545
static void pulsein_handler(uint8_t num) {
46+
// Interrupt register must be cleared manually
47+
EXTI->PR = 1 << num;
48+
4649
// Grab the current time first.
4750
uint32_t current_us;
4851
uint64_t current_ms;
@@ -260,70 +263,41 @@ static void assign_EXTI_Interrupt(pulseio_pulsein_obj_t* self, uint8_t num) {
260263

261264
void EXTI0_IRQHandler(void)
262265
{
263-
EXTI->PR = 1 << 0;
264266
pulsein_handler(0);
265267
}
266268
void EXTI1_IRQHandler(void)
267269
{
268-
EXTI->PR = 1 << 1;
269270
pulsein_handler(1);
270271
}
271272
void EXTI2_IRQHandler(void)
272273
{
273-
EXTI->PR = 1 << 2;
274274
pulsein_handler(2);
275275
}
276276
void EXTI3_IRQHandler(void)
277277
{
278-
EXTI->PR = 1 << 3;
279278
pulsein_handler(3);
280279
}
281280
void EXTI4_IRQHandler(void)
282281
{
283-
EXTI->PR = 1 << 4;
284282
pulsein_handler(4);
285283
}
284+
286285
void EXTI9_5_IRQHandler(void)
287286
{
288287
uint32_t pending = EXTI->PR;
289-
if(pending & (1 << 5)) {
290-
EXTI->PR = 1 << 5;
291-
pulsein_handler(5);
292-
} else if (pending & (1 << 6)) {
293-
EXTI->PR = 1 << 6;
294-
pulsein_handler(6);
295-
} else if (pending & (1 << 7)) {
296-
EXTI->PR = 1 << 7;
297-
pulsein_handler(7);
298-
} else if (pending & (1 << 8)) {
299-
EXTI->PR = 1 << 8;
300-
pulsein_handler(8);
301-
} else if (pending & (1 << 9)) {
302-
EXTI->PR = 1 << 9;
303-
pulsein_handler(9);
288+
for (uint i = 5; i <= 9; i++) {
289+
if(pending & (1 << i)) {
290+
pulsein_handler(i);
291+
}
304292
}
305293
}
306294

307295
void EXTI15_10_IRQHandler(void)
308296
{
309297
uint32_t pending = EXTI->PR;
310-
if(pending & (1 << 10)) {
311-
EXTI->PR = 1 << 10;
312-
pulsein_handler(10);
313-
} else if (pending & (1 << 11)) {
314-
EXTI->PR = 1 << 11;
315-
pulsein_handler(11);
316-
} else if (pending & (1 << 12)) {
317-
EXTI->PR = 1 << 12;
318-
pulsein_handler(12);
319-
} else if (pending & (1 << 13)) {
320-
EXTI->PR = 1 << 13;
321-
pulsein_handler(13);
322-
} else if (pending & (1 << 14)) {
323-
EXTI->PR = 1 << 14;
324-
pulsein_handler(14);
325-
} else if (pending & (1 << 15)) {
326-
EXTI->PR = 1 << 15;
327-
pulsein_handler(15);
298+
for (uint i = 10; i <= 15; i++) {
299+
if(pending & (1 << i)) {
300+
pulsein_handler(i);
301+
}
328302
}
329303
}

0 commit comments

Comments
 (0)