8 releases
0.1.7 | Jan 24, 2021 |
---|---|
0.1.6 | Jan 7, 2021 |
0.1.5 | Dec 26, 2020 |
0.1.4 | Mar 22, 2020 |
0.1.3 | Feb 8, 2020 |
#1693 in Embedded development
29 downloads per month
1MB
908 lines
axp173
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
-
Add dependency to
Cargo.toml
:cargo add axp173
-
Instantiate and init the device:
// ... declare and configure your I2c peripheral ... // Init AXP173 PMIC let axp173 = axp173::Axp173::new(i2c); axp173.init()?; Ok(axp173)
-
Configure the PMIC
// Set charging current to 100mA axp173 .set_charging_current(ChargingCurrent::CURRENT_100MA)?; // Enable internal ADCs // 25Hz sample rate, Disable TS, enable current sensing ADC axp173 .set_adc_settings( AdcSettings::default() .set_adc_sample_rate(AdcSampleRate::RATE_25HZ) .ts_adc(false) .set_ts_pin_mode(TsPinMode::SHUT_DOWN) .vbus_voltage_adc(true) .vbus_current_adc(true) .batt_voltage_adc(true) .batt_current_adc(true), )?; // Enable battery gas gauge axp173.set_coulomb_counter(true)?; axp173.resume_coulomb_counter()?; // Power-off the device after 4 seconds of // long press of power button axp173.set_shutdown_long_press_time(ShutdownLongPressTime::SEC_4)?; // Clear pending IRQs and enable some interesting IRQs axp173.clear_all_irq()?; axp173.set_irq(axp173::Irq::ButtonShortPress, true)?; axp173.set_irq(axp173::Irq::BatteryCharged, true)?; axp173.set_irq(axp173::Irq::VbusPluggedIn, true)?;
-
Handle PMIC IRQs:
// 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:
- Coulomb counter reading
- Coulomb counter control
- IRQs
- Battery voltage & current readings
- VBUS voltage & current readings
- AXP173 on-chip buffer
- Reading
- Checking default values
- Writing
- AXP173 LDO2, LDO3, LDO4 enable/disable
- LDO voltage setup
- VBUS presence
- Battery presence
- Battery charging status
- Charging current setup
- Charging regulated voltage setup
- Internal ADC settings:
- Sample rate
- Enable/Disable various ADC channels (batt. voltage, current, etc.)
- Button settings
- DC/DC settings
- Temperature sensor readings
- Instantaneous battery power reading