How to control the GPIO?


#1

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


#2

Hi,

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


#3

On this moment can’t use Gpio?

Mraa is quite demanding compared to wiringpi


#4

If you’re into C, I would check out TinyGPIO on the Pi… https://github.com/dasfoo/rpi-gpio/blob/master/gpio.c (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): https://elinux.org/RPi_GPIO_Code_Samples#Direct_register_access

RK3399 datasheet, Section 20.4 http://opensource.rock-chips.com/images/e/ee/Rockchip_RK3399TRM_V1.4_Part1-20170408.pdf


#5

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

#6

Tipp:

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

#8

GPIO pin number can be simplified by below table


#9

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