AXP2101 Embedded Rust Driver
A complete no_std Rust driver for the AXP2101 Power Management IC (PMIC) using the embedded-hal traits.
Features
- ✅ Full Power Rail Control: DCDC1-5, ALDO1-4, BLDO1-2, DLDO1-2, CPUSLDO
- ✅ Battery Charging: Configurable charging parameters, LED control, thermal regulation
- ✅ ADC Measurements: Battery voltage/percentage, VBUS, temperature, system voltage
- ✅ Interrupt Handling: Complete IRQ support with enable/disable/status
- ✅ Watchdog Timer: Configurable timeout and behavior
- ✅ Power Sequencing: Fast power-on, wake-up control, PWROK management
- ✅ Status Monitoring: VBUS, battery connection, charging state
- ✅ Button Battery: Support for coin cell charging
- ✅
no_stdCompatible: Perfect for embedded systems - ✅ Embedded HAL 1.0: Uses modern traits
- ✅ Async Support: Optional async API with
embedded-hal-async
Usage
Add this to your Cargo.toml:
[]
= "0.3"
= "1.0"
Async Support
For async operations, enable the async feature:
[]
= { = "0.3", = ["async"] }
= "1.0"
Basic Example
use ;
use I2c;
Async Example
When the async feature is enabled, you can use the async API:
use AsyncAxp2101;
use I2c;
async
The async API provides the same functionality as the synchronous version, but all methods return futures that must be awaited. This is perfect for async runtimes like embassy or tokio (for std environments).
Configure Battery Charging
use ;
// Set charging parameters
pmic.set_charger_constant_curr?; // 200mA
pmic.set_charge_target_voltage?; // 4.2V
pmic.set_precharge_curr?;
pmic.set_thermal_threshold?;
// Control charging LED
pmic.set_charging_led_mode?;
Handle Interrupts
use *;
// Enable specific interrupts
pmic.enable_irq?;
// In your interrupt handler:
let status = pmic.get_irq_status?;
if status.is_vbus_insert_irq
if status.is_bat_charge_done_irq
// Clear interrupts
pmic.clear_irq_status?;
Power Rails
DCDC Converters
| Rail | Voltage Range | Step Size | Notes |
|---|---|---|---|
| DCDC1 | 1500-3400mV | 100mV | High efficiency |
| DCDC2 | 500-1540mV | 10/20mV | Dual range |
| DCDC3 | 500-3400mV | 10/20/100mV | Three ranges |
| DCDC4 | 500-1840mV | 10/20mV | Dual range |
| DCDC5 | 1400-3700mV | 100mV | GPIO output |
LDO Regulators
| Rail | Voltage Range | Step Size | Typical Use |
|---|---|---|---|
| ALDO1-4 | 500-3500mV | 100mV | Always-on LDO |
| BLDO1-2 | 500-3500mV | 100mV | Battery LDO |
| CPUSLDO | 500-1400mV | 50mV | CPU supply |
| DLDO1 | 500-3400mV | 100mV | Digital LDO |
| DLDO2 | 500-1400mV | 50mV | Digital LDO |
Documentation
Full API documentation is available at docs.rs/axp2101.
Compatibility
- Rust: 2021 edition or later
- embedded-hal: 1.0
- Platforms: Any platform with I2C support via embedded-hal
Tested on:
- ESP32-C3/S3 (M5Stack CoreS3)
- STM32F4
- RP2040
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Resources
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
Trevor Flahardy
Based on the original C++ implementation by Lewis He and initial Rust port by Juraj Michálek.