Skip to content

Commit 34d9283

Browse files
committed
samples: fuelgauge: unify fuel gauge sample
Replace IC specific fuel gauge example with a generic fuel gauge example and move the fuel gauge sample to sample/drivers folder Signed-off-by: Philipp Steiner <[email protected]>
1 parent 69bf084 commit 34d9283

24 files changed

+573
-150
lines changed

boards/adafruit/feather_esp32s2/adafruit_feather_esp32s2_tft_reverse.dts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
aliases {
2121
backlight = &led1;
22+
fuel-gauge0 = &max17048;
2223
};
2324

2425
leds {

boards/adafruit/feather_esp32s3/adafruit_feather_esp32s3_procpu.dts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
sw0 = &button0;
3939
led0 = &led0;
4040
led-strip = &led_strip;
41+
fuel-gauge0 = &max17048;
4142
};
4243

4344
buttons {

boards/adafruit/feather_esp32s3_tft/adafruit_feather_esp32s3_tft_procpu.dts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
aliases {
2323
i2c-0 = &i2c0;
2424
watchdog0 = &wdt0;
25+
fuel-gauge0 = &max17048;
2526
};
2627

2728
chosen {

samples/fuel_gauge/max17048/CMakeLists.txt renamed to samples/drivers/fuel_gauge/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
cmake_minimum_required(VERSION 3.20.0)
44
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
5-
project(max17048)
5+
project(fuel_gauge)
66

77
FILE(GLOB app_sources src/*.c)
88
target_sources(app PRIVATE ${app_sources})
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
.. zephyr:code-sample:: fuel_gauge
2+
:name: Fuel Gauge
3+
4+
Use fuel gauge API to access fuel gauge properties and get charge information.
5+
6+
Overview
7+
********
8+
9+
This sample shows how to use the Zephyr :ref:`fuel_gauge_api` API driver for.
10+
11+
First, the sample tries to read all public fuel gauge properties to verify which are supported by
12+
the used fuel gauge driver.
13+
Second, the sample then reads the battery percentage and voltage proper periodically using the
14+
``FUEL_GAUGE_RELATIVE_STATE_OF_CHARGE`` and ``FUEL_GAUGE_VOLTAGE`` properties.
15+
16+
.. note::
17+
The sample does not set/write any properties to avoid misconfiguration the IC.
18+
19+
Building and Running
20+
********************
21+
22+
The sample can be configured to support a fuel gauge.
23+
24+
Features
25+
********
26+
By using this fuel gauge you can get the following information:
27+
28+
* Read all public fuel gauge properties except ``FUEL_GAUGE_BATTERY_CUTOFF``
29+
* Battery charge status as percentage (periodically)
30+
* Battery voltage (periodically)
31+
32+
Sample output
33+
*************
34+
35+
.. code-block:: console
36+
*** Booting Zephyr OS build f95fd665ad26 ***
37+
[00:00:00.116,000] <inf> app: Found device "lc709203f@0b"
38+
[00:00:00.116,000] <inf> app: Test-Read generic fuel gauge properties to verify which are supported
39+
[00:00:00.116,000] <inf> app: Info: not all properties are supported by all fuel gauges!
40+
[00:00:00.116,000] <inf> app: Property "FUEL_GAUGE_AVG_CURRENT" is not supported
41+
[00:00:00.116,000] <inf> app: Property "FUEL_GAUGE_CURRENT" is not supported
42+
[00:00:00.116,000] <inf> app: Property "FUEL_GAUGE_CHARGE_CUTOFF" is not supported
43+
[00:00:00.116,000] <inf> app: Property "FUEL_GAUGE_CYCLE_COUNT" is not supported
44+
[00:00:00.116,000] <inf> app: Property "FUEL_GAUGE_CONNECT_STATE" is not supported
45+
[00:00:00.116,000] <inf> app: Property "FUEL_GAUGE_FLAGS" is not supported
46+
[00:00:00.116,000] <inf> app: Property "FUEL_GAUGE_FULL_CHARGE_CAPACITY" is not supported
47+
[00:00:00.116,000] <inf> app: Property "FUEL_GAUGE_PRESENT_STATE" is not supported
48+
[00:00:00.116,000] <inf> app: Property "FUEL_GAUGE_REMAINING_CAPACITY" is not supported
49+
[00:00:00.116,000] <inf> app: Property "FUEL_GAUGE_RUNTIME_TO_EMPTY" is not supported
50+
[00:00:00.116,000] <inf> app: Property "FUEL_GAUGE_RUNTIME_TO_FULL" is not supported
51+
[00:00:00.116,000] <inf> app: Property "FUEL_GAUGE_SBS_MFR_ACCESS" is not supported
52+
[00:00:00.116,000] <inf> app: Property "FUEL_GAUGE_ABSOLUTE_STATE_OF_CHARGE" is not supported
53+
[00:00:00.122,000] <inf> app: Property "FUEL_GAUGE_RELATIVE_STATE_OF_CHARGE" is supported
54+
[00:00:00.122,000] <inf> app: Relative state of charge: 100
55+
[00:00:00.122,000] <err> lc709203f: Thermistor not enabled
56+
[00:00:00.122,000] <inf> app: Property "FUEL_GAUGE_TEMPERATURE" is not supported
57+
[00:00:00.123,000] <inf> app: Property "FUEL_GAUGE_VOLTAGE" is supported
58+
[00:00:00.123,000] <inf> app: Voltage: 4190000
59+
[00:00:00.124,000] <inf> app: Property "FUEL_GAUGE_SBS_MODE" is supported
60+
[00:00:00.124,000] <inf> app: SBS mode: 1
61+
[00:00:00.124,000] <inf> app: Property "FUEL_GAUGE_CHARGE_CURRENT" is not supported
62+
[00:00:00.124,000] <inf> app: Property "FUEL_GAUGE_CHARGE_VOLTAGE" is not supported
63+
[00:00:00.124,000] <inf> app: Property "FUEL_GAUGE_STATUS" is not supported
64+
[00:00:00.124,000] <inf> app: Property "FUEL_GAUGE_DESIGN_CAPACITY" is supported
65+
[00:00:00.124,000] <inf> app: Design capacity: 500
66+
[00:00:00.124,000] <inf> app: Property "FUEL_GAUGE_DESIGN_VOLTAGE" is not supported
67+
[00:00:00.124,000] <inf> app: Property "FUEL_GAUGE_SBS_ATRATE" is not supported
68+
[00:00:00.124,000] <inf> app: Property "FUEL_GAUGE_SBS_ATRATE_TIME_TO_FULL" is not supported
69+
[00:00:00.124,000] <inf> app: Property "FUEL_GAUGE_SBS_ATRATE_TIME_TO_EMPTY" is not supported
70+
[00:00:00.124,000] <inf> app: Property "FUEL_GAUGE_SBS_ATRATE_OK" is not supported
71+
[00:00:00.125,000] <inf> app: Property "FUEL_GAUGE_SBS_REMAINING_CAPACITY_ALARM" is not supported
72+
[00:00:00.125,000] <inf> app: Property "FUEL_GAUGE_SBS_REMAINING_TIME_ALARM" is not supported
73+
[00:00:00.125,000] <err> app: Error: cannot get property "FUEL_GAUGE_MANUFACTURER_NAME": -88
74+
[00:00:00.125,000] <err> app: Error: cannot get property "FUEL_GAUGE_DEVICE_NAME": -88
75+
[00:00:00.125,000] <err> app: Error: cannot get property "FUEL_GAUGE_DEVICE_CHEMISTRY": -88
76+
[00:00:00.125,000] <inf> app: Property "FUEL_GAUGE_CURRENT_DIRECTION" is supported
77+
[00:00:00.125,000] <inf> app: Current direction: 0
78+
[00:00:00.126,000] <inf> app: Property "FUEL_GAUGE_STATE_OF_CHARGE_ALARM" is supported
79+
[00:00:00.126,000] <inf> app: State of charge alarm: 8
80+
[00:00:00.127,000] <inf> app: Property "FUEL_GAUGE_LOW_VOLTAGE_ALARM" is supported
81+
[00:00:00.127,000] <inf> app: Low voltage alarm: 0
82+
[00:00:00.127,000] <inf> app: Polling fuel gauge data 'FUEL_GAUGE_RELATIVE_STATE_OF_CHARGE' & 'FUEL_GAUGE_VOLTAGE'
83+
[00:00:00.128,000] <inf> app: Fuel gauge data: Charge: 100%, Voltage: 4190mV
84+
[00:00:05.130,000] <inf> app: Fuel gauge data: Charge: 100%, Voltage: 4190mV
85+
[00:00:10.131,000] <inf> app: Fuel gauge data: Charge: 100%, Voltage: 4190mV
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) 2025 Philipp Steiner <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
aliases {
9+
fuel-gauge0 = &lc709203f;
10+
};
11+
};
12+
13+
&i2c0 {
14+
lc709203f: lc709203f@0b {
15+
compatible = "onnn,lc709203f";
16+
status = "okay";
17+
reg = <0x0b>;
18+
power-domains = <&i2c_reg>;
19+
apa = "500mAh";
20+
battery-profile = <0x01>;
21+
};
22+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (c) 2025 Philipp Steiner <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
aliases {
9+
fuel-gauge0 = &max17048;
10+
};
11+
};
12+
13+
&i2c0 {
14+
max17048: max17048@36 {
15+
compatible = "maxim,max17048";
16+
status = "okay";
17+
reg = <0x36 >;
18+
power-domains = <&i2c_reg>;
19+
};
20+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) 2025 Philipp Steiner <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
aliases {
9+
fuel-gauge0 = &lc709203f;
10+
};
11+
};
12+
13+
&i2c0 {
14+
lc709203f: lc709203f@0b {
15+
compatible = "onnn,lc709203f";
16+
status = "okay";
17+
reg = <0x0b>;
18+
power-domains = <&i2c_reg>;
19+
apa = "500mAh";
20+
battery-profile = <0x01>;
21+
};
22+
};

0 commit comments

Comments
 (0)