Closed
Description
I suggest the code below be added to wiring_digital.c and the Arduino language. This would make the task easier for beginning programmers and eliminate the need to check the state of the pin first, making a speed improvement at the same time.
void digitalToggle(uint8_t pin) {
uint8_t timer = digitalPinToTimer(pin);
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
volatile uint8_t *out;
if (port == NOT_A_PIN) return;
if (timer != NOT_ON_TIMER) turnOffPWM(timer);
out = portOutputRegister(port);
uint8_t oldSREG = SREG;
cli();
*out ^= bit;
SREG = oldSREG;
}