Repository navigation
Fix/i2c fault recovery upstream #111
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
Merged
+1,247
−37
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
06496a5
fix(firmware): detect and recover from I2C bus faults
b84376a
fix(firmware): restore and watch the PCA9685 output mode
8e841f6
fix(firmware): track each I2C chip on its own and guard the bus restart
fc6a7e1
chore: ignore the PlatformIO VS Code extension's generated files
23f9e95
fix(firmware): act on failed servo writes and close OLED recovery gaps
ebdb608
fix(firmware): fault the PCA9685 at once on a failed write and lighte…
blakelton 2c63672
fix(firmware): verify recovery writes and close the gaps Copilot found
blakelton fbc642b
fix(firmware): step the PCA9685 recovery and enable outputs between p…
blakelton 0358011
fix(firmware): keep watching an OLED whose boot setup failed
blakelton e02c2b5
fix(firmware): finish servo recovery with the channel resync
blakelton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| #include "hardware/i2c_fault.h" | ||
|
|
||
| I2cFaultAction I2cFaultTracker::due(uint32_t now) const { | ||
| // Unsigned subtraction keeps the intervals right across the millis() wrap. | ||
| if (down_) { | ||
| return now - lastAttemptMs_ >= retryDelayMs_ | ||
| ? I2cFaultAction::Recover | ||
| : I2cFaultAction::None; | ||
| } | ||
|
|
||
| return !checked_ || now - lastCheckMs_ >= kI2cCheckIntervalMs | ||
| ? I2cFaultAction::Check | ||
| : I2cFaultAction::None; | ||
| } | ||
|
|
||
| bool I2cFaultTracker::noteCheck(bool ok, uint32_t now) { | ||
| checked_ = true; | ||
| lastCheckMs_ = now; | ||
|
|
||
| if (ok) { | ||
| failures_ = 0; | ||
| return false; | ||
| } | ||
|
|
||
| if (++failures_ < kI2cFailuresToFault) { | ||
| return false; | ||
| } | ||
|
|
||
| takeDown(now); | ||
| return true; | ||
| } | ||
|
|
||
| bool I2cFaultTracker::noteFault(uint32_t now) { | ||
| if (down_) { | ||
| return false; | ||
| } | ||
|
|
||
| takeDown(now); | ||
| return true; | ||
| } | ||
|
|
||
| void I2cFaultTracker::takeDown(uint32_t now) { | ||
| down_ = true; | ||
| faults_++; | ||
| lastFaultMs_ = now; | ||
| attempts_ = 0; | ||
| // The first recovery attempt runs right away. | ||
| retryDelayMs_ = 0; | ||
| lastAttemptMs_ = now; | ||
| } | ||
|
|
||
| void I2cFaultTracker::noteRecovery(bool ok, uint32_t now) { | ||
| attempts_++; | ||
| lastAttemptMs_ = now; | ||
|
|
||
| if (ok) { | ||
| down_ = false; | ||
| failures_ = 0; | ||
| recoveries_++; | ||
| lastCheckMs_ = now; | ||
| return; | ||
| } | ||
|
|
||
| if (retryDelayMs_ == 0) { | ||
| retryDelayMs_ = kI2cFirstRetryMs; | ||
| } else if (retryDelayMs_ >= kI2cMaxRetryMs / 2) { | ||
| retryDelayMs_ = kI2cMaxRetryMs; | ||
| } else { | ||
| retryDelayMs_ *= 2; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.