GPIO (General Purpose Input / Output)
GPIO stands for general purpose input/output. It is a type of pin found on an integrated circuit that does not have a specific function.
A general purpose input/output (GPIO) is an MCU pin whose function the software chooses.
GPIO
GPIO stands for general purpose input/output. It is a type of pin found on an integrated circuit that does not have a specific function. While most pins have a dedicated purpose, such as sending a signal to a certain component, the function of a GPIO pin is customizable and can be controlled by the software.
It can work as an input, reading logical signals such as from a button. It can work as an output, controlling something like an LED, a relay or a motor. Sometimes a pin does both, as an input and as an output (push-pull).
Pin
Each port bit of the general-purpose I/O (GPIO) ports can be individually configured by software in several modes:
- input or output
- analog
- alternate function (AF)
Pin characteristics:
- Input: no
pull-upand nopull-down, or pull-up or pull-down - Output:
push-pulloropen-drainwith pull-up or pull-down capability - Alternate function: push-pull or open-drain with pull-up or pull-down capability

GPIO design
Each GPIO pin of the microcontroller consists of three key components:

Enable line
- Configures the pin mode:
input,output,alternate function,analog, etc. - Controls the activation of internal pull-up resistors
- Enables/disables input/output buffers and logic enable
Output buffer
- It is a combination of two transistors (PMOS + NMOS)
- In push-pull mode both can work
- In open-drain only
NMOSis active - Allows to output logic levels to an external pin
When the signal 0 comes out, control goes through the NMOS transistor and no logical one is supplied to the pin.

When the signal 1 comes out, control goes through the PMOS transistor and a logical one is supplied to the pin.

Input buffer
- Monitors the signal level on the pin
- Can be enabled or disabled, for example to disable reading during output
- Used to read the logic level or generate interrupts
When a 0 signal is received on the pin, control passes through the NMOS transistor and goes to GND.

When a 1 signal is received on the pin, control passes through the PMOS transistor and is powered from +VCC.

GPIO modes
By default all GPIOs on most microcontrollers are configured in input mode. In this mode they are not connected to either Vcc or GND, and the pin is in the High Impedance (Hi-Z) state. This means that the GPIO is not “involved” in the circuit’s operation, but may be subject to noise and flow currents, especially if the input is left floating.
| Mode | Description | Example |
|---|---|---|
| Input | Reading signal from outside | Button, sensor |
| Input Pull-Up | Input with pull-up to Vcc (internal resistor) | Button to GND |
| Input Pull-Down | Input with pull-down to GND | Button to Vcc |
| Output Push-Pull | Normal output (0 or 1) | LED, relay |
| Output Open-Drain | Only “0”, “1” via external resistor | I²C, external bus |
| Analog | ADC/DAC is used on the output | Temperature sensor, audio |
| Alternate Function | Used by peripherals (SPI, PWM, UART) | SPI, I²C, PWM |
If we wanted to use some pin as an input, we would use either .into_pull_up_input() or .into_pull_down_input() to tell the chip to expect the system voltage (3.3 volts) to be present or absent, and react if that changes.
// RP2040 (Rust embedded-hal, hi-Z)
_pin_28.into_pull_down_input(); // Set GPIO 28 as input with pull-down
_pin_28.into_floating_input(); // Set GPIO 28 as floating input
_pin_28.into_pull_up_input(); // Set GPIO 28 as input with pull-up
_pin_28.into_pull_up_disabled(); // Disable pull-up on GPIO 28
_pin_28.into_pull_down_disabled(); // Disable pull-down on GPIO 28
_pin_28.into_push_pull_output(); // Set GPIO 28 as push-pull output
Output
Push-Pull
- GPIO uses two transistors:
PMOS(to supply “1”) andNMOS(to supply “0”) - In push-pull mode, the pin can actively supply the line with logical 1 (Vcc) via PMOS, and logical 0 (GND) via NMOS
- This is the standard mode for driving LEDs, relays and other loads
Open-Drain
- In this mode, GPIO can only short the pin to ground (0) via
NMOS - The internal
PMOSis missing or disabled, so you cannot apply “1” directly - When GPIO is driven to logic “1”, the transistor is off and the pin becomes floating
- To make the line logic “1”, a pull-up resistor is used:
- Internal (enabled by software if available)
- External (usually 4.7k to 10k Ohm to Vcc)
This is useful when you need a common bus with many devices connected to it. All participants can only pull down, which avoids a conflict.
Neighbors in time
Related: the posts that share this one's subject, and where the thread goes next.