{"id":21817757,"url":"https://github.com/eupn/axp173-rs","last_synced_at":"2025-04-14T01:33:34.481Z","repository":{"id":54860478,"uuid":"237777834","full_name":"eupn/axp173-rs","owner":"eupn","description":"Device-agnostic X-Powers AXP173 power management IC driver","archived":false,"fork":false,"pushed_at":"2021-02-28T07:59:24.000Z","size":1223,"stargazers_count":10,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-10T10:00:40.827Z","etag":null,"topics":["axp173","embedded-hal-driver","i2c","pmic","rust-embedded"],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eupn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-02T13:47:52.000Z","updated_at":"2025-02-19T21:46:33.000Z","dependencies_parsed_at":"2022-08-14T05:00:43.057Z","dependency_job_id":null,"html_url":"https://github.com/eupn/axp173-rs","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eupn%2Faxp173-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eupn%2Faxp173-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eupn%2Faxp173-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eupn%2Faxp173-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eupn","download_url":"https://codeload.github.com/eupn/axp173-rs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248808266,"owners_count":21164817,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["axp173","embedded-hal-driver","i2c","pmic","rust-embedded"],"created_at":"2024-11-27T15:48:17.107Z","updated_at":"2025-04-14T01:33:34.454Z","avatar_url":"https://github.com/eupn.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"## `axp173`\n\n![CI](https://github.com/eupn/axp173-rs/workflows/CI/badge.svg)\n[![](https://img.shields.io/crates/v/axp173.svg?style=flat)](https://crates.io/crates/axp173)\n[![](https://img.shields.io/crates/d/axp173.svg?maxAge=3600)](https://crates.io/crates/axp173)\n\n\u003cimg src=\"doc/axp173.jpg\" width=\"200\" height=\"200\"\u003e\u003cimg src=\"doc/axp173_block_diagram.png\" width=\"400\" height=\"800\"\u003e\n\n## What is this?\n\nThis is a [embedded-hal](https://github.com/rust-embedded/embedded-hal) driver \nfor X-Powers' Power Management IC [AXP173](http://www.x-powers.com/en.php/Info/product_detail/article_id/27).\n\nIt's device-agnostic and uses embedded-hal's `Write`/`WriteRead` for I2C communication.\n\n## Usage\n\n1. Add dependency to `Cargo.toml`:\n\n    ```bash\n    cargo add axp173\n    ```\n    \n2. Instantiate and init the device:\n\n    ```rust\n    // ... declare and configure your I2c peripheral ...\n    \n    // Init AXP173 PMIC\n    let axp173 = axp173::Axp173::new(i2c);\n    axp173.init()?;\n    Ok(axp173)\n    ```\n\n3. Configure the PMIC\n\n   ```rust\n   // Set charging current to 100mA\n   axp173\n       .set_charging_current(ChargingCurrent::CURRENT_100MA)?;\n\n   // Enable internal ADCs\n   // 25Hz sample rate, Disable TS, enable current sensing ADC\n   axp173\n       .set_adc_settings(\n           AdcSettings::default()\n               .set_adc_sample_rate(AdcSampleRate::RATE_25HZ)\n               .ts_adc(false)\n               .set_ts_pin_mode(TsPinMode::SHUT_DOWN)\n               .vbus_voltage_adc(true)\n               .vbus_current_adc(true)\n               .batt_voltage_adc(true)\n               .batt_current_adc(true),\n       )?;\n\n   // Enable battery gas gauge\n   axp173.set_coulomb_counter(true)?;\n   axp173.resume_coulomb_counter()?;\n\n   // Power-off the device after 4 seconds of\n   // long press of power button\n   axp173.set_shutdown_long_press_time(ShutdownLongPressTime::SEC_4)?;\n   \n   // Clear pending IRQs and enable some interesting IRQs\n   axp173.clear_all_irq()?;\n   axp173.set_irq(axp173::Irq::ButtonShortPress, true)?;\n   axp173.set_irq(axp173::Irq::BatteryCharged, true)?;\n   axp173.set_irq(axp173::Irq::VbusPluggedIn, true)?;\n   ```\n   \n4. Handle PMIC IRQs:\n   ```rust   \n   // Inside an IRQ ISR:\n   if axp173.check_irq(Irq::ButtonShortPress)? {\n       axp173.clear_irq(Irq::ButtonShortPress)?;\n       defmt::info!(\"Button pressed\");\n   }\n   axp173.clear_all_irq()?; // Clear everything else\n   ```\n\n## Status\n\nWhat is done and tested and what is not yet:\n\n- [x] Coulomb counter reading\n- [x] Coulomb counter control\n- [x] IRQs\n- [x] Battery voltage \u0026 current readings\n- [x] VBUS voltage \u0026 current readings\n- [x] AXP173 on-chip buffer\n  - [x] Reading\n  - [x] Checking default values\n  - [x] Writing\n- [x] AXP173 LDO2, LDO3, LDO4 enable/disable\n- [x] LDO voltage setup\n- [x] VBUS presence\n- [x] Battery presence\n- [x] Battery charging status\n- [x] Charging current setup\n- [x] Charging regulated voltage setup\n- [x] Internal ADC settings:\n  - [x] Sample rate\n  - [x] Enable/Disable various ADC channels (batt. voltage, current, etc.)\n- [x] Button settings\n- [ ] DC/DC settings\n- [ ] Temperature sensor readings\n- [ ] Instantaneous battery power reading\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feupn%2Faxp173-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feupn%2Faxp173-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feupn%2Faxp173-rs/lists"}