From: SnickerSun Date: Mon, 9 Sep 2024 09:53:05 +0000 (+0800) Subject: 添加power+function按键同时按下开机,检测为SafeMode的函数。 X-Git-Tag: release_V1.2.70_20241020_135402~521^2 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=refs%2Fchanges%2F921%2Fhead;p=mirrors%2FFD230.git 添加power+function按键同时按下开机,检测为SafeMode的函数。 后面可以用这个函数切换SafeMode启动。 --- diff --git a/code/sdk/application/brandy/brandy_standard/board_init.c b/code/sdk/application/brandy/brandy_standard/board_init.c index 909649a35..08157ef72 100755 --- a/code/sdk/application/brandy/brandy_standard/board_init.c +++ b/code/sdk/application/brandy/brandy_standard/board_init.c @@ -18,6 +18,7 @@ #include "lcd_mipi.h" #include "lcd_bus.h" #include "button_porting.h" +#include "custom_runtime.h" static const lcd_bus_api g_display_api_qspi = { .bus_init = lcd_qspi_init, @@ -104,7 +105,18 @@ static startup_reason_t startup_reason = STARTUP_OTHER; #define PRESS_COUNT_LIMIT 5 static button_press_state_t porting_button_get_state(void) { - if ((readl(ANA_STS) & 0x3) == 0) { + if ((readl(ANA_STS) & 0x3) == 0) + { + return PRESSED; + } else { + return RELEASED; + } +} +#define FUNCTION_BUTTON_GPIO_PIN S_AGPIO_R10 +static button_press_state_t porting_function_button_get_state(void) +{ + if (uapi_gpio_get_val(FUNCTION_BUTTON_GPIO_PIN) == GPIO_LEVEL_LOW) + { return PRESSED; } else { return RELEASED; @@ -145,6 +157,16 @@ void check_pwrkey_3s(void) } // button_api->button_unregister_callback(PIN_NONE); } + +bool need_enter_safemode(void) +{ + if (PRESSED == porting_button_get_state() && PRESSED == porting_function_button_get_state()) + { + return true; + }else{ + return false; + } +} void board_init(uint32_t flash_id, uint32_t flash_unique_id) { /* flash init */ @@ -158,6 +180,15 @@ void board_init(uint32_t flash_id, uint32_t flash_unique_id) pio_func_init(); gpio_func_init(); check_pwrkey_3s(); + if (need_enter_safemode() == true) + { + //TODO 设置进入安全模式的全局变量 + PRINT("entering SafeMode\r\n"); + uapi_dev_runtime_set_safemode_flag(1); + }else{ + PRINT("entering NormalMode\r\n"); + } + #ifdef QSPI_DISPLAY PRINT("qspi**************\r\n"); lcd_bus_register_api(&g_display_api_qspi, BUS_DISPLAY_QSPI); diff --git a/code/sdk/drivers/peripheral/utils/custom_runtime.c b/code/sdk/drivers/peripheral/utils/custom_runtime.c index c52aae258..eaf42f095 100644 --- a/code/sdk/drivers/peripheral/utils/custom_runtime.c +++ b/code/sdk/drivers/peripheral/utils/custom_runtime.c @@ -61,6 +61,7 @@ typedef struct * */ typedef struct { + uint8_t enter_safemode; uint8_t in_silent_mode; uint8_t in_lowpower_mode; uint8_t stepcount; @@ -403,4 +404,16 @@ void uapi_dev_runtime_set_absolute_static_status(uint8_t status) uint8_t uapi_dev_runtime_get_absolute_static_status(void) { return g_runtime.absolute_static_state; +} + + +// 安全模式 +void uapi_dev_runtime_set_safemode_flag(uint8_t status) +{ + g_runtime.enter_safemode = status; +} +// 安全模式 +uint8_t uapi_dev_runtime_get_safemode_flag(void) +{ + return g_runtime.enter_safemode; } \ No newline at end of file diff --git a/code/sdk/drivers/peripheral/utils/custom_runtime.h b/code/sdk/drivers/peripheral/utils/custom_runtime.h index ea9f71a26..35416d87e 100644 --- a/code/sdk/drivers/peripheral/utils/custom_runtime.h +++ b/code/sdk/drivers/peripheral/utils/custom_runtime.h @@ -191,6 +191,12 @@ uint8_t uapi_sleep_mode_flag_get(void); void uapi_dev_runtime_set_absolute_static_status(uint8_t status); uint8_t uapi_dev_runtime_get_absolute_static_status(void); + +// 安全模式 +void uapi_dev_runtime_set_safemode_flag(uint8_t status); +// 安全模式 +uint8_t uapi_dev_runtime_get_safemode_flag(void); + #ifdef __cplusplus #if __cplusplus }