Skip to content
Jaslo edited this page Nov 3, 2018 · 1 revision

gpio.h

This header grants easy access to the Pis GPIOs.

Functions

  • uint32_t *gpio_map(void): This function maps the peripheral. On success it return a pointer to the mapped memory. When an error accurs NULL is returned.

  • void gpio_unmap(void): Unmaps the peripheral again.

  • void gpio_func(uint32_t pin, pin_functions function): With functions makes the GPIO an input, output or one of the alternate functions. pin specifies the bcm2835 pin and function the function the pin should have.

  • extern void gpio_set(uint32_t pin): Sets the GPIO pin.

  • extern void gpio_clr(uint32_t pin): Clears the GPIO pin.

  • extern bool gpio_tst(uint32_t pin): Returns the voltage level of the GPIO pin.

  • void gpio_pud(uint32_t pin, pud val): This function activates or disables an pullup or -down on GPIO pin.

  • void gpio_inp(uint32_t pin): Makes the GPIO pin an input.

  • void gpio_out(uint32_t pin): Makes the GPIO pin an output.

  • void gpio_ca_pud(void): Clears all pullup and -downs. Because pullup and -downs are not cleared after a reset this function is called inside gpio_map() and gpio_unmap.

Registers

Every register is specified by a macro in the header and directly accessible (example: GPFSEL0). To make life easier there is a pointer to the base register for every number of registers that do the same thing for different pins (example: GPFSEL0 to GPFSEL5 and the pointer GPFSEL to the base register).

Sources and useful documentation

Clone this wiki locally