Issue #17: Add override function for button

This commit is contained in:
Mario Hüttel 2020-08-30 18:20:58 +02:00
parent 80edd09528
commit 914abd8562
2 changed files with 18 additions and 0 deletions

View File

@ -29,6 +29,7 @@
static volatile uint64_t IN_SECTION(.ccm.bss) to_active_timestamp; static volatile uint64_t IN_SECTION(.ccm.bss) to_active_timestamp;
static volatile enum button_state IN_SECTION(.ccm.bss) int_state; static volatile enum button_state IN_SECTION(.ccm.bss) int_state;
static volatile enum button_state IN_SECTION(.ccm.bss) override_state;
void button_init() void button_init()
{ {
@ -40,6 +41,7 @@ void button_init()
to_active_timestamp = 0ULL; to_active_timestamp = 0ULL;
int_state = BUTTON_IDLE; int_state = BUTTON_IDLE;
override_state = BUTTON_IDLE;
SYSCFG->EXTICR[1] |= 0x3; SYSCFG->EXTICR[1] |= 0x3;
EXTI->IMR |= (1U<<4); EXTI->IMR |= (1U<<4);
@ -53,6 +55,12 @@ enum button_state button_read_event()
uint64_t time_delta; uint64_t time_delta;
enum button_state temp_state; enum button_state temp_state;
if (override_state != BUTTON_IDLE) {
temp_state = override_state;
override_state = BUTTON_IDLE;
return temp_state;
}
if (BUTTON_PORT->IDR & (1U<<BUTTON_PIN)) { if (BUTTON_PORT->IDR & (1U<<BUTTON_PIN)) {
temp_state = int_state; temp_state = int_state;
int_state = BUTTON_IDLE; int_state = BUTTON_IDLE;
@ -96,3 +104,8 @@ void EXTI4_IRQHandler(void)
to_active_timestamp = systick_get_global_tick(); to_active_timestamp = systick_get_global_tick();
} }
} }
void button_override_event(enum button_state state)
{
override_state = state;
}

View File

@ -72,5 +72,10 @@ enum button_state button_read_event();
*/ */
void button_deinit(); void button_deinit();
/**
* @brief This function overrides the button event.
* @param state State to set
*/
void button_override_event(enum button_state state);
#endif /* __BUTTON_H__ */ #endif /* __BUTTON_H__ */