Difference between revisions of "How to use GPIO for RK3399 RSB4710"
Yunjin.jiang (talk | contribs) (Created page with "= Introduction = GPIO, 全称 General-Purpose Input/Output(通用输入输出),是一种软件运行期间能够动态配置和控制的通用引脚。 RK3399有5组GP...") |
Yunjin.jiang (talk | contribs) |
||
Line 11: | Line 11: | ||
例如 GPIO2_A2,可以利用成以下功能: | 例如 GPIO2_A2,可以利用成以下功能: | ||
− | * | + | *GPIO2_A2 |
− | GPIO2_A2 | + | *CIF_D2 |
− | |||
− | * | ||
− | CIF_D2 | ||
= Configuration = | = Configuration = |
Revision as of 07:15, 14 February 2020
Contents
Introduction
GPIO, 全称 General-Purpose Input/Output(通用输入输出),是一种软件运行期间能够动态配置和控制的通用引脚。
RK3399有5组GPIO bank:GPIO0~GPIO4,每组又以 A0~A7, B0~B7, C0~C7, D0~D7 作为编号区分(不是所有 bank 都有全部编号,例如 GPIO4 就只有 C0~C7, D0~D2)。
所有的GPIO在上电后的初始状态都是输入模式,可以通过软件设为上拉或下拉,也可以设置为中断脚,驱动强度都是可编程的。
每个 GPIO 口除了通用输入输出功能外,还可能有其它复用功能,
例如 GPIO2_A2,可以利用成以下功能:
- GPIO2_A2
- CIF_D2
Configuration
The RK3399 bank/bit notation for GPIOs must be formed as "GPIO<GPIO_bank>_<gpio_bit>"
The numeric value of GPIO is calculated as follows:
32 x (gpio_bank) + gpio_bit
gpio_bit : A0~A7 0-7 B0~B7 8-15 C0~C7 16-23 D0~D7 24-31
E.g. GPIO2_A4 becomes 68
RSB-4710
GPIO Number | GPIO formed | Numeric Representation |
GPIO0 | GPIO7_A3 |
219 |
GPIO1 |
GPIO7_A4 |
220 |
GPIO2 |
GPIO7_A5 |
221 |
GPIO3 |
GPIO7_C5 |
237 |
GPIO4 |
GPIO8_A2 |
250 |
GPIO5 |
GPIO8_A3 |
251 |
GPIO6 |
GPIO8_A0 |
248 |
GPIO7 |
GPIO8_A1 |
249 |
Test
Export GPIO then you can use control GPIO from userr space through sysfs
Export GPIO0
# echo 219 > /sys/class/gpio/export
Set GPIO direction to in/out
# echo "out" > /sys/class/gpio/gpio219/direction
Set GPIO value 0/1 if GPIO pin define is output
# echo 1 > /sys/class/gpio/gpio219/value
Used as IRQ signal
Note:You have to configure GPIO to input
# echo "rising" > /sys/class/gpio/gpio219/edge
- rising: Trigger on rising edge
- falling: Trigger on falling edge
- both: Trigger on both edges
- none: Disable interrupt on both edges
Unexport GPIO0
# echo 219 > /sys/class/gpio/unexport
Test
GPIO 219 and GPIO 220 are taken as an example:
- Connect GPIO 219 and GPIO 220
- Export GPIO 219 and GPIO 220
# echo 219 > /sys/class/gpio/export # echo 220 > /sys/class/gpio/export
- Set GPIO 219 to output
# echo "out" > /sys/class/gpio/gpio219/direction
- Set GPIO 220 to input
# echo "in" > /sys/class/gpio/gpio220/direction
- Change GPIO 219 to 1 and read GPIO 220 value
# echo 1 > /sys/class/gpio/gpio219/value # cat /sys/class/gpio/gpio220/value 1
- Change GPIO 219 to 0 and read GPIO 220 value
# echo 0 > /sys/class/gpio/gpio219/value # cat /sys/class/gpio/gpio220/value 0