From 3834bd404c73fe6c61a2d3d9857b234adf1dc565 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Mon, 27 Apr 2020 20:18:12 +0200 Subject: [PATCH] Fix button module and adjust long keypress time to a sane value --- stm-firmware/button.c | 9 +++++++-- stm-firmware/include/reflow-controller/button.h | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/stm-firmware/button.c b/stm-firmware/button.c index 6f0db95..76dc782 100644 --- a/stm-firmware/button.c +++ b/stm-firmware/button.c @@ -32,6 +32,7 @@ static volatile enum button_state int_state; void button_init() { rcc_manager_enable_clock(&RCC->AHB1ENR, BITMASK_TO_BITNO(BUTTON_RCC_MASK)); + rcc_manager_enable_clock(&RCC->APB2ENR, BITMASK_TO_BITNO(RCC_APB2ENR_SYSCFGEN)); BUTTON_PORT->MODER &= MODER_DELETE(BUTTON_PIN); BUTTON_PORT->PUPDR &= PUPDR_DELETE(BUTTON_PIN); BUTTON_PORT->PUPDR |= PULLUP(BUTTON_PIN); @@ -41,7 +42,7 @@ void button_init() SYSCFG->EXTICR[1] |= 0x3; EXTI->IMR |= (1U<<4); - EXTI->FTSR |= (1U<<4); + EXTI->RTSR |= (1U<<4); EXTI->FTSR |= (1U<<4); NVIC_EnableIRQ(EXTI4_IRQn); } @@ -49,10 +50,12 @@ void button_init() enum button_state button_read_event() { uint64_t time_delta; + enum button_state temp_state; if (BUTTON_PORT->IDR & (1U<= BUTTON_LONG_ON_TIME_MS) @@ -69,6 +72,8 @@ void button_deinit() BUTTON_PORT->MODER &= MODER_DELETE(BUTTON_PIN); BUTTON_PORT->PUPDR &= PUPDR_DELETE(BUTTON_PIN); rcc_manager_disable_clock(&RCC->AHB1ENR, BITMASK_TO_BITNO(BUTTON_RCC_MASK)); + EXTI->IMR &= ~(1U<<4); + rcc_manager_disable_clock(&RCC->APB2ENR, BITMASK_TO_BITNO(RCC_APB2ENR_SYSCFGEN)); } void EXTI4_IRQHandler(void) diff --git a/stm-firmware/include/reflow-controller/button.h b/stm-firmware/include/reflow-controller/button.h index 46d648d..ac44344 100644 --- a/stm-firmware/include/reflow-controller/button.h +++ b/stm-firmware/include/reflow-controller/button.h @@ -25,8 +25,8 @@ #define BUTTON_RCC_MASK RCC_AHB1ENR_GPIODEN #define BUTTON_PIN 4 -#define BUTTON_SHORT_ON_TIME_MS 50 -#define BUTTON_LONG_ON_TIME_MS 800 +#define BUTTON_SHORT_ON_TIME_MS 50UL +#define BUTTON_LONG_ON_TIME_MS 400UL enum button_state {BUTTON_IDLE = 0, BUTTON_SHORT_RELEASED, BUTTON_LONG_RELEASED, BUTTON_SHORT, BUTTON_LONG};