Difference between revisions of "How to use GPIO for RK3399 RSB4710"

From ESS-WIKI
Jump to: navigation, search
Line 48: Line 48:
 
Export GPIO then you can use control GPIO from userr space through sysfs
 
Export GPIO then you can use control GPIO from userr space through sysfs
  
Export GPIO0
+
Export GPIO1
<pre># echo 219 > /sys/class/gpio/export
+
<pre># echo 72 > /sys/class/gpio/export
 
</pre>
 
</pre>
  
 
Set GPIO direction to in/out
 
Set GPIO direction to in/out
<pre># echo "out" > /sys/class/gpio/gpio219/direction
+
<pre># echo "out" > /sys/class/gpio/gpio72/direction
 
</pre>
 
</pre>
  
 
Set GPIO value 0/1 if GPIO pin define is output
 
Set GPIO value 0/1 if GPIO pin define is output
<pre>#  echo 1 > /sys/class/gpio/gpio219/value
+
<pre>#  echo 1 > /sys/class/gpio/gpio72/value
 
</pre>
 
</pre>
  
Line 63: Line 63:
  
 
Note:You have to configure GPIO to input
 
Note:You have to configure GPIO to input
<pre>#  echo "rising" > /sys/class/gpio/gpio219/edge
+
<pre>#  echo "rising" > /sys/class/gpio/gpio72/edge
 
</pre>
 
</pre>
  
Line 71: Line 71:
 
*none: Disable interrupt on both edges
 
*none: Disable interrupt on both edges
  
Unexport GPIO0
+
Unexport GPIO1
<pre># echo 219 > /sys/class/gpio/unexport
+
<pre># echo 72 > /sys/class/gpio/unexport
 
</pre>
 
</pre>
  
 
'''Test'''
 
'''Test'''
  
GPIO 219 and GPIO 220 are taken as an example:
+
GPIO1 and GPIO2 are taken as an example:
  
*Connect GPIO 219 and GPIO 220
+
*Connect GPIO1 and GPIO2
*Export GPIO 219 and GPIO 220
+
*Export GPIO1 and GPIO2
<pre># echo 219 > /sys/class/gpio/export
+
<pre># echo 72 > /sys/class/gpio/export
# echo 220 > /sys/class/gpio/export
+
# echo 50 > /sys/class/gpio/export
 
</pre>
 
</pre>
  
*Set GPIO 219 to output
+
*Set GPIO 1 to output
<pre># echo "out" > /sys/class/gpio/gpio219/direction
+
<pre># echo "out" > /sys/class/gpio/gpio72/direction
 
</pre>
 
</pre>
  
*Set GPIO 220 to input
+
*Set GPIO 2 to input
<pre># echo "in" > /sys/class/gpio/gpio220/direction
+
<pre># echo "in" > /sys/class/gpio/gpio50/direction
 
</pre>
 
</pre>
  
*Change GPIO 219 to 1 and read GPIO 220 value
+
*Change GPIO1 to 1 and read GPIO2value
<pre># echo 1 > /sys/class/gpio/gpio219/value
+
<pre># echo 1 > /sys/class/gpio/gpio72/value
# cat /sys/class/gpio/gpio220/value 1
+
# cat /sys/class/gpio/gpio50/value  
 +
1
 
</pre>
 
</pre>
  
*Change GPIO 219 to 0 and read GPIO 220 value
+
*Change GPIO1&nbsp;to 0 and read GPIO2&nbsp;value
<pre># echo 0 > /sys/class/gpio/gpio219/value
+
<pre># echo 0 > /sys/class/gpio/gpio72/value
# cat /sys/class/gpio/gpio220/value 0</pre>
+
# cat /sys/class/gpio/gpio50/value  
 +
0</pre>

Revision as of 02:00, 7 May 2020

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_B0 becomes 72

RSB-4710

GPIO Number GPIO formed Numeric Representation
GPIO1
GPIO2_B0
72
GPIO2
GPIO1_C1
50
GPIO3
GPIO4_A3
131
GPIO4
GPIO3_D4
124
GPIO5
GPIO4_A4
132
GPIO6
GPIO0_B0
8

Test

Export GPIO then you can use control GPIO from userr space through sysfs

Export GPIO1

# echo 72 > /sys/class/gpio/export

Set GPIO direction to in/out

# echo "out" > /sys/class/gpio/gpio72/direction

Set GPIO value 0/1 if GPIO pin define is output

#  echo 1 > /sys/class/gpio/gpio72/value

Used as IRQ signal

Note:You have to configure GPIO to input

#  echo "rising" > /sys/class/gpio/gpio72/edge
  • rising: Trigger on rising edge
  • falling: Trigger on falling edge
  • both: Trigger on both edges
  • none: Disable interrupt on both edges

Unexport GPIO1

# echo 72 > /sys/class/gpio/unexport

Test

GPIO1 and GPIO2 are taken as an example:

  • Connect GPIO1 and GPIO2
  • Export GPIO1 and GPIO2
# echo 72 > /sys/class/gpio/export
# echo 50 > /sys/class/gpio/export
  • Set GPIO 1 to output
# echo "out" > /sys/class/gpio/gpio72/direction
  • Set GPIO 2 to input
# echo "in" > /sys/class/gpio/gpio50/direction
  • Change GPIO1 to 1 and read GPIO2value
# echo 1 > /sys/class/gpio/gpio72/value
# cat /sys/class/gpio/gpio50/value 
1
  • Change GPIO1 to 0 and read GPIO2 value
# echo 0 > /sys/class/gpio/gpio72/value
# cat /sys/class/gpio/gpio50/value 
0