Add INA226 battery meter support#11656
Conversation
…zzer-ignore-fix dshot beeper ignore list fix
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
Branch Targeting SuggestionYou've targeted the
If This is an automated suggestion to help route contributions to the appropriate branch. |
|
Test firmware build ready — commit Download firmware for PR #11656 238 targets built. Find your board's
|
|
My AI-based tool brought up a question that may be interesting (or not): In power_limits.c, powerLimiterApply() was changed from: int16_t current = getAmperageSample(); getAmperage() returns the cached value after the 1 Hz PT1 low-pass filter (AMPERAGE_LPF_FREQ in battery.c), while getAmperageSample() returns a fresh, unfiltered instantaneous reading. This line isn't gated behind USE_INA226, so Was this intentional? If the goal was just to make powerLimiterApply() compile without USE_ADC, would it work to instead generalize getAmperageSample() itself to dispatch by sensor type — mirroring the pattern already used in the int16_t getAmperageSample(void) That would let power_limits.c keep calling getAmperageSample() unchanged, preserving the existing (unfiltered) dynamic response for every current target, while giving INA226 the same semantics as ADC. Happy to be wrong if there's |
Summary
Add INA226 support as both a battery voltage source and current meter source.
This uses the INA226 shunt-voltage and bus-voltage registers directly, so INAV keeps using its existing battery pipeline for filtering, power, mAh/mWh, alarms, OSD, telemetry, and stats. It does not depend on the INA226 calibration/current/power registers.
Details
CURRENT_SENSOR_INA226andVOLTAGE_SENSOR_INA226.INA226to the CLIcurrent_meter_typeandvbat_meter_typesettings.USE_INA226.INA226_I2C_BUSINA226_I2C_ADDRESS0x400x010x021.25 mV/bit.ina_shunt_res_uohm.ina_shunt_res_uohmas a CLI setting for INA226 shunt resistor value in micro-ohms.USE_BATTERY_VOLTAGE_SENSORgating so non-ADC voltage sources can use the normal battery voltage/profile/power-limit settings.Target Opt-In
This PR does not change any official target default voltage/current source.
Targets that have an INA226 can opt in with something like:
INA226_I2C_ADDRESSis optional and defaults to0x40.Notes
The setting is named
ina_shunt_res_uohminstead of usingina226in the CLI setting name. This avoids issues with the settings-name compressor on some F4 targets.The first version supports one INA226 device per target. Address scanning and runtime address configuration can be added later if needed.
Hardware Test
Tested on:
MATEKH7430.3 mOhmResult:
Observed values:
The current difference is expected to depend on shunt tolerance, wiring, load stability, and filtering/calibration.
Test Photos