Add support for the rest of the megaAVR 0-series, the tinyAVR 0/1-series, and the new AVR Dx-series, make interrupt safe. #94
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.
These all have the same patterns in register locations, so can use the same formulae for them.
This also switches to using the VPORT registers instead of the PORT registers, which makes setting or clearing a single bit into an atomic, single word, single cycle operation (SBI/CBI), as opposed to requiring a read-modify-write cycle like the PORT.OUT and PORT.DIR registers do, making those operations interrupt safe like they were on classic AVRs, as well as reducing sketch size and executing faster. Taking advantage of the consistent numbering of ports returned by digitalPinToPort() among the cores supporting these parts to get the base register address shrinks the compiled sketch size a touch too.
Non-pins passed to digitalPinToPort() will get back NOT_A_PORT, which is defined as 255, would give base reg of 0x03FC, which falls into one of the many gaps in the register space on these parts as well - so it won't fiddle with some random other peripheral somewhere (as it happens, it's right before where the PORT registers start at 0x0400, which seems fitting for "port -1")