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.
This commit fixes a couple of bugs; the report_bat() function was unilaterally writing data to the i2c bus without it being requested by the master on the bus. I don't know if the arduino library is smart enough to prevent that from doing bad things with the bus signals, but even if it does, this represents a potential race condition with respect to the normal receive handling.
The other issue that this commit addresses is that the pmu charging status is determined and set as the high bit of the value that is assigned to REG_ID_BAT, but the i2c slave handling never reads from that register, instead reading a separate copy of the battery percentage level with no charging status flag.
The approach taken here is to read from the REG_ID_BAT register when responding to a request for that value, so that the charging status can be returned.
The report_bat() function has been removed; it was only ever called from the function that assigns REG_ID_BAT at the end, so there is no need for it to read and do something with the battery level, and it really should not be changing the write buffer for the i2c request handling logic.