Commit graph zephyr/drivers/fuel_gauge
Author SHA1 Message Date
Benjamin Cabé
5e1dee02db drivers: fuel_gauge: sbs_gauge: log emulator accesses at debug level
The SBS gauge emulator logged every register read and write at the info
level, so tests and applications that read an emulated gauge
periodically filled their log with them. Log them at the debug level.

Tested with the sbs_gauge tests on native_sim and qemu_x86.

Assisted-by: Claude:opus-5.5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-10-13 09:37:26 +02:00
Johannes Schuler
48b86a8c4f drivers: fuel_gauge: add fuel_gauge_set_buffer_prop
Add a set_buffer_property driver callback and the matching
fuel_gauge_set_buffer_prop() syscall so applications can write variable
length buffer properties, such as configuration images or manufacturer
defined data blocks, to a fuel gauge device. This mirrors the existing
fuel_gauge_get_buffer_prop() API.

The source is documented as an opaque, pointer-free byte buffer because
the syscall verifier can only validate the src/src_len range itself.

The callback is optional. The verifier checks the device object and the
source buffer only and leaves the callback check to
z_impl_fuel_gauge_set_buffer_prop(), so user mode callers get -ENOSYS
instead of a kernel oops when a driver does not implement it.

Signed-off-by: Johannes Schuler <jschuler@testo.de>
Assisted-by: Claude:claude-fable-5-1
2026-09-21 16:27:06 -04:00
Jordan Yates
0e7f6866ab fuel_gauge: composite: limit SoC from charger state
Allow connecting the `fuel-gauge-composite` instance to a charger
device, to limit the reported SoC to 99% while still charging, and
forcing it to 100% when charging terminates.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2026-09-10 12:16:25 +02:00
Jordan Yates
b536c10dc7 fuel_gauge: composite: compensate internal resistance
If we have a measured current and a configured internal resistance,
adjust the measured voltage to provide a less jumpy state-of-charge
computation under charging conditions.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2026-09-10 12:16:25 +02:00
Jordan Yates
8357803e1d fuel_gauge: composite: update next sample time
Set the time for the next sample from the point the sampling finishes,
not from when `composite_get_prop` is called.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2026-09-10 12:16:25 +02:00
Benjamin Cabé
de17503453 drivers: fuel_gauge: composite: Store capacity on sensor fetch success
When composite_channel_get() succeeds (rc == 0) for
FUEL_GAUGE_FULL_CHARGE_CAPACITY_UAH or FUEL_GAUGE_DESIGN_CAPACITY,
the function previously skipped assigning the fetched sensor_val into
val->full_charge_capacity_uah or val->design_cap. Handle rc == 0 to
correctly populate the property.

Assisted-by: Antigravity:gemini-3.6-flash
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-08-23 14:41:44 -04:00
Philipp Steiner
be5e77c5b8 cleanup: remove copyright emails and reformat networking sources
Remove my email address from copyright notices across
board, fuel-gauge, networking, sample, and test files

Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
2026-08-20 14:14:56 +02:00
Flavio Ceolin
0d65ce46dd drivers: fuel_gauge: reject oversized len
The userspace verifiers for fuel_gauge_get_props() and
fuel_gauge_set_props() declared two variable-length arrays sized by the
caller-supplied len argument:

  union fuel_gauge_prop_val k_vals[len];
  fuel_gauge_prop_t k_props[len];

Both VLAs were allocated before any validation, including before the
K_SYSCALL_DRIVER_FUEL_GAUGE() object check. Fix it removing the kernel
copy of these data. That is safe becasue there is no embbeded pointers.

Signed-off-by: Flavio Ceolin <flavio@hubble.com>
2026-08-11 20:56:21 -04:00
Jeff Sun
794960511c driver: fuel_gauge: hy4245: add state of health support
Add support for getting the State of Health (SOH) property from the
hy4245 fuel gauge driver.

Signed-off-by: Jeff Sun <jsun@testo.net.cn>
2026-08-03 08:49:37 -04:00
Benjamin Cabé
6b13ddc117 drivers: fuel_gauge: sbs_gauge: Cast average current to signed int16
SBS_GAUGE_CMD_AVG_CURRENT returns a 16-bit signed integer (in mA,
negative when discharging). Cast tmp_val to int16_t before
multiplying by 1000 so negative values are properly extended to
int32_t instead of producing large positive uA values.

Assisted-by: Antigravity:gemini-3.6-flash
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-07-28 11:34:05 +01:00
Benjamin Cabé
efd0c6c2aa drivers: fuel_gauge: lc709203f: Propagate error code from temp mode config
Store the return value of lc709203f_set_temp_mode() in ret so errors
during temperature mode configuration are properly logged and detected
rather than testing a stale return value.

