Difference between revisions of "IoTGateway/BSP/Android/Gettingstarted/How to use GPIO"

From ESS-WIKI
Jump to: navigation, search
Line 14: Line 14:
  
 
===== ROM-3421 =====
 
===== ROM-3421 =====
 +
 +
{| border="1" cellspacing="1" cellpadding="1" style="width:500px;"
 +
|-
 +
| GPIO Number
 +
| GPIO formed
 +
| Numeric Representation
 +
|-
 +
| GPIO0
 +
| GPIO6_IO11
 +
| <br/>
 +
|-
 +
| GPIO1<br/>
 +
| GPIO6_IO14
 +
| <br/>
 +
|-
 +
| GPIO2<br/>
 +
| GPIO6_IO15<br/>
 +
| <br/>
 +
|-
 +
| GPIO3<br/>
 +
| GPIO6_IO16
 +
| <br/>
 +
|-
 +
| GPIO4<br/>
 +
| GPIO2_IO25<br/>
 +
| <br/>
 +
|-
 +
| GPIO5<br/>
 +
| GPIO2_IO23<br/>
 +
| <br/>
 +
|-
 +
| GPIO6<br/>
 +
| GPIO2_IO24<br/>
 +
| <br/>
 +
|-
 +
| GPIO7<br/>
 +
| GPIO6_IO08<br/>
 +
| 168
 +
|-
 +
| GPIO8<br/>
 +
| GPIO2_IO06<br/>
 +
| 38
 +
|}
  
 
===== ROM7420 =====
 
===== ROM7420 =====
Line 55: Line 98:
 
| 130
 
| 130
 
|}
 
|}
 +
 +
==== Test ====
 +
 +
Export GPIO then you can use control GPIO from userr space through sysfs
 +
 +
Export GPIO 27
 +
<pre># echo 27 /sys/class/gpio/export
 +
</pre>
 +
 +
Set GPIO direction to in/out
 +
<pre># echo "in" > /sys/class/gpio/gpio27/direction
 +
</pre>
 +
 +
Set GPIO value 0/1 if GPIO pin define is output
 +
<pre>#  echo 1 > /sys/class/gpio/gpio27/value
 +
</pre>
 +
 +
Directly force a GPIO to output and set its initial value(high=1 low=0)
 +
<pre># echo high > /sys/class/gpio/gpio27/direction
 +
</pre>
 +
 +
Used as IRQ signal
 +
 +
Note:You have to configure GPIO to input
 +
<pre>#  echo "rising" > /sys/class/gpio/gpio27/edge
 +
</pre>
 +
 +
*rising: Trigger on rising edge
 +
*falling: Trigger on falling edge
 +
*both: Trigger on both edges
 +
*none: Disable interrupt on both edges
 +
 +
Unexport GPIO 27
 +
<pre># echo 27 /sys/class/gpio/unexport
 +
</pre>
 +
 +
==== Test ====
 +
 +
GPIO 27 and GPIO 29 are taken as an example:
 +
 +
*Connect GPIO 27 and GPIO 29
 +
*Export GPIO 27 and GPIO 29
 +
<pre># echo 27 /sys/class/gpio/export
 +
# echo 29 /sys/class/gpio/export
 +
</pre>
 +
 +
*Set GPIO 27 to output
 +
<pre># echo "out" > /sys/class/gpio/gpio27/direction
 +
</pre>
 +
 +
*Set GPIO 29 to input
 +
<pre># echo "in" > /sys/class/gpio/gpio29/direction
 +
</pre>
 +
 +
*Change GPIO 27 to 1 and read GPIO 29 value
 +
<pre># echo 1 > /sys/class/gpio/gpio27/value
 +
# cat /sys/class/gpio/gpio29/value
 +
1
 +
</pre>
 +
 +
*Change GPIO 27 to 0 and read GPIO 29 value
 +
<pre># echo 0 > /sys/class/gpio/gpio27/value
 +
# cat /sys/class/gpio/gpio29/value
 +
0
 +
</pre>

Revision as of 08:19, 26 January 2017

Configuration/Test

Configuration

The i.MX 6 bank/bit notation for GPIOs must be formed as "GPIO<GPIO_bank>_IO<gpio_bit>" 

The numeric value of GPIO is calculated as follows:

32 x (gpio_bank- 1) + gpio_bit

E.g. GPIO2_IO04 becomes 36


ROM-3421
GPIO Number GPIO formed Numeric Representation
GPIO0 GPIO6_IO11
GPIO1
GPIO6_IO14
GPIO2
GPIO6_IO15

GPIO3
GPIO6_IO16
GPIO4
GPIO2_IO25

GPIO5
GPIO2_IO23

GPIO6
GPIO2_IO24

GPIO7
GPIO6_IO08
168
GPIO8
GPIO2_IO06
38
ROM7420
GPIO Number GPIO formed Numeric Representation
GPIO0 GPIO6_IO11 171
GPIO1
GPIO6_IO14 174
GPIO2
GPIO6_IO15
175
GPIO3
GPIO6_IO16 176
GPIO4
GPIO2_IO25
57
GPIO5
GPIO2_IO23
55
GPIO6
GPIO2_IO24
56
GPIO7
GPIO5_IO02
130

Test

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

Export GPIO 27

# echo 27 /sys/class/gpio/export

Set GPIO direction to in/out

# echo "in" > /sys/class/gpio/gpio27/direction

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

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

Directly force a GPIO to output and set its initial value(high=1 low=0)

# echo high > /sys/class/gpio/gpio27/direction

Used as IRQ signal

Note:You have to configure GPIO to input

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

Unexport GPIO 27

# echo 27 /sys/class/gpio/unexport

Test

GPIO 27 and GPIO 29 are taken as an example:

  • Connect GPIO 27 and GPIO 29
  • Export GPIO 27 and GPIO 29
# echo 27 /sys/class/gpio/export
# echo 29 /sys/class/gpio/export
  • Set GPIO 27 to output
# echo "out" > /sys/class/gpio/gpio27/direction
  • Set GPIO 29 to input
# echo "in" > /sys/class/gpio/gpio29/direction
  • Change GPIO 27 to 1 and read GPIO 29 value
# echo 1 > /sys/class/gpio/gpio27/value
# cat /sys/class/gpio/gpio29/value
1
  • Change GPIO 27 to 0 and read GPIO 29 value
# echo 0 > /sys/class/gpio/gpio27/value
# cat /sys/class/gpio/gpio29/value
0