Difference between revisions of "GPIOlib"
From ArmadeusWiki
(creation) |
(→Usage) |
||
Line 19: | Line 19: | ||
==Usage== | ==Usage== | ||
− | * Find | + | ===Blink APFxxDev i.MX LED=== |
+ | * Find the GPIO number connected to the LED, eg: | ||
+ | ** for APF27Dev: '''PF14 ->''' PortF (n°6) pin 14 -> (6-1)*32 + 14 -> GPIO n°'''174''' | ||
+ | ** for APF51Dev: GPIO1_2 -> Port 1 pin 2 -> GPIO n° 2 | ||
+ | * Define envt variable (for portability): | ||
+ | <pre class="apf"> | ||
+ | # export LED=174 (APF27Dev) | ||
+ | or | ||
+ | # export LED=2 (APF51Dev) | ||
+ | </pre> | ||
* Ask kernel to export the GPIO: | * Ask kernel to export the GPIO: | ||
<pre class="apf"> | <pre class="apf"> | ||
− | # echo | + | # echo $LED > /sys/class/gpio/export |
</pre> | </pre> | ||
* Access functions are created: | * Access functions are created: | ||
<pre class="apf"> | <pre class="apf"> | ||
− | # ls /sys/class/gpio/ | + | # ls /sys/class/gpio/gpio$LED/ |
active_low edge subsystem value | active_low edge subsystem value | ||
direction power uevent | direction power uevent | ||
Line 32: | Line 41: | ||
* Check GPIO direction and put in output: | * Check GPIO direction and put in output: | ||
<pre class="apf"> | <pre class="apf"> | ||
− | # cat /sys/class/gpio/ | + | # cat /sys/class/gpio/gpio$LED/direction |
in | in | ||
− | # echo out > /sys/class/gpio/ | + | # echo out > /sys/class/gpio/gpio$LED/direction |
− | # cat /sys/class/gpio/ | + | # cat /sys/class/gpio/gpio$LED/direction |
out | out | ||
</pre> | </pre> | ||
− | * Play with GPIO value: | + | * Play with GPIO value to blink LED: |
+ | <pre class="apf"> | ||
+ | # echo 1 > /sys/class/gpio/gpio$LED/value | ||
+ | # echo 0 > /sys/class/gpio/gpio$LED/value | ||
+ | </pre> | ||
+ | |||
+ | ===Get APFxxDev i.MX switch status=== | ||
+ | * Find the GPIO number connected to the switch, eg: | ||
+ | ** for APF27Dev: '''PF15 ->''' PortF (n°6) pin 15 -> (6-1)*32 + 15 -> '''GPIO n°175''' | ||
+ | ** for APF51Dev: '''GPIO1_3''' -> Port 1 pin 3 -> '''GPIO n°3''' ((1-1)*32 + 3) | ||
+ | * Define envt variable (for portability): | ||
+ | <pre class="apf"> | ||
+ | # export LED=175 (APF27Dev) | ||
+ | or | ||
+ | # export LED=3 (APF51Dev) | ||
+ | </pre> | ||
+ | * Ask kernel to export the GPIO: | ||
+ | <pre class="apf"> | ||
+ | # echo $LED > /sys/class/gpio/export | ||
+ | </pre> | ||
+ | * Access functions are created: | ||
+ | <pre class="apf"> | ||
+ | # ls /sys/class/gpio/gpio$LED/ | ||
+ | active_low edge subsystem value | ||
+ | direction power uevent | ||
+ | </pre> | ||
+ | * Check GPIO direction and put in output: | ||
+ | <pre class="apf"> | ||
+ | # cat /sys/class/gpio/gpio$LED/direction | ||
+ | in | ||
+ | </pre> | ||
+ | * Get switch status: | ||
<pre class="apf"> | <pre class="apf"> | ||
− | # | + | # cat /sys/class/gpio/gpio$LED/value |
− | # | + | 1 (released) |
+ | ... | ||
+ | # cat /sys/class/gpio/gpio$LED/value | ||
+ | 0 (pressed) | ||
</pre> | </pre> | ||
==Links== | ==Links== | ||
* http://www.kernel.org/doc/Documentation/gpio.txt | * http://www.kernel.org/doc/Documentation/gpio.txt |
Revision as of 11:12, 2 May 2011
Page under construction... Informations on this page are not guaranteed !!
With recent Linux kernel (> 2.6.3x), there is an abstraction layer meant to ease GPIO usage: gpiolib. We will explain here how to use it.
Contents
Installation
- If not already done:
$ make linux26-menuconfig
Device Drivers ---> -*- GPIO Support ---> [*] /sys/class/gpio/... (sysfs interface)
$ make
- reflash your kernel (if needed)
Usage
Blink APFxxDev i.MX LED
- Find the GPIO number connected to the LED, eg:
- for APF27Dev: PF14 -> PortF (n°6) pin 14 -> (6-1)*32 + 14 -> GPIO n°174
- for APF51Dev: GPIO1_2 -> Port 1 pin 2 -> GPIO n° 2
- Define envt variable (for portability):
# export LED=174 (APF27Dev) or # export LED=2 (APF51Dev)
- Ask kernel to export the GPIO:
# echo $LED > /sys/class/gpio/export
- Access functions are created:
# ls /sys/class/gpio/gpio$LED/ active_low edge subsystem value direction power uevent
- Check GPIO direction and put in output:
# cat /sys/class/gpio/gpio$LED/direction in # echo out > /sys/class/gpio/gpio$LED/direction # cat /sys/class/gpio/gpio$LED/direction out
- Play with GPIO value to blink LED:
# echo 1 > /sys/class/gpio/gpio$LED/value # echo 0 > /sys/class/gpio/gpio$LED/value
Get APFxxDev i.MX switch status
- Find the GPIO number connected to the switch, eg:
- for APF27Dev: PF15 -> PortF (n°6) pin 15 -> (6-1)*32 + 15 -> GPIO n°175
- for APF51Dev: GPIO1_3 -> Port 1 pin 3 -> GPIO n°3 ((1-1)*32 + 3)
- Define envt variable (for portability):
# export LED=175 (APF27Dev) or # export LED=3 (APF51Dev)
- Ask kernel to export the GPIO:
# echo $LED > /sys/class/gpio/export
- Access functions are created:
# ls /sys/class/gpio/gpio$LED/ active_low edge subsystem value direction power uevent
- Check GPIO direction and put in output:
# cat /sys/class/gpio/gpio$LED/direction in
- Get switch status:
# cat /sys/class/gpio/gpio$LED/value 1 (released) ... # cat /sys/class/gpio/gpio$LED/value 0 (pressed)