| Crates.io | axp192-dd |
| lib.rs | axp192-dd |
| version | 0.2.3 |
| created_at | 2025-06-01 08:05:41.905168+00 |
| updated_at | 2025-06-18 21:53:46.993231+00 |
| description | A driver for the AXP192 power management IC (uses device-driver crate) |
| homepage | |
| repository | https://github.com/okhsunrog/axp192-dd |
| max_upload_size | |
| id | 1696954 |
| size | 165,272 |
This crate provides a no_std driver for the AXP192 power management IC, commonly used in M5Stack devices and other embedded systems. The project aims to support the full functionality of the AXP192 PMIC, leveraging the device-driver crate with a declarative YAML manifest (device.yaml) for a robust, type-safe register map definition. The low-level API covers 100% of the AXP192's registers, with device.yaml providing a comprehensive and accurate description of all registers and their fields. While the low-level API is complete, some high-level convenience methods for easier access may still be added in the future.
The axp192-dd driver offers:
device.yaml, enabling device-driver to generate a type-safe, low-level register access API. This approach enhances maintainability and extensibility.bisync crate to provide both asynchronous (Axp192Async) and blocking (Axp192) drivers from the same codebase, with no feature flags required.ll field of the Axp192/Axp192Async struct) offers direct, type-safe access to all registers defined in device.yaml via raw values or enums.no_std and no-alloc: Optimized for bare-metal and RTOS environments.defmt and the log facade for debugging.Caution! The AXP192 controls power to the microcontroller and critical components. Incorrect configuration may cause malfunctions, data loss, or hardware damage.
device.yaml.device-driver.device.yaml for details)
no_std and no-alloc.defmt and log facade.Add axp192-dd to Cargo.toml:
[dependencies]
axp192-dd = "0.1.0"
# For blocking usage (Axp192):
embedded-hal = "1.0.0"
# For async usage (Axp192Async):
embedded-hal-async = "1.0.0"
Note: Add the relevant
embedded-halcrate for your use case, no need for both
- Use
embedded-halfor blocking drivers (Axp192)- Use
embedded-hal-asyncfor async drivers (Axp192Async)
Instantiate the driver with your I2C bus:
Blocking:
use axp192_dd::{Axp192, LdoId};
use embedded_hal::i2c::I2c;
let i2c_bus_impl = /* your I2C bus */;
let mut axp = Axp192::new(i2c_bus_impl);
axp.set_ldo_voltage_mv(LdoId::Ldo2, 3300)?;
Async:
use axp192_dd::{Axp192Async, LdoId};
use embedded_hal_async::i2c::I2c;
let i2c_bus_impl = /* your I2C bus */;
let mut axp = Axp192Async::new(i2c_bus_impl);
axp.set_ldo_voltage_mv(LdoId::Ldo2, 3300).await?;
Examples for ESP32-C3 using esp-hal are included. Setup is required (see esp-hal docs).
examples/test_pmic_async.rs
cargo run --release --example test_pmic_async --features defmt
examples/test_pmic_blocking.rs
cargo run --release --example test_pmic_blocking --features defmt
The AXP192 register map is defined in device.yaml, which device-driver uses to generate Rust code. This file specifies:
Access the low-level API via axp.ll (e.g., axp.ll.power_status().read()). High-level methods provide convenient access to common features.
The AXP192 is used in devices including:
default = []: No default features; async and blocking drivers are always available.std: Enables std features for thiserror.log: Enables log facade logging. Requires log = { version = "0.4", optional = true }.defmt: Enables defmt logging. Requires defmt = { version = "1.0", optional = true }.Please submit issues, fork the repository, and create pull requests.
This project is dual-licensed under the MIT License or Apache License 2.0, at your option.