...your main source of everything AVR32 Linux

View | r1.2 | > | r1.1 | ...

Navigation

GpioDevInterface 2 - 23 Sep 2008 - Main.HaavardSkinnemoen
Line: 1 to 1
 
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.

Added:
>
>
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:


GpioDevInterface 1 - 21 Jun 2007 - Main.HaavardSkinnemoen
Line: 1 to 1
Added:
>
>
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"

Revision 2 r2 - 23 Sep 2008 - 10:44 - HaavardSkinnemoen
Revision 1 r1 - 21 Jun 2007 - 09:52 - HaavardSkinnemoen
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