Difference between revisions of "IoTGateway/BSP/Android/Gettingstarted/How to use GPIO"
From ESS-WIKI
Line 22: | Line 22: | ||
|- | |- | ||
| GPIO0 | | GPIO0 | ||
− | | | + | | GPIO_0 |
| <br/> | | <br/> | ||
|- | |- | ||
| GPIO1<br/> | | GPIO1<br/> | ||
− | | | + | | GPIO2_IO2 |
| <br/> | | <br/> | ||
|- | |- | ||
| GPIO2<br/> | | GPIO2<br/> | ||
− | | | + | | GPIO2_IO3<br/> |
| <br/> | | <br/> | ||
|- | |- | ||
| GPIO3<br/> | | GPIO3<br/> | ||
− | | | + | | GPIO_3 |
| <br/> | | <br/> | ||
|- | |- | ||
| GPIO4<br/> | | GPIO4<br/> | ||
− | | | + | | GPIO_17<br/> |
| <br/> | | <br/> | ||
|- | |- | ||
| GPIO5<br/> | | GPIO5<br/> | ||
− | | | + | | GPIO_18<br/> |
| <br/> | | <br/> | ||
|- | |- | ||
| GPIO6<br/> | | GPIO6<br/> | ||
− | | | + | | GPIO7_IO6<br/> |
| <br/> | | <br/> | ||
|- | |- |
Revision as of 10:05, 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 | GPIO_0 | |
GPIO1 |
GPIO2_IO2 | |
GPIO2 |
GPIO2_IO3 |
|
GPIO3 |
GPIO_3 | |
GPIO4 |
GPIO_17 |
|
GPIO5 |
GPIO_18 |
|
GPIO6 |
GPIO7_IO6 |
|
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