Difference between revisions of "ROM-6881 How to use GPIO"

From ESS-WIKI
Jump to: navigation, search
(Created page with " = Configuration = The RK3588 bank/bit notation for GPIOs must be formed as "GPIO<GPIO_bank>_<gpio_bit>"  The numeric value of GPIO is calculated as foll...")
 
Line 14: Line 14:
 
== ROM-6881 ==
 
== ROM-6881 ==
  
{| border="1" cellpadding="1" cellspacing="1"
+
{| border="1" cellpadding="1" cellspacing="1" style="width: 411px;"
 
|-
 
|-
 
| GPIO Number
 
| GPIO Number
| GPIO formed
+
| style="width: 123px;" | GPIO formed
| Numeric Representation
+
| style="width: 186px;" | Numeric Representation
 
|-
 
|-
 
| GPIO0
 
| GPIO0
| Ext-GPIO0 P00
+
| style="width: 123px;" | Ext-GPIO0 P00
| 493
+
| style="width: 186px;" | 493
 
|-
 
|-
 
| GPIO1
 
| GPIO1
| Ext-GPIO0 P01
+
| style="width: 123px;" | Ext-GPIO0 P01
| 494
+
| style="width: 186px;" | 494
 
|-
 
|-
 
| GPIO2
 
| GPIO2
| Ext-GPIO0 P02
+
| style="width: 123px;" | Ext-GPIO0 P02
| 495
+
| style="width: 186px;" | 495
 
|-
 
|-
 
| GPIO3
 
| GPIO3
| Ext-GPIO0 P03
+
| style="width: 123px;" | Ext-GPIO0 P03
| 496
+
| style="width: 186px;" | 496
 
|-
 
|-
 
| GPIO4
 
| GPIO4
| Ext-GPIO0 P04
+
| style="width: 123px;" | Ext-GPIO0 P04
| 497
+
| style="width: 186px;" | 497
 
|-
 
|-
 
| GPIO5
 
| GPIO5
| GPIO4_B5
+
| style="width: 123px;" | GPIO4_B5
| 141
+
| style="width: 186px;" | 141
 
|-
 
|-
 
| GPIO6
 
| GPIO6
| Ext-GPIO0 P05
+
| style="width: 123px;" | Ext-GPIO0 P05
| 498
+
| style="width: 186px;" | 498
 
|-
 
|-
 
| GPIO7
 
| GPIO7
| Ext-GPIO0 P06
+
| style="width: 123px;" | Ext-GPIO0 P06
| 499
+
| style="width: 186px;" | 499
 
|-
 
|-
 
| GPIO8
 
| GPIO8
| Ext-GPIO0 P07
+
| style="width: 123px;" | Ext-GPIO0 P07
| 500
+
| style="width: 186px;" | 500
 
|-
 
|-
 
| GPIO9
 
| GPIO9
| GPIO4_A0
+
| style="width: 123px;" | GPIO4_A0
| 128
+
| style="width: 186px;" | 128
 
|-
 
|-
 
| GPIO10
 
| GPIO10
| GPIO3_C0
+
| style="width: 123px;" | GPIO3_C0
| 112
+
| style="width: 186px;" | 112
 
|-
 
|-
 
| GPIO11
 
| GPIO11
| GPIO3_C1
+
| style="width: 123px;" | GPIO3_C1
| 113
+
| style="width: 186px;" | 113
 
|}
 
|}
  
Line 73: Line 73:
 
Here we take GPIO0&nbsp;of ROM-6881 as an example.
 
Here we take GPIO0&nbsp;of ROM-6881 as an example.
  
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 GPIO0
Line 85: Line 85:
 
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/gpio493/value
 
<pre>#  echo 1 > /sys/class/gpio/gpio493/value
 +
</pre>
 +
 +
 +
Unexport GPIO0
 +
<pre># echo 493 > /sys/class/gpio/unexport
 
</pre>
 
</pre>
  
Line 98: Line 103:
 
*none: Disable interrupt on both edges  
 
*none: Disable interrupt on both edges  
  
