From fd98c5e1624c8fbe8b3ea8fdf85aca6b1dfb096d Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Mon, 12 Nov 2018 11:49:40 +0900 Subject: [PATCH] ackbtn driver: Add possible FST-01 and FST-01G support. --- ChangeLog | 6 ++++++ contrib/ackbtn-stm32f103.c | 21 ++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index f16a4ac..9979c14 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2018-11-12 NIIBE Yutaka + + * contrib/ackbtn-stm32f103.c (ackbtn_init): Support FST-01 and + FST-01G, using PA2. + (ackbtn_disable): Fix to correctly clear pending interrupt. + 2018-11-09 NIIBE Yutaka * eventflag.c (eventflag_set_mask): New. diff --git a/contrib/ackbtn-stm32f103.c b/contrib/ackbtn-stm32f103.c index dc28bb6..d06a5e2 100644 --- a/contrib/ackbtn-stm32f103.c +++ b/contrib/ackbtn-stm32f103.c @@ -34,6 +34,14 @@ #include "board.h" #include "sys.h" +/* + * All EXTI registers (EXTI_IMR, EXTI_EMR, EXTI_PR , EXTI_RTSR, and + * EXTI_FTSR) have same structure, where each bit of X is used for + * line X, from 0 up to 19. + * + * We use 31-bit of PIN_CONFIG to represent if it's for rising edge or + * falling edge. + */ static uint32_t pin_config; #define PINCFG_EDGE 0x80000000 #define PINCFG_EDGE_RISING PINCFG_EDGE @@ -47,6 +55,16 @@ ackbtn_init (chopstx_intr_t *intr) switch (SYS_BOARD_ID) { + case BOARD_ID_FST_01: + case BOARD_ID_FST_01G: + /* PA2 can be connected to a hall sensor or a switch */ + afio_exticr_index = 0; + afio_exticr_extiX_pY = AFIO_EXTICR1_EXTI2_PA; + irq_num = EXTI2_IRQ; + pin_config = 0x0004; /* EXTI_PR_PR2 == EXTI_IMR_MR2 == EXTI_RTSR_TR2 */ + pin_config |= PINCFG_EDGE_RISING; + break; + case BOARD_ID_FST_01SZ: default: /* PA3 is connected to a hall sensor DRV5032FA */ @@ -88,7 +106,8 @@ ackbtn_disable (void) { /* Disable interrupt having the mask */ EXTI->IMR &= ~(pin_config & ~PINCFG_EDGE); - /* Clear pending interrupt */ + /* Clear pending interrupt */ + EXTI->PR |= (pin_config & ~PINCFG_EDGE); /* Disable edge detection */ EXTI->RTSR &= ~(pin_config & ~PINCFG_EDGE);