Difference between revisions of "IoTGateway/BSP/Android/Gettingstarted/How to use GPIO"
From ESS-WIKI
(5 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
==== Configuration ==== | ==== 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: | ||
+ | <pre>32 x (gpio_bank- 1) + gpio_bit | ||
+ | </pre> | ||
+ | E.g. GPIO2_IO04 becomes 36 | ||
− | ROM7420 | + | |
+ | |||
+ | ===== ROM-3421 ===== | ||
+ | |||
+ | {| border="1" cellspacing="1" cellpadding="1" style="width:500px;" | ||
+ | |- | ||
+ | | GPIO Number | ||
+ | | GPIO formed | ||
+ | | Numeric Representation | ||
+ | |- | ||
+ | | GPIO0 | ||
+ | | GPIO_1 | ||
+ | | 1 | ||
+ | |- | ||
+ | | GPIO1<br/> | ||
+ | | GPIO2_IO2 | ||
+ | | 34 | ||
+ | |- | ||
+ | | GPIO2<br/> | ||
+ | | GPIO2_IO3<br/> | ||
+ | | 35 | ||
+ | |- | ||
+ | | GPIO3<br/> | ||
+ | | GPIO_3 | ||
+ | | 3 | ||
+ | |- | ||
+ | | GPIO4<br/> | ||
+ | | GPIO7_IO12<br/> | ||
+ | | 204 | ||
+ | |- | ||
+ | | GPIO5<br/> | ||
+ | | GPIO7_IO13<br/> | ||
+ | | 205 | ||
+ | |- | ||
+ | | GPIO6<br/> | ||
+ | | GPIO7_IO6<br/> | ||
+ | | 198 | ||
+ | |- | ||
+ | | GPIO7<br/> | ||
+ | | GPIO6_IO08<br/> | ||
+ | | 168 | ||
+ | |- | ||
+ | | GPIO8<br/> | ||
+ | | GPIO2_IO06<br/> | ||
+ | | 38 | ||
+ | |} | ||
+ | |||
+ | ===== ROM7420 ===== | ||
{| border="1" cellspacing="1" cellpadding="1" style="width:500px;" | {| border="1" cellspacing="1" cellpadding="1" style="width:500px;" | ||
|- | |- | ||
| GPIO Number | | GPIO Number | ||
− | | | + | | GPIO formed |
+ | | Numeric Representation | ||
|- | |- | ||
| GPIO0 | | GPIO0 | ||
+ | | GPIO6_IO11 | ||
| 171 | | 171 | ||
|- | |- | ||
| GPIO1<br/> | | GPIO1<br/> | ||
+ | | GPIO6_IO14 | ||
| 174 | | 174 | ||
|- | |- | ||
| GPIO2<br/> | | GPIO2<br/> | ||
+ | | GPIO6_IO15<br/> | ||
| 175 | | 175 | ||
|- | |- | ||
| GPIO3<br/> | | GPIO3<br/> | ||
+ | | GPIO6_IO16 | ||
| 176 | | 176 | ||
|- | |- | ||
| GPIO4<br/> | | GPIO4<br/> | ||
+ | | GPIO2_IO25<br/> | ||
| 57 | | 57 | ||
|- | |- | ||
| GPIO5<br/> | | GPIO5<br/> | ||
+ | | GPIO2_IO23<br/> | ||
| 55 | | 55 | ||
|- | |- | ||
− | | | + | | GPIO6<br/> |
+ | | GPIO2_IO24<br/> | ||
| 56 | | 56 | ||
|- | |- | ||
| GPIO7<br/> | | GPIO7<br/> | ||
+ | | GPIO5_IO02<br/> | ||
| 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 "out" > /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> | ||
+ | |||
+ | 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> |
Latest revision as of 10:44, 19 June 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 | GPIO_1 | 1 |
GPIO1 |
GPIO2_IO2 | 34 |
GPIO2 |
GPIO2_IO3 |
35 |
GPIO3 |
GPIO_3 | 3 |
GPIO4 |
GPIO7_IO12 |
204 |
GPIO5 |
GPIO7_IO13 |
205 |
GPIO6 |
GPIO7_IO6 |
198 |
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 "out" > /sys/class/gpio/gpio27/direction
Set GPIO value 0/1 if GPIO pin define is output
# echo 1 > /sys/class/gpio/gpio27/value
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