Finding VPORTx from pin number

Say I have connection to digital pin20 on my Nano Every (ATMega4809). I can look at the Every pinout and see the port and pin designations. Then do things like:

VPORTF.DIR |= PIN4_bm; or,
VPORTB.OUT |= PIN4_bm;

Which are very fast.

I know you can use these functions:

bit = digitalPinToBitMask(pin);
port = digitalPinToPort(pin);
reg = portModeRegister(port);
out = portOutputRegister(port);

then:

*reg &= ~bit;   		
*out &= ~bit;

or similar.

But these are not as fast as the VPORT methods. Is there a way access VPORTx from pin numbers in a similar manner??

Thanks

K

Thanks !

And for the quick response.

I found a similar method that recognizes the unique port/pin designations on the Nano Every. Example below (sorry for the format :frowning: ):

#define __digitalPinToVDDRReg(P) \
  (((P) == 2 || (P) == 7) ? &VPORTA.DIR : \ 
((P) == 5 || (P) == 9 || (P) == 10) \
                                          ? &VPORTB.DIR \
                                        : \ 
((P) == 4) \
                                          ? &VPORTC.DIR \
                                        : \ 
(((P) >= 14 && (P) <= 17) || (P) == 20 || (P) == 21) \
                                          ? &VPORTD.DIR \
                                        : ((P) == 8 || (P) == 11 || (P) == 12 || (P) == 13) ? &VPORTE.DIR \
                                                                                            : &VPORTF.DIR)  // pins D3 and D6

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.