Skip to main content

Crate bq27441

Crate bq27441 

Source
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§

BatteryConfig
User-facing battery configuration snapshot.
BlockWriteOptions
Options for data memory block writes.
Bq27441
Blocking BQ27441 driver.
Bq27441Asyncasync
Asynchronous BQ27441 driver.
Bq27441Device
Root block of the Bq27441Device driver
BusyWait
Poll immediately without inserting delays between attempts.
ChargeTerminationThresholds
Charge termination alarm thresholds (Charge Termination subclass, TRM §6.4.1.2).
ConfigureOptions
Options for Bq27441::configure_battery / Bq27441Async::configure_battery.
ControlStatus
Parsed CONTROL_STATUS subcommand response (TRM §4.1.1).
CurrentThresholds
Current detection thresholds (Current Thresholds subclass, TRM §6.4.2.2).
DataMemoryBlock
A single 32-byte data memory block.
DeviceInterface
Blocking I²C interface wrapper.
DeviceInterfaceAsyncasync
Asynchronous I²C interface wrapper.
DischargeThresholds
SOC alert thresholds (Discharge subclass, TRM §6.4.1.4).
GoldenSnapshot
Snapshot of the data memory blocks commonly exported as a golden file.
LearningProgress
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).
SafetyThresholds
Temperature safety thresholds (Safety subclass, TRM §6.4.1.1).
UpdateStatus
Update Status data-flash byte (TRM §6.4.2.3.2).

Enums§

ChemId
Battery chemistry variant.
ConfigExit
How to leave CONFIG UPDATE mode after applying configuration.
ControlCmd
Control subcommand codes.
Error
Error type for BQ27441 operations.
LearningPhase
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.
DelayMsAsyncasync
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).