FOX Board G20 is a ready-to-use low cost Linux embedded Single Board Computer designed to reduce the time to market of your Linux embedded applications


The main fields of application are: 

  • Solid-state web application servers
  • Embedded devices enhanced with Internet connectivity and Linux flexibility (a debian derived distro can be installed)


Two 40 pin sockets pitch 2.54mm are available to plug the board on specific application carriers or add-on boards. On these pins 3.3 Volt signals are available which can be used to implement RS232/RS485/RS422, I2C, SPI, GPIO, A/D and PWM interfaces.


Temperature range: 0 to +70 Celsius degree (°C)

Average power consumpiom: 80 mA @ 5V (0.4 Watt) without microSD, ethernet link, USB devices or other peripherals.



To access the gpio from java I developed a java class that works fine with this fantasic board. This class accesses the gpio system using the sysfs filesystem provided by linux.


Here you are the full source code.

 

/*
 * 
 * g20_gpio is written by Luigi D'Andrea (www.xappsoftware.com)
 * It is distributed under the BSD license
 *
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Copyright (c) 2010, Luigi DíAndrea (www.xappsoftware.com)
 * All rights reserved.
 * 
 * Redistributions of source code must retain the above copyright notice,
 *   this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, 
 *   this list of conditions and the following disclaimer in the documentation
 *   and/or other materials provided with the distribution.
 * Neither the name of the http://www.xappsoftware.com web site nor the names
 *   of its contributors may be used to endorse or promote products derived from
 *   this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY http://www.xappsoftware.com AND CONTRIBUTORS
 * ìAS ISî AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package g20_gpio;

import java.io.*;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/**
 * Utility for gpio on the Fox g20
 * @version 1.0.0
 * @author ldandrea
 */

public class gpio {
    public enum DIRECTIONS { OUT, IN};
    public int KernelId;
    public String jumperName;
    private DIRECTIONS currDir;
    private int currValue;
    /**
     * @see pinout document for the Fox G20
     */
    private static int[] kID = 
    {
        82,	83,	80,	81,	66,	67,	64,
	65,	110,	111,	108,	109,	105,	106,
	103,	104,	101,	102,	73,	72,	87,
	86,	89,	88,	60,	59,	58,	57,
	92,	71,	70,	93,	90,	69,	68,
	91,	75,	74,	77,	76,	85,	84,
        95,	94,	63,	62,	38,	39,	41,
        99,	98,	97,	96,	56,	55,	42,
        54,	43
    };
    /**
     * @see pinout document for the Fox G20
     */
    private static String[] jName =
    {
        "J7.3",	"J7.4",	"J7.5",	"J7.6",	"J7.7",	"J7.8",	"J7.9",
        "J7.10","J7.11","J7.12","J7.13","J7.14","J7.15","J7.16",
        "J7.17","J7.18","J7.19","J7.20","J7.21","J7.22","J7.31",
        "J7.32","J7.33","J7.34","J7.35","J7.36","J7.37","J7.38",
        "J6.3" ,"J6.4" ,"J6.5" ,"J6.6" ,"J6.7" ,"J6.8" ,"J6.9" ,
        "J6.10","J6.13","J6.14","J6.15","J6.16","J6.17","J6.18",
        "J6.19","J6.20","J6.21","J6.22","J6.24","J6.25","J6.26",
        "J6.27","J6.28","J6.29","J6.30","J6.31","J6.32","J6.36",
        "J6.37","J6.38"
    };

    /**
     * @return the current stored direction of the gpio, can be different 
     * from the real value.
     */
    public DIRECTIONS getCurrDir() {
        return currDir;
    }

    /**
     * @return the current stored value for the gpio, can be different 
     * from the real value.
     */
    public int getCurrValue() {
        return currValue;
    }


    /**
     * @see pinout document for the Fox G20
     * @param jumperName is the gpio we want to create expressed in a String 
     * format as described in the pinout document.
     */
    public gpio(String jumperName)
    {
        Boolean test = false;
        this.jumperName = jumperName;
        for(int i=0; i<58; i++)
        {
            if(jName[i].equals(this.jumperName))
            {
                this.KernelId = kID[i];
                test   = true;
            }
        }
        if(!test)
        {
            this.jumperName    = "J7.3";
            this.KernelId      = 82;
        }        
        if(!sysfsExists(this.KernelId))
            sysfsCreate(this.KernelId);
        setDirection(DIRECTIONS.OUT);
        clearValue();
        
    }
    
