Fix button module and adjust long keypress time to a sane value
This commit is contained in:
parent
eb3b0eb459
commit
3834bd404c
@ -32,6 +32,7 @@ static volatile enum button_state int_state;
|
|||||||
void button_init()
|
void button_init()
|
||||||
{
|
{
|
||||||
rcc_manager_enable_clock(&RCC->AHB1ENR, BITMASK_TO_BITNO(BUTTON_RCC_MASK));
|
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->MODER &= MODER_DELETE(BUTTON_PIN);
|
||||||
BUTTON_PORT->PUPDR &= PUPDR_DELETE(BUTTON_PIN);
|
BUTTON_PORT->PUPDR &= PUPDR_DELETE(BUTTON_PIN);
|
||||||
BUTTON_PORT->PUPDR |= PULLUP(BUTTON_PIN);
|
BUTTON_PORT->PUPDR |= PULLUP(BUTTON_PIN);
|
||||||
@ -41,7 +42,7 @@ void button_init()
|
|||||||
|
|
||||||
SYSCFG->EXTICR[1] |= 0x3;
|
SYSCFG->EXTICR[1] |= 0x3;
|
||||||
EXTI->IMR |= (1U<<4);
|
EXTI->IMR |= (1U<<4);
|
||||||
EXTI->FTSR |= (1U<<4);
|
EXTI->RTSR |= (1U<<4);
|
||||||
EXTI->FTSR |= (1U<<4);
|
EXTI->FTSR |= (1U<<4);
|
||||||
NVIC_EnableIRQ(EXTI4_IRQn);
|
NVIC_EnableIRQ(EXTI4_IRQn);
|
||||||
}
|
}
|
||||||
@ -49,10 +50,12 @@ void button_init()
|
|||||||
enum button_state button_read_event()
|
enum button_state button_read_event()
|
||||||
{
|
{
|
||||||
uint64_t time_delta;
|
uint64_t time_delta;
|
||||||
|
enum button_state temp_state;
|
||||||
|
|
||||||
if (BUTTON_PORT->IDR & (1U<<BUTTON_PIN)) {
|
if (BUTTON_PORT->IDR & (1U<<BUTTON_PIN)) {
|
||||||
return int_state;
|
temp_state = int_state;
|
||||||
int_state = BUTTON_IDLE;
|
int_state = BUTTON_IDLE;
|
||||||
|
return temp_state;
|
||||||
} else {
|
} else {
|
||||||
time_delta = systick_get_global_tick() - to_active_timestamp;
|
time_delta = systick_get_global_tick() - to_active_timestamp;
|
||||||
if (time_delta >= BUTTON_LONG_ON_TIME_MS)
|
if (time_delta >= BUTTON_LONG_ON_TIME_MS)
|
||||||
@ -69,6 +72,8 @@ void button_deinit()
|
|||||||
BUTTON_PORT->MODER &= MODER_DELETE(BUTTON_PIN);
|
BUTTON_PORT->MODER &= MODER_DELETE(BUTTON_PIN);
|
||||||
BUTTON_PORT->PUPDR &= PUPDR_DELETE(BUTTON_PIN);
|
BUTTON_PORT->PUPDR &= PUPDR_DELETE(BUTTON_PIN);
|
||||||
rcc_manager_disable_clock(&RCC->AHB1ENR, BITMASK_TO_BITNO(BUTTON_RCC_MASK));
|
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)
|
void EXTI4_IRQHandler(void)
|
||||||
|
@ -25,8 +25,8 @@
|
|||||||
#define BUTTON_RCC_MASK RCC_AHB1ENR_GPIODEN
|
#define BUTTON_RCC_MASK RCC_AHB1ENR_GPIODEN
|
||||||
#define BUTTON_PIN 4
|
#define BUTTON_PIN 4
|
||||||
|
|
||||||
#define BUTTON_SHORT_ON_TIME_MS 50
|
#define BUTTON_SHORT_ON_TIME_MS 50UL
|
||||||
#define BUTTON_LONG_ON_TIME_MS 800
|
#define BUTTON_LONG_ON_TIME_MS 400UL
|
||||||
|
|
||||||
enum button_state {BUTTON_IDLE = 0, BUTTON_SHORT_RELEASED, BUTTON_LONG_RELEASED, BUTTON_SHORT, BUTTON_LONG};
|
enum button_state {BUTTON_IDLE = 0, BUTTON_SHORT_RELEASED, BUTTON_LONG_RELEASED, BUTTON_SHORT, BUTTON_LONG};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user