diff --git a/ChangeLog b/ChangeLog index c6763fd..5db7cca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2018-09-27 NIIBE Yutaka + + * contrib/ackbtn-stm32f103.c: New. + * rules.mk [USE_ACKBTN] (CSRC): Add ack-button support. + 2018-09-26 NIIBE Yutaka Fix for chopstx_intr_done. No spurious interrupts. diff --git a/NEWS b/NEWS index 7206a05..89245a9 100644 --- a/NEWS +++ b/NEWS @@ -6,12 +6,17 @@ NEWS - Noteworthy changes Released 2018-09-XX ** Function chopstx_intr_wait is not deprecated, now. -Once, it was said that it's deprecated, but it's active again. +Once, it was said that it's deprecated, but it's active again +to match the new function of chopstx_intr_done. ** API change: chopstx_poll, chopstx_intr_wait, chopstx_intr_done To avoid spurious interrupt, we introduce new function chopstx_intr_done, which should be called after interrupt handling. +** New driver: Acknowledge button for FST-01SZ +Use case is waiting user's acknowledge. We use EXTI interrupt feature +of STM32. + * Major changes in Chopstx 1.9 diff --git a/board/board-fst-01.h b/board/board-fst-01.h index 209d3aa..3b89c66 100644 --- a/board/board-fst-01.h +++ b/board/board-fst-01.h @@ -71,6 +71,7 @@ * Those will be removed soon, once such an driver will be improved * in new style. */ +#if defined(PINPAD_CIR_SUPPORT) /* For pin-cir settings of Gnuk */ #define TIMx TIM2 #define INTR_REQ_TIM TIM2_IRQ @@ -83,3 +84,4 @@ #define ENABLE_RCC_APB1 #define RCC_APBnENR_TIMxEN RCC_APB1ENR_TIM2EN #define RCC_APBnRSTR_TIMxRST RCC_APB1RSTR_TIM2RST +#endif diff --git a/board/board-fst-01g.h b/board/board-fst-01g.h index d569840..63a8cc7 100644 --- a/board/board-fst-01g.h +++ b/board/board-fst-01g.h @@ -71,7 +71,7 @@ * Those will be removed soon, once such an driver will be improved * in new style. */ -/* For pin-cir settings of Gnuk */ +#if defined(PINPAD_CIR_SUPPORT) #define TIMx TIM2 #define INTR_REQ_TIM TIM2_IRQ #define AFIO_EXTICR_INDEX 0 @@ -83,3 +83,4 @@ #define ENABLE_RCC_APB1 #define RCC_APBnENR_TIMxEN RCC_APB1ENR_TIM2EN #define RCC_APBnRSTR_TIMxRST RCC_APB1RSTR_TIM2RST +#endif diff --git a/board/board-fst-01sz.h b/board/board-fst-01sz.h index 78420ed..949ceec 100644 --- a/board/board-fst-01sz.h +++ b/board/board-fst-01sz.h @@ -36,12 +36,8 @@ #define RCC_ENR_IOP_EN RCC_APB2ENR_IOPAEN #define RCC_RSTR_IOP_RST RCC_APB2RSTR_IOPARST -#if 0 /* For PA, AFIO setting is not needed. */ -#define AFIO_EXTICR_INDEX 0 -#define AFIO_EXTICR1_EXTIx_Py AFIO_EXTICR1_EXTI3_PA -#endif - -#define EXTI_PR EXTI_PR_PR3 -#define EXTI_IMR EXTI_IMR_MR3 -#define EXTI_RTSR_TR EXTI_RTSR_TR3 -#define INTR_REQ_EXTI EXTI3_IRQ +/* + * Board specific information other than clock and GPIO initial + * setting should not be in board-*.h, but each driver should include + * such specific information by itself. + */ diff --git a/board/board-stm8s-discovery.h b/board/board-stm8s-discovery.h index 1247b11..3192ad7 100644 --- a/board/board-stm8s-discovery.h +++ b/board/board-stm8s-discovery.h @@ -44,7 +44,7 @@ #define VAL_GPIO_OTHER_CRH 0x88888888 /* PB15...PB8 */ -/* For pin-cir settings of Gnuk */ +#if defined(PINPAD_CIR_SUPPORT) #define TIMx TIM3 #define INTR_REQ_TIM TIM3_IRQ #define AFIO_EXTICR_INDEX 1 @@ -58,3 +58,4 @@ #define RCC_APBnRSTR_TIMxRST RCC_APB1RSTR_TIM3RST #define AFIO_MAPR_SOMETHING AFIO_MAPR_TIM3_REMAP_PARTIALREMAP /* Remap (PB4, PB5) -> (TIM3_CH1, TIM3_CH2) */ +#endif diff --git a/contrib/ackbtn-stm32f103.c b/contrib/ackbtn-stm32f103.c new file mode 100644 index 0000000..5ec7441 --- /dev/null +++ b/contrib/ackbtn-stm32f103.c @@ -0,0 +1,87 @@ +/* + * ackbtn-stm32f103.c - Acknowledge button support for STM32F103 + * + * Copyright (C) 2018 g10 Code GmbH + * Author: NIIBE Yutaka + * + * This file is a part of Chopstx, a thread library for embedded. + * + * Chopstx is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Chopstx is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * As additional permission under GNU GPL version 3 section 7, you may + * distribute non-source form of the Program without the copy of the + * GNU GPL normally required by section 4, provided you inform the + * receipents of GNU GPL by a written offer. + * + */ + +#include +#include +#include + +#include "board.h" +#include "mcu/stm32f103.h" + +static uint32_t pin_config; + +void +ackbtn_init (chopstx_intr_t *intr) +{ + uint8_t irq_num; + uint32_t afio_exticr_index; + uint32_t afio_exticr_extiX_pY; + int rising_edge; + + switch (SYS_BOARD_ID) + { + case BOARD_ID_FST_01SZ: + default: + /* PA3 is connected to a hall sensor DRV5032FA */ + afio_exticr_index = 0; + afio_exticr_extiX_pY = AFIO_EXTICR1_EXTI3_PA; + irq_num = EXTI3_IRQ; + pin_config = 0x0008; /* EXTI_PR_PR3 == EXTI_IMR_MR3 == EXTI_RTSR_TR3 */ + rising_edge = 1; + break; + } + + chopstx_claim_irq (intr, irq_num); + + /* Configure EXTI line */ + if (afio_exticr_extiX_pY) + AFIO->EXTICR[afio_exticr_index] |= afio_exticr_extiX_pY; + + /* Interrupt is masked, now */ + EXTI->IMR &= ~pin_config; + + /* Configure which edge is detected */ + if (rising_edge) + EXTI->RTSR |= pin_config; + else + EXTI->FTSR |= pin_config; +} + +void +ackbtn_enable (void) +{ + EXTI->PR |= pin_config; /* Clear pending interrupt */ + EXTI->IMR |= pin_config; /* Enable interrupt clearing the mask */ +} + +void +ackbtn_disable (void) +{ + EXTI->IMR &= ~pin_config; /* Disable interrupt having the mask */ + EXTI->PR |= pin_config; /* Clear pending interrupt */ +} diff --git a/contrib/ackbtn-stm32f103.h b/contrib/ackbtn-stm32f103.h new file mode 100644 index 0000000..da0e29c --- /dev/null +++ b/contrib/ackbtn-stm32f103.h @@ -0,0 +1,3 @@ +void ackbtn_init (chopstx_intr_t *intr); +void ackbtn_enable (void); +void ackbtn_disable (void); diff --git a/mcu/clk_gpio_init-stm32.c b/mcu/clk_gpio_init-stm32.c index 5ec1091..9f1bab0 100644 --- a/mcu/clk_gpio_init-stm32.c +++ b/mcu/clk_gpio_init-stm32.c @@ -155,7 +155,7 @@ gpio_init (void) AFIO->MAPR |= AFIO_MAPR_SOMETHING; #endif - /* LED is mandatory. If it's on an independent port, we configure it. */ + /* LED is mandatory. We configure it always. */ GPIO_LED->ODR = VAL_GPIO_LED_ODR; GPIO_LED->CRH = VAL_GPIO_LED_CRH; GPIO_LED->CRL = VAL_GPIO_LED_CRL; diff --git a/rules.mk b/rules.mk index 110079e..d7197c2 100644 --- a/rules.mk +++ b/rules.mk @@ -28,6 +28,9 @@ endif ifneq ($(USE_USART),) CSRC += $(CHOPSTX)/contrib/usart-$(CHIP).c endif +ifneq ($(USE_ACKBTN),) +CSRC += $(CHOPSTX)/contrib/ackbtn-$(CHIP).c +endif INCDIR += $(CHOPSTX)