I am using Arduino Nano to test a code that will be ported on an ATTiny chip, which will need to perform operations at a frequency near clock maximum, calling for a very succinct coding.
My goal: to streamline coding for two different chips in one file with the least repetitions and operations possible.
Specifically, I have a pin
#ifdef TIMSK0 //Nano vs atTiny const byte wavePin = 5, waveBit = B100000; byte *wavePort = &PORTD; #define NANO #else const byte wavePin = 0, waveBit = PB1; byte *wavePort = &PORTB; #endif
Notice the pointer? It works, but I have the impression this may not be the most efficient option, as it adds an operation (by looking up the reference). I have also planned to do constantly check which chip we are loading it in this fashion
#ifdef NANO PORTD #else PORTB #endif |= waveBit * waveOn); #ifdef NANO PORTD #else PORTB #endif &= ~(waveBit * !waveOn));
But again, while this may be perfectly fine in operations, it hurts the eyes and is rather repetitive.
Is there a way to create a direct access to a port?