Crate max170xx

source ·
Expand description

This is a platform agnostic Rust driver for the ultra-compact, low-cost, host-side fuel-gauge systems for lithium-ion (Li+) batteries in handheld and portable equipment using the embedded-hal traits.

It is compatible with MAX17043, MAX17044, MAX17048, MAX17049, MAX17058 and MAX17059.

This driver allows you to:

§The devices

The devices are ultra-compact, low-cost, host-side fuel-gauge systems for lithium-ion (Li+) batteries in handheld and portable equipment. There are models configured to operate with a single or dual lithium cell pack.

The devices use a sophisticated Li+ battery-modeling scheme, called ModelGauge(TM) to track the battery’s relative state-of-charge (SOC) continuously over a widely varying charge/discharge profile. Unlike traditional fuel gauges, the ModelGauge algorithm eliminates the need for battery relearn cycles and an external current-sense resistor. Temperature compensation is possible in the application with minimal interaction between a μC and the device.

The communication is done through an I2C interface.

Datasheets: MAX17043/MAX17044, MAX17048/MAX17049, MAX17058/MAX17059

§Usage examples (see also examples folder)

To use this driver, import this crate and an embedded_hal implementation, then instantiate the device.

Please find additional examples using hardware in this repository: driver-examples

§Read state of charge and cell voltage

use linux_embedded_hal::I2cdev;
use max170xx::Max17043;

let dev = I2cdev::new("/dev/i2c-1").unwrap();
let mut sensor = Max17043::new(dev);
let soc = sensor.soc().unwrap();
let voltage = sensor.voltage().unwrap();
println!("Charge: {:.2}%", soc);
println!("Voltage: {:.2}V", voltage);

§Trigger software reset

use linux_embedded_hal::I2cdev;
use max170xx::Max17043;

let dev = I2cdev::new("/dev/i2c-1").unwrap();
let mut sensor = Max17043::new(dev);
sensor.reset().unwrap();

§Quick start

use linux_embedded_hal::I2cdev;
use max170xx::Max17043;

let dev = I2cdev::new("/dev/i2c-1").unwrap();
let mut sensor = Max17043::new(dev);
// ... noisy power-up ...
sensor.quickstart().unwrap();

§Read charge/discharge rate

use linux_embedded_hal::I2cdev;
use max170xx::Max17048;

let dev = I2cdev::new("/dev/i2c-1").unwrap();
let mut sensor = Max17048::new(dev);
let rate = sensor.charge_rate().unwrap();
println!("Charge rate: {:.2}%/h", rate);

Structs§

Enums§

  • All possible errors in this crate