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
Baro and Mag driver check for I2C bus being busy #13509
Conversation
Do you want to test this code? You can flash it directly from Betaflight Configurator:
WARNING: It may be unstable. Use only for testing! |
SITL (virtual barometer) needs to be fixed but fix can be tested for other targets. |
38e4a6c
to
32173a3
Compare
There was a problem hiding this 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)
if (busReadRegisterBufferStart(dev, AK8975_MAG_REG_ST1, &status, sizeof(status))) { | ||
state = STATE_WAIT_STATUS1; | ||
} |
There was a problem hiding this comment.
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):
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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..
@SteveCEvans : It should fix #13497 |
Co-authored-by: Petr Ledvina <ledvinap@gmail.com>
Thanks @ledvinap for your insightful review comments as always. |
May fix: #13497
Please test.