Skip to content

sensors/ina226: Add a uORB interface. - #20379

Open
Fishwaldo wants to merge 1 commit into
apache:masterfrom
Fishwaldo:upstream-sensors-ina226-uorb-pr
Open

Fishwaldo wants to merge 1 commit into
apache:masterfrom
Fishwaldo:upstream-sensors-ina226-uorb-pr

Conversation

@Fishwaldo

Copy link
Copy Markdown
Contributor

Summary

Adds a uORB interface for the INA226, publishing voltage, current and power from a single reading. It sits beside the existing character driver and replaces it when CONFIG_SENSORS_INA226_UORB is set.

Impact

New file behind CONFIG_SENSORS_INA226_UORB, default n, depending on SENSORS_INA226 and UORB. With it set, ina226_uorb.c is built in place of ina226.c and ina226_register_uorb() replaces ina226_register(). Unset, nothing changes.

Testing

ESWIN EIC7700 EVB, four INA226 rails on i2c11:

nsh> sensortest -n 1 voltage5
voltage5: timestamp:93633993 value:12.03
nsh> sensortest -n 1 current5
current5: timestamp:94560994 value:0.73
nsh> sensortest -n 1 power5
power5: timestamp:95488993 value:8.79

12.03V x 0.73A is 8.78W against the 8.79W reported, so the three values are consistent with having been measured together. Built for eic7700-evb:nsh with -Wno-cpp -Werror, with the uORB driver selected and ina226.c excluded.

@github-actions github-actions Bot added Area: Sensors Sensors issues Size: L The size of the change in this PR is large labels Sep 28, 2026
@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

Comment thread drivers/sensors/ina226_uorb.c Outdated
Comment thread drivers/sensors/ina226_uorb.c Outdated
The INA226 driver was character mode only, and stayed that way after
everything around it moved, because the sensor framework had no type it
could publish: there was nothing for volts or amps until now.

Add the framework version beside it, in the shape the tree uses for a
part with both.  The old driver is untouched and still builds by
default; the new one replaces it when SENSORS_INA226_UORB is set.

The part publishes three topics, voltage, current and power, from a
single reading that they all share the timestamp of.  Reading once per
topic would put three transfers on the bus for one sample and, worse,
would leave the three values describing three different instants, which
is the wrong property for a power measurement: the product of a voltage
and a current measured at different moments is not the power at either.
The power is computed here rather than read from the part, because the
part's own power register needs its calibration register given a
current scale first, and multiplying two values already in hand does
not.

One worker feeds all three, so it starts when the first topic is
subscribed and stops when the last goes away, and the part is left
powered down until then rather than converting into a void.

Each topic keeps the interval it asked for and the worker runs at the
shortest of them, since one reading serves all three.  Neither is taken
at face value: asking faster than the part converts returns the same
reading twice, and a period shorter than a clock tick rounds down to no
delay at all, which would leave the worker re-queueing itself with the
bus never idle.  Both floors are applied and the caller is told what it
will actually get, which is what the interface is for.

The shunt is rejected if it is zero or negative, which would otherwise
divide by zero on the first reading.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Justin Hammond <justin@dynam.ac>
@Fishwaldo
Fishwaldo force-pushed the upstream-sensors-ina226-uorb-pr branch from f23f1b4 to 8510c6c Compare September 28, 2026 04:41

@acassis acassis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Fishwaldo please include Documentation to this new sensor driver

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Sensors Sensors issues Size: L The size of the change in this PR is large

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants