My tried a true method for the mega series was this:
#define PIEZO_PORT PORTB
#define PIEZO_POS_PIN 0
#define PIEZO_NEG_PIN 1
Then in code...
PIEZO_PORT=_BV(PIEZO_POS_PIN);
DDR(PIEZO_PORT)=_BV(PIEZO_POS_PIN) | _BV(PIEZO_NEG_PIN);
Because I use these macros as well:
#define PIN(x) (*(&x - 2)) // Address of Data Direction Register of Port X
#define DDR(x) (*(&x - 1)) // Address of Input Register of Port X
So now, I'm using an atmega4809 -
#define SPI_PORT PORTE
#define MOSI_PIN 0
#define MISO_PIN 1
#define SCK_PIN 2
#define SS_PIN 3
The dot notation allows me to replace PORTE with SPI_PORT, but the PIN0CTRL is causing me a bit of trouble. Should I also define a MOSI_PIN_CTRL as PIN0CTRL ?
SPI_PORT.PIN0CTRL=PORT_PULLUPEN_bm; //PE0 mosi enable pullup
SPI_PORT.DIRSET=_BV(MISO_PIN); //PE1 miso output
SPI_PORT.PIN2CTRL=PORT_PULLUPEN_bm; //PE2 sck enable pullup
SPI_PORT.PIN3CTRL=PORT_ISC_RISING_gc | PORT_PULLUPEN_bm; //PE3 SS interrupt rising edge and enable pullup
SPI0_CTRLA=SPI_ENABLE_bm;
SPI0_INTCTRL=SPI_IE_bm;