From 7ad2adcfd707da0cde0bee5b370509447e6eae68 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Wed, 6 May 2026 11:08:35 +0800 Subject: [PATCH] =?utf8?q?debug=E9=A1=B5=E9=9D=A2=E6=B7=BB=E5=8A=A0?= =?utf8?q?=E5=85=85=E7=94=B5ic=E5=AF=84=E5=AD=98=E5=99=A8=E6=89=93?= =?utf8?q?=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../fd272/service/msg_center/CMakeLists.txt | 1 + .../debug_output_notification.h | 1 + .../debug_output_notification.cpp | 20 ++++++ .../sdk/zhihui/drivers/charge/hp4570/hp4570.c | 63 +++++++++++++++++++ .../sdk/zhihui/drivers/charge/hp4570/hp4570.h | 4 ++ 5 files changed, 89 insertions(+) diff --git a/code/sdk/application/wearable/fd272/service/msg_center/CMakeLists.txt b/code/sdk/application/wearable/fd272/service/msg_center/CMakeLists.txt index 7a1dba1bb..86e0922b0 100644 --- a/code/sdk/application/wearable/fd272/service/msg_center/CMakeLists.txt +++ b/code/sdk/application/wearable/fd272/service/msg_center/CMakeLists.txt @@ -151,6 +151,7 @@ set(PRIVATE_HEADER ${ROOT_DIR}/application/wearable/fd272/nativeapp/nativeui/ ${ROOT_DIR}/zhihui/drivers + ${ROOT_DIR}/zhihui/drivers/charge/hp4570 ${ROOT_DIR}/zhihui/services ${ROOT_DIR}/zhihui/UI/producttest/include/ ) diff --git a/code/sdk/application/wearable/fd272/service/msg_center/include/notify/debug_output_notification/debug_output_notification.h b/code/sdk/application/wearable/fd272/service/msg_center/include/notify/debug_output_notification/debug_output_notification.h index 08aabfd7f..ddc157bcd 100644 --- a/code/sdk/application/wearable/fd272/service/msg_center/include/notify/debug_output_notification/debug_output_notification.h +++ b/code/sdk/application/wearable/fd272/service/msg_center/include/notify/debug_output_notification/debug_output_notification.h @@ -43,6 +43,7 @@ namespace OHOS std::string get_uart_at_status(void); std::string get_current_vote_status(void); std::string get_offline_log_status(void); + std::string get_hp4570_register_dump(void); private: diff --git a/code/sdk/application/wearable/fd272/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp b/code/sdk/application/wearable/fd272/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp index 624a85180..bab0c5838 100644 --- a/code/sdk/application/wearable/fd272/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp +++ b/code/sdk/application/wearable/fd272/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp @@ -58,6 +58,11 @@ #ifdef SUPPORT_BATTERY_SERVICE #include "battery_hal.h" #include "battery_service.h" +#if defined(ENABLE_HP4570) +extern "C" { +#include "hp4570.h" +} +#endif #endif #ifdef SUPPORT_CAT1_SERVICE @@ -192,6 +197,7 @@ namespace OHOS debugOutputItemInfo[index++] = {index, "CAT1升级"}; debugOutputItemInfo[index++] = {index, "CWM日志开关"}; + debugOutputItemInfo[index++] = {index, "充电iC寄存器的值"}; usedLen = index; /* -------------------------------- 添加数据 -------------------------------- */ @@ -854,6 +860,17 @@ namespace OHOS return std::string("offline_log_status:") + std::to_string(offline); } + std::string DebugOutputViewEventListener::get_hp4570_register_dump(void) + { +#if defined(SUPPORT_BATTERY_SERVICE) && defined(ENABLE_HP4570) + char buf[2048]; + (void)hp4570n_dump_debug_registers(buf, sizeof(buf)); + return std::string(buf); +#else + return "HP4570 未启用(需 SUPPORT_BATTERY_SERVICE + ENABLE_HP4570)"; +#endif + } + bool DebugOutputViewEventListener::OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event) { std::string viewId = view.GetViewId(); @@ -1196,6 +1213,9 @@ namespace OHOS } } break; + case 22: + str = get_hp4570_register_dump(); + break; default: str = "--"; break; diff --git a/code/sdk/zhihui/drivers/charge/hp4570/hp4570.c b/code/sdk/zhihui/drivers/charge/hp4570/hp4570.c index c7d8ab87e..3f568411a 100644 --- a/code/sdk/zhihui/drivers/charge/hp4570/hp4570.c +++ b/code/sdk/zhihui/drivers/charge/hp4570/hp4570.c @@ -20,6 +20,7 @@ #include "hp4570.h" #include "custom_utils.h" +#include struct CHIP_STATE{ bool vin_fault; @@ -50,6 +51,68 @@ static bool hp4570n_read_reg(uint8_t reg, uint8_t *value){ return custom_i2c_read_regs(hp4570n_i2c_addr, reg, 1, value, 1, HP4570N_I2C_BUS); } +size_t hp4570n_dump_debug_registers(char *buf, size_t buf_len) +{ + static const struct { + uint8_t reg; + const char *name; + } rows[] = { + { HP4570N_REG_DPM_SET, "DPM_SET" }, + { HP4570N_REG_SYS_CTRL0, "SYS_CTRL0" }, + { HP4570N_REG_SYS_CTRL1, "SYS_CTRL1" }, + { HP4570N_REG_IDSG_ITERM_SET, "IDSG_ITERM_SET" }, + { HP4570N_REG_BAT_VOL_SET, "BAT_VOL_SET" }, + { HP4570N_REG_SYS_CTRL2, "SYS_CTRL2" }, + { HP4570N_REG_SYS_CTRL3, "SYS_CTRL3" }, + { HP4570N_REG_SYS_CTRL4, "SYS_CTRL4" }, + { HP4570N_REG_CHIP_STAT0, "CHIP_STAT0" }, + { HP4570N_REG_CHIP_STAT1, "CHIP_STAT1" }, + { HP4570N_REG_CHIP_STAT2, "CHIP_STAT2" }, + { HP4570N_REG_VIPRE, "VIPRE" }, + { HP4570N_REG_EXT_CTRL, "EXT_CTRL" }, + { HP4570N_REG_SYS_CTRL5, "SYS_CTRL5" }, + { HP4570N_REG_SYS_CTRL6, "SYS_CTRL6" }, + { HP4570N_REG_SYS_CTRL7, "SYS_CTRL7" }, + { HP4570N_REG_SYS_WAKE_UP_SRC, "SYS_WAKE_UP_SRC" }, + { HP4570N_REG_INT0_ENABLE, "INT0_ENABLE" }, + { HP4570N_REG_INT0_STAT, "INT0_STAT" }, + { HP4570N_REG_VID_LSB, "VID_LSB" }, + { HP4570N_REG_VID_MSB, "VID_MSB" }, + { HP4570N_REG_PID_LSB, "PID_LSB" }, + { HP4570N_REG_PID_MSB, "PID_MSB" }, + { HP4570N_REG_CHIP_VER, "CHIP_VER" }, + }; + + if (buf == NULL || buf_len == 0) { + return 0; + } + buf[0] = '\0'; + size_t off = 0; + for (size_t i = 0; i < sizeof(rows) / sizeof(rows[0]); i++) { + uint8_t v = 0; + int n; + /* custom_i2c_read_regs returns ERRCODE_SUCC(0) on success; hp4570n_read_reg wrongly casts that to bool false */ + errcode_t rc = custom_i2c_read_regs(hp4570n_i2c_addr, rows[i].reg, 1, &v, 1, HP4570N_I2C_BUS); + if (rc == ERRCODE_SUCC) { + n = snprintf(buf + off, buf_len - off, "%s(0x%02x):0x%02x\n", + rows[i].name, (unsigned int)rows[i].reg, v); + } else { + n = snprintf(buf + off, buf_len - off, "%s(0x%02x):read fail(0x%x)\n", + rows[i].name, (unsigned int)rows[i].reg, (unsigned int)rc); + } + if (n < 0) { + break; + } + if ((size_t)n >= buf_len - off) { + off = buf_len - 1; + break; + } + off += (size_t)n; + } + buf[buf_len - 1] = '\0'; + return off; +} + #define INPUT_PARA_FAIL_RETURN(value, min, max) \ do { \ if (value < min || value > max) \ diff --git a/code/sdk/zhihui/drivers/charge/hp4570/hp4570.h b/code/sdk/zhihui/drivers/charge/hp4570/hp4570.h index 9858a2f9f..216dae718 100644 --- a/code/sdk/zhihui/drivers/charge/hp4570/hp4570.h +++ b/code/sdk/zhihui/drivers/charge/hp4570/hp4570.h @@ -23,6 +23,7 @@ #ifndef HP4570N_CHARGER_H #define HP4570N_CHARGER_H +#include #include #include #include "std_def.h" @@ -423,6 +424,9 @@ static const uint16_t HP4570N_t_hiccup_time[HP4570N_NUM_T_HICCUP_VAL] = { bool hp4570n_init(uint8_t chip_ver); bool hp4570n_identify(uint8_t chip_ver); +/** Dump key charger registers into buf (NUL-terminated). Returns written length (excluding NUL). */ +size_t hp4570n_dump_debug_registers(char *buf, size_t buf_len); + void hp4570n_set_pwrkey_en(bool en);// PWRKEY function enable control bool hp4570n_set_trst_dgl_mS(uint32_t time);// Pull INT low to disconnect the battery then auto on -- 2.17.1