Skip to content

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

Open
SpenceKonde wants to merge 6 commits intoPaulStoffregen:masterfrom
SpenceKonde:master
Open

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
SpenceKonde wants to merge 6 commits intoPaulStoffregen:masterfrom
SpenceKonde:master

Conversation

@SpenceKonde
Copy link
Copy Markdown

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")

Instead of checking for the single 0-series megaAVR that is most common, check for all tinyAVR 0/1-series, megaAVR 0-series (__AVR_ARCH__103) as well as the Dx series (__AVR_ARCH__=104), since they use the same kind of peripherals
Use the VPORTx registers - should give slightly smaller, faster, atomic code. Previous implementation used the PORTx registers; those are not in the I/O space, so |= and &= were not atomic! They still may not be in all cases (depending on what the compiler is able to optimize away) - but this will transparently take advantage of updates to the macros supplied with the cores which do, if/when they come.
Fix -fpermissive warning
@SpenceKonde
Copy link
Copy Markdown
Author

Just discovered something: AVR_ARCH is 102, 103, or 104 for the new Dx series parts, not always 104. 103 which is what it is on the tinyAVR/megaAVR 0/1-series as well as 32k Dx parts; these can map all of their flash in the data space at once. 102 is for 64k (two sections), and 104 is for 128k parts (which have to split their flash into 4 sections)

Updated pr to account for this discovery.

@BigGene
Copy link
Copy Markdown

BigGene commented May 19, 2021

Please add this support for the new AVRs in the next version. Thanks!

@WeirdConstructor
Copy link
Copy Markdown

I would really love to have this PR merged and a current version of this. Currently I have to manually modify util/OneWire_direct_gpio.h with a hack to get OneWire to work with DS18B20.

@uzi18
Copy link
Copy Markdown

uzi18 commented Aug 17, 2024

Try OneWireNg

@WeirdConstructor
Copy link
Copy Markdown

Try OneWireNg

Ah, thanks a lot! That one works out of the box (even though the API is a slight bit more complicated).

@jens-ylja
Copy link
Copy Markdown

I'd also like to get this merged.
I have an ATtiny814 here and can confirm it's working with this one too.

I use OneWire with milesburton/DallasTemperature on top (setup taken over from my other projects) and would rather like to keep than switching to OneWireNg as proposed in thread.

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.

5 participants