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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MbedPerAccess.cpp Source File

MbedPerAccess.cpp

00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 2 of the License, or
00005  * (at your option) any later version.
00006  * 
00007  * This program is distributed in the hope that it will be useful,
00008  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00009  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010  * GNU General Public License for more details.
00011  * 
00012  * You should have received a copy of the GNU General Public License
00013  * along with this program; if not, write to the Free Software
00014  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00015  * MA 02110-1301, USA.
00016  * 
00017  */
00018  
00019 /**
00020 *   \brief          Implements the mbed perephiral access interface
00021 *   \author         Navin Bhaskar
00022 */
00023 
00024 /**
00025  * Implements the peripheral access functionalities
00026  */
00027 
00028 #include "MbedPerAccess.h"
00029 #include "error.h"
00030 #include "mbed.h"
00031 
00032 /**
00033  * Outputs the given logic level at the given pin
00034  */
00035 
00036 uint MbedPerAccess::digitalOut(uint pinNo, uint val)
00037 {
00038     DigitalOut ports[] = {p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20,
00039                           p21, p22, p23, p24, p25, p26, p27, p28, p29, LED1, LED1, LED2, LED3, LED4
00040                          };
00041     if (pinNo > _maxDigiOutPins) {
00042 
00043         return ERR_INVALID_PIN;
00044     }
00045     if (val == 0) {
00046         ports[pinNo] = 0;
00047     } else {
00048         ports[pinNo] = 1;
00049     }
00050     return ERR_SUCCESS;
00051 }
00052 
00053 /**
00054  * Reads the voltage level at given pin and returns
00055  * it's logical value.
00056  */
00057 
00058 uint MbedPerAccess::digitalIn(uint pinNo, uint * val)
00059 {
00060     DigitalIn ports[] = {p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20,
00061                          p21, p22, p23, p24, p25, p26, p27, p28, p29
00062                         };
00063     if (pinNo > _maxDigiInPins) {
00064         return ERR_INVALID_PIN;
00065     }
00066 
00067 
00068     *val = ports[pinNo];
00069     return ERR_SUCCESS;
00070 }
00071 
00072 /**
00073  * Outputs the analog value.
00074  */
00075 
00076 uint MbedPerAccess::analogOut(uint pinNo, uint val)
00077 {
00078     AnalogOut aout(p18);
00079     if (val > _maxAnOutVal) {
00080         return ERR_INVALID_ARG;
00081     }
00082     /* Only one analog out */
00083     if (pinNo != 18) {
00084         return ERR_INVALID_PIN;
00085     }
00086     aout = val;
00087     return ERR_SUCCESS;
00088 }
00089 
00090 /**
00091  * Reads the volatge at the given analog input pin
00092  * and returns the digital representation of the same
00093  */
00094 
00095 uint MbedPerAccess::analogIn(uint pinNo, uint * outVal)
00096 {
00097     AnalogIn ana_in[] = { p15, p16, p17, p18, p19, p20};
00098     if (pinNo > _maxAnInPins) {
00099         return ERR_INVALID_PIN;
00100     }
00101 
00102     *outVal = ana_in[pinNo];
00103     return ERR_SUCCESS;
00104 }