Skip to content

Commit 8688537

Browse files
committed
feat: add digitalToggle() function
Implement efficient pin state toggling using direct port manipulation. Need to add digitalToggle() declaration to common.h in Arduino API Core
1 parent 993398c commit 8688537

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

cores/arduino/wiring_digital.c

+16
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,22 @@ PinStatus digitalRead( pin_size_t ulPin )
118118
return LOW ;
119119
}
120120

121+
void digitalToggle(pin_size_t ulPin)
122+
{
123+
// Handle the case the pin isn't usable as PIO
124+
if (g_APinDescription[ulPin].ulPinType == PIO_NOT_A_PIN)
125+
{
126+
return;
127+
}
128+
129+
EPortType port = g_APinDescription[ulPin].ulPort;
130+
uint32_t pin = g_APinDescription[ulPin].ulPin;
131+
uint32_t pinMask = (1ul << pin);
132+
133+
PORT->Group[port].OUTTGL.reg = pinMask;
134+
return;
135+
}
136+
121137
#ifdef __cplusplus
122138
}
123139
#endif

0 commit comments

Comments
 (0)