summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2019-06-01 16:08:11 +1000
committerDamien George <damien.p.george@gmail.com>2019-06-03 16:47:35 +1000
commit10e173aaeadd589653fda89da34766322b77059d (patch)
treee597995754e8f0cfccb0c674efba46f3994b8b51
parent345e9864aac03693eec6cddd09a0dcd47df9c453 (diff)
stm32/extint: Add extint_set() function for internal C access to EXTI.
-rw-r--r--ports/stm32/extint.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/ports/stm32/extint.c b/ports/stm32/extint.c
index 59b20d5bd..1f147d42d 100644
--- a/ports/stm32/extint.c
+++ b/ports/stm32/extint.c
@@ -297,6 +297,53 @@ void extint_register_pin(const pin_obj_t *pin, uint32_t mode, bool hard_irq, mp_
}
}
+void extint_set(const pin_obj_t *pin, uint32_t mode) {
+ uint32_t line = pin->pin;
+
+ mp_obj_t *cb = &MP_STATE_PORT(pyb_extint_callback)[line];
+
+ extint_disable(line);
+
+ *cb = MP_OBJ_SENTINEL;
+
+ pyb_extint_mode[line] = (mode & 0x00010000) ? // GPIO_MODE_IT == 0x00010000
+ EXTI_Mode_Interrupt : EXTI_Mode_Event;
+
+ {
+ // Configure and enable the callback
+
+ pyb_extint_hard_irq[line] = 1;
+ pyb_extint_callback_arg[line] = MP_OBJ_FROM_PTR(pin);
+
+ // Route the GPIO to EXTI
+ __HAL_RCC_SYSCFG_CLK_ENABLE();
+ SYSCFG->EXTICR[line >> 2] =
+ (SYSCFG->EXTICR[line >> 2] & ~(0x0f << (4 * (line & 0x03))))
+ | ((uint32_t)(GPIO_GET_INDEX(pin->gpio)) << (4 * (line & 0x03)));
+
+ // Enable or disable the rising detector
+ if ((mode & GPIO_MODE_IT_RISING) == GPIO_MODE_IT_RISING) {
+ EXTI_RTSR |= 1 << line;
+ } else {
+ EXTI_RTSR &= ~(1 << line);
+ }
+
+ // Enable or disable the falling detector
+ if ((mode & GPIO_MODE_IT_FALLING) == GPIO_MODE_IT_FALLING) {
+ EXTI_FTSR |= 1 << line;
+ } else {
+ EXTI_FTSR &= ~(1 << line);
+ }
+
+ // Configure the NVIC
+ NVIC_SetPriority(IRQn_NONNEG(nvic_irq_channel[line]), IRQ_PRI_EXTINT);
+ HAL_NVIC_EnableIRQ(nvic_irq_channel[line]);
+
+ // Enable the interrupt
+ extint_enable(line);
+ }
+}
+
void extint_enable(uint line) {
if (line >= EXTI_NUM_VECTORS) {
return;
@@ -552,6 +599,9 @@ const mp_obj_type_t extint_type = {
void extint_init0(void) {
for (int i = 0; i < PYB_EXTI_NUM_VECTORS; i++) {
+ if (MP_STATE_PORT(pyb_extint_callback)[i] == MP_OBJ_SENTINEL) {
+ continue;
+ }
MP_STATE_PORT(pyb_extint_callback)[i] = mp_const_none;
pyb_extint_mode[i] = EXTI_Mode_Interrupt;
}