Feature/mpu6050 drdy interrupt - #19601
Merged
Merged
Conversation
FelipeMdeO
requested review from
acassis,
linguini1 and
raiden00pl
as code owners
August 3, 2026 02:23
|
FelipeMdeO
force-pushed
the
feature/mpu6050-drdy-interrupt
branch
from
August 3, 2026 22:03
7ca8160 to
60d0560
Compare
xiaoxiang781216
approved these changes
Aug 4, 2026
Contributor
|
@FelipeMdeO please fix doc error: |
fetch() timestamps a sample when the application asks for it, not when the device measured it, and reads accel and gyro separately so the two topics never share an instant. Add an optional push mode behind CONFIG_SENSORS_MPU6050_INT: the board supplies mpu6050_config_s::attach, the handler timestamps and defers to HPWORK, and the worker reads once and pushes both topics. The I2C read cannot run in the interrupt. The mode is chosen at build time, so fetch() is simply left out of the ops table and out of the build when the option is set: an instance uses one model or the other, never the mixture that made poll() unusable on l3gd20. A board that enables it without attach fails with -EINVAL. Also set CONFIG so the DLPF is on. Left at reset the gyroscope output is 8 kHz, not 1 kHz, so SMPLRT_DIV 9 gave 800 Hz rather than the documented 100 Hz; measured 833 Hz before and 101 Hz after. fetch() hid this since the application set the pace. Signed-off-by: Felipe Moura <moura.fmo@gmail.com>
The registration example showed the three argument form, which no longer compiles, and fetch() as the only way samples are taken. Update it, add a section on the two acquisition modes and the attach() a board provides for the interrupt one, and state the 100 Hz sample rate. Signed-off-by: Felipe Moura <moura.fmo@gmail.com>
FelipeMdeO
force-pushed
the
feature/mpu6050-drdy-interrupt
branch
from
August 4, 2026 11:13
60d0560 to
9482eb6
Compare
Contributor
Author
I am not sure what is this issue. BTW I rebased and push it again, let's wait pipeline run again. |
acassis
approved these changes
Aug 4, 2026
jerpelea
approved these changes
Aug 4, 2026
xiaoxiang781216
approved these changes
Aug 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The MPU6050 driver only implemented
fetch(), so samples were read ondemand: timestamped when the application asked rather than when the device
measured, with the scheduler's jitter baked in, and with accelerometer and
gyroscope coming from two separate I2C reads so the two topics were never
sampled at the same instant. The part has an INT pin and a data ready
interrupt; nothing used them.
Two commits:
Push mode behind
CONFIG_SENSORS_MPU6050_INT, plus a DLPF fix. Theboard supplies
mpu6050_config_s::attachto wire the INT pin; thehandler timestamps and defers to HPWORK, and the worker reads the device
once and pushes both topics from that single sample. The I2C read cannot
run in the interrupt, hence the work queue. The mode is chosen at build
time, so
fetch()is simply left out of the ops table and out of thebuild when the option is set: an instance uses one model or the other,
never the mixture that made
poll()unusable on l3gd20 (drivers/sensors/sensor: fix poll()/read() for fetch()-only sensors #19596). A boardthat enables the option without supplying
attachis misconfigured, soregistration fails with
-EINVALrather than silently falling back.The same commit sets
CONFIGso the DLPF is on. The sample rate is thegyroscope output rate divided by
1 + SMPLRT_DIV, and that output is1 kHz only while the DLPF is enabled.
CONFIGwas left at its 0 resetvalue, which disables the DLPF and puts the output at 8 kHz, so the
divider of 9 gave 800 Hz rather than the intended 100 Hz.
fetch()hidthis because the application set the pace and simply read the most recent
sample; the interrupt made the real rate visible.
Update the driver documentation for the new registration signature
and the two acquisition modes.
Impact
Boards that wire the INT pin get samples timestamped at acquisition, both
topics sampled from the same read, and one I2C transaction per sample
instead of one per
read(). Boards that do not wire it are unaffected:the option defaults to
nand thefetch()path is unchanged. The DLPFfix applies to both modes and corrects the configured rate to the 100 Hz
the code already documented, additionally giving the anti-alias filtering
that a 100 Hz sampler should have.
Testing
Host: Ubuntu 24.04.3 LTS.
checkpatch.sh(style +-mcommit messages)clean on all four commits.
Compiles clean in both modes —
sim(x86_64) withCONFIG_SENSORS_MPU6050_INTon and off, and xtensa-esp-elf-gcc 14.2.0 forthe hardware runs below. The refactor was re-verified on hardware after the
fact: same 101 Hz and no duplicates, so it is behaviour neutral as claimed.
On hardware — ESP32-S3-DevKitC + MPU6050 (GY-521), I2C0 on
SDA GPIO5 / SCL GPIO4, INT on GPIO6. The board glue providing
attach()for that target is not part of this PR.
Sample rate, measured over 100 samples of
uorb_listener sensor_accel0,before and after the DLPF commit:
The duplicates before the fix are the worker being re-triggered faster than
the device produced new data. After it, every interrupt yields a fresh
sample at the intended rate.
Both topics from one interrupt, note the shared timestamp:
Teardown: 8 rounds of
uorb_listener -r 5 sensor_accel0 &followed bySIGINTmid-poll.psafterward shows no leaked task and an idlehpworkthread, and
uorb_listener -n 3 sensor_accel0right after still completes3/3 — the interrupt is disabled when the last subscriber leaves and
re-enabled when one returns.