增加41562关机进入船运模式
authorcaisking <caiyqm@qq.com>
Thu, 11 Jun 2026 11:09:17 +0000 (19:09 +0800)
committercaisking <caiyqm@qq.com>
Thu, 11 Jun 2026 11:09:17 +0000 (19:09 +0800)
code/sdk/zhihui/UI/producttest/src/testchanging.cpp
code/sdk/zhihui/drivers/charge/sgm41562/sgm41562.c
code/sdk/zhihui/drivers/charge/sgm41562/sgm41562.h
code/sdk/zhihui/services/battery/service/charge_ic.cpp
code/sdk/zhihui/services/battery/service/charge_ic.h
code/sdk/zhihui/utils/custom_utils.c

index a6aeca3..cbcbd1f 100644 (file)
 extern "C"
 {
 #endif
-#endif
+#endif 
     #include "pm_veto.h"
     #include "pm.h"
 
+    #ifdef ENABLE_HP4570
+    #include "hp4570.h"
+    #endif
+
+
 #ifdef __cplusplus
 #if __cplusplus
 }
index 0ad02a7..f6bebb7 100644 (file)
@@ -10,6 +10,7 @@
 
 #include "sgm41562.h"
 #include "custom_utils.h"
+#include "tcxo.h"
 
 #undef pr_debug
 #define pr_debug printf
@@ -645,16 +646,61 @@ void sgm41562_entry_shutdown_lpm(void)
        printf("[%s] shutdown lpm done\n", __func__);
 }
 
-/** @brief 船运模式或关机低功耗(见 SGM41562_USE_FET_DIS_SHIP) */
+#define SGM41562_SHIP_ENTRY_DELAY_MS  1100
+
+/** @brief 进入船运:关 WDT/监测,REG00 允许 VIN 退出,REG06 FET_DIS 断 BAT→SYS */
 void sgm41562_entry_shipmode(void)
 {
-#ifdef SGM41562_USE_FET_DIS_SHIP
-       (void)sgm41562_ctrl_setting(REG_BIT_EN_CEB, true);
-       (void)sgm41562_ctrl_setting(REG_BIT_EN_HIZ, true);
-       (void)sgm41562_set_batfet_dis(true);
-#else
-       sgm41562_entry_shutdown_lpm();
-#endif
+       int ret;
+       uint8_t reg_val = 0;
+
+       ret = sgm41562_set_watchdog_timer(SGM41562_WDT_TIMER_DISABLE);
+       if (ret)
+               printf("[%s] disable watchdog fail %d\n", __func__, ret);
+
+       ret = sgm41562_ctrl_setting(REG_BIT_EN_TIMER, false);
+       if (ret)
+               printf("[%s] disable safety timer fail %d\n", __func__, ret);
+
+       ret = sgm41562_ctrl_setting(REG_BIT_EN_TERM, false);
+       if (ret)
+               printf("[%s] disable term fail %d\n", __func__, ret);
+
+       ret = sgm41562_ctrl_setting(REG_BIT_EN_NTC, false);
+       if (ret)
+               printf("[%s] disable NTC fail %d\n", __func__, ret);
+
+       ret = sgm41562_ctrl_setting(REG_BIT_EN_PCB_OTP, true);
+       if (ret)
+               printf("[%s] disable PCB OTP fail %d\n", __func__, ret);
+
+       ret = sgm41562_ctrl_setting(REG_BIT_EN_CEB, true);
+       if (ret)
+               printf("[%s] disable charge fail %d\n", __func__, ret);
+
+       ret = sgm41562_ctrl_setting(REG_BIT_EN_HIZ, true);
+       if (ret)
+               printf("[%s] enable HIZ fail %d\n", __func__, ret);
+
+       /* REG00:插 VBUS / nINT 可退出船运(规格书 Table 3) */
+       ret = sgm41562_update_bits(SGM41562_CHRG_REG_0,
+               SGM41562_VIN_EXIT_SHIP | SGM41562_INT_EXIT_SHIP,
+               SGM41562_VIN_EXIT_SHIP | SGM41562_INT_EXIT_SHIP);
+       if (ret)
+               printf("[%s] set ship exit bits fail %d\n", __func__, ret);
+
+       ret = sgm41562_ctrl_setting(REG_BIT_FET_DIS, true);
+       if (ret)
+               printf("[%s] FET_DIS fail %d\n", __func__, ret);
+
+       uapi_tcxo_delay_ms(SGM41562_SHIP_ENTRY_DELAY_MS);
+
+       if (sgm41562_read_reg(SGM41562_CHRG_REG_8, &reg_val) == 0) {
+               printf("[%s] REG08 PG_STAT=%u after ship entry\n", __func__,
+                       (unsigned int)((reg_val & SGM41562_PG_STAT) ? 1U : 0U));
+       }
+
+       printf("[%s] ship mode entry done\n", __func__);
 }
 
 bool sgm41562_set_chrg_ichg_mA(uint16_t current_mA)
