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

From ESS-WIKI
Jump to: navigation, search
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
= 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 =
 
= Configuration =
  
Line 24: Line 9:
 
gpio_bit : A0~A7 0-7 B0~B7 8-15 C0~C7 16-23 D0~D7 24-31
 
gpio_bit : A0~A7 0-7 B0~B7 8-15 C0~C7 16-23 D0~D7 24-31
  
E.g. GPIO2_A4 becomes 68
+
E.g. GPIO2_B0 becomes 72
  
RSB-4710
+
== RSB-4710 ==
  
 
{| cellspacing="1" cellpadding="1" border="1"
 
{| cellspacing="1" cellpadding="1" border="1"
Line 34: Line 19:
 
| Numeric Representation
 
| Numeric Representation
 
|-
 
|-
| GPIO0
+
| GPIO1<br/>
| GPIO7_A3<br/>
+
| GPIO2_B0<br/>
| 219<br/>
+
| 72
 +
|-
 +
| GPIO2<br/>
 +
| GPIO1_C2<br/>
 +
| 50<br/>
 +
|-
 +
| <s>GPIO3</s><br/>
 +
| <s>GPIO4_A3</s><br/>
 +
| <s>131</s>
 +
|-
 +
| GPIO4<br/>
 +
| GPIO3_D4<br/>
 +
| 124
 +
|-
 +
| GPIO5<br/>
 +
| GPIO4_A4<br/>
 +
| 132
 +
|-
 +
| GPIO6<br/>
 +
| GPIO0_B0<br/>
 +
| 8
 +
|}
 +
 
 +
<span style="color:#FF0000;">'''Note:'''</span>
 +
 
 +
GPIO3 is used to mute speak in later version.
 +
 
 +
== ROM-5780 ==
 +
 
 +
{| border="1" cellspacing="1" cellpadding="0" width="500" style="width: 360px;"
 +
|-
 +
| style="width: 97px;" | <div>GPIO Number</div>
 +
| style="width: 93px;" | <div>GPIO formed</div>
 +
| style="width: 158px;" | <div>Numeric Representation</div>
 +
|-
 +
| style="width: 97px;" | <div>GPIO0</div>
 +
| style="width: 93px;" | <div>GPIO1_A2</div>
 +
| style="width: 158px;" | <div>34</div>
 +
|-
 +
| style="width: 97px;" | <div>GPIO1</div>
 +
| style="width: 93px;" | <div>GPIO1_A3</div>
 +
| style="width: 158px;" | <div>35</div>
 +
|-
 +
| style="width: 97px;" | <div>GPIO2</div>
 +
| style="width: 93px;" | <div>GPIO1_B1</div>
 +
| style="width: 158px;" | <div>41</div>
 +
|-
 +
| style="width: 97px;" | <div>GPIO3</div>
 +
| style="width: 93px;" | <div>GPIO1_B2</div>
 +
| style="width: 158px;" | <div>42</div>
 +
|-
 +
| style="width: 97px;" | <div>GPIO4</div>
 +
| style="width: 93px;" | <div>GPIO1_B5</div>
 +
| style="width: 158px;" | <div>45</div>
 +
|-
 +
| style="width: 97px;" | <div>GPIO5</div>
 +
| style="width: 93px;" | <div>GPIO1_C2</div>
 +
| style="width: 158px;" | <div>50</div>
 +
|-
 +
| style="width: 97px;" | <div>GPIO6</div>
 +
| style="width: 93px;" | <div>GPIO1_C4</div>
 +
| style="width: 158px;" | <div>52</div>
 +
|-
 +
| style="width: 97px;" | <div>GPIO7</div>
 +
| style="width: 93px;" | <div>GPIO1_C6</div>
 +
| style="width: 158px;" | <div>54</div>
 +
|-
 +
| style="width: 97px;" | <div>GPIO8</div>
 +
| style="width: 93px;" | <div>GPIO1_C7</div>
 +
| style="width: 158px;" | <div>55</div>
 +
|-
 +
| style="width: 97px;" | <div>GPIO9</div>
 +
| style="width: 93px;" | <div>GPIO2_A2</div>
 +
| style="width: 158px;" | <div>66</div>
 +
|-
 +
| style="width: 97px;" | <div>GPIO10</div>
 +
| style="width: 93px;" | <div>GPIO2_A3</div>
 +
| style="width: 158px;" | <div>67</div>
 +
|-
 +
| style="width: 97px;" | <div>GPIO11</div>
 +
| style="width: 93px;" | <div>GPIO4_C5</div>
 +
| style="width: 158px;" | <div>149</div>
 +
|}
 +
 
 +
== RSB-3710 ==
 +
 
 +
{| cellspacing="1" cellpadding="1" border="1"
 +
|-
 +
| GPIO Number
 +
| GPIO formed
 +
| Numeric Representation
 
|-
 
|-
 
| GPIO1<br/>
 
| GPIO1<br/>
| GPIO7_A4<br/>
+
| EXP1_0<br/>
| 220<br/>
+
| 504
 
|-
 
|-
 
| GPIO2<br/>
 
| GPIO2<br/>
| GPIO7_A5<br/>
+
| EXP1_1<br/>
| 221<br/>
+
| 505
 
|-
 
|-
 
| GPIO3<br/>
 
| GPIO3<br/>
| GPIO7_C5<br/>
+
| EXP1_2<br/>
| 237<br/>
+
| 506
 
|-
 
|-
 
| GPIO4<br/>
 
| GPIO4<br/>
| GPIO8_A2<br/>
+
| EXP1_3<br/>
| 250<br/>
+
| 507
 
|-
 
|-
 
| GPIO5<br/>
 
| GPIO5<br/>
| GPIO8_A3<br/>
+
| EXP2_0<br/>
| 251<br/>
+
| 496
 
|-
 
|-
 
| GPIO6<br/>
 
| GPIO6<br/>
| GPIO8_A0<br/>
+
| EXP2_1<br/>
| 248<br/>
+
| 497
 
|-
 
|-
 
| GPIO7<br/>
 
| GPIO7<br/>
| GPIO8_A1<br/>
+
| EXP2_2<br/>
| 249
+
| 498
 +
|-
 +
| GPIO8<br/>
 +
| EXP2_3<br/>
 +
| 499
 +
|-
 +
| GPIO9<br/>
 +
| EXP2_4<br/>
 +
| 500
 +
|-
 +
| GPIO10<br/>
 +
| EXP2_5<br/>
 +
| 501
 +
|-
 +
| GPIO11<br/>
 +
| EXP2_6<br/>
 +
| 502
 +
|-
 +
| GPIO12<br/>
 +
| EXP2_7<br/>
 +
| 503
 
|}
 
|}
 +
 +
