axp173

CI

What is this?

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.

Usage

  1. Add dependency to Cargo.toml:

    bash cargo add axp173

  2. 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) ```

  3. 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)?;

    // Clear pending IRQs and enable some interesting IRQs axp173.clearallirq()?; axp173.setirq(axp173::Irq::ButtonShortPress, true)?; axp173.setirq(axp173::Irq::BatteryCharged, true)?; axp173.set_irq(axp173::Irq::VbusPluggedIn, true)?; ```

  4. Handle PMIC IRQs: rust // Inside an IRQ ISR: if axp173.check_irq(Irq::ButtonShortPress)? { axp173.clear_irq(Irq::ButtonShortPress)?; defmt::info!("Button pressed"); } axp173.clear_all_irq()?; // Clear everything else

Status

What is done and tested and what is not yet: