GPIO_OUT_REG = 2097152 → Binary: 0b0010 0000 0000 0000 0000 0000
= Bit 21 is HIGH (2²¹ = 2097152)
GPIO_OUT_REG = 0 → All bits LOW → pin is LOW
This confirms:
-
You’re setting bit 21 (GPIO21 → D3) →
HIGH
-
You’re clearing it →
LOW
-
This is exactly what you’d expect from correctly toggling GPIO21 using W1TS/W1TC (write-one-to-set / write-one-to-clear) registers on the ESP32-C6.
-
The printed values directly match the bitmask of
1 << 21
.
EDIT:
Mark this as the Solution so others can FInd it.