<span style="color:#FF0000;">'''Note:'''</span>
 +
 +
RSB-3710 uses two i2c GPIO expenders.
  
 
= Test =
 
= Test =
 +
 +
Here we take GPIO1 of 4710 as an example.3710 and 5780 are&nbsp;similar to set up.
  
 
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 86: Line 187:
  
 
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 94: Line 195:
 
*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>

Latest revision as of 04:19, 13 September 2022

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_C2
50
GPIO3
GPIO4_A3
131
GPIO4
GPIO3_D4
124
GPIO5
GPIO4_A4
132
GPIO6
GPIO0_B0
8

Note:

GPIO3 is used to mute speak in later version.

ROM-5780

GPIO Number
GPIO formed
Numeric Representation
GPIO0
GPIO1_A2
34
GPIO1
GPIO1_A3
35
GPIO2
GPIO1_B1
41
GPIO3
GPIO1_B2
42
GPIO4
GPIO1_B5
45
GPIO5
GPIO1_C2
50
GPIO6
GPIO1_C4
52
GPIO7
GPIO1_C6
54
GPIO8
GPIO1_C7
55
GPIO9
GPIO2_A2
66
GPIO10
GPIO2_A3
67
GPIO11
GPIO4_C5
149

RSB-3710

GPIO Number GPIO formed Numeric Representation
GPIO1
EXP1_0
504
GPIO2
EXP1_1
505
GPIO3
EXP1_2
506
GPIO4
EXP1_3
507
GPIO5
EXP2_0
496
GPIO6
EXP2_1
497
GPIO7
EXP2_2
498
GPIO8
EXP2_3
499
GPIO9
EXP2_4
500
GPIO10
EXP2_5
501
GPIO11
EXP2_6
502
GPIO12
EXP2_7
503

Note:

RSB-3710 uses two i2c GPIO expenders.

Test

Here we take GPIO1 of 4710 as an example.3710 and 5780 are similar to set up.

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