From db98f69ee84f860a39e303608a8fe128dbb4c453 Mon Sep 17 00:00:00 2001 From: 1624952103 Date: Thu, 26 Mar 2026 15:09:40 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0=E5=85=85=E7=94=B5=E7=94=B5?= =?utf8?q?=E6=B1=A0=E6=9B=B2=E7=BA=BF=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=85=85?= =?utf8?q?=E7=94=B5=E6=97=A5=E5=BF=97=E6=89=93=E5=8D=B0=EF=BC=8C=E5=A2=9E?= =?utf8?q?=E5=8A=A0=E4=BD=8E=E7=94=B5=E5=8E=8B=E5=85=85=E7=94=B5=E5=9B=BE?= =?utf8?q?=E7=89=87=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../brandy/brandy_standard/board_init.c | 114 +++++++++--------- .../brandy/brandy_standard/input_app.c | 2 +- .../wearable/ohos_startup/ohosfwk_startup.c | 95 +++++++++++++++ .../battery/service/battery_driver.cpp | 46 ++++++- 4 files changed, 194 insertions(+), 63 deletions(-) diff --git a/code/sdk/application/brandy/brandy_standard/board_init.c b/code/sdk/application/brandy/brandy_standard/board_init.c index 5efe6bbb3..ad961efe8 100644 --- a/code/sdk/application/brandy/brandy_standard/board_init.c +++ b/code/sdk/application/brandy/brandy_standard/board_init.c @@ -211,67 +211,67 @@ void check_pwrkey_3s(void) } } -static void check_power_on_voltage(void) -{ - #if defined(SUPPORT_BATTERY_SERVICE) - - extern uint8_t get_charge_stat(void); - extern bool batteryservice_get_voltage_by_channel(float *voltage, uint8_t channel); - #define ADC_CHANNEL_BAT_VOLTAGE 2 - - // if(!get_charge_stat()) - { - float batV = 0.0f; - disable_charge(); - uapi_tcxo_delay_ms(1000); - batteryservice_get_voltage_by_channel(&batV,ADC_CHANNEL_BAT_VOLTAGE); - enable_charge(); - PRINT("battery Voltage %.02f\n",batV); - - if(batV <= 3.3f) - { - if(get_charge_stat()) - { - for(int i = 0; i < 3;i++) - { +// static void check_power_on_voltage(void) +// { +// #if defined(SUPPORT_BATTERY_SERVICE) + +// extern uint8_t get_charge_stat(void); +// extern bool batteryservice_get_voltage_by_channel(float *voltage, uint8_t channel); +// #define ADC_CHANNEL_BAT_VOLTAGE 2 + +// // if(!get_charge_stat()) +// { +// float batV = 0.0f; +// disable_charge(); +// uapi_tcxo_delay_ms(1000); +// batteryservice_get_voltage_by_channel(&batV,ADC_CHANNEL_BAT_VOLTAGE); +// enable_charge(); +// PRINT("battery Voltage %.02f\n",batV); + +// if(batV <= 3.3f) +// { +// if(get_charge_stat()) +// { +// for(int i = 0; i < 3;i++) +// { - // while(batV <= 3.3) - // { - disable_charge(); - uapi_tcxo_delay_ms(1000); - batteryservice_get_voltage_by_channel(&batV,ADC_CHANNEL_BAT_VOLTAGE); - PRINT("battery Voltage %.02f\n",batV); - enable_charge(); - if(batV > 3.3f) - { - break; - } - uapi_tcxo_delay_ms(5000); - // } - } - if(batV <= 3.3f) - { - extern void mcu_reset(void); - mcu_reset(); - } - - } - else - { - PRINT("Warning: Battery voltage is too low. Device will power off"); - uapi_tcxo_delay_ms(10); - extern void mcu_poweroff(void); - mcu_poweroff(); - } - - } +// // while(batV <= 3.3) +// // { +// disable_charge(); +// uapi_tcxo_delay_ms(1000); +// batteryservice_get_voltage_by_channel(&batV,ADC_CHANNEL_BAT_VOLTAGE); +// PRINT("battery Voltage %.02f\n",batV); +// enable_charge(); +// if(batV > 3.3f) +// { +// break; +// } +// uapi_tcxo_delay_ms(5000); +// // } +// } +// if(batV <= 3.3f) +// { +// extern void mcu_reset(void); +// mcu_reset(); +// } + +// } +// else +// { +// PRINT("Warning: Battery voltage is too low. Device will power off"); +// uapi_tcxo_delay_ms(10); +// extern void mcu_poweroff(void); +// mcu_poweroff(); +// } + +// } - } +// } -#endif +// #endif -} +// } bool need_enter_safemode(void) { @@ -296,7 +296,7 @@ void board_init(uint32_t flash_id, uint32_t flash_unique_id) gpio_func_init(); check_pwrkey_3s(); - check_power_on_voltage(); + // check_power_on_voltage(); if (need_enter_safemode() == true) { diff --git a/code/sdk/application/brandy/brandy_standard/input_app.c b/code/sdk/application/brandy/brandy_standard/input_app.c index 8d184cab5..13a5d78c4 100644 --- a/code/sdk/application/brandy/brandy_standard/input_app.c +++ b/code/sdk/application/brandy/brandy_standard/input_app.c @@ -126,7 +126,7 @@ button_map_t g_brandy_button_pin_map[BUTTON_PIN_MAP_MAX] = { #ifdef BOARD_N9 { S_AGPIO_R3, BUTTON_1 }, #else - { S_AGPIO_R10, BUTTON_1 }, + { PIN_NONE, BUTTON_1 }, #endif #ifdef BOARD_LEINIAO { S_AGPIO_L12, BUTTON_2 }, diff --git a/code/sdk/application/wearable/ohos_startup/ohosfwk_startup.c b/code/sdk/application/wearable/ohos_startup/ohosfwk_startup.c index 5a70c16d6..4bb906c58 100644 --- a/code/sdk/application/wearable/ohos_startup/ohosfwk_startup.c +++ b/code/sdk/application/wearable/ohos_startup/ohosfwk_startup.c @@ -22,6 +22,10 @@ #include "soc_lcd_api.h" +#if defined(SUPPORT_BATTERY_SERVICE) +#include "battery_service.h" +#endif + // int32_t user_get_random_bytes(uint32_t size, uint8_t *randnum) // { // return uapi_drv_cipher_trng_get_random_bytes(randnum, size); @@ -42,6 +46,72 @@ // return 0; // } + +//true电压过低 false电压正常 +static bool check_power_on_voltage(void) +{ + #if defined(SUPPORT_BATTERY_SERVICE) + + extern uint8_t get_charge_stat(void); + extern bool batteryservice_get_voltage_by_channel(float *voltage, uint8_t channel); + #define ADC_CHANNEL_BAT_VOLTAGE 2 + + // if(!get_charge_stat()) + { + float batV = 0.0f; + disable_charge(); + uapi_tcxo_delay_ms(1000); + batteryservice_get_voltage_by_channel(&batV,ADC_CHANNEL_BAT_VOLTAGE); + enable_charge(); + + PRINT("battery Voltage %.02f\n",batV); + + return (batV <= 3.3f) ? true : false; + // if(batV < 3.3f) + // { + // // if(get_charge_stat()) + // // { + // // for(int i = 0; i < 3;i++) + // // { + + + // // // while(batV <= 3.3) + // // // { + // // disable_charge(); + // // uapi_tcxo_delay_ms(1000); + // // batteryservice_get_voltage_by_channel(&batV,ADC_CHANNEL_BAT_VOLTAGE); + // // PRINT("battery Voltage %.02f\n",batV); + // // enable_charge(); + // // if(batV > 3.3f) + // // { + // // break; + // // } + // // uapi_tcxo_delay_ms(5000); + // // // } + // // } + // // if(batV <= 3.3f) + // // { + // // extern void mcu_reset(void); + // // mcu_reset(); + // // } + + // // } + // // else + // // { + // // PRINT("Warning: Battery voltage is too low. Device will power off"); + // // uapi_tcxo_delay_ms(10); + // // extern void mcu_poweroff(void); + // // mcu_poweroff(); + // // } + + // } + + } + +#endif + +} + void ohos_show_bootup_logo(void) { /* 未接lcd时不能调用图形相关类的实例 */ @@ -69,6 +139,31 @@ void ohos_show_bootup_logo(void) #endif + + if(check_power_on_voltage()) + { + //显示充电图片 + + while(1) + { + #ifdef SUPPORT_POWER_MANAGER + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + display_api->turn_on_screen(); + display_api->set_screen_set_keepon_timeout(-1); + #endif + if(check_power_on_voltage()) + { + uapi_watchdog_kick(); + uapi_tcxo_delay_ms(5000); + } + else + mcu_reset(); + } + } + + + + #if defined(CONFIG_OTA_UPDATE_SUPPORT) && defined(ENABLE_UIKIT) if (upg_check_upgrade_need_upgrade()) { diff --git a/code/sdk/zhihui/services/battery/service/battery_driver.cpp b/code/sdk/zhihui/services/battery/service/battery_driver.cpp index c0c201dd4..f3e9bd994 100644 --- a/code/sdk/zhihui/services/battery/service/battery_driver.cpp +++ b/code/sdk/zhihui/services/battery/service/battery_driver.cpp @@ -478,6 +478,33 @@ float battery_percent_map[][2]={ #endif }; +float battery_charge_percent_map[][2]={ +#ifdef BOARD_FD272 + {4.375, 100}, + {4.255, 95}, + {4.155, 90}, + {4.069, 85}, + {3.996, 80}, + {3.933, 75}, + {3.877, 70}, + {3.828, 65}, + {3.784, 60}, + {3.744, 55}, + {3.708, 50}, + {3.674, 45}, + {3.643, 40}, + {3.614, 35}, + {3.586, 30}, + {3.560, 25}, + {3.535, 20}, + {3.510, 15}, + {3.480, 10}, + {3.415, 5}, + {3.300, 0} +#endif +}; + + #ifdef BOARD_LEINIAO #define batteryservice_VOLTAGE_MAX (4.2f) #elif defined BOARD_FD272 @@ -720,18 +747,21 @@ static int battery_get_percent_by_voltage(float voltage) { uint32_t current_time = 0; int percent = 0; - int map_len = sizeof(battery_percent_map)/sizeof(battery_percent_map[0]); + // ===================== 最小修改:根据充电状态选择MAP ===================== + const float (*battery_map)[2] = get_charge_stat() ? battery_charge_percent_map : battery_percent_map; + int map_len = sizeof(battery_charge_percent_map)/sizeof(battery_charge_percent_map[0]); // 两个map长度一样 + // ====================================================================== float temp_value = 0.0f; for (int i =0;i battery_percent_map[i+1][0] ) + if (voltage <= battery_map[i][0] && voltage > battery_map[i+1][0] ) { //电压差 前大后小 - float r_div = ( battery_percent_map[i][0] - voltage)/(battery_percent_map[i][0] - battery_percent_map[i+1][0]); + float r_div = ( battery_map[i][0] - voltage)/(battery_map[i][0] - battery_map[i+1][0]); //百分比 前大后小 - temp_value = battery_percent_map[i][1] - (battery_percent_map[i][1] - battery_percent_map[i+1][1] ) * r_div ; + temp_value = battery_map[i][1] - (battery_map[i][1] - battery_map[i+1][1] ) * r_div ; percent = (int)(temp_value + 0.5); @@ -784,7 +814,7 @@ static int battery_get_percent_by_voltage(float voltage) history_percent = percent; // printf("batterymap[%d]=%f,batterymap[%d]=%f, r_div = %f , temp_value = %f ,percent = %d\n", - // i,battery_percent_map[i][0],i+1,battery_percent_map[i+1][0], + // i,battery_map[i][0],i+1,battery_map[i+1][0], // r_div,temp_value,percent // ); break; @@ -792,6 +822,8 @@ static int battery_get_percent_by_voltage(float voltage) } + printf("000 history_percent:%d ,percent : %d ,voltage:%.3f \n",history_percent,percent,voltage); + if (voltage <= batteryservice_VOLTAGE_MIN) percent = 0; @@ -799,17 +831,21 @@ static int battery_get_percent_by_voltage(float voltage) { if(get_charge_stat() && history_percent < 100 && history_percent) //充电中则均匀增加 { + printf("111 history_percent:%d ,percent : %d ,voltage:%.3f \n",history_percent,percent,voltage); // uapi_save_runtime_log(RUNTIME_LOG_BATTERY_MIN_UP); history_percent++; percent = history_percent; } else if(!get_charge_stat() && history_percent) //未充电且history_percent不为0 则保持不变 { + printf("222 history_percent:%d ,percent : %d ,voltage:%.3f \n",history_percent,percent,voltage); percent = history_percent; } else { + printf("333 history_percent:%d ,percent : %d ,voltage:%.3f \n",history_percent,percent,voltage); percent = 100; + history_percent = 100; } } -- 2.17.1