GPIOs¶
Macros¶
-
GPIO_OFFSET¶ 0x200000This macro defines the offset at which the GPIO registers are located from the peripheral base.
-
GPIO_SIZE¶ 0xB0This macro holds the size of the GPIO registers which needs to be mapped.
Registers¶
-
volatile uint32_t *
gpio_base_ptr¶ This pointer points, when mapped, to the base of the GPIO registers.
-
struct
gpio_register_map¶ This struct maps the registers of the GPIOs. The names of the struct members correspond to the registers from the Datasheet:
struct gpio_register_map { uint32_t FSEL[6]; uint32_t: 32; uint32_t SET[2]; uint32_t: 32; uint32_t CLR[2]; uint32_t: 32; uint32_t LEV[2]; uint32_t: 32; uint32_t EDS[2]; uint32_t: 32; uint32_t REN[2]; uint32_t: 32; uint32_t FEN[2]; uint32_t: 32; uint32_t HEN[2]; uint32_t: 32; uint32_t LEN[2]; uint32_t: 32; uint32_t AREN[2]; uint32_t: 32; uint32_t AFEN[2]; uint32_t: 32; uint32_t PUD; uint32_t PUDCLK[2]; };
-
GP¶ #define GP ((volatile struct gpio_register_map *)gpio_base_ptr)By using this macro, the registers of the GPIOs can be accessed like this
GP->SET[0].
Enums¶
-
pin_functions_t¶ This enum holds the values for the various pin functions:
typedef enum { INPUT, OUTPUT, ALT0, ALT1, ALT2, ALT3, ALT4, ALT5 } pin_functions_t;
-
pud_t¶ This enum holds the values for the states of the pullups / -downs:
typedef enum { PUD_DISABLE, PUD_DOWN, PUD_UP } pud_t;
Functions¶
-
uint32_t *
gpio_map(void)¶ This function maps the GPIO registers. It calls
peripheral_map()with the valuesGPIO_OFFSETandGPIO_SIZE.
-
void
gpio_unmap(void)¶ This function unmaps the GPIOs.
-
void
gpio_func(uint32_t pin, pin_functions_t function)¶ This function sets the pin
pinto the pin functionfunction.
-
void
gpio_set(uint32_t pin)¶ Set the pin
pin.
-
void
gpio_clr(uint32_t pin)¶ Clear the pin
pin.
-
uint32_t
gpio_tst(uint32_t pin)¶ Test the pin
pin. This function returns0orfalsewhen the pin is low and non-zero if the pin is high.
-
void
gpio_inp(uint32_t pin)¶ Make pin
pinan input.
-
void
gpio_out(uint32_t pin)¶ Make pin
pinan output.