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>
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
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
Fix issues found by ASan, log register writes for inspection using
console harness.
Fixes: 5f84be617e
Signed-off-by: Dmitrii Sharshakov <d3dx12.xx@gmail.com>
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>
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>
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>
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
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>
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>
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>
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>
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>
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>
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>
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>