Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
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[] = { 00039 D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, D14, D15, 00040 A0, A1, A2, A3, A4, A5, LED_RED, LED_GREEN, LED_BLUE 00041 }; 00042 if (pinNo > _maxDigiOutPins) { 00043 00044 return ERR_INVALID_PIN; 00045 } 00046 if (val == 0) { 00047 ports[pinNo] = 0; 00048 } else { 00049 ports[pinNo] = 1; 00050 } 00051 return ERR_SUCCESS; 00052 } 00053 00054 /** 00055 * Reads the voltage level at given pin and returns 00056 * it's logical value. 00057 */ 00058 00059 uint MbedPerAccess::digitalIn(uint pinNo, uint * val) 00060 { 00061 DigitalIn ports[] = { 00062 D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, D14, D15, 00063 A0, A1, A2, A3, A4, A5 00064 }; 00065 if (pinNo > _maxDigiInPins) { 00066 return ERR_INVALID_PIN; 00067 } 00068 00069 00070 *val = ports[pinNo]; 00071 return ERR_SUCCESS; 00072 } 00073 00074 /** 00075 * Outputs the analog value. 00076 */ 00077 00078 uint MbedPerAccess::analogOut(uint pinNo, uint val) 00079 { 00080 AnalogOut aout(DAC0_OUT); 00081 if (val > _maxAnOutVal) { 00082 return ERR_INVALID_ARG; 00083 } 00084 /* Only one analog out */ 00085 if (pinNo != 0) { 00086 return ERR_INVALID_PIN; 00087 } 00088 aout = val/100.0; 00089 return ERR_SUCCESS; 00090 } 00091 00092 /** 00093 * Reads the volatge at the given analog input pin 00094 * and returns the digital representation of the same 00095 */ 00096 00097 uint MbedPerAccess::analogIn(uint pinNo, uint * outVal) 00098 { 00099 float val; 00100 AnalogIn ana_in[] = { A0, A1, A2, A3, A4, A5 }; 00101 if (pinNo > _maxAnInPins) { 00102 return ERR_INVALID_PIN; 00103 } 00104 00105 val = ana_in[pinNo]; 00106 *outVal = (int)(val*100); 00107 return ERR_SUCCESS; 00108 }
Generated on Thu Aug 4 2022 08:49:39 by
1.7.2