|
|
|
@ -10,10 +10,12 @@
|
|
|
|
//button handle list head.
|
|
|
|
//button handle list head.
|
|
|
|
static struct Button* head_handle = NULL;
|
|
|
|
static struct Button* head_handle = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void button_handler(struct Button* handle);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @brief Initializes the button struct handle.
|
|
|
|
* @brief Initializes the button struct handle.
|
|
|
|
* @param handle: the button handle strcut.
|
|
|
|
* @param handle: the button handle struct.
|
|
|
|
* @param pin_level: read the HAL GPIO of the connet button level.
|
|
|
|
* @param pin_level: read the HAL GPIO of the connected button level.
|
|
|
|
* @param active_level: pressed GPIO level.
|
|
|
|
* @param active_level: pressed GPIO level.
|
|
|
|
* @param button_id: the button id.
|
|
|
|
* @param button_id: the button id.
|
|
|
|
* @retval None
|
|
|
|
* @retval None
|
|
|
|
@ -30,7 +32,7 @@ void button_init(struct Button* handle, uint8_t(*pin_level)(uint8_t), uint8_t ac
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @brief Attach the button event callback function.
|
|
|
|
* @brief Attach the button event callback function.
|
|
|
|
* @param handle: the button handle strcut.
|
|
|
|
* @param handle: the button handle struct.
|
|
|
|
* @param event: trigger event type.
|
|
|
|
* @param event: trigger event type.
|
|
|
|
* @param cb: callback function.
|
|
|
|
* @param cb: callback function.
|
|
|
|
* @retval None
|
|
|
|
* @retval None
|
|
|
|
@ -42,7 +44,7 @@ void button_attach(struct Button* handle, PressEvent event, BtnCallback cb)
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @brief Inquire the button event happen.
|
|
|
|
* @brief Inquire the button event happen.
|
|
|
|
* @param handle: the button handle strcut.
|
|
|
|
* @param handle: the button handle struct.
|
|
|
|
* @retval button event.
|
|
|
|
* @retval button event.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
PressEvent get_button_event(struct Button* handle)
|
|
|
|
PressEvent get_button_event(struct Button* handle)
|
|
|
|
@ -52,10 +54,10 @@ PressEvent get_button_event(struct Button* handle)
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @brief Button driver core function, driver state machine.
|
|
|
|
* @brief Button driver core function, driver state machine.
|
|
|
|
* @param handle: the button handle strcut.
|
|
|
|
* @param handle: the button handle struct.
|
|
|
|
* @retval None
|
|
|
|
* @retval None
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
void button_handler(struct Button* handle)
|
|
|
|
static void button_handler(struct Button* handle)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint8_t read_gpio_level = handle->hal_button_Level(handle->button_id);
|
|
|
|
uint8_t read_gpio_level = handle->hal_button_Level(handle->button_id);
|
|
|
|
|
|
|
|
|
|
|
|
@ -69,7 +71,7 @@ void button_handler(struct Button* handle)
|
|
|
|
handle->button_level = read_gpio_level;
|
|
|
|
handle->button_level = read_gpio_level;
|
|
|
|
handle->debounce_cnt = 0;
|
|
|
|
handle->debounce_cnt = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else { //leved not change ,counter reset.
|
|
|
|
} else { //level not change ,counter reset.
|
|
|
|
handle->debounce_cnt = 0;
|
|
|
|
handle->debounce_cnt = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -93,7 +95,6 @@ void button_handler(struct Button* handle)
|
|
|
|
EVENT_CB(PRESS_UP);
|
|
|
|
EVENT_CB(PRESS_UP);
|
|
|
|
handle->ticks = 0;
|
|
|
|
handle->ticks = 0;
|
|
|
|
handle->state = 2;
|
|
|
|
handle->state = 2;
|
|
|
|
|
|
|
|
|
|
|
|
} else if(handle->ticks > LONG_TICKS) {
|
|
|
|
} else if(handle->ticks > LONG_TICKS) {
|
|
|
|
handle->event = (uint8_t)LONG_PRESS_START;
|
|
|
|
handle->event = (uint8_t)LONG_PRESS_START;
|
|
|
|
EVENT_CB(LONG_PRESS_START);
|
|
|
|
EVENT_CB(LONG_PRESS_START);
|
|
|
|
@ -131,7 +132,7 @@ void button_handler(struct Button* handle)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
handle->state = 0;
|
|
|
|
handle->state = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else if(handle->ticks > SHORT_TICKS){ // long press up
|
|
|
|
} else if(handle->ticks > SHORT_TICKS) { // long press up
|
|
|
|
handle->state = 0;
|
|
|
|
handle->state = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
@ -141,22 +142,21 @@ void button_handler(struct Button* handle)
|
|
|
|
//continue hold trigger
|
|
|
|
//continue hold trigger
|
|
|
|
handle->event = (uint8_t)LONG_PRESS_HOLD;
|
|
|
|
handle->event = (uint8_t)LONG_PRESS_HOLD;
|
|
|
|
EVENT_CB(LONG_PRESS_HOLD);
|
|
|
|
EVENT_CB(LONG_PRESS_HOLD);
|
|
|
|
|
|
|
|
|
|
|
|
} else { //releasd
|
|
|
|
} else { //releasd
|
|
|
|
handle->event = (uint8_t)PRESS_UP;
|
|
|
|
handle->event = (uint8_t)PRESS_UP;
|
|
|
|
EVENT_CB(PRESS_UP);
|
|
|
|
EVENT_CB(PRESS_UP);
|
|
|
|
handle->state = 0; //reset
|
|
|
|
handle->state = 0; //reset
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
handle->state = 0; //reset
|
|
|
|
handle->state = 0; //reset
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @brief Start the button work, add the handle into work list.
|
|
|
|
* @brief Start the button work, add the handle into work list.
|
|
|
|
* @param handle: target handle strcut.
|
|
|
|
* @param handle: target handle struct.
|
|
|
|
* @retval 0: succeed. -1: already exist.
|
|
|
|
* @retval 0: succeed. -1: already exist.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
int button_start(struct Button* handle)
|
|
|
|
int button_start(struct Button* handle)
|
|
|
|
@ -173,7 +173,7 @@ int button_start(struct Button* handle)
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @brief Stop the button work, remove the handle off work list.
|
|
|
|
* @brief Stop the button work, remove the handle off work list.
|
|
|
|
* @param handle: target handle strcut.
|
|
|
|
* @param handle: target handle struct.
|
|
|
|
* @retval None
|
|
|
|
* @retval None
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
void button_stop(struct Button* handle)
|
|
|
|
void button_stop(struct Button* handle)
|
|
|
|
@ -181,12 +181,13 @@ void button_stop(struct Button* handle)
|
|
|
|
struct Button** curr;
|
|
|
|
struct Button** curr;
|
|
|
|
for(curr = &head_handle; *curr; ) {
|
|
|
|
for(curr = &head_handle; *curr; ) {
|
|
|
|
struct Button* entry = *curr;
|
|
|
|
struct Button* entry = *curr;
|
|
|
|
if (entry == handle) {
|
|
|
|
if(entry == handle) {
|
|
|
|
*curr = entry->next;
|
|
|
|
*curr = entry->next;
|
|
|
|
// free(entry);
|
|
|
|
// free(entry);
|
|
|
|
return;//glacier add 2021-8-18
|
|
|
|
return;//glacier add 2021-8-18
|
|
|
|
} else
|
|
|
|
} else {
|
|
|
|
curr = &entry->next;
|
|
|
|
curr = &entry->next;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -195,7 +196,7 @@ void button_stop(struct Button* handle)
|
|
|
|
* @param None.
|
|
|
|
* @param None.
|
|
|
|
* @retval None
|
|
|
|
* @retval None
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
void button_ticks()
|
|
|
|
void button_ticks(void)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
struct Button* target;
|
|
|
|
struct Button* target;
|
|
|
|
for(target=head_handle; target; target=target->next) {
|
|
|
|
for(target=head_handle; target; target=target->next) {
|
|
|
|
|