From c0762d003aa7c8b8653d61629c569ca3b8838c65 Mon Sep 17 00:00:00 2001 From: Aaron Massey Date: Wed, 30 Nov 2022 16:09:12 -0700 Subject: [PATCH] fuel_gauge: Implement sbs gauge read for mfr acc Implement and weakly test fetching the manufacturer access word from an SBS compatible fuel gauge. Signed-off-by: Aaron Massey --- drivers/fuel_gauge/sbs_gauge/sbs_gauge.c | 4 ++++ subsys/emul/i2c/emul_sbs_gauge.c | 1 + tests/drivers/fuel_gauge/sbs_gauge/src/test_sbs_gauge.c | 3 +++ 3 files changed, 8 insertions(+) diff --git a/drivers/fuel_gauge/sbs_gauge/sbs_gauge.c b/drivers/fuel_gauge/sbs_gauge/sbs_gauge.c index 187eb9a720..38dbaab9a0 100644 --- a/drivers/fuel_gauge/sbs_gauge/sbs_gauge.c +++ b/drivers/fuel_gauge/sbs_gauge/sbs_gauge.c @@ -69,6 +69,10 @@ static int sbs_gauge_get_prop(const struct device *dev, struct fuel_gauge_get_pr rc = sbs_cmd_reg_read(dev, SBS_GAUGE_CMD_AVG_TIME2FULL, &val); prop->value.runtime_to_empty = val; break; + case FUEL_GAUGE_SBS_MFR_ACCESS: + rc = sbs_cmd_reg_read(dev, SBS_GAUGE_CMD_MANUFACTURER_ACCESS, &val); + prop->value.sbs_mfr_access_word = val; + break; case FUEL_GAUGE_STATE_OF_CHARGE: rc = sbs_cmd_reg_read(dev, SBS_GAUGE_CMD_ASOC, &val); prop->value.state_of_charge = val; diff --git a/subsys/emul/i2c/emul_sbs_gauge.c b/subsys/emul/i2c/emul_sbs_gauge.c index 97fb7e3906..dfbb5657c3 100644 --- a/subsys/emul/i2c/emul_sbs_gauge.c +++ b/subsys/emul/i2c/emul_sbs_gauge.c @@ -53,6 +53,7 @@ static int emul_sbs_gauge_reg_read(const struct emul *target, int reg, int *val) ARG_UNUSED(target); switch (reg) { + case SBS_GAUGE_CMD_MANUFACTURER_ACCESS: case SBS_GAUGE_CMD_VOLTAGE: case SBS_GAUGE_CMD_AVG_CURRENT: case SBS_GAUGE_CMD_TEMP: diff --git a/tests/drivers/fuel_gauge/sbs_gauge/src/test_sbs_gauge.c b/tests/drivers/fuel_gauge/sbs_gauge/src/test_sbs_gauge.c index c7ceebf216..bf35c228cf 100644 --- a/tests/drivers/fuel_gauge/sbs_gauge/src/test_sbs_gauge.c +++ b/tests/drivers/fuel_gauge/sbs_gauge/src/test_sbs_gauge.c @@ -123,6 +123,9 @@ ZTEST_F(sbs_gauge_new_api, test_get_props__returns_ok) { .property_type = FUEL_GAUGE_CYCLE_COUNT, }, + { + .property_type = FUEL_GAUGE_SBS_MFR_ACCESS, + }, }; int ret = fixture->api->get_property(fixture->dev, props, ARRAY_SIZE(props));