feat(drivers): 添加IP5306 PMIC驱动支持
- 添加IP5306 PMIC驱动实现,包括I2C通信和GPIO唤醒功能 - 实现电源管理芯片的状态读取接口(充电状态、满电状态) - 集成Wakeup保持脉冲功能,支持可配置的脉冲宽度和间隔时间 - 添加设备树绑定文件和Kconfig配置选项 refactor(blinky): 集成IP5306电源管理芯片到电池模块 - 在电池模块中集成IP5306 PMIC状态监控功能 - 修改日志输出格式,显示电池电压及充电/满电状态 - 增加设备初始化检查和错误处理机制 - 配置电源管理限制级别为暂停模式 build: 配置CMakeLists.txt以包含驱动子目录 - 更新主CMakeLists.txt文件添加drivers子目录 - 配置驱动程序的构建层次结构(pmic -> ip5306) - 设置条件编译目标源文件 docs: 添加设备树和板级配置支持 - 添加mini_keyboard板的I2C引脚控制配置 - 配置IP5306设备节点和相关GPIO引脚定义 - 启用I2C配置选项以支持PMIC通信
This commit is contained in:
@@ -5,8 +5,10 @@
|
||||
|
||||
#define MODULE battery_module
|
||||
#include <caf/events/module_state_event.h>
|
||||
#include <caf/events/power_manager_event.h>
|
||||
#include <caf/events/power_event.h>
|
||||
|
||||
#include <drivers/pmic/ip5306.h>
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/devicetree.h>
|
||||
#include <zephyr/drivers/sensor.h>
|
||||
@@ -17,12 +19,16 @@
|
||||
LOG_MODULE_REGISTER(MODULE, LOG_LEVEL_INF);
|
||||
|
||||
#define VBATT_NODE DT_PATH(vbatt)
|
||||
#define IP5306_NODE DT_NODELABEL(ip5306)
|
||||
#define BATTERY_SAMPLE_INTERVAL K_SECONDS(1)
|
||||
|
||||
BUILD_ASSERT(DT_NODE_HAS_STATUS(VBATT_NODE, okay),
|
||||
"Missing /vbatt voltage-divider node in devicetree");
|
||||
BUILD_ASSERT(DT_NODE_HAS_STATUS(IP5306_NODE, okay),
|
||||
"Missing ip5306 node in devicetree");
|
||||
|
||||
static const struct device *const vbatt_dev = DEVICE_DT_GET(VBATT_NODE);
|
||||
static const struct device *const ip5306_dev = DEVICE_DT_GET(IP5306_NODE);
|
||||
static struct k_work_delayable battery_sample_work;
|
||||
static bool initialized;
|
||||
static bool running;
|
||||
@@ -48,7 +54,9 @@ static int measurement_enable(bool enable)
|
||||
|
||||
static void battery_sample_fn(struct k_work *work)
|
||||
{
|
||||
struct ip5306_status pmic_status;
|
||||
struct sensor_value voltage;
|
||||
int voltage_mv;
|
||||
int err;
|
||||
|
||||
ARG_UNUSED(work);
|
||||
@@ -69,7 +77,15 @@ static void battery_sample_fn(struct k_work *work)
|
||||
goto reschedule;
|
||||
}
|
||||
|
||||
LOG_INF("Battery voltage: %d mV", sensor_value_to_mv(&voltage));
|
||||
err = ip5306_get_status(ip5306_dev, &pmic_status);
|
||||
if (err) {
|
||||
LOG_WRN("IP5306 status read failed (%d)", err);
|
||||
goto reschedule;
|
||||
}
|
||||
|
||||
voltage_mv = sensor_value_to_mv(&voltage);
|
||||
LOG_INF("Battery: %d mV, charging=%d, full=%d",
|
||||
voltage_mv, pmic_status.charging, pmic_status.full);
|
||||
|
||||
reschedule:
|
||||
if (running) {
|
||||
@@ -84,7 +100,19 @@ static int module_init(void)
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
if (!device_is_ready(ip5306_dev)) {
|
||||
LOG_ERR("ip5306 device not ready");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
int err = ip5306_init(ip5306_dev);
|
||||
if (err) {
|
||||
LOG_ERR("ip5306 init failed (%d)", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
k_work_init_delayable(&battery_sample_work, battery_sample_fn);
|
||||
power_manager_restrict(MODULE_IDX(MODULE), POWER_MANAGER_LEVEL_SUSPENDED);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user