GPIO

General Purpose Input/Output (GPIO) is a generic pin on a integrated circuit chip whose behavior (including whether it is an input or output pin) can be controlled / programmed by the user at run time.

Overview

GPIO pins have no special purpose defined, and usually go unused by default. The idea is that sometimes the system integrator building a full system that uses the chip might find it useful to have a handful of additional digital control lines, and having these available from the chip can save the hassle of having to arrange additional circuitry to provide them.

A GPIO port is a group of GPIO pins (typically 8 GPIO pins) arranged in a group, and treated as a single port.

Accessing the GPIO pins through sysfs with mainline kernel

The GPIO pins can be accessed from user space using sysfs. To enabled this you need the following kernel option enabled: CONFIG_GPIO_SYSFS

The Process

Copy the file /media/nanda/script.bin to your PC. This file configures the A13.

Now we need to make it a text file so we use the bin2fex. On a linux machine go into the directory where you compiled the sunxi-tools and from there type this: ./bin2fex /path/to/script.bin > script.fex This will create a text file named script.fex in your current directory.

Now we need to edit it with a text editor and define the pins that are going to be used for GPIO. Look for a section named "[gpio_para]" if there is no such section (probably there will not be) go to the bottom of the file and add it like this:

[gpio_para]
gpio_used = 1
gpio_num = 1
gpio_pin_1 = port:PE11<1>

gpio_used

Do you want to use any GPIO at all? 1=yes 0=no

gpio_num

The number of total gpio ports you want / pins you are using?

gpio_pin_$Num = PXN<Z>

Where $Num is the GPIO pin number. starting from 1.

PXN is the name of the pin you want to use

Z is pin a output or a input? 0 for input or 1 for output.

In this example I used pin PE11 which is pin number 12 on the GPIO-2.
The PXN names can be found here: http://linux-sunxi.org/A13-OLinuXino#Expansion_ports.
TO CHECK: when I used PE11 this pin is part of the [csi0_para] so I went to [csi0_para] and made csi_used = 0 Not sure if this is needed, but I think it is.

Now we need to make the modified fex file back to bin format so again from the directory where you compiled the sunxi-tools: ./fex2bin script.fex > script.bin

Now put back the script.bin on the board and overwrite the old script.bin in /media/nanda

Unmount the /media/nanda: umount /media/nanda

Reboot the A13

Log back in and now if you did everything correct in /sys/devices/virtual/misc/sun4i-gpio/pin you will see "pe11"

If you solder a LED and a resistor to the right pin and ground (for example pin 2) http://linux-sunxi.org/images/e/e7/A13-olinuxino-brd.png and type: "echo 1 > /sys/devices/virtual/misc/sun4i-gpio/pin/pe11" the LED will light and "echo 0 > /sys/devices/virtual/misc/sun4i-gpio/pin/pe11" will turn it off.