Lets you control your mbed from an easy to use GUI. Entire project is on git hub: https://github.com/navin-bhaskar/Controller For usage info follow this link http://navinbhaskar.blogspot.in/2013/02/arduino-controller-3.html

Dependencies:   mbed

MbedPerAccess.cpp

Committer:
Navin
Date:
2013-02-26
Revision:
1:9d3340bcd863
Parent:
0:fe5850ccdb6f

File content as of revision 1:9d3340bcd863:

/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 * 
 */
 
/**
*   \brief          Implements the mbed perephiral access interface
*   \author         Navin Bhaskar
*/

/**
 * Implements the peripheral access functionalities
 */

#include "MbedPerAccess.h"
#include "error.h"
#include "mbed.h"

/**
 * Outputs the given logic level at the given pin
 */

uint MbedPerAccess::digitalOut(uint pinNo, uint val)
{
    DigitalOut ports[] = {p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20,
                          p21, p22, p23, p24, p25, p26, p27, p28, p29, LED1, LED1, LED2, LED3, LED4
                         };
    if (pinNo > _maxDigiOutPins) {

        return ERR_INVALID_PIN;
    }
    if (val == 0) {
        ports[pinNo] = 0;
    } else {
        ports[pinNo] = 1;
    }
    return ERR_SUCCESS;
}

/**
 * Reads the voltage level at given pin and returns
 * it's logical value.
 */

uint MbedPerAccess::digitalIn(uint pinNo, uint * val)
{
    DigitalIn ports[] = {p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20,
                         p21, p22, p23, p24, p25, p26, p27, p28, p29
                        };
    if (pinNo > _maxDigiInPins) {
        return ERR_INVALID_PIN;
    }


    *val = ports[pinNo];
    return ERR_SUCCESS;
}

/**
 * Outputs the analog value.
 */

uint MbedPerAccess::analogOut(uint pinNo, uint val)
{
    AnalogOut aout(p18);
    if (val > _maxAnOutVal) {
        return ERR_INVALID_ARG;
    }
    /* Only one analog out */
    if (pinNo != 18) {
        return ERR_INVALID_PIN;
    }
    aout = val;
    return ERR_SUCCESS;
}

/**
 * Reads the volatge at the given analog input pin
 * and returns the digital representation of the same
 */

uint MbedPerAccess::analogIn(uint pinNo, uint * outVal)
{
    AnalogIn ana_in[] = { p15, p16, p17, p18, p19, p20};
    if (pinNo > _maxAnInPins) {
        return ERR_INVALID_PIN;
    }

    *outVal = ana_in[pinNo];
    return ERR_SUCCESS;
}