Assisted-by: Antigravity:gemini-3.6-flash
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-07-23 18:01:45 -04:00
Florian Moesch
8110e732b4 drivers: fuel_gauge: fix FUEL_GAUGE_CYCLE_COUNT to whole cycles
FUEL_GAUGE_CYCLE_COUNT was documented and treated inconsistently:

Drivers had inconsistently been reporting full charge/discharge cycles or
"1/100ths" of a cycle in the ``FUEL_GAUGE_CYCLE_COUNT`` property.
The property now consistently reports full cycles, and drivers that
previously reported fractions of a cycle (i.e. ADP5360 and BQ27Z746) have
been updated to report full cycles instead.
Applications that relied on the old behavior should be updated.

Signed-off-by: Florian Moesch <florian.moesch@draeger.com>
2026-07-01 23:45:05 -04:00
Dev Joshi
5ac0d14e42 drivers: fg: Add units to enum/union fields
This commit adds units to fields in enums and union. It marks the
legacy enum/union fields as __deprecated as they will be removed in next
release.

It also updates the release notes and migration notes with the
deprecation notice as required by the policy.

Signed-off-by: Dev Joshi <devbhave@qti.qualcomm.com>
2026-06-12 10:05:28 +02:00
Jan Carlo Roleda
497b9b25a0 drivers: fuel_gauge: Add Fuel Gauge Driver for ADP5360
Implements fuel gauge subsystem for ADP5360 MFD driver.

Signed-off-by: Jan Carlo Roleda <jancarlo.roleda@analog.com>
Co-authored-by: Francis Roi Manabat <francisroi.manabat@analog.com>
2026-04-20 18:10:14 +02:00
Pisit Sawangvonganan
edae0e7e30 drivers: fix typo in (ethernet, flash, fpga, fuel_gauge, gpio, i2c)
Utilize a code spell-checking tool to scan for and correct spelling errors
in all files within:
- `drivers/ethernet`
- `drivers/flash`
- `drivers/fpga`
- `drivers/fuel_gauge`
- `drivers/gpio`
- `drivers/i2c`

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2026-03-27 20:21:24 -04:00
Dev Joshi
925224a98e drivers: fuelgauge: add support for SOH property
This commit adds support for State-of-Health (SOH) property in the
fuel_gauge subsystem.

Signed-off-by: Dev Joshi <devbhave@qti.qualcomm.com>
2026-02-20 10:28:42 -08:00
Fin Maaß
0957115fc9 drivers: fuel_gauge: i2c: replace use of i2c_burst_write
i2c_burst_write is not portable,
as it is not supported by some drivers,
replace its use with i2c_write.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2026-01-07 17:30:32 +01:00
Saravanan Sekar
89df5f55ed drivers: fuelgauge: Add Hycon Technology HY4245 driver
Add a support for Hycon Technology HY4245 fuel gauge driver.

The HY4245 operates with Single and Two Cells Li+ battery cells as a
stand–along battery gauge. The device uses GaugePackTM algorithm, which
mixes Coulomb–Counting and Open–Circuit–Voltage (OCV) measurements with
battery cell characteristics to manage battery gauge, to maintain accurate
battery capacity estimates with compensation for rate, temperature, age
and self–discharge effects.

Signed-off-by: Saravanan Sekar <saravanan@linumiz.com>
2025-11-24 14:58:39 -05:00
Josuah Demangeon
30950b888d style: drivers: sort Kconfig and CMake includes
Use the "zephyr-keep-sorted-start/stop" comment to have CI check
the alphabetical order of includes, to help reducing the chance
of conflicts while contributing drivers.

Signed-off-by: Josuah Demangeon <me@josuah.net>
2025-11-17 13:48:03 -05:00
Benjamin Cabé
a6a520da26 drivers: fuel_gauge: remove dead code in set_prop functions
Remove useless assignments to `val` parameter in sbs_gauge_set_prop()
and bq27z746_set_prop(). Since `val` is passed by value, modifying it
has no effect. Also remove unused `tmp_val` variable.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-10-31 20:03:00 -04:00
Anas Nashif
303af992e5 style: fix 'if (' usage in cmake files
Replace with 'if(' and 'else(' per the cmake style guidelines.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-10-29 11:44:13 +02:00
Tahsin Mutlugun
b1c497ce02 drivers: fuel_gauge: ltc2959: Fix build warnings from declarations
C standards prior to C23 do not allow variable declarations immediately
after labels. Wrap such declarations in blocks to eliminate build
warnings.

