Lets you control the FRDM-K64F board over the PC using the GUI software (https://github.com/navin-bhaskar/Controller) written in Python. To use the software, connect the FRDM-K64Fto your PC (via USB cable connected to USB port labelled as "open SDA") and start the software to control the FRDM-K64F. For more info on usage, please go to: http://navinbhaskar.blogspot.in/2013/02/arduino-controller-3.html

Dependencies:   mbed

Committer:
Navin
Date:
Fri Aug 08 02:27:42 2014 +0000
Revision:
0:7ce46d3f9f5d
This application lets you control the FRDM-K64F Frdm board with a front end GUI software written in Python (https://github.com/navin-bhaskar/Controller)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Navin 0:7ce46d3f9f5d 1 /*
Navin 0:7ce46d3f9f5d 2 * This program is free software; you can redistribute it and/or modify
Navin 0:7ce46d3f9f5d 3 * it under the terms of the GNU General Public License as published by
Navin 0:7ce46d3f9f5d 4 * the Free Software Foundation; either version 2 of the License, or
Navin 0:7ce46d3f9f5d 5 * (at your option) any later version.
Navin 0:7ce46d3f9f5d 6 *
Navin 0:7ce46d3f9f5d 7 * This program is distributed in the hope that it will be useful,
Navin 0:7ce46d3f9f5d 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Navin 0:7ce46d3f9f5d 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Navin 0:7ce46d3f9f5d 10 * GNU General Public License for more details.
Navin 0:7ce46d3f9f5d 11 *
Navin 0:7ce46d3f9f5d 12 * You should have received a copy of the GNU General Public License
Navin 0:7ce46d3f9f5d 13 * along with this program; if not, write to the Free Software
Navin 0:7ce46d3f9f5d 14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
Navin 0:7ce46d3f9f5d 15 * MA 02110-1301, USA.
Navin 0:7ce46d3f9f5d 16 *
Navin 0:7ce46d3f9f5d 17 */
Navin 0:7ce46d3f9f5d 18
Navin 0:7ce46d3f9f5d 19 /**
Navin 0:7ce46d3f9f5d 20 * \brief Implements the mbed perephiral access interface
Navin 0:7ce46d3f9f5d 21 * \author Navin Bhaskar
Navin 0:7ce46d3f9f5d 22 */
Navin 0:7ce46d3f9f5d 23
Navin 0:7ce46d3f9f5d 24 /**
Navin 0:7ce46d3f9f5d 25 * Implements the peripheral access functionalities
Navin 0:7ce46d3f9f5d 26 */
Navin 0:7ce46d3f9f5d 27
Navin 0:7ce46d3f9f5d 28 #include "MbedPerAccess.h"
Navin 0:7ce46d3f9f5d 29 #include "error.h"
Navin 0:7ce46d3f9f5d 30 #include "mbed.h"
Navin 0:7ce46d3f9f5d 31
Navin 0:7ce46d3f9f5d 32 /**
Navin 0:7ce46d3f9f5d 33 * Outputs the given logic level at the given pin
Navin 0:7ce46d3f9f5d 34 */
Navin 0:7ce46d3f9f5d 35
Navin 0:7ce46d3f9f5d 36 uint MbedPerAccess::digitalOut(uint pinNo, uint val)
Navin 0:7ce46d3f9f5d 37 {
Navin 0:7ce46d3f9f5d 38 DigitalOut ports[] = {
Navin 0:7ce46d3f9f5d 39 D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, D14, D15,
Navin 0:7ce46d3f9f5d 40 A0, A1, A2, A3, A4, A5, LED_RED, LED_GREEN, LED_BLUE
Navin 0:7ce46d3f9f5d 41 };
Navin 0:7ce46d3f9f5d 42 if (pinNo > _maxDigiOutPins) {
Navin 0:7ce46d3f9f5d 43
Navin 0:7ce46d3f9f5d 44 return ERR_INVALID_PIN;
Navin 0:7ce46d3f9f5d 45 }
Navin 0:7ce46d3f9f5d 46 if (val == 0) {
Navin 0:7ce46d3f9f5d 47 ports[pinNo] = 0;
Navin 0:7ce46d3f9f5d 48 } else {
Navin 0:7ce46d3f9f5d 49 ports[pinNo] = 1;
Navin 0:7ce46d3f9f5d 50 }
Navin 0:7ce46d3f9f5d 51 return ERR_SUCCESS;
Navin 0:7ce46d3f9f5d 52 }
Navin 0:7ce46d3f9f5d 53
Navin 0:7ce46d3f9f5d 54 /**
Navin 0:7ce46d3f9f5d 55 * Reads the voltage level at given pin and returns
Navin 0:7ce46d3f9f5d 56 * it's logical value.
Navin 0:7ce46d3f9f5d 57 */
Navin 0:7ce46d3f9f5d 58
Navin 0:7ce46d3f9f5d 59 uint MbedPerAccess::digitalIn(uint pinNo, uint * val)
Navin 0:7ce46d3f9f5d 60 {
Navin 0:7ce46d3f9f5d 61 DigitalIn ports[] = {
Navin 0:7ce46d3f9f5d 62 D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, D14, D15,
Navin 0:7ce46d3f9f5d 63 A0, A1, A2, A3, A4, A5
Navin 0:7ce46d3f9f5d 64 };
Navin 0:7ce46d3f9f5d 65 if (pinNo > _maxDigiInPins) {
Navin 0:7ce46d3f9f5d 66 return ERR_INVALID_PIN;
Navin 0:7ce46d3f9f5d 67 }
Navin 0:7ce46d3f9f5d 68
Navin 0:7ce46d3f9f5d 69
Navin 0:7ce46d3f9f5d 70 *val = ports[pinNo];
Navin 0:7ce46d3f9f5d 71 return ERR_SUCCESS;
Navin 0:7ce46d3f9f5d 72 }
Navin 0:7ce46d3f9f5d 73
Navin 0:7ce46d3f9f5d 74 /**
Navin 0:7ce46d3f9f5d 75 * Outputs the analog value.
Navin 0:7ce46d3f9f5d 76 */
Navin 0:7ce46d3f9f5d 77
Navin 0:7ce46d3f9f5d 78 uint MbedPerAccess::analogOut(uint pinNo, uint val)
Navin 0:7ce46d3f9f5d 79 {
Navin 0:7ce46d3f9f5d 80 AnalogOut aout(DAC0_OUT);
Navin 0:7ce46d3f9f5d 81 if (val > _maxAnOutVal) {
Navin 0:7ce46d3f9f5d 82 return ERR_INVALID_ARG;
Navin 0:7ce46d3f9f5d 83 }
Navin 0:7ce46d3f9f5d 84 /* Only one analog out */
Navin 0:7ce46d3f9f5d 85 if (pinNo != 0) {
Navin 0:7ce46d3f9f5d 86 return ERR_INVALID_PIN;
Navin 0:7ce46d3f9f5d 87 }
Navin 0:7ce46d3f9f5d 88 aout = val/100.0;
Navin 0:7ce46d3f9f5d 89 return ERR_SUCCESS;
Navin 0:7ce46d3f9f5d 90 }
Navin 0:7ce46d3f9f5d 91
Navin 0:7ce46d3f9f5d 92 /**
Navin 0:7ce46d3f9f5d 93 * Reads the volatge at the given analog input pin
Navin 0:7ce46d3f9f5d 94 * and returns the digital representation of the same
Navin 0:7ce46d3f9f5d 95 */
Navin 0:7ce46d3f9f5d 96
Navin 0:7ce46d3f9f5d 97 uint MbedPerAccess::analogIn(uint pinNo, uint * outVal)
Navin 0:7ce46d3f9f5d 98 {
Navin 0:7ce46d3f9f5d 99 float val;
Navin 0:7ce46d3f9f5d 100 AnalogIn ana_in[] = { A0, A1, A2, A3, A4, A5 };
Navin 0:7ce46d3f9f5d 101 if (pinNo > _maxAnInPins) {
Navin 0:7ce46d3f9f5d 102 return ERR_INVALID_PIN;
Navin 0:7ce46d3f9f5d 103 }
Navin 0:7ce46d3f9f5d 104
Navin 0:7ce46d3f9f5d 105 val = ana_in[pinNo];
Navin 0:7ce46d3f9f5d 106 *outVal = (int)(val*100);
Navin 0:7ce46d3f9f5d 107 return ERR_SUCCESS;
Navin 0:7ce46d3f9f5d 108 }