axp173
This is a embedded-hal driver for X-Powers' Power Management IC AXP173.
It's device-agnostic and uses embedded-hal's Write
/WriteRead
for I2C communication.
Add dependency to Cargo.toml
:
bash
cargo add axp173
Instantiate and init the device:
```rust // ... declare and configure your I2c peripheral ...
// Init AXP173 PMIC let axp173 = axp173::Axp173::new(i2c); axp173.init()?; Ok(axp173) ```
Configure the PMIC
```rust // Set charging current to 100mA axp173 .setchargingcurrent(ChargingCurrent::CURRENT_100MA)?;
// Enable internal ADCs // 25Hz sample rate, Disable TS, enable current sensing ADC axp173 .setadcsettings( AdcSettings::default() .setadcsamplerate(AdcSampleRate::RATE25HZ) .tsadc(false) .settspinmode(TsPinMode::SHUTDOWN) .vbusvoltageadc(true) .vbuscurrentadc(true) .battvoltageadc(true) .battcurrent_adc(true), )?;
// Enable battery gas gauge axp173.setcoulombcounter(true)?; axp173.resumecoulombcounter()?;
// Power-off the device after 4 seconds of // long press of power button axp173.setshutdownlongpresstime(ShutdownLongPressTime::SEC_4)?; ```
TODO
What is done and tested and what is not yet: