Commit graph

70 commits

Author SHA1 Message Date
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
Anas Nashif
1a9de05767 syscall: rename Z_SYSCALL_DRIVER_ -> K_SYSCALL_DRIVER_
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
Anas Nashif
9c4d881183 syscall: rename Z_SYSCALL_ to K_SYSCALL_
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
Anas Nashif
9c1aeb5fd3 syscall: rename z_user_ to k_usermode_
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
Anas Nashif
56fddd805a syscall: rename z_user_from_copy -> k_usermode_from_copy
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
Anas Nashif
4e396174ce kernel: move syscall_handler.h to internal include directory
Move the syscall_handler.h header, used internally only to a dedicated
internal folder that should not be used outside of Zephyr.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Martin Calsyn
12c0204b60 drivers: fuel_gauge: max17048: Fix overflow when calculating voltage
Annotate the calculation with type casts to force
promotion to uint32_t and then cast back down
to uint16_t for the return. This solves the issue
with invalid voltage (mV) values being returned
due to overflow during the conversion from the
register value on the max17048 chip.

Signed-off-by: Martin Calsyn <martin.calsyn@outcomex.com.au>
2023-10-13 19:07:38 +01:00
Aaron Massey
32b27384a6 fuel_gauge: Fix desired current/voltage units
The desired current/voltage properties make use of milliamps/volts while
the present current/voltage properties make use of microamps/volts.

Fix the desired current/voltage properties to be consistent with the
present current/voltage properties where they're most likely to be used
with.

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2023-10-09 19:01:49 +03:00
Aaron Massey
12cbfcf397 fuel_gauge: Repl property struct w/ union
Based on review of the similar charger driver API, it's been demonstrated
from the community that embedding a per value property type when fetching
properties. Separating off the property types from the property values
themselves also allow an array of property types to declared as static
const.

Break up fuel_gauge_property struct into a fuel_gauge_prop_val union and a
fuel_gauge_prop_t property type as inputs into fuel gauge API functions.

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2023-09-27 12:07:59 +02:00
Aaron Massey
329ecd1e12 fuel_gauge: Remove status from fuel gauge properties
Based on review of the similar charger driver API, it's been demonstrated
from the community that embedding a per value status code when fetching
multiple properties isn't particularly wanted or needed. It was largely
considered not worth the additional maintenance to have the extra per
property error information.

Remove the status field from the fuel_gauge property value structs.

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2023-09-27 12:07:59 +02:00
Aaron Massey
bddd88955d fuel_gauge: Add fuel_guage_set_props()
The fuel_gauge_set_prop() function prototype declares a function that sets
multiple fuel gauge properties at once. The naming suggests it ought to
fetch a singular property at a time. Moreso, some clients may just want to
set properties one at a time and may feel uncomfortable using a prototype
for fetching multiple properties when wanting to fetch them one at a time.

Modify fuel_gauge_set_prop() to fetch a single property and add
fuel_gauge_set_props() to support fetching multiple properties. Modify
existing tests/drivers/samples.

This is part of #61818 work.

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2023-09-27 12:07:59 +02:00
Aaron Massey
e294b16a2f fuel_gauge: Add fuel_guage_get_props()
The fuel_gauge_get_prop() function prototype declares a function that
retrieves multiple fuel gauge properties at once. The naming suggests it
ought to fetch a singular property at a time. Moreso, some clients may just
want to fetch properties one at a time and may feel uncomfortable using a
prototype for fetching multiple properties when wanting to fetch them one
at a time.

Modify fuel_gauge_get_prop() to fetch a single property and add
fuel_gauge_get_props() to support fetching multiple properties. Modify
existing tests/drivers/samples.

This is part of #61818 work.

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2023-09-27 12:07:59 +02:00
Aaron Massey
a7b25d599b fuel_gauge: Join get/set prop structs
The fuel gauge API uses separate get/set property structs to indicate what
properties are readable or writable. This lead to duplication in property
names and potential confusion for new users of the API. See issue #61818.
In addition to above, drivers already determine at runtime if a property is
supported for read or write actions.

