From: caisking Date: Wed, 17 Jun 2026 02:22:22 +0000 (+0800) Subject: 充放电拷机适配41562 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=f41dbb5f9129886b72805727c5e1caa852730917;p=mirrors%2FFD230.git 充放电拷机适配41562 --- diff --git a/code/sdk/zhihui/UI/producttest/CMakeLists.txt b/code/sdk/zhihui/UI/producttest/CMakeLists.txt index c2631cc93..2107a990c 100644 --- a/code/sdk/zhihui/UI/producttest/CMakeLists.txt +++ b/code/sdk/zhihui/UI/producttest/CMakeLists.txt @@ -76,7 +76,9 @@ set(PRIVATE_HEADER ${ROOT_DIR}/zhihui/services/factorytest_service ${ROOT_DIR}/zhihui/services/cc_cycle_service ${ROOT_DIR}/zhihui/drivers/ + ${ROOT_DIR}/zhihui/drivers/charge ${ROOT_DIR}/zhihui/drivers/charge/hp4570 + ${ROOT_DIR}/zhihui/drivers/charge/sgm41562 ${ROOT_DIR}/zhihui/4g/cat1Service/include ${ROOT_DIR}/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/include ${ROOT_DIR}/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/include diff --git a/code/sdk/zhihui/UI/producttest/include/ccCycleBurnView.h b/code/sdk/zhihui/UI/producttest/include/ccCycleBurnView.h index 63da3a4c8..9a64f2ef1 100644 --- a/code/sdk/zhihui/UI/producttest/include/ccCycleBurnView.h +++ b/code/sdk/zhihui/UI/producttest/include/ccCycleBurnView.h @@ -1,12 +1,14 @@ #ifndef CC_CYCLE_BURN_VIEW_H #define CC_CYCLE_BURN_VIEW_H +#include "charge_ic_config.h" + #include "View.h" #include "components/ui_scroll_view.h" #include "components/ui_view_group.h" #include "components/ui_label.h" -#ifdef ENABLE_HP4570 +#ifdef ENABLE_CC_CYCLE #include "cc_cycle_service.h" #endif @@ -47,7 +49,9 @@ namespace OHOS UILabel *statusLabel_{nullptr}; UILabel *footerLabel_{nullptr}; bool viewInit_{false}; +#ifdef ENABLE_CC_CYCLE void UpdatePhaseBackground(cc_cycle_phase_e phase, uint8_t defectType); +#endif }; } diff --git a/code/sdk/zhihui/UI/producttest/include/testPresenter.h b/code/sdk/zhihui/UI/producttest/include/testPresenter.h index 28b2006e8..1a5677392 100644 --- a/code/sdk/zhihui/UI/producttest/include/testPresenter.h +++ b/code/sdk/zhihui/UI/producttest/include/testPresenter.h @@ -24,6 +24,7 @@ #include "producttest/include/testhrsenson.h" #include "components/ui_label_button_ext.h" #include "common/key_code.h" +#include "charge_ic_config.h" @@ -62,7 +63,7 @@ namespace OHOS #endif LUMINANCE, CHARG, -#ifdef ENABLE_HP4570 +#ifdef ENABLE_CC_CYCLE CCCYCLE, #endif SPEAK, diff --git a/code/sdk/zhihui/UI/producttest/include/testView.h b/code/sdk/zhihui/UI/producttest/include/testView.h index c9aa08d4d..8a6c74dbd 100644 --- a/code/sdk/zhihui/UI/producttest/include/testView.h +++ b/code/sdk/zhihui/UI/producttest/include/testView.h @@ -1,6 +1,8 @@ #ifndef TEST_VIEW_H #define TEST_VIEW_H +#include "charge_ic_config.h" + #include "View.h" #include "components/ui_view_group.h" @@ -26,7 +28,7 @@ #include "producttest/include/testhrsenson.h" #include "producttest/include/testgsenson.h" #include "producttest/include/testold.h" -#ifdef ENABLE_HP4570 +#ifdef ENABLE_CC_CYCLE #include "producttest/include/testCcCycle.h" #endif #include "producttest/include/testbt.h" @@ -88,7 +90,7 @@ namespace OHOS bool ChangeTPTESTView(int16_t thisView); bool ChangLUMTESTView(int16_t thisView); bool ChangchargingTESTView(int16_t thisView); -#ifdef ENABLE_HP4570 +#ifdef ENABLE_CC_CYCLE bool ChangeCcCycleTESTView(int16_t thisView); #endif bool ChangspeakTESTView(int16_t thisView); @@ -154,7 +156,7 @@ namespace OHOS testTPView *test_TP_view{nullptr}; testLUMView *test_lum_view{nullptr}; testCHANINGView *test_charging_view{nullptr}; -#ifdef ENABLE_HP4570 +#ifdef ENABLE_CC_CYCLE testCcCycleView *test_cc_cycle_view{nullptr}; #endif testSPEAKView *test_speak_view{nullptr}; diff --git a/code/sdk/zhihui/UI/producttest/src/ccCycleBurnPresenter.cpp b/code/sdk/zhihui/UI/producttest/src/ccCycleBurnPresenter.cpp index a2246c966..7d35c360c 100644 --- a/code/sdk/zhihui/UI/producttest/src/ccCycleBurnPresenter.cpp +++ b/code/sdk/zhihui/UI/producttest/src/ccCycleBurnPresenter.cpp @@ -1,3 +1,4 @@ +#include "charge_ic_config.h" #include "AppViewIDs.h" #include "NativeAbility.h" #include "NativeRegisterManager.h" @@ -14,7 +15,7 @@ #include #include -#ifdef ENABLE_HP4570 +#ifdef ENABLE_CC_CYCLE #include "cc_cycle_service.h" #endif #include "alarm/include/AlarmClockModel.h" @@ -76,7 +77,7 @@ static void cc_burn_alarm_start_on_graphic(void) static void cc_burn_check_alarm(void) { -#ifdef ENABLE_HP4570 +#ifdef ENABLE_CC_CYCLE if (cc_cycle_take_defect_alarm() != 0) { if (!g_ccBurnAlarmPlaying) { ::GraphicService::GetInstance()->PostGraphicEvent(cc_burn_alarm_start_on_graphic); @@ -92,11 +93,10 @@ static void cc_burn_refresh_on_graphic(void) if (!cc_burn_ui_may_update()) { return; } -#ifdef ENABLE_HP4570 - if (!cc_cycle_is_running()) { - return; +#ifdef ENABLE_CC_CYCLE + if (cc_cycle_is_running()) { + cc_burn_check_alarm(); } - cc_burn_check_alarm(); #endif OHOS::ccCycleBurnView *v = OHOS::ccCycleBurnView::GetInstance(); if (v == nullptr || !v->IsViewReady()) { @@ -116,7 +116,7 @@ static void cc_burn_show_ui_on_graphic(void) if (g_hideBurnUiPending) { return; } -#ifdef ENABLE_HP4570 +#ifdef ENABLE_CC_CYCLE if (!cc_cycle_is_running()) { return; } @@ -146,7 +146,7 @@ static void cc_burn_hide_ui_deferred(void) g_hideBurnUiPending = 0; return; } -#ifdef ENABLE_HP4570 +#ifdef ENABLE_CC_CYCLE factorytest_set_pending_subview(OHOS::CCCYCLE); #else factorytest_set_pending_subview(OHOS::TESTVIEW); @@ -243,7 +243,7 @@ namespace OHOS g_hideBurnUiPending = 0; g_burnUiValid = 1; view_->AttachDragListener(); -#ifdef ENABLE_HP4570 +#ifdef ENABLE_CC_CYCLE if (cc_cycle_is_running() && g_ccBurnRefreshTimer != nullptr) { (void)osTimerStart(g_ccBurnRefreshTimer, 1000); } @@ -321,7 +321,7 @@ void cc_cycle_hide_burn_ui(void) if (g_ccBurnRefreshTimer != nullptr) { (void)osTimerStop(g_ccBurnRefreshTimer); } -#ifdef ENABLE_HP4570 +#ifdef ENABLE_CC_CYCLE cc_cycle_on_burn_ui_exit(); #endif { diff --git a/code/sdk/zhihui/UI/producttest/src/ccCycleBurnView.cpp b/code/sdk/zhihui/UI/producttest/src/ccCycleBurnView.cpp index c8d796f95..9e5db2d0f 100644 --- a/code/sdk/zhihui/UI/producttest/src/ccCycleBurnView.cpp +++ b/code/sdk/zhihui/UI/producttest/src/ccCycleBurnView.cpp @@ -1,3 +1,4 @@ +#include "charge_ic_config.h" #include "producttest/include/ccCycleBurnView.h" #include "producttest/include/ccCycleBurnPresenter.h" #include "wearable_log.h" @@ -5,7 +6,7 @@ #include "gfx_utils/color.h" #include -#ifdef ENABLE_HP4570 +#ifdef ENABLE_CC_CYCLE #include "cc_cycle_service.h" #include "battery_hal.h" #endif @@ -37,7 +38,7 @@ namespace OHOS { return g_burnView; } - +#ifdef ENABLE_CC_CYCLE void ccCycleBurnView::UpdatePhaseBackground(cc_cycle_phase_e phase, uint8_t defectType) { if (burnContentGroup_ == nullptr) { @@ -75,13 +76,13 @@ namespace OHOS phaseLabel_->SetText("空闲"); } } - +#endif void ccCycleBurnView::RefreshStatus(void) { if (!IsViewReady() || GetInstance() != this) { return; } -#ifdef ENABLE_HP4570 +#ifdef ENABLE_CC_CYCLE cc_cycle_phase_e p = cc_cycle_get_phase(); uint8_t defect = cc_cycle_get_defect_type(); UpdatePhaseBackground(p, defect); diff --git a/code/sdk/zhihui/UI/producttest/src/testCcCycle.cpp b/code/sdk/zhihui/UI/producttest/src/testCcCycle.cpp index e3ca614bf..41b489ce4 100644 --- a/code/sdk/zhihui/UI/producttest/src/testCcCycle.cpp +++ b/code/sdk/zhihui/UI/producttest/src/testCcCycle.cpp @@ -16,7 +16,9 @@ #include #include -#ifdef ENABLE_HP4570 +#include "charge_ic_config.h" + +#ifdef ENABLE_CC_CYCLE #include "cc_cycle_service.h" #include "battery_hal.h" @@ -121,7 +123,7 @@ namespace OHOS if (buf == NULL || buf_size == 0) { return; } - /* 与 debug 页 get_hp4570_register_dump 一致:仅 hp4570n_dump_debug_registers */ + /* 与 cc_cycle 一致:走 charge_ic_dump_debug_registers */ (void)cc_cycle_format_ic_registers(buf, (unsigned int)buf_size); } @@ -802,4 +804,4 @@ namespace OHOS } } -#endif /* ENABLE_HP4570 */ +#endif /* ENABLE_CC_CYCLE */ diff --git a/code/sdk/zhihui/UI/producttest/src/testPresenter.cpp b/code/sdk/zhihui/UI/producttest/src/testPresenter.cpp index c6e90cfe7..b1cd0eedd 100644 --- a/code/sdk/zhihui/UI/producttest/src/testPresenter.cpp +++ b/code/sdk/zhihui/UI/producttest/src/testPresenter.cpp @@ -26,7 +26,7 @@ #ifdef CUSTOM_ZHIHUI #include "factorytest_protocol.h" #endif -#ifdef ENABLE_HP4570 +#ifdef ENABLE_CC_CYCLE #include "cc_cycle_service.h" #include "producttest/include/testCcCycle.h" #endif @@ -121,7 +121,7 @@ namespace OHOS "\"message\":\"pending_subview_apply\",\"data\":{\"v1\":%d}}\n", (int)target); // #endregion testView::GetInstance()->ChangeView(TESTVIEW, target); -#ifdef ENABLE_HP4570 +#ifdef ENABLE_CC_CYCLE if (target == CCCYCLE) { testCcCycleView *ccView = testCcCycleView::GetInstance(); if (ccView != nullptr && ccView->IsUiReady()) { @@ -143,7 +143,7 @@ namespace OHOS void testPresenter::OnPause(void) { -#ifdef ENABLE_HP4570 +#ifdef ENABLE_CC_CYCLE testCcCycleView *ccView = testCcCycleView::GetInstance(); if (ccView != nullptr) { ccView->PauseStatusTimer(); @@ -292,7 +292,7 @@ namespace OHOS return true; } -#ifdef ENABLE_HP4570 +#ifdef ENABLE_CC_CYCLE if (strcmp(view.GetViewId(), "cc_cycle_sw") == 0) { cc_cycle_set_enabled(cc_cycle_get_enabled() ? 0 : 1); if (testCcCycleView::GetInstance() != nullptr) { @@ -366,7 +366,7 @@ namespace OHOS if(strcmp(view.GetViewId(),Test_ViewMapper_t[i].viewid_str_next) == 0) { int nextIdx = i + 1; -#ifdef ENABLE_HP4570 +#ifdef ENABLE_CC_CYCLE if (nextIdx < len && Test_ViewMapper_t[nextIdx].viewId == CCCYCLE) { nextIdx++; } diff --git a/code/sdk/zhihui/UI/producttest/src/testView.cpp b/code/sdk/zhihui/UI/producttest/src/testView.cpp index 6a5f12aac..586be03ea 100644 --- a/code/sdk/zhihui/UI/producttest/src/testView.cpp +++ b/code/sdk/zhihui/UI/producttest/src/testView.cpp @@ -49,7 +49,7 @@ namespace OHOS #endif {LUMINANCE, "luminanceButton", "亮度", "luminanceButton_next", &testView::ChangLUMTESTView, true}, {CHARG, "chargingButton", "电池充电", "chargingButton_next", &testView::ChangchargingTESTView, true}, -#ifdef ENABLE_HP4570 +#ifdef ENABLE_CC_CYCLE {CCCYCLE, "ccCycleButton", "充放电拷机", "ccCycleButton_next", &testView::ChangeCcCycleTESTView, true}, #endif {SPEAK, "speakButton", "喇叭", "speakButton_next", &testView::ChangspeakTESTView, true}, @@ -103,7 +103,7 @@ namespace OHOS bool testView::ShouldShowChainNextButton(int16_t viewId) { -#ifdef ENABLE_HP4570 +#ifdef ENABLE_CC_CYCLE if (viewId == CCCYCLE) { return false; } @@ -519,7 +519,7 @@ namespace OHOS for (int i = 1; i < len; i++) { -#ifdef ENABLE_HP4570 +#ifdef ENABLE_CC_CYCLE if (Test_ViewMapper_t[i].viewId == CCCYCLE) { continue; } @@ -534,7 +534,7 @@ namespace OHOS button[btnIdx++] = SetTheButton_ext(buttonconfig, clickListener); buttonconfig.y += interval; } -#ifdef ENABLE_HP4570 +#ifdef ENABLE_CC_CYCLE for (int i = 1; i < len; i++) { if (Test_ViewMapper_t[i].viewId != CCCYCLE) { continue; @@ -669,7 +669,7 @@ namespace OHOS return true; } -#ifdef ENABLE_HP4570 +#ifdef ENABLE_CC_CYCLE bool testView::ChangeCcCycleTESTView(int16_t thisView) { if (SystemScrollView[thisView] == nullptr) { @@ -1027,7 +1027,7 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemView:: SystemScrollView[%d] is nullptr", showView); } -#ifdef ENABLE_HP4570 +#ifdef ENABLE_CC_CYCLE testCcCycleView *ccView = testCcCycleView::GetInstance(); if (ccView != nullptr) { if (showView == CCCYCLE) { @@ -1166,7 +1166,7 @@ namespace OHOS test_G_view = nullptr; SystemScrollView[hideView] = nullptr; break; -#ifdef ENABLE_HP4570 +#ifdef ENABLE_CC_CYCLE case CCCYCLE: if (SystemScrollView[hideView] != nullptr) group->Remove(SystemScrollView[hideView]); diff --git a/code/sdk/zhihui/UI/producttest/src/testchanging.cpp b/code/sdk/zhihui/UI/producttest/src/testchanging.cpp index cbcbd1ffa..30fe6c2aa 100644 --- a/code/sdk/zhihui/UI/producttest/src/testchanging.cpp +++ b/code/sdk/zhihui/UI/producttest/src/testchanging.cpp @@ -4,6 +4,8 @@ #include "producttest/include/testchanging.h" #include "producttest/include/testchangingC.h" +#include "charge_ic_config.h" + #ifdef SUPPORT_BATTERY_SERVICE #include "battery_hal.h" #include "charge_ic.h" @@ -22,10 +24,6 @@ extern "C" #include "pm_veto.h" #include "pm.h" - #ifdef ENABLE_HP4570 - #include "hp4570.h" - #endif - #ifdef __cplusplus #if __cplusplus @@ -64,6 +62,9 @@ namespace OHOS float pcb_temp = 0.0F; uint8_t power = 0; uint8_t charge_id = 0; + bool vbus_pg = false; + bool chrg_fast = false; + bool chrg_done = false; if (buf == nullptr || buf_size == 0) { return; @@ -72,12 +73,19 @@ namespace OHOS power = battery_get_voltage(&voltage); battery_get_pcb_temp(&pcb_temp); battery_get_battery_temp(&bat_temp); +#if defined(ENABLE_CC_CYCLE) + { + charge_ic_cc_status_t cc_status = {0}; + charge_id = charge_ic_get_display_id(); + if (charge_ic_read_cc_status(&cc_status)) { + vbus_pg = cc_status.vbus_pg != 0; + chrg_fast = cc_status.chrg_active != 0; + chrg_done = cc_status.chrg_done != 0; + } + } +#else + charge_id = (charge_ic_get_id() == 0x2 || charge_ic_get_id() == 0x4) ? 1 : 0; #endif -#ifdef ENABLE_HP4570 - charge_id = (0x2 == hp4570n_get_id()) ? 1 : 0; - bool vbus_pg = hp4570n_read_status_vbus_pg(); - bool chrg_fast = hp4570n_read_chrg_stat_fast_chrg(); - bool chrg_done = hp4570n_read_chrg_stat_chrg_done(); (void)sprintf_s(buf, buf_size, "power:%d\nvoltage:%.2f\nbat_temp:%.2f\npcb_temp:%.2f\ncharge Ic:%d\nvbus_pg:%d chrg:%d/%d", power, voltage, bat_temp, pcb_temp, charge_id, (int)vbus_pg, (int)chrg_fast, (int)chrg_done); diff --git a/code/sdk/zhihui/drivers/charge/CMakeLists.txt b/code/sdk/zhihui/drivers/charge/CMakeLists.txt index b4834cb1f..dccad6f42 100644 --- a/code/sdk/zhihui/drivers/charge/CMakeLists.txt +++ b/code/sdk/zhihui/drivers/charge/CMakeLists.txt @@ -12,6 +12,7 @@ set(SOURCES ) set(PUBLIC_HEADER + ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/hp4570 ${CMAKE_CURRENT_SOURCE_DIR}/sgm41562 ${CMAKE_CURRENT_SOURCE_DIR}/service diff --git a/code/sdk/zhihui/drivers/charge/charge_ic_cc_ops.h b/code/sdk/zhihui/drivers/charge/charge_ic_cc_ops.h new file mode 100644 index 000000000..1558f8fa5 --- /dev/null +++ b/code/sdk/zhihui/drivers/charge/charge_ic_cc_ops.h @@ -0,0 +1,29 @@ +/** + * @brief 充放电拷机(cc_cycle)充电 IC 统一状态与宏接口头 + * + * 各驱动在 hp4570.h / sgm41562.h 等中定义 XXX_CC_* 宏; + * charge_ic.cpp 按运行时识别类型分发,框架层仅调用 charge_ic_* API。 + */ + +#ifndef CHARGE_IC_CC_OPS_H +#define CHARGE_IC_CC_OPS_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** @brief 拷机/产测 IC 状态快照(展示与不良快照共用) */ +typedef struct { + uint8_t vbus_pg; /**< 1=输入 Power Good */ + uint8_t chrg_active; /**< 1=预充/快充进行中(展示用,各 IC 语义见驱动宏) */ + uint8_t chrg_done; /**< 1=Charge Done */ +} charge_ic_cc_status_t; + +#ifdef __cplusplus +} +#endif + +#endif /* CHARGE_IC_CC_OPS_H */ diff --git a/code/sdk/zhihui/drivers/charge/charge_ic_config.h b/code/sdk/zhihui/drivers/charge/charge_ic_config.h new file mode 100644 index 000000000..d67ebdd3e --- /dev/null +++ b/code/sdk/zhihui/drivers/charge/charge_ic_config.h @@ -0,0 +1,15 @@ +/** + * @brief 各充电 IC 1C 电流配置(service 与 driver 共用,单一修改点) + */ + +#ifndef CHARGE_IC_CONFIG_H +#define CHARGE_IC_CONFIG_H + +#define CHARGE_1C_MA_HP4570 200u +#define CHARGE_1C_MA_SGM41562 200u /* TEMP: 41562 1C 测试 */ + +#if defined(ENABLE_HP4570) || defined(ENABLE_SGM41562) +#define ENABLE_CC_CYCLE 1 +#endif + +#endif /* CHARGE_IC_CONFIG_H */ diff --git a/code/sdk/zhihui/drivers/charge/hp4570/hp4570.c b/code/sdk/zhihui/drivers/charge/hp4570/hp4570.c index f1b7c4917..e3db59d4f 100644 --- a/code/sdk/zhihui/drivers/charge/hp4570/hp4570.c +++ b/code/sdk/zhihui/drivers/charge/hp4570/hp4570.c @@ -19,6 +19,7 @@ */ #include "hp4570.h" +#include "charge_ic_config.h" #include "custom_utils.h" #include @@ -177,8 +178,8 @@ bool hp4570n_init(uint8_t chip_ver){ ret = hp4570n_set_low_chrg_ipre_mA(30); printf("hp4570n_set_low_chrg_ipre_mA(30) ret:%d\n",ret); - ret = hp4570n_set_chrg_ichg_mA(256); - printf("hp4570n_set_chrg_ichg_mA(256) ret:%d\n",ret); + ret = hp4570n_set_chrg_ichg_mA(CHARGE_1C_MA_HP4570); + printf("hp4570n_set_chrg_ichg_mA(%u) ret:%d\n", (unsigned)CHARGE_1C_MA_HP4570, ret); ret = hp4570n_set_chrg_iterm_mA(30); printf("hp4570n_set_chrg_iterm_mA(30) ret:%d\n",ret); @@ -1096,8 +1097,8 @@ void hp4570n_reset(void) ret = hp4570n_set_low_chrg_ipre_mA(30); printf("hp4570n_set_low_chrg_ipre_mA(30) ret:%d\n",ret); - ret = hp4570n_set_chrg_ichg_mA(256); - printf("hp4570n_set_chrg_ichg_mA(256) ret:%d\n",ret); + ret = hp4570n_set_chrg_ichg_mA(CHARGE_1C_MA_HP4570); + printf("hp4570n_set_chrg_ichg_mA(%u) ret:%d\n", (unsigned)CHARGE_1C_MA_HP4570, ret); ret = hp4570n_set_chrg_iterm_mA(30); printf("hp4570n_set_chrg_iterm_mA(30) ret:%d\n",ret); diff --git a/code/sdk/zhihui/drivers/charge/hp4570/hp4570.h b/code/sdk/zhihui/drivers/charge/hp4570/hp4570.h index 4c79789f7..9b6803a82 100644 --- a/code/sdk/zhihui/drivers/charge/hp4570/hp4570.h +++ b/code/sdk/zhihui/drivers/charge/hp4570/hp4570.h @@ -533,6 +533,36 @@ uint8_t hp4570n_get_id(void); void hp4570n_reset(void); +/** @name cc_cycle 拷机操作宏(由 charge_ic.cpp 分发) */ +/** @{ */ +#define HP4570_CC_SET_CYCLE_PATH(enable) \ + do { \ + if (enable) { \ + hp4570n_set_hiz_en(false); \ + hp4570n_set_ceb_en(true); \ + } else { \ + hp4570n_set_ceb_en(false); \ + hp4570n_set_hiz_en(true); \ + } \ + } while (0) + +#define HP4570_CC_READ_ICHG_MA(p_ma) \ + hp4570n_read_chrg_ichg_mA(p_ma) + +#define HP4570_CC_HW_IS_ACTIVELY_CHARGING() \ + (hp4570n_read_chrg_stat_fast_chrg() || hp4570n_read_chrg_stat_pre_chrg() || \ + hp4570n_read_chrg_stat_dead_chrg()) + +#define HP4570_CC_READ_STATUS(st) \ + do { \ + if ((st) != NULL) { \ + (st)->vbus_pg = hp4570n_read_status_vbus_pg() ? 1 : 0; \ + (st)->chrg_active = hp4570n_read_chrg_stat_fast_chrg() ? 1 : 0; \ + (st)->chrg_done = hp4570n_read_chrg_stat_chrg_done() ? 1 : 0; \ + } \ + } while (0) +/** @} */ + #ifdef __cplusplus } #endif diff --git a/code/sdk/zhihui/drivers/charge/sgm41562/sgm41562.c b/code/sdk/zhihui/drivers/charge/sgm41562/sgm41562.c index f6bebb73c..fa105f07b 100644 --- a/code/sdk/zhihui/drivers/charge/sgm41562/sgm41562.c +++ b/code/sdk/zhihui/drivers/charge/sgm41562/sgm41562.c @@ -9,6 +9,7 @@ #include #include "sgm41562.h" +#include "charge_ic_config.h" #include "custom_utils.h" #include "tcxo.h" @@ -341,6 +342,26 @@ static int sgm41562_get_term_curr(void) return curr; } +/** @brief 设置 REG0D PRE_ICHG [7:4] 预充电流(uA) */ +static int sgm41562_set_prechg_curr(int prechg_uA) +{ + int ret; + int reg_val; + + if (prechg_uA < SGM41562_PRE_ICHG_MIN_uA) { + prechg_uA = SGM41562_PRE_ICHG_MIN_uA; + } else if (prechg_uA > SGM41562_PRE_ICHG_MAX_uA) { + prechg_uA = SGM41562_PRE_ICHG_MAX_uA; + } + + reg_val = (prechg_uA - SGM41562_PRE_ICHG_MIN_uA) / SGM41562_PRE_ICHG_STEP_uA; + reg_val <<= 4; + + ret = sgm41562_update_bits(SGM41562_CHRG_REG_D, + SGM41562_PRE_ICHG_MASK, (uint8_t)reg_val); + return ret; +} + /** @brief 设置 REG03 TERM_I [3:0] 截止电流(uA) */ static int sgm41562_set_term_curr( int term_curr) { @@ -605,6 +626,19 @@ void sgm41562_set_batfet_dis(bool en) (void)sgm41562_ctrl_setting(REG_BIT_FET_DIS, en); } +/** @brief 退出船运/HIZ:清 EN_HIZ、开 BATFET、允充(CEB=0) */ +void sgm41562_exit_shipmode(void) +{ + (void)sgm41562_ctrl_setting(REG_BIT_EN_HIZ, false); + (void)sgm41562_set_batfet_dis(false); + (void)sgm41562_ctrl_setting(REG_BIT_EN_CEB, 0); +} + +void sgm41562_set_hiz_en(bool en) +{ + (void)sgm41562_ctrl_setting(REG_BIT_EN_HIZ, en); +} + /** @brief 关机低功耗:关 WDT/NTC/定时器,SWITCH_MODE 保持 BAT→SYS(规格书 REV.A §Battery Discharge) */ void sgm41562_entry_shutdown_lpm(void) { @@ -711,6 +745,23 @@ bool sgm41562_set_chrg_ichg_mA(uint16_t current_mA) return (ret == 0); } +bool sgm41562_read_chrg_ichg_mA(uint16_t *current_mA) +{ + uint8_t reg_val = 0; + uint32_t ichg_uA; + + if (current_mA == NULL) { + return false; + } + if (sgm41562_read_reg(SGM41562_CHRG_REG_2, ®_val) != 0) { + return false; + } + reg_val &= SGM41562_FAST_ICC_MASK; + ichg_uA = (uint32_t)reg_val * SGM41562_FAST_ICC_STEP_uA + SGM41562_FAST_ICC_MIN_uA; + *current_mA = (uint16_t)(ichg_uA / 1000u); + return true; +} + bool sgm41562_read_chrg_stat_chrg_done(void) { uint8_t chrg_stat = 0; @@ -721,6 +772,36 @@ bool sgm41562_read_chrg_stat_chrg_done(void) return (chrg_stat & SGM41562_CHG_STAT_MASK) == SGM41562_TERM_CHRG; } +bool sgm41562_read_chrg_stat_fast_chrg(void) +{ + uint8_t chrg_stat = 0; + + if (sgm41562_read_reg(SGM41562_CHRG_REG_8, &chrg_stat) != 0) { + return false; + } + return (chrg_stat & SGM41562_CHG_STAT_MASK) == SGM41562_FAST_CHRG; +} + +bool sgm41562_read_chrg_stat_pre_chrg(void) +{ + uint8_t chrg_stat = 0; + + if (sgm41562_read_reg(SGM41562_CHRG_REG_8, &chrg_stat) != 0) { + return false; + } + return (chrg_stat & SGM41562_CHG_STAT_MASK) == SGM41562_PRECHRG; +} + +bool sgm41562_read_status_vbus_pg(void) +{ + uint8_t chrg_stat = 0; + + if (sgm41562_read_reg(SGM41562_CHRG_REG_8, &chrg_stat) != 0) { + return false; + } + return (chrg_stat & SGM41562_PG_STAT) != 0; +} + uint8_t sgm41562_get_id(void) { uint8_t val = 0; @@ -1229,9 +1310,11 @@ int sgm41562_hw_init(void) printf("sgm41562_hw_chipid_detect successful\n"); + sgm41562_exit_shipmode(); + struct sgm41562_init_data data = {0}; - data.ichg = 256 * 1000; + data.ichg = (int)CHARGE_1C_MA_SGM41562 * 1000; data.vreg = SGM41562_VBAT_REG_DEF_uV; data.iterm = SGM41562_TERM_I_DEF_uA; data.vlim = SGM41562_VINDPM_DEF_uV; @@ -1264,10 +1347,18 @@ int sgm41562_hw_init(void) if (ret) goto err_out; + ret = sgm41562_set_prechg_curr(30000); + if (ret) + goto err_out; + ret = sgm41562_set_watchdog_timer(SGM41562_WDT_TIMER_DISABLE); if (ret) goto err_out; + ret = sgm41562_ctrl_setting(REG_BIT_EN_TERM, 1); + if (ret) + goto err_out; + //关闭 NTC // ret = sgm41562_ctrl_setting(REG_BIT_EN_NTC, false); // if (ret) @@ -1276,55 +1367,7 @@ int sgm41562_hw_init(void) if (ret) goto err_out; - // printf("ichrg:%d uA, chrg_vol:%d uV, input_limit:%d uA\n", - // data.ichg, data.vreg, data.ilim); - - -#if 0 - uint8_t reg_data = 0; - - sgm41562_read_reg(SGM41562_CHRG_REG_0,®_data); - printf("SGM41562_CHRG_REG_0 :0x%x\n",reg_data); - - sgm41562_read_reg(SGM41562_CHRG_REG_1,®_data); - printf("SGM41562_CHRG_REG_1 :0x%x\n",reg_data); - - sgm41562_read_reg(SGM41562_CHRG_REG_2,®_data); - printf("SGM41562_CHRG_REG_2 :0x%x\n",reg_data); - - sgm41562_read_reg(SGM41562_CHRG_REG_3,®_data); - printf("SGM41562_CHRG_REG_3 :0x%x\n",reg_data); - - sgm41562_read_reg(SGM41562_CHRG_REG_4,®_data); - printf("SGM41562_CHRG_REG_4 :0x%x\n",reg_data); - - sgm41562_read_reg(SGM41562_CHRG_REG_5,®_data); - printf("SGM41562_CHRG_REG_5 :0x%x\n",reg_data); - - sgm41562_read_reg(SGM41562_CHRG_REG_6,®_data); - printf("SGM41562_CHRG_REG_6 :0x%x\n",reg_data); - - sgm41562_read_reg(SGM41562_CHRG_REG_7,®_data); - printf("SGM41562_CHRG_REG_7 :0x%x\n",reg_data); - - sgm41562_read_reg(SGM41562_CHRG_REG_8,®_data); - printf("SGM41562_CHRG_REG_8 :0x%x\n",reg_data); - - sgm41562_read_reg(SGM41562_CHRG_REG_9,®_data); - printf("SGM41562_CHRG_REG_9 :0x%x\n",reg_data); - - sgm41562_read_reg(SGM41562_CHRG_REG_A,®_data); - printf("SGM41562_CHRG_REG_A :0x%x\n",reg_data); - - sgm41562_read_reg(SGM41562_CHRG_REG_B,®_data); - printf("SGM41562_CHRG_REG_B :0x%x\n",reg_data); - - sgm41562_read_reg(SGM41562_CHRG_REG_C,®_data); - printf("SGM41562_CHRG_REG_C :0x%x\n",reg_data); - - sgm41562_read_reg(SGM41562_CHRG_REG_D,®_data); - printf("SGM41562_CHRG_REG_D :0x%x\n",reg_data); -#endif + sgm41562_read_all_reg(); return 0; err_out: diff --git a/code/sdk/zhihui/drivers/charge/sgm41562/sgm41562.h b/code/sdk/zhihui/drivers/charge/sgm41562/sgm41562.h index d59629fc6..abc3b1bb1 100644 --- a/code/sdk/zhihui/drivers/charge/sgm41562/sgm41562.h +++ b/code/sdk/zhihui/drivers/charge/sgm41562/sgm41562.h @@ -49,7 +49,8 @@ extern "C" { #define SGM41562_VINDPM_V_MIN_uV 3880000 #define SGM41562_VINDPM_V_MAX_uV 5080000 #define SGM41562_VINDPM_STEP_uV 80000 -#define SGM41562_VINDPM_DEF_uV 4600000 +/* 规格书 VIN_MIN >= VBAT_REG+250mV */ +#define SGM41562_VINDPM_DEF_uV 4850000 #define SGM41562_PRE_TO BIT(3) #define SGM41562_INT_EXIT_SHIP BIT(2) #define SGM41562_VIN_EXIT_SHIP BIT(1) @@ -103,7 +104,8 @@ extern "C" { #define SGM41562_VBAT_REG_MIN_uV 3500000 #define SGM41562_VBAT_REG_MAX_uV 4770000 #define SGM41562_VBAT_REG_STEP_uV 10000 -#define SGM41562_VBAT_REG_DEF_uV 4550000 +/* FD272 恒压 4.60V*/ +#define SGM41562_VBAT_REG_DEF_uV 4600000 #define SGM41562_VRECH_THRE_uV BIT(0) /** @} */ @@ -339,6 +341,14 @@ void sgm41562_set_charge_en(bool en); */ void sgm41562_set_batfet_dis(bool en); +/** + * @brief 退出船运/HIZ:清 EN_HIZ、开 BATFET、允充 + */ +void sgm41562_exit_shipmode(void); + +/** @brief REG01 EN_HIZ:true=输入高阻(拷机放电禁充) */ +void sgm41562_set_hiz_en(bool en); + /** * @brief 关机低功耗:关 WDT/NTC/充电定时器,REG0A SWITCH_MODE=1 保持 BAT→SYS * @note MCU 仍由电池供电时使用;规格书 I_BAT_Q 可降至 <1.2µA(IC 部分) @@ -360,12 +370,24 @@ void sgm41562_entry_shipmode(void); */ bool sgm41562_set_chrg_ichg_mA(uint16_t current_mA); +/** @brief 读 REG02 FAST_ICC 配置电流(mA) */ +bool sgm41562_read_chrg_ichg_mA(uint16_t *current_mA); + /** * @brief 判断是否充电截止(EOC) * @return true REG08 CHG_STAT 为 TERM_CHRG,false 未完成或读失败 */ bool sgm41562_read_chrg_stat_chrg_done(void); +/** @brief REG08 CHG_STAT 为 FAST_CHRG */ +bool sgm41562_read_chrg_stat_fast_chrg(void); + +/** @brief REG08 CHG_STAT 为 PRECHRG */ +bool sgm41562_read_chrg_stat_pre_chrg(void); + +/** @brief REG08 PG_STAT:1=输入 Power Good */ +bool sgm41562_read_status_vbus_pg(void); + /** * @brief 读取 REG0B Device ID 原始值 * @return 寄存器值;读失败返回 0 @@ -375,6 +397,39 @@ uint8_t sgm41562_get_id(void); /** @brief 软复位:重新执行 sgm41562_hw_init() */ void sgm41562_reset(void); +/** @name cc_cycle 拷机操作宏(由 charge_ic.cpp 分发) */ +/** @{ */ +#define SGM41562_CC_SET_CYCLE_PATH(enable) \ + do { \ + if (enable) { \ + sgm41562_exit_shipmode(); \ + sgm41562_set_batfet_dis(false); \ + sgm41562_set_charge_en(false); \ + sgm41562_set_hiz_en(false); \ + } else { \ + sgm41562_set_charge_en(true); \ + sgm41562_set_hiz_en(true); \ + sgm41562_set_batfet_dis(false); \ + } \ + } while (0) + +#define SGM41562_CC_READ_ICHG_MA(p_ma) \ + sgm41562_read_chrg_ichg_mA(p_ma) + +#define SGM41562_CC_HW_IS_ACTIVELY_CHARGING() \ + (sgm41562_read_chrg_stat_fast_chrg() || sgm41562_read_chrg_stat_pre_chrg()) + +#define SGM41562_CC_READ_STATUS(st) \ + do { \ + if ((st) != NULL) { \ + (st)->vbus_pg = sgm41562_read_status_vbus_pg() ? 1 : 0; \ + (st)->chrg_active = (sgm41562_read_chrg_stat_fast_chrg() || \ + sgm41562_read_chrg_stat_pre_chrg()) ? 1 : 0; \ + (st)->chrg_done = sgm41562_read_chrg_stat_chrg_done() ? 1 : 0; \ + } \ + } while (0) +/** @} */ + #ifdef __cplusplus } #endif diff --git a/code/sdk/zhihui/services/battery/service/charge_ic.cpp b/code/sdk/zhihui/services/battery/service/charge_ic.cpp index bd74aeaee..a37ead6dd 100644 --- a/code/sdk/zhihui/services/battery/service/charge_ic.cpp +++ b/code/sdk/zhihui/services/battery/service/charge_ic.cpp @@ -395,27 +395,12 @@ void charge_ic_set_cycle_charge_path(bool enable_charge) switch (g_charge_ic_type) { case CHARGE_IC_TYPE_HP4570: #if defined(ENABLE_HP4570) - if (enable_charge) { - hp4570n_set_hiz_en(false); - hp4570n_set_ceb_en(true); - } else { - hp4570n_set_ceb_en(false); - hp4570n_set_hiz_en(true); - } + HP4570_CC_SET_CYCLE_PATH(enable_charge); #endif break; case CHARGE_IC_TYPE_SGM41562: #if defined(ENABLE_SGM41562) - if (enable_charge) { - sgm41562_exit_shipmode(); - sgm41562_set_batfet_dis(false); - sgm41562_set_charge_en(false); - sgm41562_set_hiz_en(false); - } else { - sgm41562_set_charge_en(true); - sgm41562_set_hiz_en(true); - sgm41562_set_batfet_dis(false); - } + SGM41562_CC_SET_CYCLE_PATH(enable_charge); #endif break; default: @@ -432,13 +417,13 @@ bool charge_ic_read_chrg_ichg_mA(uint16_t *current_mA) switch (g_charge_ic_type) { case CHARGE_IC_TYPE_HP4570: #if defined(ENABLE_HP4570) - return hp4570n_read_chrg_ichg_mA(current_mA); + return HP4570_CC_READ_ICHG_MA(current_mA); #else return false; #endif case CHARGE_IC_TYPE_SGM41562: #if defined(ENABLE_SGM41562) - return sgm41562_read_chrg_ichg_mA(current_mA); + return SGM41562_CC_READ_ICHG_MA(current_mA); #else return false; #endif @@ -452,17 +437,13 @@ bool charge_ic_hw_is_actively_charging(void) switch (g_charge_ic_type) { case CHARGE_IC_TYPE_HP4570: #if defined(ENABLE_HP4570) - if (hp4570n_read_chrg_stat_fast_chrg() || hp4570n_read_chrg_stat_pre_chrg() || - hp4570n_read_chrg_stat_dead_chrg()) { - return true; - } - return false; + return HP4570_CC_HW_IS_ACTIVELY_CHARGING(); #else return false; #endif case CHARGE_IC_TYPE_SGM41562: #if defined(ENABLE_SGM41562) - return sgm41562_read_chrg_stat_fast_chrg() || sgm41562_read_chrg_stat_pre_chrg(); + return SGM41562_CC_HW_IS_ACTIVELY_CHARGING(); #else return false; #endif @@ -482,4 +463,44 @@ bool charge_ic_should_finish_cc_charging(uint8_t soc, uint8_t soc_full, uint8_t return false; } +bool charge_ic_read_cc_status(charge_ic_cc_status_t *out) +{ + if (out == NULL || g_charge_ic_type == CHARGE_IC_TYPE_NONE) { + return false; + } + + out->vbus_pg = 0; + out->chrg_active = 0; + out->chrg_done = 0; + + switch (g_charge_ic_type) { + case CHARGE_IC_TYPE_HP4570: +#if defined(ENABLE_HP4570) + HP4570_CC_READ_STATUS(out); + return true; +#else + return false; +#endif + case CHARGE_IC_TYPE_SGM41562: +#if defined(ENABLE_SGM41562) + SGM41562_CC_READ_STATUS(out); + return true; +#else + return false; +#endif + default: + return false; + } +} + +uint8_t charge_ic_get_display_id(void) +{ + if (g_charge_ic_type == CHARGE_IC_TYPE_NONE) { + return 0; + } + + uint8_t id = charge_ic_get_id(); + return (id == 0x2 || id == 0x4) ? 1 : 0; +} + #endif /* ENABLE_CC_CYCLE */ diff --git a/code/sdk/zhihui/services/battery/service/charge_ic.h b/code/sdk/zhihui/services/battery/service/charge_ic.h index 45cd2cb04..03371e1ab 100644 --- a/code/sdk/zhihui/services/battery/service/charge_ic.h +++ b/code/sdk/zhihui/services/battery/service/charge_ic.h @@ -12,6 +12,7 @@ #include #include "errcode.h" #include "charge_ic_config.h" +#include "charge_ic_cc_ops.h" #ifdef __cplusplus extern "C" { @@ -73,6 +74,12 @@ bool charge_ic_hw_is_actively_charging(void); /** @brief 拷机充电阶段是否应结束(SOC 满或 CHG_DONE) */ bool charge_ic_should_finish_cc_charging(uint8_t soc, uint8_t soc_full, uint8_t chg_done_min_soc); + +/** @brief 读拷机/产测 IC 状态快照 */ +bool charge_ic_read_cc_status(charge_ic_cc_status_t *out); + +/** @brief 产测/快照展示用 charge IC 标识(已识别为 HP4570/SGM41562 时为 1) */ +uint8_t charge_ic_get_display_id(void); #endif #ifdef __cplusplus diff --git a/code/sdk/zhihui/services/cc_cycle_service/CMakeLists.txt b/code/sdk/zhihui/services/cc_cycle_service/CMakeLists.txt index 042d84ade..143df4a54 100644 --- a/code/sdk/zhihui/services/cc_cycle_service/CMakeLists.txt +++ b/code/sdk/zhihui/services/cc_cycle_service/CMakeLists.txt @@ -13,8 +13,6 @@ set(PRIVATE_HEADER ${ROOT_DIR}/zhihui/services/battery/hal ${ROOT_DIR}/zhihui/services/battery/service ${ROOT_DIR}/zhihui/drivers/charge - ${ROOT_DIR}/zhihui/drivers/charge/hp4570 - ${ROOT_DIR}/zhihui/drivers/charge/sgm41562 ${ROOT_DIR}/zhihui/services/gnss/inc ${ROOT_DIR}/application/brandy/brandy_standard ${ROOT_DIR}/application/wearable/fd272/service/power_manager/include diff --git a/code/sdk/zhihui/services/cc_cycle_service/cc_cycle_service.c b/code/sdk/zhihui/services/cc_cycle_service/cc_cycle_service.c index 9b6cc9d76..498efb101 100644 --- a/code/sdk/zhihui/services/cc_cycle_service/cc_cycle_service.c +++ b/code/sdk/zhihui/services/cc_cycle_service/cc_cycle_service.c @@ -21,14 +21,6 @@ #include "pm.h" #endif -#ifdef ENABLE_HP4570 -#include "hp4570.h" -#endif - -#ifdef ENABLE_SGM41562 -#include "sgm41562.h" -#endif - #if defined(SUPPORT_GNSS) #include "gnss_ctl.h" #endif @@ -784,9 +776,8 @@ static uint32_t cc_phase_duration_sec(uint32_t start_ts, uint32_t now) static uint8_t cc_read_charge_ic_id(void) { -#ifdef SUPPORT_BATTERY_SERVICE - uint8_t id = charge_ic_get_id(); - return (id == 0x2 || id == 0x4) ? 1 : 0; +#if defined(SUPPORT_BATTERY_SERVICE) && defined(ENABLE_CC_CYCLE) + return charge_ic_get_display_id(); #else return 0; #endif @@ -797,6 +788,7 @@ static void cc_fill_ic_status_fields(float *voltage, float *temp, uint8_t *charg { float v = 0.0f; float t = 0.0f; + charge_ic_cc_status_t cc_status = {0}; if (voltage != NULL) { *voltage = 0.0f; @@ -817,54 +809,18 @@ static void cc_fill_ic_status_fields(float *voltage, float *temp, uint8_t *charg if (charge_id != NULL) { *charge_id = cc_read_charge_ic_id(); } -#ifdef SUPPORT_BATTERY_SERVICE - if (charge_ic_get_type() == CHARGE_IC_TYPE_HP4570) { -#ifdef ENABLE_HP4570 - if (vbus_pg != NULL) { - *vbus_pg = hp4570n_read_status_vbus_pg() ? 1 : 0; - } - if (chrg_fast != NULL) { - *chrg_fast = hp4570n_read_chrg_stat_fast_chrg() ? 1 : 0; - } - if (chrg_done != NULL) { - *chrg_done = hp4570n_read_chrg_stat_chrg_done() ? 1 : 0; - } -#endif - } else if (charge_ic_get_type() == CHARGE_IC_TYPE_SGM41562) { -#ifdef ENABLE_SGM41562 - if (vbus_pg != NULL) { - *vbus_pg = sgm41562_read_status_vbus_pg() ? 1 : 0; - } - if (chrg_fast != NULL) { - *chrg_fast = (sgm41562_read_chrg_stat_fast_chrg() || - sgm41562_read_chrg_stat_pre_chrg()) ? 1 : 0; - } - if (chrg_done != NULL) { - *chrg_done = sgm41562_read_chrg_stat_chrg_done() ? 1 : 0; - } +#ifdef ENABLE_CC_CYCLE + (void)charge_ic_read_cc_status(&cc_status); #endif - } else { - if (vbus_pg != NULL) { - *vbus_pg = 0; - } - if (chrg_fast != NULL) { - *chrg_fast = 0; - } - if (chrg_done != NULL) { - *chrg_done = 0; - } - } -#else if (vbus_pg != NULL) { - *vbus_pg = 0; + *vbus_pg = cc_status.vbus_pg; } if (chrg_fast != NULL) { - *chrg_fast = 0; + *chrg_fast = cc_status.chrg_active; } if (chrg_done != NULL) { - *chrg_done = 0; + *chrg_done = cc_status.chrg_done; } -#endif } static void cc_capture_defect_snapshot(uint8_t defect_type, uint8_t soc, uint32_t now)