Expand description
High-level BQ27441 battery fuel gauge driver with synchronous and asynchronous support.
This driver provides access to the BQ27441-G1 battery fuel gauge IC from Texas Instruments. It supports I²C communication with both blocking and async modes.
§Features
- State of Charge (SOC) monitoring
- Voltage, current, and temperature measurements
- Remaining capacity and full charge capacity reporting
- Power and current averaging
- State of Health (SOH) reporting
- Configuration via Data Memory
- SEALED/UNSEALED access modes
- Multiple power modes (NORMAL, SLEEP, HIBERNATE, SHUTDOWN)
§Examples
§Blocking I2C
use bq27441::Bq27441;
// Create driver with default I2C address (0x55)
let mut gauge = Bq27441::new(i2c)?;
// Read battery voltage
let voltage_mv = gauge.voltage()?;
// Read state of charge (0-100%)
let soc = gauge.state_of_charge()?;
// Read remaining capacity
let capacity_mah = gauge.remaining_capacity()?;
§Async I2C
use bq27441::Bq27441Async;
// Create async driver
let mut gauge = Bq27441Async::new(i2c).await?;
// Read battery status asynchronously
let voltage = gauge.voltage().await?;
let soc = gauge.state_of_charge().await?;
With the async feature enabled, Bq27441Async also implements
embedded_batteries_async::smart_battery::SmartBattery for integration with
generic battery-management code. Commands the BQ27441 does not support return
Error::Unsupported.
Modules§
- field_
sets - Module containing the generated fieldsets of the registers and commands
- subclass
- Data Memory subclass identifiers (TRM Tables 6-2–6-6).
Structs§
- Battery
Config - User-facing battery configuration snapshot.
- Block
Write Options - Options for data memory block writes.
- Bq27441
- Blocking BQ27441 driver.
- Bq27441
Async async - Asynchronous BQ27441 driver.
- Bq27441
Device - Root block of the Bq27441Device driver
- Busy
Wait - Poll immediately without inserting delays between attempts.
- Charge
Termination Thresholds - Charge termination alarm thresholds (Charge Termination subclass, TRM §6.4.1.2).
- Configure
Options - Options for
Bq27441::configure_battery/Bq27441Async::configure_battery. - Control
Status - Parsed
CONTROL_STATUSsubcommand response (TRM §4.1.1). - Current
Thresholds - Current detection thresholds (Current Thresholds subclass, TRM §6.4.2.2).
- Data
Memory Block - A single 32-byte data memory block.
- Device
Interface - Blocking I²C interface wrapper.
- Device
Interface Async async - Asynchronous I²C interface wrapper.
- Discharge
Thresholds - SOC alert thresholds (Discharge subclass, TRM §6.4.1.4).
- Golden
Snapshot - Snapshot of the data memory blocks commonly exported as a golden file.
- Learning
Progress - Snapshot of learning-cycle progress from control status and flags.
- OpConfig
- Operation configuration register (
OpConfig, TRM Table 6-7). - OpConfigB
- Operation configuration B register (
OpConfigB, TRM Table 6-8). - RaTable
- Impedance Track Ra table for golden-file programming (Ra RAM subclass 89).
- Safety
Thresholds - Temperature safety thresholds (Safety subclass, TRM §6.4.1.1).
- Update
Status - Update Status data-flash byte (TRM §6.4.2.3.2).
Enums§
- ChemId
- Battery chemistry variant.
- Config
Exit - How to leave CONFIG UPDATE mode after applying configuration.
- Control
Cmd - Control subcommand codes.
- Error
- Error type for BQ27441 operations.
- Learning
Phase - System-side learning-cycle phase encoded in Update Status (slua903 §3 footnote).
- SohStatus
- State-of-health status byte (TRM §4.15,
StateOfHealth()high byte).
Constants§
- BLOCK_
SIZE - Size of a Data Memory transfer block in bytes.
- CHECKSUM_
SETTLE_ MS - Delay after writing a block checksum before readback verification (SLUA801 §4.2).
- DEFAULT_
I2C_ ADDRESS - Default I²C address for BQ27441.
- DEVICE_
TYPE_ ID - Expected device type ID.
- RA_
TABLE_ LEN - Number of Ra table entries in subclass 89.
- UNSEAL_
KEY - Unseal key value (sent twice to unseal device).
Traits§
- DelayMs
- Blocking delay used while polling config-mode flags.
- Delay
MsAsync async - Async delay used while polling config-mode flags.
Functions§
- qmax_
mah - Convert Qmax Cell 0 and design capacity to learned Qmax in mAh (TRM §6.4.2.3.1).