Join the get/set fuel gauge property structs as a single struct.

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2023-09-18 10:38:59 +01:00
Fabio Baltieri
c99f7ec019 drivers: fuel_gauge: fix i2c_dump_msgs_rw argument
Fix another i2c_dump_msgs_rw:

/drivers/fuel_gauge/bq27z746/emul_bq27z746.c:282:26: warning: passing
argument 1 of ‘i2c_dump_msgs_rw’ from incompatible pointer type

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-09-13 12:37:32 +01:00
Marcel Krüger
387f3c2092 drivers: fuelgauge: Add TI BQ27z746 driver
Add driver for the Texas Instruments BQ27z746 fuel gauge

Signed-off-by: Marcel Krüger <marcel.krueger@ithinx.io>
2023-09-13 12:05:04 +02:00
Aaron Massey
c6fd21c5de emul: Remove unused ZTEST_DMEM in sbs emulator
The redefinition of ZTEST_DMEM in the SBS emulator is unused. We ought to
remove it as it's dead code.

Remove the unused #define ZTEST_DMEM.

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2023-09-12 17:23:00 +01:00
Aaron Massey
8035ec69fa emul: Add syscall support for fuel gauge emulators
In order to ease user thread testing with fuel gauges, enable syscalls for
the fuel gauge emulator backend API.

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2023-09-12 17:23:00 +01:00
Michał Barnaś
4aac1756a9 i2c: use device instead of name for i2c dump messages
This commit changes the parameter of i2c_dump_msgs function from
string name to pointer to the device structure.
It allows for comparison of device pointers and allow to use
the printed device name in i2c shell commands.

Signed-off-by: Michał Barnaś <mb@semihalf.com>
2023-09-06 17:54:53 +02:00
Daniel Leung
302f06534e fuel_gauge: sbs_gauge: fix uninitialized variable warning
The return variable rc in sbs_gauge_do_battery_cutoff() needs to
be initialized, or else it would return random value if the for
loop is never entered.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-08-23 19:36:41 -04:00
Aaron Massey
82bfb26446 fuel_gauge: Add battery cutoff support
Many fuel gauge ICs offer a battery cutoff/shipping mode functionality that
cutoff charge from the battery. This is often useful for preserving battery
charge on devices while in storage.

Add battery cutoff support to the fuel gauge API with a generic default SBS
driver showing an example of support in tests.

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2023-08-22 18:05:50 +02:00
Marcel Krüger
f2ba0b7ae2 drivers: fuel_gauge: max17048: Remov unused var
Remove the unused variable 'data' from function
max17048_emul_transfer_i2c()

Signed-off-by: Marcel Krüger <marcel.krueger@ithinx.io>
2023-07-13 09:21:52 +02:00
Aaron Massey
3e33d6af89 emul: SBS Gauge emulator reset rule
Since we have state that gets mutated between tests in the SBS fuel gauge
emulator we ought to reset its state before each test.

Add a reset rule to the SBS fuel gauge emulator that resets the state
before each test. Note: This includes allowing the emulator state to be
modified by user-threads.

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2023-07-07 09:22:20 +02:00
Aaron Massey
e1401fcf5e emul: Add SBS Gauge emulator backend_api
In order to support easier setup of test scenarios with fuel gauge
emulators, we should expose an API that can change internal emulator state.

Add a minimal fuel gauge emulator backend API for setting the charging
current and voltage with a sample implementation in the emul_sbs_gauge with
an associated driver test.

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2023-07-07 09:22:20 +02:00
Daniel Leung
26ecaba4af drivers: syscalls: use zephyr_syscall_header
This adds a few line use zephyr_syscall_header() to include
headers containing syscall function prototypes.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-06-17 07:57:45 -04:00
Alvaro Garcia
4d854a562c drivers: fixed div by zero when reading max17048
Avoid divsion by zero when current rate is zero

Signed-off-by: Alvaro Garcia <maxpowel@gmail.com>
2023-06-02 18:51:25 -04:00