GithubHelp home page GithubHelp logo

eldruin / max170xx-rs Goto Github PK

View Code? Open in Web Editor NEW
8.0 3.0 2.0 60 KB

Platform-agnostic Rust driver for the MAX170xx 1-cell/2-cell fuel-gauge systems with ModelGauge for lithium-ion (Li+) batteries. Compatible with MAX17043, MAX17044, MAX17048, MAX17049, MAX17058 and MAX17059.

License: Apache License 2.0

Rust 100.00%
fuel-gauge battery-monitor driver rust i2c embedded-hal-driver no-std battery battery-cell lithium-battery-monitor

max170xx-rs's Introduction

Rust MAX170xx 1-Cell/2-Cell Fuel Gauge for Lithium-ion (Li+) Batteries Driver

crates.io Docs Build Status Coverage Status Minimum Supported Rust Version

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:

  • Get state of charge. See: soc().
  • Get battery voltage. See: voltage().
  • Software reset. See: reset().
  • Quickstart. See: quickstart().
  • Get IC version. See: version().
  • Only on MAX17048/MAX17049:
    • Get charge/discharge rate. See: charge_rate().
  • Only on MAX17048/MAX17049/MAX17058/MAX17059:
    • Set table registers. See: set_table().

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

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

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

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

Support

For questions, issues, feature requests, and other changes, please file an issue in the github project.

Minimum Supported Rust Version (MSRV)

This crate is guaranteed to compile on stable Rust 1.62 and up. It might compile with older versions but that may change in any new patch release.

License

Licensed under either of

at your option.

Contributing

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

max170xx-rs's People

Contributors

bencochran avatar eldruin avatar paumanok avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

max170xx-rs's Issues

Charge rate reports wrong values

When the battery discharges wrong values get reported (MAX17048). The reason for that is that this register is i16 formatted in reality and has negative values when the battery discharges. But the library converts them to u16.

I know that it's an old repo, but I found this lib useful for me. Will you merge aa PR if I will make one with the fix :) ?

Multiple devices on I2C bus

Hi - is it possible to use this crate when there are more than one slave device on the I2C bus? I can see that the struct's init takes ownership of the I2C struct.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.