index b21d3aa..d59629f 100644 (file)
@@ -346,9 +346,9 @@ void sgm41562_set_batfet_dis(bool en);
 void sgm41562_entry_shutdown_lpm(void);\r
 \r
 /**\r
- * @brief  进入船运/关机低功耗配置\r
- * @note   未定义 SGM41562_USE_FET_DIS_SHIP 时等同 sgm41562_entry_shutdown_lpm()\r
- * @note   定义 SGM41562_USE_FET_DIS_SHIP=1 且 nINT 有外部上拉时置 REG06 FET_DIS 进船运\r
+ * @brief  进入船运模式(REG06 FET_DIS,断 BAT→SYS)\r
+ * @note   需无 VIN;退出:插充电线(REG00 VIN_EXIT_SHIP)或 nINT 拉低 2s\r
+ * @note   nINT 需外部上拉;船运后 SYS 掉电,插 VBUS 可重新上电\r
  */\r
 void sgm41562_entry_shipmode(void);\r
 \r
index 37ad268..80ccb2b 100644 (file)
@@ -45,11 +45,13 @@ static charge_ic_type_t charge_ic_detect(void)
 
 #if defined(ENABLE_SGM41562)
     if (sgm41562_probe()) {
+        printf("[charge_ic] SGM41562 detected\n");
         return CHARGE_IC_TYPE_SGM41562;
     }
 #endif
 #if defined(ENABLE_HP4570)
     if (hp4570n_identify(HP4570N) == 0) {
+        printf("[charge_ic] HP4570 detected\n");
         return CHARGE_IC_TYPE_HP4570;
     }
 #endif
@@ -64,6 +66,7 @@ errcode_t charge_ic_init(void)
 
     g_charge_ic_type = charge_ic_detect();
     if (g_charge_ic_type == CHARGE_IC_TYPE_NONE) {
+        printf("[charge_ic] no charge IC detected\n");
         return ERRCODE_FAIL;
     }
 
@@ -266,6 +269,6 @@ void charge_ic_shutdown_lpm(void)
     }
 
 #if defined(ENABLE_SGM41562)
-    sgm41562_entry_shutdown_lpm();
+    sgm41562_entry_shipmode();
 #endif
 }
index 9b6fea1..b74fdf5 100644 (file)
@@ -43,7 +43,7 @@ charge_ic_type_t charge_ic_get_type(void);
 /** @brief 导出充电 IC 调试寄存器到 buf,返回写入字节数 */
 size_t charge_ic_dump_debug_registers(char *buf, size_t buf_len);
 
-/** @brief 关机前配置 SGM41562 进入低功耗(HP4570 无需处理) */
+/** @brief 关机前 SGM41562 进船运(FET_DIS);依赖开机 charge_ic_init 已识别 */
 void charge_ic_shutdown_lpm(void);
 
 #ifdef __cplusplus
index 6f1bc67..afb00c1 100644 (file)
@@ -356,14 +356,8 @@ void uapi_poweroff_device(void)
     PRINT("[PWR_FLOW] uapi_poweroff_device: poweroff_bt_dsp_display\r\n");
     poweroff_bt_dsp_display();
 #ifdef SUPPORT_BATTERY_SERVICE
-    {
-        char charge_ic_dump[512];
-        (void)charge_ic_dump_debug_registers(charge_ic_dump, sizeof(charge_ic_dump));
-        PRINT("[PWR_FLOW] charge_ic before shutdown lpm:\r\n%s\r\n", charge_ic_dump);
-        charge_ic_shutdown_lpm();
-        (void)charge_ic_dump_debug_registers(charge_ic_dump, sizeof(charge_ic_dump));
-        PRINT("[PWR_FLOW] charge_ic after shutdown lpm:\r\n%s\r\n", charge_ic_dump);
-    }
+    PRINT("[PWR_FLOW] uapi_poweroff_device: charge_ic shipmode\r\n");
+    charge_ic_shutdown_lpm();
 #endif
     PRINT("[PWR_FLOW] uapi_poweroff_device: mcu_poweroff\r\n");
     mcu_poweroff();