How to control the GPIO?


How to control the GPIO?
Are you planning to introduce your own version eg WiringPi?



We plan to port libmraa on ROCK Pi 4, which we think it’s a more professional project.


On this moment can’t use Gpio?

Mraa is quite demanding compared to wiringpi


If you’re into C, I would check out TinyGPIO on the Pi… (there are newer versions on the net too) you can just change the hardware addresses and start hacking i guess. Even more low level (which should also work on the RockPi):

RK3399 datasheet, Section 20.4


Rockchip GPIO has 5 banks, GPIO0~GPIO4, each bank has 32pins, naming as below:

GPIO0_A0 ~ A7 
GPIO0_B0 ~ B7
GPIO0_C0 ~ C7
GPIO0_D0 ~ D7

GPIO1_A0 ~ A7
GPIO1_D0 ~ D7

For Rockchip 4.4 kernel, the GPIO number can be calculated as below, take GPIO4_D5(PIN22 on 40PIN GPIO) as an example:

GPIO4_D5 = 32*4 + 8*3 + 5 = 157

To set GPIO4_D5 output

cd /sys/class/gpio
echo 157 > export
cd gpio157
echo out > direction
echo 1 > value     # output high
echo 0 > value     # output low



You can set the output value of an output and configuring the pin as a output in one command:

# Sets the pin as output and sets it to logical HIGH
echo "high" > /sys/class/gpio/gpio157/direction
# Sets the pin as output and sets it to logical LOW
echo "low" > /sys/class/gpio/gpio157/direction


GPIO pin number can be simplified by below table


Nice. i will add it to the wiki :slight_smile: