5 static bool _twr_exti_initialized =
false;
15 static inline void _twr_exti_irq_handler(
void);
20 uint8_t port = ((uint8_t) line >> 4) & 7;
23 uint8_t pin = (uint8_t) line & 15;
26 uint16_t mask = 1 << pin;
32 _twr_exti[pin].line = line;
35 _twr_exti[pin].callback = callback;
38 _twr_exti[pin].param = param;
41 if (!_twr_exti_initialized)
44 _twr_exti_initialized =
true;
47 RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN;
50 NVIC_EnableIRQ(EXTI0_1_IRQn);
51 NVIC_EnableIRQ(EXTI2_3_IRQn);
52 NVIC_EnableIRQ(EXTI4_15_IRQn);
56 SYSCFG->EXTICR[pin >> 2] |= port << ((pin & 3) << 2);
93 uint8_t pin = (uint8_t) line & 15;
96 uint16_t mask = 1 << pin;
102 if (line == _twr_exti[pin].line)
115 static inline void _twr_exti_irq_handler(
void)
118 if ((EXTI->PR & 0x0001) != 0) { EXTI->PR = 0x0001; _twr_exti[0].callback(_twr_exti[0].line, _twr_exti[0].param);
return; }
119 if ((EXTI->PR & 0x0002) != 0) { EXTI->PR = 0x0002; _twr_exti[1].callback(_twr_exti[1].line, _twr_exti[1].param);
return; }
120 if ((EXTI->PR & 0x0004) != 0) { EXTI->PR = 0x0004; _twr_exti[2].callback(_twr_exti[2].line, _twr_exti[2].param);
return; }
121 if ((EXTI->PR & 0x0008) != 0) { EXTI->PR = 0x0008; _twr_exti[3].callback(_twr_exti[3].line, _twr_exti[3].param);
return; }
122 if ((EXTI->PR & 0x0010) != 0) { EXTI->PR = 0x0010; _twr_exti[4].callback(_twr_exti[4].line, _twr_exti[4].param);
return; }
123 if ((EXTI->PR & 0x0020) != 0) { EXTI->PR = 0x0020; _twr_exti[5].callback(_twr_exti[5].line, _twr_exti[5].param);
return; }
124 if ((EXTI->PR & 0x0040) != 0) { EXTI->PR = 0x0040; _twr_exti[6].callback(_twr_exti[6].line, _twr_exti[6].param);
return; }
125 if ((EXTI->PR & 0x0080) != 0) { EXTI->PR = 0x0080; _twr_exti[7].callback(_twr_exti[7].line, _twr_exti[7].param);
return; }
126 if ((EXTI->PR & 0x0100) != 0) { EXTI->PR = 0x0100; _twr_exti[8].callback(_twr_exti[8].line, _twr_exti[8].param);
return; }
127 if ((EXTI->PR & 0x0200) != 0) { EXTI->PR = 0x0200; _twr_exti[9].callback(_twr_exti[9].line, _twr_exti[9].param);
return; }
128 if ((EXTI->PR & 0x0400) != 0) { EXTI->PR = 0x0400; _twr_exti[10].callback(_twr_exti[10].line, _twr_exti[10].param);
return; }
129 if ((EXTI->PR & 0x0800) != 0) { EXTI->PR = 0x0800; _twr_exti[11].callback(_twr_exti[11].line, _twr_exti[11].param);
return; }
130 if ((EXTI->PR & 0x1000) != 0) { EXTI->PR = 0x1000; _twr_exti[12].callback(_twr_exti[12].line, _twr_exti[12].param);
return; }
131 if ((EXTI->PR & 0x2000) != 0) { EXTI->PR = 0x2000; _twr_exti[13].callback(_twr_exti[13].line, _twr_exti[13].param);
return; }
132 if ((EXTI->PR & 0x4000) != 0) { EXTI->PR = 0x4000; _twr_exti[14].callback(_twr_exti[14].line, _twr_exti[14].param);
return; }
133 if ((EXTI->PR & 0x8000) != 0) { EXTI->PR = 0x8000; _twr_exti[15].callback(_twr_exti[15].line, _twr_exti[15].param);
return; }
136 void EXTI0_1_IRQHandler(
void)
138 _twr_exti_irq_handler();
141 void EXTI2_3_IRQHandler(
void)
143 _twr_exti_irq_handler();
146 void EXTI4_15_IRQHandler(
void)
148 _twr_exti_irq_handler();
void twr_exti_register(twr_exti_line_t line, twr_exti_edge_t edge, void(*callback)(twr_exti_line_t, void *), void *param)
Enable EXTI line interrupt and register callback function.
void twr_exti_unregister(twr_exti_line_t line)
Disable EXTI line interrupt.
twr_exti_line_t
EXTI lines.
twr_exti_edge_t
Interrupt edge sensitivity.
@ TWR_EXTI_EDGE_FALLING
EXTI line is configured to falling edge sensitivity.
@ TWR_EXTI_EDGE_RISING_AND_FALLING
EXTI line is configured to both rising and falling edge sensitivity.
@ TWR_EXTI_EDGE_RISING
EXTI line is configured to rising edge sensitivity.
void twr_irq_disable(void)
Disable interrupt requests globally (call can be nested)
void twr_irq_enable(void)
Enable interrupt requests globally (call can be nested)