gpio(3)
okay so bestie, you opened the gpio(3) page from the Library Functions Manual and I'm SO glad you're here π This is the lowkey iconic guide to controlling the GPIO interface on your Raspberry Pi. Let's get into it, no cap.
β¨ NAME β¨
gpioβ GPIO register access
πΈ SYNOPSIS πΈ
Functions
here's the full roster of function signatures, bestie. memorize them like your fave lyrics:
void bcm2835_gpio_fsel (uint8_t pin, uint8_t mode)
void bcm2835_gpio_set (uint8_t pin)
void bcm2835_gpio_clr (uint8_t pin)
void bcm2835_gpio_set_multi (uint32_t mask)
void bcm2835_gpio_clr_multi (uint32_t mask)
uint8_t bcm2835_gpio_lev (uint8_t pin)
uint8_t bcm2835_gpio_eds (uint8_t pin)
uint32_t bcm2835_gpio_eds_multi (uint32_t mask)
void bcm2835_gpio_set_eds (uint8_t pin)
void bcm2835_gpio_set_eds_multi (uint32_t mask)
void bcm2835_gpio_ren (uint8_t pin)
void bcm2835_gpio_clr_ren (uint8_t pin)
void bcm2835_gpio_fen (uint8_t pin)
void bcm2835_gpio_clr_fen (uint8_t pin)
void bcm2835_gpio_hen (uint8_t pin)
void bcm2835_gpio_clr_hen (uint8_t pin)
void bcm2835_gpio_len (uint8_t pin)
void bcm2835_gpio_clr_len (uint8_t pin)
void bcm2835_gpio_aren (uint8_t pin)
void bcm2835_gpio_clr_aren (uint8_t pin)
void bcm2835_gpio_afen (uint8_t pin)
void bcm2835_gpio_clr_afen (uint8_t pin)
void bcm2835_gpio_pud (uint8_t pud)
void bcm2835_gpio_pudclk (uint8_t pin, uint8_t on)
uint32_t bcm2835_gpio_pad (uint8_t group)
void bcm2835_gpio_set_pad (uint8_t group, uint32_t control)
void bcm2835_delay (unsigned int millis)
void bcm2835_delayMicroseconds (uint64_t micros)
void bcm2835_gpio_write (uint8_t pin, uint8_t on)
void bcm2835_gpio_write_multi (uint32_t mask, uint8_t on)
void bcm2835_gpio_write_mask (uint32_t value, uint32_t mask)
void bcm2835_gpio_set_pud (uint8_t pin, uint8_t pud)
uint8_t bcm2835_gpio_get_pud (uint8_t pin)
π¦ DESCRIPTION π¦
Detailed Description
so basically these functions are your backstage pass to the GPIO interface. You can set what each GPIO pin does (its function), peek at the input state, and set the output state. It's giving main character energy for all your hardware projects β¨
π Function Documentation π
void bcm2835_delay (unsigned int millis) [extern]
What it do: Delays for the number of milliseconds you pass in. It uses nanosleep(), so it doesn't burn CPU while waiting. But bestie, you're at the mercy of nanosleep() β from the manual: If the interval specified in req is not an exact multiple of the granularity underlying clock (see time(7)), then the interval will be rounded up to the next multiple. Also, after the sleep completes, there may still be a delay before the CPU becomes free to once again execute the calling thread. π
millisβ Delay in milliseconds
void bcm2835_delayMicroseconds (uint64_t micros) [extern]
What it do: Delays for the number of microseconds you pass in. It uses a combo of nanosleep() and a busy wait loop on the BCM2835 system timers. However, you're still at the mercy of nanosleep(). From the manual: If the interval specified in req is not an exact multiple of the granularity underlying clock (see time(7)), then the interval will be rounded up to the next multiple. Furthermore, after the sleep completes, there may still be a delay before the CPU becomes free to once again execute the calling thread. For times less than about 450 microseconds, it uses a busy wait on the System Timer. It is reported that a delay of 0 microseconds on RaspberryPi will in fact result in a delay of about 80 microseconds. Your mileage may vary. π
microsβ Delay in microseconds
void bcm2835_gpio_afen (uint8_t pin) [extern]
What it do: Enable Asynchronous Falling Edge Detect Enable for the specified pin. When a falling edge is detected, it sets the appropriate pin in Event Detect Status. Asynchronous means the incoming signal is not sampled by the system clock. As such, falling edges of very short duration can be detected. β¨
pinβ GPIO number, or one ofRPI_GPIO_P1_*fromRPiGPIOPin.
void bcm2835_gpio_aren (uint8_t pin) [extern]
What it do: Enable Asynchronous Rising Edge Detect Enable for the specified pin. When a rising edge is detected, it sets the appropriate pin in Event Detect Status. Asynchronous means the incoming signal is not sampled by the system clock. As such, rising edges of very short duration can be detected. β¨
pinβ GPIO number, or one ofRPI_GPIO_P1_*fromRPiGPIOPin.
void bcm2835_gpio_clr (uint8_t pin) [extern]
What it do: Sets the specified pin output to LOW.
pinβ GPIO number, or one ofRPI_GPIO_P1_*fromRPiGPIOPin.
See also: bcm2835_gpio_write()
void bcm2835_gpio_clr_afen (uint8_t pin) [extern]
What it do: Disable Asynchronous Falling Edge Detect Enable for the specified pin.
pinβ GPIO number, or one ofRPI_GPIO_P1_*fromRPiGPIOPin.
void bcm2835_gpio_clr_aren (uint8_t pin) [extern]
What it do: Disable Asynchronous Rising Edge Detect Enable for the specified pin.
pinβ GPIO number, or one ofRPI_GPIO_P1_*fromRPiGPIOPin.
void bcm2835_gpio_clr_fen (uint8_t pin) [extern]
What it do: Disable Falling Edge Detect Enable for the specified pin.
pinβ GPIO number, or one ofRPI_GPIO_P1_*fromRPiGPIOPin.
void bcm2835_gpio_clr_hen (uint8_t pin) [extern]
What it do: Disable High Detect Enable for the specified pin.
pinβ GPIO number, or one ofRPI_GPIO_P1_*fromRPiGPIOPin.
void bcm2835_gpio_clr_len (uint8_t pin) [extern]
What it do: Disable Low Detect Enable for the specified pin.
pinβ GPIO number, or one ofRPI_GPIO_P1_*fromRPiGPIOPin.
void bcm2835_gpio_clr_multi (uint32_t mask) [extern]
What it do: Sets any of the first 32 GPIO output pins specified in the mask to LOW.
maskβ Mask of pins to affect. Use eg:(1 << RPI_GPIO_P1_03) | (1 << RPI_GPIO_P1_05)
See also: bcm2835_gpio_write_multi()
void bcm2835_gpio_clr_ren (uint8_t pin) [extern]
What it do: Disable Rising Edge Detect Enable for the specified pin.
pinβ GPIO number, or one ofRPI_GPIO_P1_*fromRPiGPIOPin.
uint8_t bcm2835_gpio_eds (uint8_t pin) [extern]
What it do: Event Detect Status. Tests whether the specified pin has detected a level or edge as requested by bcm2835_gpio_ren(), bcm2835_gpio_fen(), bcm2835_gpio_hen(), bcm2835_gpio_len(), bcm2835_gpio_aren(), bcm2835_gpio_afen(). Clear the flag for a given pin by calling bcm2835_gpio_set_eds(pin); π
pinβ GPIO number, or one ofRPI_GPIO_P1_*fromRPiGPIOPin.
Returns: HIGH if the event detect status for the given pin is true.
uint32_t bcm2835_gpio_eds_multi (uint32_t mask) [extern]
What it do: Same as bcm2835_gpio_eds() but checks if any of the pins specified in the mask have detected a level or edge.
maskβ Mask of pins to check. Use eg:(1 << RPI_GPIO_P1_03) | (1 << RPI_GPIO_P1_05)
Returns: Mask of pins HIGH if the event detect status for the given pin is true.
void bcm2835_gpio_fen (uint8_t pin) [extern]
What it do: Enable Falling Edge Detect Enable for the specified pin. When a falling edge is detected, it sets the appropriate pin in Event Detect Status. The GPRENn registers use synchronous edge detection. This means the input signal is sampled using the system clock and then it is looking for a ?100? pattern on the sampled signal. This has the effect of suppressing glitches. β¨
pinβ GPIO number, or one ofRPI_GPIO_P1_*fromRPiGPIOPin.
void bcm2835_gpio_fsel (uint8_t pin, uint8_t mode) [extern]
What it do: Sets the Function Select register for the given pin, which configures the pin as Input, Output or one of the 6 alternate functions.
pinβ GPIO number, or one ofRPI_GPIO_P1_*fromRPiGPIOPin.modeβ Mode to set the pin to, one ofBCM2835_GPIO_FSEL_*frombcm2835FunctionSelect
uint8_t bcm2835_gpio_get_pud (uint8_t pin) [extern]
What it do: On the BCM2711 based RPI 4, gets the current Pull-up/down mode for the specified pin. Returns one of BCM2835_GPIO_PUD_* from bcm2835PUDControl. On earlier RPI versions not based on the BCM2711, returns BCM2835_GPIO_PUD_ERROR. π
pinβ GPIO number, or one ofRPI_GPIO_P1_*fromRPiGPIOPin.
void bcm2835_gpio_hen (uint8_t pin) [extern]
What it do: Enable High Detect Enable for the specified pin. When a HIGH level is detected on the pin, it sets the appropriate pin in Event Detect Status.
pinβ GPIO number, or one ofRPI_GPIO_P1_*fromRPiGPIOPin.
void bcm2835_gpio_len (uint8_t pin) [extern]
What it do: Enable Low Detect Enable for the specified pin. When a LOW level is detected on the pin, it sets the appropriate pin in Event Detect Status.
pinβ GPIO number, or one ofRPI_GPIO_P1_*fromRPiGPIOPin.
uint8_t bcm2835_gpio_lev (uint8_t pin) [extern]
What it do: Reads the current level on the specified pin and returns either HIGH or LOW. Works whether or not the pin is an input or an output. π
pinβ GPIO number, or one ofRPI_GPIO_P1_*fromRPiGPIOPin.
Returns: the current level either HIGH or LOW
uint32_t bcm2835_gpio_pad (uint8_t group) [extern]
What it do: Reads and returns the Pad Control for the given GPIO group. Caution: requires root access. β οΈ
groupβ The GPIO pad group number, one ofBCM2835_PAD_GROUP_GPIO_*
Returns: Mask of bits from BCM2835_PAD_* from bcm2835PadGroup
void bcm2835_gpio_pud (uint8_t pud) [extern]
What it do: Sets the Pull-up/down register for the given pin. This is used with bcm2835_gpio_pudclk() to set the Pull-up/down resistor for the given pin. However, it is usually more convenient to use bcm2835_gpio_set_pud(). π
pudβ The desired Pull-up/down mode. One ofBCM2835_GPIO_PUD_*frombcm2835PUDControlOn the RPI 4, although this function andbcm2835_gpio_pudclk()are supported for backward compatibility, new code should always usebcm2835_gpio_set_pud().
See also: bcm2835_gpio_set_pud()
void bcm2835_gpio_pudclk (uint8_t pin, uint8_t on) [extern]
What it do: Clocks the Pull-up/down value set earlier by bcm2835_gpio_pud() into the pin.
pinβ GPIO number, or one ofRPI_GPIO_P1_*fromRPiGPIOPin.onβ HIGH to clock the value frombcm2835_gpio_pud()into the pin. LOW to remove the clock.
On the RPI 4, although this function and bcm2835_gpio_pud() are supported for backward compatibility, new code should always use bcm2835_gpio_set_pud().
See also: bcm2835_gpio_set_pud()
void bcm2835_gpio_ren (uint8_t pin) [extern]
What it do: Enable Rising Edge Detect Enable for the specified pin. When a rising edge is detected, it sets the appropriate pin in Event Detect Status. The GPRENn registers use synchronous edge detection. This means the input signal is sampled using the system clock and then it is looking for a ?011? pattern on the sampled signal. This has the effect of suppressing glitches. β¨
pinβ GPIO number, or one ofRPI_GPIO_P1_*fromRPiGPIOPin.
void bcm2835_gpio_set (uint8_t pin) [extern]
What it do: Sets the specified pin output to HIGH.
pinβ GPIO number, or one ofRPI_GPIO_P1_*fromRPiGPIOPin.
See also: bcm2835_gpio_write()
void bcm2835_gpio_set_eds (uint8_t pin) [extern]
Okay so bestie, this one sets the Event Detect Status register for a given pin to 1, which β plot twist β actually clears the flag. Yes it's giving chaos but that's just how it is. Use it after you see an Event Detect Status on the pin. π
β¨ Parameters β¨
pinβ the GPIO number, or one ofRPI_GPIO_P1_*fromRPiGPIOPin.
void bcm2835_gpio_set_eds_multi (uint32_t mask) [extern]
Literally the same energy as bcm2835_gpio_set_eds() but it clears the flag for any pin that's set in the mask. Multi-pin slay. π
β¨ Parameters β¨
maskβ mask of the pins to clear. Use, eg:(1 << RPI_GPIO_P1_03) | (1 << RPI_GPIO_P1_05)
void bcm2835_gpio_set_multi (uint32_t mask) [extern]
Sets any of the first 32 GPIO output pins specified in the mask to HIGH. Obsessed honestly.
β¨ Parameters β¨
maskβ mask of the pins to affect. Use, eg:(1 << RPI_GPIO_P1_03) | (1 << RPI_GPIO_P1_05)
π See also
bcm2835_gpio_write_multi()
void bcm2835_gpio_set_pad (uint8_t group, uint32_t control) [extern]
Sets the Pad Control for the given GPIO group.
π¨ Caution bestie: this one requires root access. Like, actual root. Don't come crying to me when it doesn't work without it. π
β¨ Parameters β¨
groupβ the GPIO pad group number, one ofBCM2835_PAD_GROUP_GPIO_*controlβ mask of bits fromBCM2835_PAD_*frombcm2835PadGroup. Ngl, you do not need to includeBCM2835_PAD_PASSWRDin the mask, because that's automatically included for you. Considerate of it fr fr. π«Ά
void bcm2835_gpio_set_pud (uint8_t pin, uint8_t pud) [extern]
Sets the Pull-up/down mode for the specified pin. This is so much more convenient than clocking the mode in manually with bcm2835_gpio_pud() and bcm2835_gpio_pudclk(). The way that it just does the whole thing for youβ¦ iconic. β¨
β¨ Parameters β¨
pinβ the GPIO number, or one ofRPI_GPIO_P1_*fromRPiGPIOPin.pudβ the desired Pull-up/down mode. One ofBCM2835_GPIO_PUD_*frombcm2835PUDControl.
void bcm2835_gpio_write (uint8_t pin, uint8_t on) [extern]
Sets the output state of the specified pin. The main character of GPIO calls, lowkey. π
β¨ Parameters β¨
pinβ the GPIO number, or one ofRPI_GPIO_P1_*fromRPiGPIOPin.onβHIGHsets the output toHIGHandLOWtoLOW.
void bcm2835_gpio_write_mask (uint32_t value, uint32_t mask) [extern]
Sets the first 32 GPIO output pins specified in the mask to the value given by value. Two masks, one vibe check. π
β¨ Parameters β¨
valueβ the values required for each bit masked in bymask, eg:(1 << RPI_GPIO_P1_03) | (1 << RPI_GPIO_P1_05)maskβ mask of the pins to affect. Use, eg:(1 << RPI_GPIO_P1_03) | (1 << RPI_GPIO_P1_05)
void bcm2835_gpio_write_multi (uint32_t mask, uint8_t on) [extern]
Sets any of the first 32 GPIO output pins specified in the mask to the state given by on. Chef's kiss. π
β¨ Parameters β¨
maskβ mask of the pins to affect. Use, eg:(1 << RPI_GPIO_P1_03) | (1 << RPI_GPIO_P1_05)onβHIGHsets the output toHIGHandLOWtoLOW.
π Author π
Generated automatically by Doxygen for bcm2835 from the source code. Not a human, not a bestie, just a tool doing its thing. π§
And that's a wrap on gpio(3)! This whole page is from bcm2835, Version 1.75 β the gpio(3) manual, periodt. π
β¨π¦
π¦ where this page comes from
- debian trixie: libbcm2835-dev 1.75+ds-1 Β· GPL-3.0-only
- ubuntu noble: libbcm2835-dev 1.75+ds-1 Β· GPL-3.0-only
- ubuntu questing: libbcm2835-dev 1.75+ds-1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms