From: hcj <1224667075@qq.com> Date: Tue, 31 Dec 2024 10:02:08 +0000 (+0800) Subject: 修改button.c代码,合并更改 X-Git-Tag: v1.3.113-repair_tp~52 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=e17427a549129b277ed68c186430cfda3bc18fe5;p=mirrors%2FFD230.git 修改button.c代码,合并更改 --- diff --git a/code/sdk/drivers/drivers/driver/button/button.c b/code/sdk/drivers/drivers/driver/button/button.c index 2a9ab717c..7c4182cb1 100644 --- a/code/sdk/drivers/drivers/driver/button/button.c +++ b/code/sdk/drivers/drivers/driver/button/button.c @@ -57,6 +57,7 @@ button_info_t g_button_info = {0}; bool g_timer_is_running = false; bool g_gpio_timer_is_running = false; msg_send_callback_t g_msg_send_cb = NULL; +pin_t g_gpio_key_record = 0; static const char* g_state_str[PRESSED_MAX] = { "BUTTON_PRESSED", @@ -170,6 +171,8 @@ static void button_gpio_callback(pin_t pin, uintptr_t param) } uapi_gpio_clear_interrupt(pin); + g_gpio_key_record = pin; + uapi_gpio_disable_interrupt(g_gpio_key_record); button_press_state_t press_state = button_get_press_state(pin); unsigned int irq_sts = osal_irq_lock(); if (press_state == PRESSED) { @@ -201,6 +204,12 @@ static void button_debounced_handler(void) button_group_set_bit(&pressed_group, bit); button_group_clear_bit(&g_button_debounced.debounced, bit); } + + if ((button_get_press_state(pin) == RELEASED) && + (time - g_button_debounced.debounced_time >= INTERFERENCE_INTERVAL)) { + /* Interference */ + button_group_clear_bit(&g_button_debounced.debounced, bit); + } } } @@ -229,6 +238,7 @@ static void button_debounced_timer_callback(uint32_t data) } else { button_peripheral_api *button_api = button_port_get_api(); button_api->button_remove_veto(1); + uapi_gpio_enable_interrupt(g_gpio_key_record); } } diff --git a/code/sdk/drivers/peripheral/button/button.c b/code/sdk/drivers/peripheral/button/button.c index 88e8a4f8b..e8247c3f9 100644 --- a/code/sdk/drivers/peripheral/button/button.c +++ b/code/sdk/drivers/peripheral/button/button.c @@ -55,8 +55,9 @@ timer_handle_t g_button_timer = {0}; timer_handle_t g_gpio_button_timer = {0}; button_info_t g_button_info = {0}; bool g_timer_is_running = false; -bool g_button_timer_is_running = false; +bool g_gpio_timer_is_running = false; msg_send_callback_t g_msg_send_cb = NULL; +pin_t g_gpio_key_record = 0; static const char* g_state_str[PRESSED_MAX] = { "BUTTON_PRESSED", @@ -108,28 +109,28 @@ static void button_send_msg(uint8_t pin_group, button_press_state_t state) static void button_timer_start(void) { bool start = false; - if (!g_timer_is_running) { - g_timer_is_running = true; + if (!g_gpio_timer_is_running) { + g_gpio_timer_is_running = true; start = true; } if (start) { - uapi_rtc_stop(g_button_timer); - uapi_rtc_start(g_button_timer, BUTTON_TIMER_INTERVAL, button_debounced_timer_callback, 0); + uapi_rtc_stop(g_gpio_button_timer); + uapi_rtc_start(g_gpio_button_timer, BUTTON_TIMER_INTERVAL, button_debounced_timer_callback, 0); } } static void button_timer_start_check_released(void) { bool start = false; - if (!g_button_timer_is_running) { - g_button_timer_is_running = true; + if (!g_timer_is_running) { + g_timer_is_running = true; start = true; } if (start) { - uapi_rtc_stop(g_gpio_button_timer); - uapi_rtc_start(g_gpio_button_timer, BUTTON_CHECK_RELEADSED, button_check_released_timer_callback, 0); + uapi_rtc_stop(g_button_timer); + uapi_rtc_start(g_button_timer, BUTTON_CHECK_RELEADSED, button_check_released_timer_callback, 0); } } @@ -154,8 +155,7 @@ static void button_irq_callback(pin_t pin) button_api->button_clear_interrupt(pin); button_press_state_t press_state = button_get_press_state(pin); button_send_msg(BUTTON_PWREN_ID, press_state); - printf("button_irq_callback pin\r\n"); - button_api->button_add_veto(0); + button_api->button_add_veto(0); button_timer_start_check_released(); } @@ -171,6 +171,8 @@ static void button_gpio_callback(pin_t pin, uintptr_t param) } uapi_gpio_clear_interrupt(pin); +g_gpio_key_record = pin; + uapi_gpio_disable_interrupt(g_gpio_key_record); button_press_state_t press_state = button_get_press_state(pin); unsigned int irq_sts = osal_irq_lock(); if (press_state == PRESSED) { @@ -202,6 +204,12 @@ static void button_debounced_handler(void) button_group_set_bit(&pressed_group, bit); button_group_clear_bit(&g_button_debounced.debounced, bit); } + + if ((button_get_press_state(pin) == RELEASED) && + (time - g_button_debounced.debounced_time >= INTERFERENCE_INTERVAL)) { + /* Interference */ + button_group_clear_bit(&g_button_debounced.debounced, bit); + } } } @@ -216,7 +224,7 @@ static void button_debounced_handler(void) static void button_debounced_timer_callback(uint32_t data) { unused(data); - g_timer_is_running = false; + g_gpio_timer_is_running = false; button_debounced_handler(); @@ -230,6 +238,7 @@ static void button_debounced_timer_callback(uint32_t data) } else { button_peripheral_api *button_api = button_port_get_api(); button_api->button_remove_veto(1); +uapi_gpio_enable_interrupt(g_gpio_key_record); } } @@ -237,7 +246,7 @@ static void button_check_released_timer_callback(uint32_t data) { unused(data); - g_button_timer_is_running = false; + g_timer_is_running = false; button_peripheral_api *button_api = button_port_get_api(); button_press_state_t press_state; diff --git a/code/sdk/drivers/peripheral/button/button.h b/code/sdk/drivers/peripheral/button/button.h index 4e644042f..c9036efb3 100644 --- a/code/sdk/drivers/peripheral/button/button.h +++ b/code/sdk/drivers/peripheral/button/button.h @@ -28,6 +28,7 @@ extern "C" { #define BUTTON_PIN_MAP_MAX 8 #define BUTTON_CLICK_INTERVAL 10 #define DEBOUNCED_INTERVAL (BUTTON_CLICK_INTERVAL * 2) +#define INTERFERENCE_INTERVAL (BUTTON_CLICK_INTERVAL * 10) #define BUTTON_TIMER_INTERVAL (BUTTON_CLICK_INTERVAL) #define BUTTON_CHECK_RELEADSED 20 // pwren的检查时间