Initial INA4230 quad-channel power monitor driver implementation#1
Initial INA4230 quad-channel power monitor driver implementation#1LTAFlight wants to merge 11 commits into
Conversation
Cargo Vet Audit Passed
|
There was a problem hiding this comment.
Pull request overview
Introduces an async, platform-agnostic Rust driver crate for the TI INA4230 quad-channel power/energy monitor, with generated register accessors and higher-level sensor trait APIs built on embedded-hal-async / embedded-sensors.
Changes:
- Added high-level
Ina4230driver with async I²C interface adapter and sensor-trait measurement APIs (V/I/P/E). - Added calibration helpers and unit conversion utilities, plus basic async I²C mock-based tests.
- Added register manifest (
INA4230.toml), CI workflow to verify generatedsrc/device.rs, and updated crate metadata/docs for publishing.
Reviewed changes
Copilot reviewed 5 out of 8 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
src/lib.rs |
Core driver API, async I²C interface adapter, calibration + unit conversions, and unit tests. |
README.md |
Driver documentation, usage examples, calibration guidance, and regeneration instructions. |
INA4230.toml |
Device register manifest used to generate src/device.rs. |
Cargo.toml |
Crate rename/metadata for publishing, dependencies, features, and lint configuration. |
Cargo.lock |
Lockfile update reflecting new dependencies. |
.gitignore |
Ignore rule updates (notably /target and Cargo.lock). |
.github/workflows/device-driver.yml |
CI job to regenerate and diff-check src/device.rs against the manifest. |
- Fix filename casing: ina4230.toml -> INA4230.toml in workflows and Cargo.toml - Add rust-version = 1.88 to Cargo.toml - Clamp SHUNT_CAL to 15-bit max (0x7FFF) - Per-channel calibration storage ([Option<f32>; 4], [AdcRange; 4]) - Write CONFIG2.RANGE in calibrate() for hardware ADC range selection - Return NotCalibrated error when current/power/energy read before calibrate() - Replace INA4230_ADDR constant with A0/A1 enums and i2c_address() function - Add MathOverflow and EnergyOverflow error variants with check_flags() method - Make device field private - Add set_channel_active() method - Update calibrate_all() to take per-channel params [(f32, f32, AdcRange); 4] - Remove src/main.rs template leftover - Update README with new API, error handling, and channel management sections - Expand test suite to 9 tests
|
Addressed all review comments so far:
|
Co-authored-by: Felipe Balbi <felipe@balbi.sh>
Co-authored-by: Felipe Balbi <felipe@balbi.sh>
Co-authored-by: Felipe Balbi <felipe@balbi.sh>
Co-authored-by: Felipe Balbi <felipe@balbi.sh>
- Rename defmt-03 feature to defmt, update to defmt 1.0 - Update INA4230.toml defmt_feature to defmt - Regenerate src/device.rs with updated defmt feature name - Add Sda and Scl variants to A0 and A1 enums - Replace i2c_address() free function with ToAddress trait - Update ToAddress impl to cover all 16 address combinations - Update i2c_address_all_combinations test to verify all 16 addresses
|
Renamed defmt-03 feature to defmt, updated to defmt 1.0 Updated Readme: |
- Remove [lib] doctest = false — doctests now enabled - Pin tokio to =1.45.0 - Fix math formula blocks to use text fence in README - Change rust,no_run to rust,ignore for examples that cannot compile in doctest context - Keep simple const declaration blocks as runnable doctests
- Fix all clippy errors in lib.rs - Restore device module allow attributes matching bq25723 approved pattern - Regenerate src/device.rs with updated defmt feature name - Remove [lib] doctest = false, enable doctests - Change rust,no_run to rust,ignore in README - Fix math formula blocks in README - Pin tokio to =1.45.0 - Add cargo-vet supply chain with ODP shared audits - Add exemptions for embedded-sensors-hal, embedded-sensors-hal-async, libc and paste
felipebalbi
left a comment
There was a problem hiding this comment.
LGTM, just missing integration of the traits in embedded-sensors and the subsequent update after that happens.
Platform-agnostic async Rust driver for the Texas Instruments INA4230
quad-channel power and energy sense monitor.
What's included
src/device.rsfromINA4230.tomlembedded-hal-asyncVoltageSensor,CurrentSensor,PowerSensor, andEnergySensortrait implementationsAdcRange::Range0/AdcRange::Range1)defmt-03logging supportTesting
cargo test)shunt voltage, current, power, and energy