TB2026-YDS Firmware
Loading...
Searching...
No Matches
Fuel gauge (MAX17260)

I2C access to the ModelGauge m5 EZ state-of-charge and analog measurements. More...

Collaboration diagram for Fuel gauge (MAX17260):

Data Structures

struct  fuel_gauge_data_t
 Snapshot of the gauge's application-facing outputs. More...
struct  fuel_gauge_debug_t
 Register-level snapshot for the debug page: config vs expected + learned state. More...

Functions

esp_err_t fuel_gauge_init (i2c_master_bus_handle_t bus)
 Attach the gauge to the shared I2C bus and run EZ config if needed.
esp_err_t fuel_gauge_read (fuel_gauge_data_t *out)
 Read and convert all fields of a fuel_gauge_data_t in one pass.
esp_err_t fuel_gauge_read_debug (fuel_gauge_debug_t *out)
 Read the configuration and learned-capacity registers for the debug page.
esp_err_t fuel_gauge_reload_ez (void)
 Re-run the EZ model load to purge the learned battery state.

Detailed Description

I2C access to the ModelGauge m5 EZ state-of-charge and analog measurements.

Function Documentation

◆ fuel_gauge_init()

esp_err_t fuel_gauge_init ( i2c_master_bus_handle_t bus)

Attach the gauge to the shared I2C bus and run EZ config if needed.

Reads the POR flag: if the gauge has already been configured (POR clear), the learned battery state is kept and only the device handle is registered. On a fresh power-up it loads the EZ model (design capacity, charge-termination current, empty voltage) and clears POR.

Parameters
busMaster bus handle from i2c_bus_init().
Returns
ESP_OK on success, ESP_ERR_TIMEOUT if the gauge never reports data ready / model refresh, ESP_ERR_INVALID_RESPONSE if a config write does not verify, or the underlying I2C error.

◆ fuel_gauge_read()

esp_err_t fuel_gauge_read ( fuel_gauge_data_t * out)

Read and convert all fields of a fuel_gauge_data_t in one pass.

Parameters
[out]outReceives the converted measurements.
Returns
ESP_OK on success, or the first I2C error encountered.

◆ fuel_gauge_read_debug()

esp_err_t fuel_gauge_read_debug ( fuel_gauge_debug_t * out)

Read the configuration and learned-capacity registers for the debug page.

Parameters
[out]outReceives the snapshot.
Returns
ESP_OK on success, or the first I2C error encountered.

◆ fuel_gauge_reload_ez()

esp_err_t fuel_gauge_reload_ez ( void )

Re-run the EZ model load to purge the learned battery state.

Preserves the cycle counter across the reload; everything else learned (full capacity, hence health) restarts from the design values, and SOC is re-estimated from voltage — best done at rest, right after a charge the estimate overshoots for a few minutes.

Returns
ESP_OK on success, ESP_ERR_TIMEOUT if the model refresh never completes, ESP_ERR_INVALID_RESPONSE if a config write does not verify, or the I2C error.