-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
Bring enableInterrupt()/disableInterrupt() in line with other single pin interfaces #48
Conversation
Thx for the PR? A thought Is the interrupt16() mask compatible with the interrupt()? Assuming mask = [15..0] |
You're welcome. Thanks for the Library! So in general I believe the the 16 functions are a bit conceptually out of whack with the single pin versions. However I see that this has to do with what arises naturally out of the MCP23S17's register map rather than any Library issue. The natural 0..15 (used in single pin functions) is: The 0..15 from the datasheet (used in 16 pin functions) is: I think the only way to get consistency would be to swap the first and second byte so that you could use reg[3] to access GPA4, matching the "natural" way (for me at least). I don't think using [15..0] would have the desired effect. However, I'm honestly not sure that's worth doing regardless. The 16 mode as implemented matches the datasheet so I'd say it's best to leave it alone and let people choose to either use the 16 bit "full" interface or the single bit at a time interface. The only reason for my difficulty was because the enableInterrupt function appeared to match the pinMode1 function but didn't. |
Alternatively, I had another thought of how to achieve consistency (again I don't know that it's worth upending the library). This section of code in begin() exists to ensure the sequential mode is active:
The phrase "note that address increment must be enabled for readReg16() and writeReg16() to work" is actually not quite accurate. On page 13 of the datasheet -
Because all read16 and write16 work on A/B pairs (that I've seen at least), even with sequential mode off, they would work and bounce between the registers. So my proposal is: turn off sequential mode (IOCON.SEQOP=1) and target the B port for all read16/write16. That way the upper byte is associated with the B port and the following lower byte is associated with the A port. Obviously this would be a breaking change and warrants more consideration, but I think it would have the desired outcome. |
I extracted your other thoughts into a separate issue - #50 |
Fixed the same bug in the I2C version - MCP23017_RT repo |
Resolves #47
I tried to keep the spirit of the code as seen in the pinMode1 function. Also happened to hit some of the enhancements noted in the comments before the enableInterrupt function.
I don't have a very comprehensive testing setup but I did utilize the changes on the own board to set up interrupts and it behaved correctly.