Gpio.h is meant to be used for pins that are not used by Bela. If you want to use one of those , you can read them from within render() and store their values in a global variable. If using other pins, you'll have to cross check:
- the gem schematics to make sure those pins are not used on the board
- the PB2 datasheet, page 38 and following to know the GPIO bank and number
- grep for the address of each pin in the file
/sys/kernel/debug/pinctrl/f4000.pinctrl-pinctrl-single/pins to make suer they are set to the correct mode
E.g.: pin P1.03 is free; poage 38 of the datasheet says it's GPIO1_51, so you can use gpio.open({1, 51}, ...). Its address is 0x000F4258, so
# grep -i F4258 /sys/kernel/debug/pinctrl/f4000.pinctrl-pinctrl-single/pins
pin 150 (PIN150) 51:601000.gpio f4258 00054000 pinctrl-single
the "mode" is the last digit of the last number: 00054000 means it's mode 0 . It needs to be mode 7 to be a GPIO. So this pin won't work as it is. Either you look for a different one or change the pinmuxing of this, either with a device tree overlay (see https://learn.bela.io/using-bela/technical-explainers/device-tree-overlays) or with a devmem2 hack (to be repeated at every boot):
# devmem2 0xf4258 w 0x00054007
/dev/mem opened.
Memory mapped at address 0xffff863e9000.
Read at address 0x000F4258 (0xffff863e9258): 0x00054000
Write at address 0x000F4258 (0xffff863e9258): 0x00054007, readback 0x00054007
now you can repeat the grep above and see that it has the correct mode (ends in "7"):
# root@bela:~/Bela# grep -i F4258 /sys/kernel/debug/pinctrl/f4000.pinctrl-pinctrl-single/pins
pin 150 (PIN150) 51:601000.gpio f4258 00054007 pinctrl-single