Changes between Version 6 and Version 7 of gpio
- Timestamp:
- 09/27/2018 11:12:48 PM (6 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
gpio
v6 v7 63 63 Here are some example use cases for using gpio-class via sysfs: 64 64 * to see gpio names, config (direction), and current state: (requires debugfs kernel support and fs mounted) 65 {{{ 65 {{{#!bash 66 66 cat /sys/kernel/debug/gpio 67 67 }}} 68 68 * to export a GPIO that is available to userspace (ie provided by a gpio controller, not in-use by a kernel driver, and not already exported): 69 {{{ 69 {{{#!bash 70 70 echo 5 > /sys/class/gpio/export # export gpio5 (will create /sys/class/gpio/gpio5 and configure as input) 71 71 echo out > /sys/class/gpio/gpio5/direction # make it an output … … 73 73 }}} 74 74 * to see the direction of a gpio via sysfs (only allowed for GPIO's configured as bi-directional) 75 {{{ 75 {{{#!bash 76 76 cat /sys/class/gpio/gpio5/direction ;# in/out 77 77 }}} 78 78 * to set the direction of a gpio via sysfs (only allowed for GPIO's configured as bi-directional) 79 {{{ 79 {{{#!bash 80 80 echo out > /sys/class/gpio/gpio5/direction ;# set as output 81 81 echo in > /sys/class/gpio/gpio5/direction ;# set as input 82 82 }}} 83 83 * to see the state of a gpio via sysfs 84 {{{ 84 {{{#!bash 85 85 cat /sys/class/gpio/gpio5/value ;# show current state (0=low, any other value than 0=high) 86 86 }}} 87 87 * to set the state of a gpio via sysfs 88 {{{ 88 {{{#!bash 89 89 echo 0 > /sys/class/gpio/gpio5/value ;# assert low 90 90 echo 1 > /sys/class/gpio/gpio5/value ;# assert high … … 100 100 If debugfs is enabled in the kernel (as it is on Gateworks BSP's) you can see a nice table of GPIO mapping via {{{/sys/kernel/debug/gpio}}}. Some examples: 101 101 * GW5400: 102 {{{ 102 {{{#!bash 103 103 # cat /sys/kernel/debug/gpio 104 104 GPIOs 0-31, platform/209c000.gpio, 209c000.gpio: … … 129 129 * Note that this does not show GPIO's that are not used by Linux drivers such as USB HUB reset, Ethernet PHY reset, etc. 130 130 * GW2388: 131 {{{ 131 {{{#!bash 132 132 # cat /sys/kernel/debug/gpio 133 133 GPIOs 0-31, cns3xxx_gpio0: … … 147 147 }}} 148 148 * GW2387: 149 {{{ 149 {{{#!bash 150 150 # cat /sys/kernel/debug/gpio 151 151 GPIOs 0-31, cns3xxx_gpio0: … … 169 169 * Ventana: 170 170 - IMX6 GPIOs: The IMX6 has 7 32bit GPIO controllers for a possible 224 fast ARM based GPIO's 171 - GPIO1_IO [0-31]: gpio0-gpio31172 - GPIO2_IO [0-31]: gpio32-gpio63173 - GPIO3_IO [0-31]: gpio64-gpio95174 - GPIO4_IO [0-31]: gpio96-gpio127175 - GPIO5_IO [0-31]: gpio128-gpio159176 - GPIO6_IO [0-31]: gpio160-gpio191177 - GPIO7_IO [0-31]: gpio192-gpio223171 - GPIO1_IO![0-31]: gpio0-gpio31 172 - GPIO2_IO![0-31]: gpio32-gpio63 173 - GPIO3_IO![0-31]: gpio64-gpio95 174 - GPIO4_IO![0-31]: gpio96-gpio127 175 - GPIO5_IO![0-31]: gpio128-gpio159 176 - GPIO6_IO![0-31]: gpio160-gpio191 177 - GPIO7_IO![0-31]: gpio192-gpio223 178 178 - [wiki:gsc GSC] GPIOs: 179 - GSC_GPIO_P0 [0-7]: gpio240-gpio247180 - GSC_GPIO_P1 [0-7]: gpio247-gpio255179 - GSC_GPIO_P0![0-7]: gpio240-gpio247 180 - GSC_GPIO_P1![0-7]: gpio247-gpio255 181 181 - additional i2c based GPIO port-expanders present on some boards would begin at gpio116 182 182 * Laguna: 183 183 - cns3xxx GPIOs: The CNS3xxx has 2 32bit GPIO controllers for a possible 64 fast ARM based GPIO's 184 - GPIOA [0-31]: gpio0-gpio31185 - GPIOB [0-31]: gpio32-gpio63184 - GPIOA![0-31]: gpio0-gpio31 185 - GPIOB![0-31]: gpio32-gpio63 186 186 - [wiki:gsc GSC] GPIOs: 187 - GSC_GPIO_P0 [0-7]: gpio100-gpio107188 - GSC_GPIO_P1 [0-7]: gpio108-gpio115187 - GSC_GPIO_P0![0-7]: gpio100-gpio107 188 - GSC_GPIO_P1![0-7]: gpio108-gpio115 189 189 - additional i2c based GPIO port-expanders present on some boards would begin at gpio116 190 190 … … 193 193 * Laguna GPIOA8 would be the 9th IO on the GPIOA controller (the first is GPIOA0) thus map to gpio 0+8 = gpio-8 194 194 * Laguna GPIOB1 would be the 2nd IO on the GPIOB controller thus map to gpio 32+2 = gpio-34 195 * Ventana GPIO [1]:DIO16 is GPIO block 1 IO 16 thus maps to gpio0 + 16 (or 0*32+16) = gpio-16196 * Ventana GPIO [2]:DIO9 is GPIO block 2 IO 9 thus maps to gpio32 + 9 (or 1*32+9) = gpio-41195 * Ventana GPIO![1]:DIO16 is GPIO block 1 IO 16 thus maps to gpio0 + 16 (or 0*32+16) = gpio-16 196 * Ventana GPIO![2]:DIO9 is GPIO block 2 IO 9 thus maps to gpio32 + 9 (or 1*32+9) = gpio-41 197 197 * Equation: Ventana GPIO<x>__IO<y> is GPIO block x IO y thus maps to: gpio-((x-1)*32)+y 198 198 … … 364 364 365 365 Example usage (block until interrupt rising and falling edge interrupt occurs on gpio-100): 366 {{{ 366 {{{#!bash 367 367 root@OpenWrt:/# ./gpio-poll 100 both 368 368 monitoring /sys/class/gpio/gpio100/value for interrupt using poll()