From 9306306d7befda069940b6f10cedd8dfcc0c3302 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E8=83=A1=E4=BC=A0=E5=86=9B?= <1224667075@qq.com> Date: Thu, 2 Jan 2025 07:43:45 +0000 Subject: [PATCH] Merge #1586 into sdk602patch0911 from refs/changes/1586/head MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 修改button.c代码,合并更改 * refs/changes/1586/head: (2 commits squashed) - 修改button.c代码,合并更改 - 获取投票结果接口修改 Signed-off-by: aliyun8003852482 <1224667075@qq.com> Reviewed-by: Caisking <3449750381@qq.com> Reviewed-by: 罗正 <1732036298@qq.com> Reviewed-by: aliyun8003852482 <1224667075@qq.com> Reviewed-by: snickersun@163.com Reviewed-by: aliyun6865282430 <1624952103@qq.com> Merged-by: Caisking <3449750381@qq.com> CR-link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/1586 --- .../drivers/drivers/driver/button/button.c | 10 ++++++ code/sdk/drivers/peripheral/button/button.c | 35 ++++++++++++------- code/sdk/drivers/peripheral/button/button.h | 1 + .../drivers/peripheral/utils/custom_utils.c | 3 +- 4 files changed, 35 insertions(+), 14 deletions(-) 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的检查时间 diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index a50eb475a..e74c41c11 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -229,6 +229,7 @@ void uapi_poweroff_device(void) //关机保存 start_report_log(); + osDelay(50); //同步nand文件系统,重启mount速度快 reset_deal_with_fs(); @@ -1354,7 +1355,7 @@ errcode_t get_vote_status(char* str, size_t str_size) { str[0] = '\0'; for (i = 0; i < PM_ID_MAX; i++) { - if (pm_veto_ptr->veto_counts.sub_counts[i] == 1) { + if (pm_veto_ptr->veto_counts.sub_counts[i]) { // 拼接当前 pm ID 并添加换行符 snprintf(str + strlen(str), str_size - strlen(str), "%s%s\n", (flag ? " " : ""), get_pm_id_name(i)); flag = 1; -- 2.17.1