META TOPICPARENT |
name="LinuxKernel" |
GPIO /dev Interface
This is a /dev interface to the PIO/GPIO controller which can be used to toggle GPIO pins from userspace.
Usage
To set up a GPIO device, first mount configfs under /config like this:
mkdir /config
mount -t configfs config /config
GPIO "objects" are represented as subdirectories under /config/gpio. To create a new object, simply create a new directory:
mkdir /config/gpio/leds
After this, you will find four files under /config/gpio/leds:
-
gpio_id specifies which PIO controller to use (PIOA = 0, etc.)
-
pin_mask specifies which particular pins to use on the controller.
-
oe_mask specifies which pins are used as outputs. pin_mask is used to mask the value you write here, so remember to re-check oe_mask whenever you change pin_mask .
-
enabled specifies whether the gpio object is active. Write "1" to this file in order to create the gpio device.
So if you want to control the LEDS using bits 0-7 on PORTB, you can do it like this:
echo 1 > /config/gpio/leds/gpio_id
echo 0xff > /config/gpio/leds/pin_mask # Use pins 0-7
echo 0xff > /config/gpio/leds/oe_mask # Enable output on pins 0-7
echo 1 > /config/gpio/leds/enabled # Create the device
If mdev is enabled, /dev/gpio0 should appear after this. If you've created other GPIO devices before, the number may be different. Please check "dmesg" if you're unsure.
Now, you can control the LEDs by writing to /dev/gpio0:
echo -ne '\x00\x00\x00\xaa' > /dev/gpio0 # Turn on all odd-numbered LEDs
Patches
Example programs
The "gpio-test" program demonstrates various ways to read data from the GPIO device. Depending on the command line options, it can use regular blocking reads, async I/O (signals), poll(), nonblocking I/O or a combination.
- gpio-test.tar.gz: Example program for reading gpio devices
META FILEATTACHMENT |
attr="" autoattached="1" comment="Example program for reading gpio devices" date="1182419509" name="gpio-test.tar.gz" path="gpio-test.tar.gz" size="2379" user="Main.HaavardSkinnemoen" version="1" |
META FILEATTACHMENT |
attr="" autoattached="1" comment="GPIO /dev interface for AVR32 (against 2.6.22-rc5)" date="1182419255" name="avr32-gpio-dev-interface.patch" path="avr32-gpio-dev-interface.patch" size="18127" user="Main.HaavardSkinnemoen" version="1" |
|