Port manipulation made easy

Again, yes, that I know, but why not make it a premade function for everyone?

There are a zillion premade functions possible and should the core support them all?

DigitalWrite() exists as it simplifies the setting of a line very much. One line of code iso 50 or more. That's a clear added value imho.

Also using the loop would not make it set the pins together as port manipulation would, there would be a delay inbetween them.

So you want a function that sets the pins simultaneously with DPM. I missed that part.
That is only possible if the pins are on the same port e.g. PORTB
The function would already fail to do a simultaneous setting if the pins are on different ports. There will always be a (small) time difference .

(above is just my opinion, you an propose always new features @ GitHub - arduino/Arduino: Arduino IDE 1.x )

But I was just wondering if it could already be premade.

as said above, it could be made and would look something like below:

void multiDigitalWrite(int *pins, int size, int val)
{
  uint8_t shadowBits[4] = 0;
  for (int i=0; i< size; i++) 
  {
	uint8_t port = digitalPinToPort(pins[i]);
        shadowBits[port] | = digitalPinToBitMask(pins[i]);
  }

  for (int i=0; i<numberOfPorts; i++)
  {
     if (shadowBits[i] == 0) continue;  // next port

     out = portOutputRegister(ports[i]);  // use out[i] to remove this line... ?
     if (timer[i] != NOT_ON_TIMER) turnOffPWM(timer[i]);

     	if (val == LOW) {  // move this test outside the loop
		uint8_t oldSREG = SREG;
                cli();
		*out &= ~shadowBits;
		SREG = oldSREG;
	} else {
		uint8_t oldSREG = SREG;
                cli();
		*out |= shadowBits;
		SREG = oldSREG;
	}
   }
}

This is definitely not working code yet but it shows that the complexity is not too bad either compared to digitalWrite() which I used as inspiration. The function collects all the bits to set in shadowBits and set them at once. The line with continue is an optimization. There are some other points to optimize see comments.

Now it is your turn to finish it and make it work :wink: