Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Baro and Mag driver check for I2C bus being busy #13509

Merged
merged 2 commits into from Apr 9, 2024

Conversation

SteveCEvans
Copy link
Member

May fix: #13497

Please test.

@SteveCEvans SteveCEvans self-assigned this Apr 6, 2024
Copy link

github-actions bot commented Apr 6, 2024

Do you want to test this code? You can flash it directly from Betaflight Configurator:

  • Simply put #13509 (this pull request number) in the Select commit field of the Configurator firmware flasher tab (you need to Enable expert mode, Show release candidates and Development).

WARNING: It may be unstable. Use only for testing!

@haslinghuis
Copy link
Member

SITL (virtual barometer) needs to be fixed but fix can be tested for other targets.

Copy link
Contributor

@ledvinap ledvinap left a comment

Choose a reason for hiding this comment

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

(not tested yet, but looks good)

src/main/drivers/bus_i2c_busdev.c Outdated Show resolved Hide resolved
Comment on lines +138 to +140
if (busReadRegisterBufferStart(dev, AK8975_MAG_REG_ST1, &status, sizeof(status))) {
state = STATE_WAIT_STATUS1;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe code it this way (continue only is operation succeeds):

Suggested change
if (busReadRegisterBufferStart(dev, AK8975_MAG_REG_ST1, &status, sizeof(status))) {
state = STATE_WAIT_STATUS1;
}
if (!busReadRegisterBufferStart(dev, AK8975_MAG_REG_ST1, &status, sizeof(status))) {
return false;
}
state = STATE_WAIT_STATUS1;

Copy link
Member Author

Choose a reason for hiding this comment

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

That would still require a return false following the state assignment.

Copy link
Contributor

Choose a reason for hiding this comment

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

The logic is:
If operation fails, return false to retry soon
Set next state
Return false to call next state faster

first and second false have a bit different meaning.
And it is more similar to longer cases - return of something fails, continue othervise.

But resulting instructions are the same and your variant is shorter. It is only minor stylistics suggestion..

@ledvinap
Copy link
Contributor

ledvinap commented Apr 7, 2024

@SteveCEvans : It should fix #13497
It will also retry some I2C operations on NAK (only addr+reg address part in background mode). That may help considerably on noisy I2C.

Co-authored-by: Petr Ledvina <ledvinap@gmail.com>
@SteveCEvans
Copy link
Member Author

Thanks @ledvinap for your insightful review comments as always.

@haslinghuis haslinghuis merged commit 7073b0e into betaflight:master Apr 9, 2024
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: COMPLETED
4 participants