PORTD_PCR2 = 0001; //change mux to alt 1 which is GPIO
PORTD_PCR3 = 0001; //change mux to alt 1 which is GPIO
GPIOD_PDDR = 0x0C; //Pin is configured as general-purpose output
GPIOD_PDOR = 0x0; //Logic level 0 is driven on pin
Went a little to far in reducing the code.
Still need the MUX() as it hides shifts and masks.
Still need the AND for the GIO. Only want to change one pin, not all of them.
Something along this line:
#define MEANINGFUL_NAME_bm (0x00000040UL)
/* _bm means Bit Mask */
PORTD_PCR2 = PORT_PCR_MUX(1U);
PORTD_PCR3 = PORT_PCR_MUX(1U);
GPIOD_PDOR &= ~MEANINGFUL_NAME_bm; /* Drive output low */
GPIOD_PDDR &= ~MEANINGFUL_NAME_bm; /* Set pin to output [Check data sheet to see if this should be a OR, don't have data sheet at hand] */
Note that I swapped PDOR and PDDR to prevent a short glitch on the output.