General-purpose input/output (GPIO) is a generic pin on an integrated circuit whose behavior—including whether it is an input or output pin—is controllable by the user at run time. Wikipedia
Watching it change (a primer on GPIO and GPIO configuration this content is moving to GPIO Subsystem)
To see the status of our exported pins in the Edison, type this your Edison's terminal:
root@edison:~#watch-n1cat/sys/kernel/debug/gpio
Basically, it will output the configured GPIO's to console every second:
Every1s:cat/sys/kernel/debug/gpio2015-10-1321:02:27PIOs0-191,pci/0000:00:0c.0,0000:00:0c.0:gpio-61 (SW1UI4 ) in higpio-64 (bcm43xx_irq ) in higpio-71 (bcm_bt_lpm ) out logpio-77 (sd_cd ) in higpio-96 (vwlan ) out higpio-111 (Arduino ShieldSS ) out higpio-124 (hsu ) in higpio-125 (hsu ) in higpio-126 (hsu ) in higpio-127 (hsu ) in higpio-128 (hsu ) in higpio-129 (hsu ) in higpio-130 (hsu ) in higpio-131 (hsu ) in higpio-132 (hsu ) in logpio-133 (hsu ) out logpio-134 (hsu ) in higpio-184 (bcm_bt_lpm ) out logpio-185 (bcm_bt_lpm ) in loGPIOs200-215,i2c/1-0020,pcal9555a,cansleep:gpio-207 (sysfs ) in higpio-215 (sysfs ) out loGPIOs216-231,i2c/1-0021,pcal9555a,cansleep:GPIOs232-247,i2c/1-0022,pcal9555a,cansleep:GPIOs248-263,i2c/1-0023,pcal9555a,cansleep:
The gpio's displayed above, are the ones reserved (AKA exported) by default in a newly flashed yocto image Poky (Yocto Project Reference Distro) 1.7.2 edison, kernel 3.10.17-poky-edison+
This directory, is a control interface used to get userspace control over GPIO48, therefore can have the following read/write attributes:
"direction"...readsaseither"in"or"out".Thisvaluemaynormallybewritten.Writingas"out"defaultstoinitializingthevalueaslow.Toensureglitchfreeoperation,values"low"and"high"maybewrittentoconfiguretheGPIOasanoutputwiththatinitialvalue.Notethatthisattribute*willnotexist*ifthekerneldoesn't support changing the direction of a GPIO, or it was exported by kernel code that didn'texplicitlyallowuserspacetoreconfigurethisGPIO's direction. "value" ... reads as either 0 (low) or 1 (high). If the GPIO is configured as an output, this value may be written; any nonzero value is treated as high. If the pin can be configured as interrupt-generating interrupt and if it has been configured to generate interrupts (see the description of "edge"), you can poll(2) on that file and poll(2) will return whenever the interrupt was triggered. If you use poll(2), set the events POLLPRI and POLLERR. If you use select(2), set the file descriptor in exceptfds. After poll(2) returns, either lseek(2) to the beginning of the sysfs file and read the new value or close the file and re-open it to read the value. "edge" ... reads as either "none", "rising", "falling", or "both". Write these strings to select the signal edge(s) that will make poll(2) on the "value" file return. This file exists only if the pin can be configured as an interrupt generating input pin. "active_low" ... reads as either 0 (false) or 1 (true). Write any nonzero value to invert the value attribute both for reading and writing. Existing and subsequent poll(2) support configuration via the edge attribute for "rising" and "falling" edges will follow this setting.
Exercise Change GPIO Direction
As explained before the GPIO control interface has some read/write attributes, so lets go ahead and change the default direction of the GPIO48.
Review the current GPIO direction using the command to debug GPIO statuses; If the direction is "out" let's change it to "in", if it is "in", change it to "out"
To change it, from "in" to "out " we only have to write "out" to attribute GPIO48/direction like this:
echoout>/sys/class/gpio/gpio48/direction
Then checking again the GPIO status we can see, that direction has changed. Here is a table that shows the direction before and after the change:
|GPIO48PreviousDirection|GPIO48NewDirection||--|--||gpio-48 (sysfs ) **in** lo|gpio-48 (sysfs ) **out** lo |