Changes between Version 6 and Version 7 of gpio


Ignore:
Timestamp:
09/27/2018 11:12:48 PM (6 years ago)
Author:
Tim Harvey
Comment:

updated formatting

Legend:

Unmodified
Added
Removed
Modified
  • gpio

    v6 v7  
    6363Here are some example use cases for using gpio-class via sysfs:
    6464 * to see gpio names, config (direction), and current state: (requires debugfs kernel support and fs mounted)
    65 {{{
     65{{{#!bash
    6666cat /sys/kernel/debug/gpio
    6767}}}
    6868 * 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
    7070echo 5 > /sys/class/gpio/export # export gpio5 (will create /sys/class/gpio/gpio5 and configure as input)
    7171echo out > /sys/class/gpio/gpio5/direction # make it an output
     
    7373}}}
    7474 * to see the direction of a gpio via sysfs (only allowed for GPIO's configured as bi-directional)
    75 {{{
     75{{{#!bash
    7676cat /sys/class/gpio/gpio5/direction  ;# in/out
    7777}}}
    7878 * to set the direction of a gpio via sysfs (only allowed for GPIO's configured as bi-directional)
    79 {{{
     79{{{#!bash
    8080echo out > /sys/class/gpio/gpio5/direction ;# set as output
    8181echo in > /sys/class/gpio/gpio5/direction ;# set as input
    8282}}}
    8383 * to see the state of a gpio via sysfs
    84 {{{
     84{{{#!bash
    8585cat /sys/class/gpio/gpio5/value  ;# show current state (0=low, any other value than 0=high)
    8686}}}
    8787 * to set the state of a gpio via sysfs
    88 {{{
     88{{{#!bash
    8989echo 0 > /sys/class/gpio/gpio5/value  ;# assert low
    9090echo 1 > /sys/class/gpio/gpio5/value  ;# assert high
     
    100100If 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:
    101101 * GW5400:
    102 {{{
     102{{{#!bash
    103103# cat /sys/kernel/debug/gpio
    104104GPIOs 0-31, platform/209c000.gpio, 209c000.gpio:
     
    129129  * Note that this does not show GPIO's that are not used by Linux drivers such as USB HUB reset, Ethernet PHY reset, etc.
    130130 * GW2388:
    131 {{{
     131{{{#!bash
    132132# cat /sys/kernel/debug/gpio
    133133GPIOs 0-31, cns3xxx_gpio0:
     
    147147}}}
    148148 * GW2387:
    149 {{{
     149{{{#!bash
    150150# cat /sys/kernel/debug/gpio
    151151GPIOs 0-31, cns3xxx_gpio0:
     
    169169 * Ventana:
    170170  - IMX6 GPIOs: The IMX6 has 7 32bit GPIO controllers for a possible 224 fast ARM based GPIO's
    171    - 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
     171   - 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
    178178  - [wiki:gsc GSC] GPIOs:
    179    - GSC_GPIO_P0[0-7]: gpio240-gpio247
    180    - GSC_GPIO_P1[0-7]: gpio247-gpio255
     179   - GSC_GPIO_P0![0-7]: gpio240-gpio247
     180   - GSC_GPIO_P1![0-7]: gpio247-gpio255
    181181  - additional i2c based GPIO port-expanders present on some boards would begin at gpio116
    182182 * Laguna:
    183183  - cns3xxx GPIOs: The CNS3xxx has 2 32bit GPIO controllers for a possible 64 fast ARM based GPIO's
    184    - GPIOA[0-31]: gpio0-gpio31
    185    - GPIOB[0-31]: gpio32-gpio63
     184   - GPIOA![0-31]: gpio0-gpio31
     185   - GPIOB![0-31]: gpio32-gpio63
    186186  - [wiki:gsc GSC] GPIOs:
    187    - GSC_GPIO_P0[0-7]: gpio100-gpio107
    188    - GSC_GPIO_P1[0-7]: gpio108-gpio115
     187   - GSC_GPIO_P0![0-7]: gpio100-gpio107
     188   - GSC_GPIO_P1![0-7]: gpio108-gpio115
    189189  - additional i2c based GPIO port-expanders present on some boards would begin at gpio116
    190190
     
    193193 * Laguna GPIOA8 would be the 9th IO on the GPIOA controller (the first is GPIOA0) thus map to gpio 0+8 = gpio-8
    194194 * 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-16
    196  * Ventana GPIO[2]:DIO9 is GPIO block 2 IO 9 thus maps to gpio32 + 9 (or 1*32+9) = gpio-41
     195 * 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
    197197 * Equation: Ventana GPIO<x>__IO<y> is GPIO block x IO y thus maps to: gpio-((x-1)*32)+y
    198198
     
    364364
    365365Example usage (block until interrupt rising and falling edge interrupt occurs on gpio-100):
    366 {{{
     366{{{#!bash
    367367root@OpenWrt:/# ./gpio-poll 100 both
    368368monitoring /sys/class/gpio/gpio100/value for interrupt using poll()