From b16eea4f14a50ff178baf6043a6f9d6d34f906b7 Mon Sep 17 00:00:00 2001 From: zhangguoliang Date: Mon, 8 Nov 2021 19:46:56 +0800 Subject: [PATCH] feat: charger: add operation to get out voltage Signed-off-by: zhangguoliang --- drivers/power/battery_charger.c | 10 ++++++++++ include/nuttx/power/battery_charger.h | 4 ++++ include/nuttx/power/battery_ioctl.h | 1 + 3 files changed, 15 insertions(+) diff --git a/drivers/power/battery_charger.c b/drivers/power/battery_charger.c index 35e883a4f0..ea62a10ccd 100644 --- a/drivers/power/battery_charger.c +++ b/drivers/power/battery_charger.c @@ -370,6 +370,16 @@ static int bat_charger_ioctl(FAR struct file *filep, int cmd, } break; + case BATIOC_GET_VOLTAGE: + { + FAR int *outvoltsp = (FAR int *)((uintptr_t)arg); + if (outvoltsp) + { + ret = dev->ops->get_voltage(dev, outvoltsp); + } + } + break; + default: _err("ERROR: Unrecognized cmd: %d\n", cmd); ret = -ENOTTY; diff --git a/include/nuttx/power/battery_charger.h b/include/nuttx/power/battery_charger.h index 6829925d47..eee63486ca 100644 --- a/include/nuttx/power/battery_charger.h +++ b/include/nuttx/power/battery_charger.h @@ -122,6 +122,10 @@ struct battery_charger_operations_s /* Get chip id */ int (*chipid)(struct battery_charger_dev_s *dev, unsigned int *value); + + /* Get the actual output voltage for charging */ + + int (*get_voltage)(struct battery_charger_dev_s *dev, int *value); }; /* This structure defines the battery driver state structure */ diff --git a/include/nuttx/power/battery_ioctl.h b/include/nuttx/power/battery_ioctl.h index 6aa9b7d9ae..90be4614e6 100644 --- a/include/nuttx/power/battery_ioctl.h +++ b/include/nuttx/power/battery_ioctl.h @@ -55,6 +55,7 @@ #define BATIOC_CLEARFAULTS _BATIOC(0x000F) #define BATIOC_COULOMBS _BATIOC(0x0010) #define BATIOC_CHIPID _BATIOC(0x0011) +#define BATIOC_GET_VOLTAGE _BATIOC(0x0012) /* Special input values for BATIOC_INPUT_CURRENT that may optionally * be supported by lower-half driver: