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

Fix hexpansions not being consistently detected on hotplug #122

Merged
merged 2 commits into from
Jun 11, 2024

Conversation

hedgehog1029
Copy link
Contributor

@hedgehog1029 hedgehog1029 commented Jun 9, 2024

For mysterious reasons the GPIO expanders seem to not always update the state of port 1 when doing a multi-byte read. If we instead do two single-byte reads, we appear to get the correct state 100% of the time.

The datasheet has some confusing lines about how you always need to send a write command before reading the port states - I believe readfrom_mem actually does this, but since it's not actually sending any data for the write, it's only technically writing to address 0, which only updates port 0 (hence why buttons work consistently - they're all port 0!)

Fixes #89

For mysterious reasons the GPIO expanders seem to not always update the
state of port 1 when doing a multi-byte read. If we instead do two
single-byte reads, we appear to get the correct state 100% of the time.
The datasheet has some confusing lines about how you always need to send
a write command before reading the port states - I believe readfrom_mem
actually does this, but since it's not actually sending any data for the
write, it's only technically writing to address 0, which only updates
port 0 (hence why buttons work consistently - they're all port 0!)
@andypiper
Copy link
Contributor

... fixes #89 ?

@Robotmad
Copy link
Contributor

I suspect this is also needed for set_egpio_pin. Writing the the LS pins through the badge code doesn't work on some hexpansions - likely also where the pins are on port 1. Whereas code writing only one byte (port) at a time is fine.

Previous code was only writing to one expander & may have suffered from
the multi-byte read bug
@hedgehog1029
Copy link
Contributor Author

Pushed an extra commit to fix set_egpio_pin, which was broken in other ways other than relying on the buggy multi-byte reads.

@castaway
Copy link
Contributor

Tested on a badge with dodgy hexpansion finding - works for me

@kliment kliment merged commit 89dacea into emfcamp:main Jun 11, 2024
2 checks passed
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.

Hexpansion detect is occasionally dodgy
5 participants