    /**
     * @see pinout document for the Fox G20
     * @param KernelId is the value id for the gpio we want to build.
     */
    public gpio(int KernelId) {
        Boolean test = false;
        this.KernelId = KernelId;
        for(int i=0; i<58; i++)
        {
            if(kID[i]==this.KernelId)
            {
                jumperName = jName[i];
                test   = true;
            }
        }
        if(!test)
        {
            jumperName    = "J7.3";
            this.KernelId      = 82;
        }
        if(!sysfsExists(this.KernelId))
            sysfsCreate(this.KernelId);
        setDirection(DIRECTIONS.OUT);
        clearValue();
    }

    /**
     * @deprecated 
     */
    public gpio() {
        jumperName    = "J7.3";
        KernelId      = 82;
        if(!sysfsExists(82))
            sysfsCreate(82);
        setDirection(DIRECTIONS.OUT);
        clearValue();
    }


    /**
     * @see pinout document for the Fox G20
     * @return the jumper name as specified in the pinout document
     */
    public String getJumperName() {
        return jumperName;
   }

    /**
     * Returns the kernelId associated with this instance.
     * @return the current kernel id
     */
    public int getKernelId() {
        return KernelId;
    }

    /**
     * Set to zero the value for this gpio.
     */
    public void clearValue()
    {
        try
        {
            BufferedWriter out = new BufferedWriter(new FileWriter("/sys/class/gpio/gpio"+this.KernelId+"/value"));
                out.write("0");
            out.close();
            currValue= 0;
        }
        catch (IOException e)
        {
        }
    }
    
    /**
     * Set to 1 the value for this gpio.
     */
    public void setValue()
    {
        try
        {
            BufferedWriter out = new BufferedWriter(new FileWriter("/sys/class/gpio/gpio"+this.KernelId+"/value"));
                out.write("1");
            out.close();
            currValue= 1;
        }
        catch (IOException e)
        {
        }
    }

    /**
     * Reads from the file system the current value for this gpio.
     * @return the current value for this gpio if the direction is set to IN.
     * if the direction has been set to out returns -1.
     */
    public int getCurrentValue()
    {
        /* Legge il contenuto di value*/
        if(currDir==DIRECTIONS.OUT)
        {
            return -1;
        }
        else
        {
            try
            {
                BufferedReader in = new BufferedReader(new FileReader("/sys/class/gpio/gpio"+this.KernelId+"/value"));
                String str;
                str = in.readLine();
                in.close();
                if(str.equals("1"))
                {
                    return 1;
                }
                else
                    return(0);
            }
            catch (IOException e)
            {
                e.printStackTrace();
                return(-2);
            }
        }
    }
    
    /**
     * Sets the new direction for this gpio
     * @param dir is the new direction.
     * @see DIRECTIONS
     */
    public void setDirection(DIRECTIONS dir)
    {
        try
        {
            BufferedWriter out = new BufferedWriter(new FileWriter("/sys/class/gpio/gpio"+this.KernelId+"/direction"));
            if(dir==DIRECTIONS.OUT)
            {
                out.write("out");
            }
            else
            {
                out.write("in");
            }
            out.close();
            currDir = dir;
        }
        catch (IOException e)
        {
        }
    }
    
    /**
     * Creates the filesystem structure for this gpio
     * @param kernelId 
     */
    private void sysfsCreate(int kernelId)
    {
        if(!sysfsExists(this.KernelId))
        {
            try
            {
                BufferedWriter out = new BufferedWriter(new FileWriter("/sys/class/gpio/export"));
                out.write(""+kernelId);
                out.close();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
        }
    }
    
    /**
     * Verifies if the requested gpio file system structure already exists.
     * @param kernelId
     * @return true if the filesystem structure exists false otherwise.
     */
    private boolean sysfsExists(int kernelId)
    {
        java.io.File file = new File("/sys/class/gpio/"+kernelId);
        return(file.exists());
    }
}

I want to say "thank you" to http://www.robot-domestici.it/ because they lent us a fox g20 board.

GG1