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:
0:fe5850ccdb6f
Child:
1:9d3340bcd863

File content as of revision 0:fe5850ccdb6f:



/**
 * 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;
}