Signed-off-by: Tahsin Mutlugun <Tahsin.Mutlugun@analog.com>
2025-10-22 18:03:30 -04:00
Nathan Winslow
22710b7a14 drivers: fuelgauge: Added properties to prop_type.
Adds properties to fuel gauge api to support ADI LTC2959.

Signed-off-by: Nathan Winslow <natelostintimeandspace@gmail.com>
2025-10-22 18:35:37 +03:00
Jordan Yates
892013a5c6 fuel_gauge: composite: fix unreleased PM constraint
Fix the PM constraint not being released when the sample fetch API call
fails.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-10-13 08:54:24 +02:00
Dev Joshi
9320bd2911 drivers: fuelgauge: add support for TI bq40z50 chip
This commit adds driver support for bq40z50 fuel gauging chip from Texas
Instruments.

Signed-off-by: Dev Joshi <quic_devbhave@quicinc.com>
2025-09-09 21:42:23 -07:00
Philipp Steiner
df2af8d553 drivers: fuel_gauge: max17048: fix minor issues
Fixes minor issues of the max17048 driver, which came up during
another PR.
This was tested with the CI and the Adafruit ESP32-S3 Reverse TFT Feather.

Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
2025-09-04 21:03:48 +02:00
Philipp Steiner
7632193e42 drivers: fuel_gauge: apply clang-format rules for the drivers
Format existing drivers according to clang-format rules.
Not all drivers were formatted, according to the clang-format rules,
this commit resolves this.

Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
2025-09-04 21:03:48 +02:00
Philipp Steiner
175dc28b1f drivers: fuel_gauge: Refactor public driver interfaces
Refactor drivers so all have the same clean public interface.
With this change, all drivers have the same coding style.
This change does not change how the driver works and was tested with
the "fuel-gauge-build all test"

Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
2025-09-04 21:03:48 +02:00
Dmitrii Sharshakov
81455310b3 fuel_gauge: sy24561: improve emulation
Fix issues found by ASan, log register writes for inspection using
console harness.

Fixes: 5f84be617e

Signed-off-by: Dmitrii Sharshakov <d3dx12.xx@gmail.com>
2025-08-20 02:17:37 +02:00
Franck Duriez
5f84be617e driver: fuel_gauge/sy24561: add emulator
Add emulator for fuel gauge SY24561

Signed-off-by: Franck Duriez <franck.lucien.duriez@gmail.com>
2025-08-01 12:20:25 -04:00
Franck Duriez
8ef13d072e driver: fuel_gauge/sy24561: add driver
Add driver for silergy sy24561 fuel gauge

Signed-off-by: Franck Duriez <franck.lucien.duriez@gmail.com>
2025-08-01 12:20:25 -04:00
Jordan Yates
1e6af82e80 fuel_gauge: composite: query sources for capacity and soc
Query the configured data sources for capacity and soc information
before falling back to the composite fuel gauge configuration. This
means the battery properties are no longer required.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-07-31 17:16:53 -04:00
Jordan Yates
3ef54ccc5c fuel_gauge: composite: support FUEL_GAUGE_TEMPERATURE
Add support for the `FUEL_GAUGE_TEMPERATURE` property.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-07-31 17:16:53 -04:00
Jordan Yates
da526b51a8 fuel_gauge: composite: choose sensor channel types
Choose whether the data sources should be queried by the generic sensor
channels (`SENSOR_CHAN_VOLTAGE`, etc), or the fuel guage specific
channels (`SENSOR_CHAN_GAUGE_*`).

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-07-31 17:16:53 -04:00
Jordan Yates
7827b7e4ca fuel_gauge: composite: more flexible data sourcing
Instead of explicitly specifying the source for the voltage and current
channels, specify primary and secondary data sources. If the requested
sensor channel does not exist on the primary source, the secondary
source will be tried.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-07-31 17:16:53 -04:00
Jordan Yates
aed7ae5dda fuel_gauge: composite: switch to tick based sampling
To ensure that data is consistent across multiple sequential calls to
`fuel_gauge_get_prop`, sensor_fetch is only called if a certain time
period has passed since the previous sampling. This emulates the
tick-based sampling of most dedicated fuel-gauge devices.

Signed-off-by: Jordan Yates <jordan@embeint.com>

tick
2025-07-31 17:16:53 -04:00
Matt Wood
678f1bdba7 fuel_gauge: restructure cmake libraries
Adjusted drivers to include sources into a single library
to allow for the use of zephyr_library_amend when extending
with out of tree drivers in workspace projects inline with other
driver groups structure

