...your main source of everything AVR32 Linux
Logon | Register | Print

Navigation

GPIO /dev Interface

This is a /dev interface to the PIO/GPIO controller which can be used to toggle GPIO pins from userspace.

Note: This interface is deprecated. Please use the GPIO sysfs interface instead, available in 2.6.27 and later kernels. Documentation can be found in Documentation/gpio.txt in the kernel source tree.

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

r2 - 23 Sep 2008 - 10:44 - HaavardSkinnemoen
  Attachment Action Size Date Who Comment
else gpio-test.tar.gz props, move 2.3 K 21 Jun 2007 - 09:51 HaavardSkinnemoen Example program for reading gpio devices
else avr32-gpio-dev-interface.patch props, move 17.7 K 21 Jun 2007 - 09:47 HaavardSkinnemoen GPIO /dev interface for AVR32 (against 2.6.22-rc5)
Copyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Linux® is the registered trademark of Linus Torvalds in the U.S. and other countries.
Atmel®, AVR® and others are registered trademarks or trademarks of Atmel Corporation or its subsidiaries.
All other trademarks are the property of their respective owners.
Powered by Wed, 08 Feb 2006 build 8740
Syndicate this site