Unexport GPIO0
+
'''GPIO Test'''
<pre># echo 493 > /sys/class/gpio/unexport
 
</pre>
 
  
'''Test'''
+
GPIO0 and GPIO1 are taken as an example: Connect GPIO0 and GPIO1
  
GPIO0&nbsp;and GPIO1&nbsp;are taken as an example:
+
*'''Export GPIO0&nbsp;and GPIO1'''
 
 
*Connect GPIO0&nbsp;and GPIO1
 
*Export GPIO0&nbsp;and GPIO1  
 
 
<pre># echo 493 > /sys/class/gpio/export
 
<pre># echo 493 > /sys/class/gpio/export
 
# echo 494 > /sys/class/gpio/export
 
# echo 494 > /sys/class/gpio/export
 
</pre>
 
</pre>
  
*Set GPIO0&nbsp;to output  
+
*'''Set GPIO0 to output and GPIO1 to input'''
 
<pre># echo "out" > /sys/class/gpio/gpio493/direction
 
<pre># echo "out" > /sys/class/gpio/gpio493/direction
 +
# echo "in" > /sys/class/gpio/gpio494/direction
 
</pre>
 
</pre>
  
*Set GPIO2&nbsp;to input
+
*'''Change GPIO0&nbsp;to 1 and read GPIO1 value'''
<pre># echo "in" > /sys/class/gpio/gpio494/direction
 
</pre>
 
 
 
*Change GPIO0&nbsp;to 1 and read GPIO1 value  
 
 
<pre># echo 1 > /sys/class/gpio/gpio493/value
 
<pre># echo 1 > /sys/class/gpio/gpio493/value
 
# cat /sys/class/gpio/gpio494/value  
 
# cat /sys/class/gpio/gpio494/value  
Line 126: Line 123:
 
</pre>
 
</pre>
  
*Change GPIO0&nbsp;to 0 and read GPIO1&nbsp;value  
+
*'''Change GPIO0&nbsp;to 0 and read GPIO1&nbsp;value'''
 
<pre># echo 0 > /sys/class/gpio/gpio493/value
 
<pre># echo 0 > /sys/class/gpio/gpio493/value
 
# cat /sys/class/gpio/gpio494/value  
 
# cat /sys/class/gpio/gpio494/value  
 
0</pre>
 
0</pre>

Revision as of 07:44, 3 January 2024

Configuration

The RK3588 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. GPIO3_A0 becomes 96

ROM-6881

GPIO Number GPIO formed Numeric Representation
GPIO0 Ext-GPIO0 P00 493
GPIO1 Ext-GPIO0 P01 494
GPIO2 Ext-GPIO0 P02 495
GPIO3 Ext-GPIO0 P03 496
GPIO4 Ext-GPIO0 P04 497
GPIO5 GPIO4_B5 141
GPIO6 Ext-GPIO0 P05 498
GPIO7 Ext-GPIO0 P06 499
GPIO8 Ext-GPIO0 P07 500
GPIO9 GPIO4_A0 128
GPIO10 GPIO3_C0 112
GPIO11 GPIO3_C1 113

Test

Here we take GPIO0 of ROM-6881 as an example.

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

Export GPIO0

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

Set GPIO direction to in/out

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

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

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


Unexport GPIO0

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

Used as IRQ signal

Note:You have to configure GPIO to input

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

GPIO Test

GPIO0 and GPIO1 are taken as an example: Connect GPIO0 and GPIO1

  • Export GPIO0 and GPIO1
# echo 493 > /sys/class/gpio/export
# echo 494 > /sys/class/gpio/export
  • Set GPIO0 to output and GPIO1 to input
# echo "out" > /sys/class/gpio/gpio493/direction
# echo "in" > /sys/class/gpio/gpio494/direction
  • Change GPIO0 to 1 and read GPIO1 value
# echo 1 > /sys/class/gpio/gpio493/value
# cat /sys/class/gpio/gpio494/value 
1
  • Change GPIO0 to 0 and read GPIO1 value
# echo 0 > /sys/class/gpio/gpio493/value
# cat /sys/class/gpio/gpio494/value 
0