Signed-off-by: Matt Wood <matt.wood@corintech.com>
2025-07-31 16:50:59 -04:00
Pisit Sawangvonganan
b8a8173c1f drivers: kconfig: fix typo
Utilize a code spell-checking tool to scan for and correct spelling errors
in `Kconfig` files within the `drivers` directory.
Additionally, incorporates a fix recommended by the reviewer.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2025-07-01 10:58:54 -10:00
Alberto Escolar Piedras
3197e7a89d drivers/fuel_gauge/lc709203f: Avoid declaring var right after label
Avoid the following clang error
`error: label followed by a declaration is a C23 extension`
by writing this switch case as a codeblock.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-07-01 05:56:25 -10:00
Philipp Steiner
f7e723dad1 drivers: fuelgauge: Add Onsemi LC709203F driver
Add driver for the Onsemi LC709203F fuel gauge

Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
2025-06-26 22:08:44 -05:00
Felix Moessbauer
84ebbdcd4b fuel_gauge: add basic support for AXP2101 chip
The AXP2101 chip is a multi functional power chip offering a regulator,
charge controller and a fuel gauge (battery percentage and voltage).
Hereby, the fuel gauge provides much more reliable data compared to using
an ADC.

We implement minimal support for this chip (connected state, voltage and
gauge) and bind it to the fuel gauge subsystem.

Closes: #89158
Signed-off-by: Felix Moessbauer <felix.moessbauer@gmail.com>
2025-05-22 04:51:27 +02:00
Mikkel Jakobsen
e4c21da41b drivers: fuel_gauge: make read-only pointer args const in api
For the lists of properties passed as a pointer to the get_props and
set_props functions, there is no reason to not make the pointer const as
the called functions will not and should not alter the pointed-to data.

In practice, not having the pointers const can cause compilation errors
if trying to pass in a const array of properties.

Signed-off-by: Mikkel Jakobsen <mikkel.aunsbjerg@escolifesciences.com>
2024-12-24 13:54:15 +01:00
Pieter De Gendt
4483b7ebb7 drivers: fuel_gauge: Place API into iterable section
Add wrapper DEVICE_API macro to all fuel_gauge_driver_api instances.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-12-04 14:16:06 -05:00
Jordan Yates
8345775de0 fuel_gauge: sbs_gauge: fix negative currents
Fix negative currents being read as extremely high currents due to
unsigned variable use.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-11-16 13:35:03 -05:00
Pisit Sawangvonganan
847a4eaad2 style: drivers: comply with MISRA C:2012 Rule 15.6
Add missing braces to comply with MISRA C:2012 Rule 15.6 and
also following Zephyr's style guideline.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-09-11 07:40:35 -04:00
Jordan Yates
39a582a9ec fuel_gauge: composite analog fuel gauge
Construct a device that implements the fuel-gauge API from a collection
of analog sensing inputs.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-08-29 16:12:36 -04:00
Rahul Goyal
f1e38e73d7 Drivers: max17048: updated voltage parameter output
present output shows voltage in mV.
updated output shows voltage in uV.

Signed-off-by: Rahul Goyal <goyalrahul1516@gmail.com>
2024-07-10 11:36:28 +02:00
Yong Cong Sin
bbe5e1e6eb build: namespace the generated headers with zephyr/
Namespaced the generated headers with `zephyr` to prevent
potential conflict with other headers.

Introduce a temporary Kconfig `LEGACY_GENERATED_INCLUDE_PATH`
that is enabled by default. This allows the developers to
continue the use of the old include paths for the time being
until it is deprecated and eventually removed. The Kconfig will
generate a build-time warning message, similar to the
`CONFIG_TIMER_RANDOM_GENERATOR`.

Updated the includes path of in-tree sources accordingly.

Most of the changes here are scripted, check the PR for more
info.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-05-28 22:03:55 +02:00
Roman Studenikin
260fc89643 drivers: use DT_INST_PROP over DT_INST_PROP_OR if possible
It might happens that DT(_INST)_PROP_OR is used with boolean properties.
For instance:

	.single_wire = DT_INST_PROP_OR(index, single_wire, false),	\
	.tx_rx_swap = DT_INST_PROP_OR(index, tx_rx_swap, false),	\

This is not required as boolean properties are generated with false
value when not present, so the _OR macro extension is superflous
and the above code can be replaced by:

	.single_wire = DT_INST_PROP(index, single_wire),		\
	.tx_rx_swap = DT_INST_PROP(index, tx_rx_swap),			\

Signed-off-by: Roman Studenikin <srv@meta.com>
2024-01-30 00:26:58 +00:00
Anas Nashif
a08bfeb49c syscall: rename Z_OOPS -> K_OOPS
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00