Skip to content

fix reporting charging status #22

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

wez
Copy link
Contributor

@wez wez commented Apr 17, 2025

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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant