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
main.cpp@0:7ce46d3f9f5d, 2014-08-08 (annotated)
- 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?
User | Revision | Line number | New 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 | #include "mbed.h" |
Navin | 0:7ce46d3f9f5d | 19 | #include "TransLayer.h" |
Navin | 0:7ce46d3f9f5d | 20 | #include "MbedConsole.h" |
Navin | 0:7ce46d3f9f5d | 21 | #include "MbedPerAccess.h" |
Navin | 0:7ce46d3f9f5d | 22 | |
Navin | 0:7ce46d3f9f5d | 23 | /** |
Navin | 0:7ce46d3f9f5d | 24 | * \brief The main entry point of our application. |
Navin | 0:7ce46d3f9f5d | 25 | * \author Navin Bhaskar |
Navin | 0:7ce46d3f9f5d | 26 | */ |
Navin | 0:7ce46d3f9f5d | 27 | |
Navin | 0:7ce46d3f9f5d | 28 | Serial pc(USBTX, USBRX); |
Navin | 0:7ce46d3f9f5d | 29 | /** |
Navin | 0:7ce46d3f9f5d | 30 | * \fn number(char* buff) |
Navin | 0:7ce46d3f9f5d | 31 | * \brief This function converts a string into a number. |
Navin | 0:7ce46d3f9f5d | 32 | * \param[in] buff buffer containg string representation of a number (should be decimal representation). |
Navin | 0:7ce46d3f9f5d | 33 | * \retrun converted number |
Navin | 0:7ce46d3f9f5d | 34 | */ |
Navin | 0:7ce46d3f9f5d | 35 | |
Navin | 0:7ce46d3f9f5d | 36 | int number(char *buff) |
Navin | 0:7ce46d3f9f5d | 37 | { |
Navin | 0:7ce46d3f9f5d | 38 | int i = strlen(buff); |
Navin | 0:7ce46d3f9f5d | 39 | int j,temp=0; |
Navin | 0:7ce46d3f9f5d | 40 | |
Navin | 0:7ce46d3f9f5d | 41 | for(j=0; j<i; j++) { |
Navin | 0:7ce46d3f9f5d | 42 | if(buff[j] >= '0' && buff[j] <= '9') { |
Navin | 0:7ce46d3f9f5d | 43 | temp = temp*10; |
Navin | 0:7ce46d3f9f5d | 44 | temp = temp + buff[j] - '0'; |
Navin | 0:7ce46d3f9f5d | 45 | |
Navin | 0:7ce46d3f9f5d | 46 | } |
Navin | 0:7ce46d3f9f5d | 47 | } |
Navin | 0:7ce46d3f9f5d | 48 | |
Navin | 0:7ce46d3f9f5d | 49 | return temp; |
Navin | 0:7ce46d3f9f5d | 50 | } |
Navin | 0:7ce46d3f9f5d | 51 | /** |
Navin | 0:7ce46d3f9f5d | 52 | * \fn pin_control(char* buff, int len) |
Navin | 0:7ce46d3f9f5d | 53 | * \brief sets or resets a pin |
Navin | 0:7ce46d3f9f5d | 54 | */ |
Navin | 0:7ce46d3f9f5d | 55 | void pin_control(Console * cons, PerAccess * per, char* buff, int len) |
Navin | 0:7ce46d3f9f5d | 56 | { |
Navin | 0:7ce46d3f9f5d | 57 | uint temp = number(buff); |
Navin | 0:7ce46d3f9f5d | 58 | uint pinno, pinst; |
Navin | 0:7ce46d3f9f5d | 59 | uint status; |
Navin | 0:7ce46d3f9f5d | 60 | |
Navin | 0:7ce46d3f9f5d | 61 | if( len < 3) { |
Navin | 0:7ce46d3f9f5d | 62 | cons->printErr(ERR_INVALID_ARG); |
Navin | 0:7ce46d3f9f5d | 63 | } else { |
Navin | 0:7ce46d3f9f5d | 64 | pinst = temp%10; // LSB is pin state |
Navin | 0:7ce46d3f9f5d | 65 | pinno = temp/10; // rest of it is pin number |
Navin | 0:7ce46d3f9f5d | 66 | status = per->digitalOut(pinno, pinst); |
Navin | 0:7ce46d3f9f5d | 67 | cons->printErr(status); |
Navin | 0:7ce46d3f9f5d | 68 | } |
Navin | 0:7ce46d3f9f5d | 69 | } |
Navin | 0:7ce46d3f9f5d | 70 | |
Navin | 0:7ce46d3f9f5d | 71 | /** |
Navin | 0:7ce46d3f9f5d | 72 | * \fn analog_out(char* buff, int len) |
Navin | 0:7ce46d3f9f5d | 73 | * \brief Outputs an anolog voltage on a given PWM channel |
Navin | 0:7ce46d3f9f5d | 74 | */ |
Navin | 0:7ce46d3f9f5d | 75 | |
Navin | 0:7ce46d3f9f5d | 76 | void analog_out(Console * cons, PerAccess * per, char* buff, int len) |
Navin | 0:7ce46d3f9f5d | 77 | { |
Navin | 0:7ce46d3f9f5d | 78 | int temp = number(buff); |
Navin | 0:7ce46d3f9f5d | 79 | int pinno, pinval; |
Navin | 0:7ce46d3f9f5d | 80 | uint status; |
Navin | 0:7ce46d3f9f5d | 81 | if( len < 3) { |
Navin | 0:7ce46d3f9f5d | 82 | cons->printErr(ERR_INVALID_ARG); |
Navin | 0:7ce46d3f9f5d | 83 | return ; |
Navin | 0:7ce46d3f9f5d | 84 | } |
Navin | 0:7ce46d3f9f5d | 85 | |
Navin | 0:7ce46d3f9f5d | 86 | pinno = temp&0xff; // LSB is pin value |
Navin | 0:7ce46d3f9f5d | 87 | pinval = temp>>8; // MSB is pin no |
Navin | 0:7ce46d3f9f5d | 88 | |
Navin | 0:7ce46d3f9f5d | 89 | status = per->analogOut(pinno, pinval); |
Navin | 0:7ce46d3f9f5d | 90 | cons->printErr(status); |
Navin | 0:7ce46d3f9f5d | 91 | } |
Navin | 0:7ce46d3f9f5d | 92 | |
Navin | 0:7ce46d3f9f5d | 93 | /** |
Navin | 0:7ce46d3f9f5d | 94 | * \fn analog_in(char* buff, int len) |
Navin | 0:7ce46d3f9f5d | 95 | * \brief This function reads an analog volatge on a given channel and prints |
Navin | 0:7ce46d3f9f5d | 96 | * it over on the serial terminal |
Navin | 0:7ce46d3f9f5d | 97 | */ |
Navin | 0:7ce46d3f9f5d | 98 | |
Navin | 0:7ce46d3f9f5d | 99 | void analog_in(Console * cons, PerAccess * per, char* buff, int len) |
Navin | 0:7ce46d3f9f5d | 100 | { |
Navin | 0:7ce46d3f9f5d | 101 | uint adc_val; |
Navin | 0:7ce46d3f9f5d | 102 | uint ch=number(buff); |
Navin | 0:7ce46d3f9f5d | 103 | uint status; |
Navin | 0:7ce46d3f9f5d | 104 | status = per->analogIn(ch, &adc_val); |
Navin | 0:7ce46d3f9f5d | 105 | if (status == ERR_SUCCESS) { |
Navin | 0:7ce46d3f9f5d | 106 | cons->printf("%d\n", adc_val); |
Navin | 0:7ce46d3f9f5d | 107 | } |
Navin | 0:7ce46d3f9f5d | 108 | cons->printErr(status); |
Navin | 0:7ce46d3f9f5d | 109 | } |
Navin | 0:7ce46d3f9f5d | 110 | |
Navin | 0:7ce46d3f9f5d | 111 | /** |
Navin | 0:7ce46d3f9f5d | 112 | * \fn read_pin(char* buff, int len) |
Navin | 0:7ce46d3f9f5d | 113 | * \brief This function reads digital logic level at a specified pin and prints |
Navin | 0:7ce46d3f9f5d | 114 | * it over serial port prints 1 if high else it prints 0 |
Navin | 0:7ce46d3f9f5d | 115 | */ |
Navin | 0:7ce46d3f9f5d | 116 | |
Navin | 0:7ce46d3f9f5d | 117 | void read_pin(Console * cons, PerAccess * per, char* buff, int len) |
Navin | 0:7ce46d3f9f5d | 118 | { |
Navin | 0:7ce46d3f9f5d | 119 | uint read_val; |
Navin | 0:7ce46d3f9f5d | 120 | uint pin=number(buff); |
Navin | 0:7ce46d3f9f5d | 121 | uint status; |
Navin | 0:7ce46d3f9f5d | 122 | |
Navin | 0:7ce46d3f9f5d | 123 | status = per->digitalIn(pin, &read_val); |
Navin | 0:7ce46d3f9f5d | 124 | |
Navin | 0:7ce46d3f9f5d | 125 | if (status == ERR_SUCCESS) { |
Navin | 0:7ce46d3f9f5d | 126 | cons->printf("%d\n", read_val); |
Navin | 0:7ce46d3f9f5d | 127 | } |
Navin | 0:7ce46d3f9f5d | 128 | cons->printErr(status); |
Navin | 0:7ce46d3f9f5d | 129 | } |
Navin | 0:7ce46d3f9f5d | 130 | |
Navin | 0:7ce46d3f9f5d | 131 | |
Navin | 0:7ce46d3f9f5d | 132 | int main(void) |
Navin | 0:7ce46d3f9f5d | 133 | { |
Navin | 0:7ce46d3f9f5d | 134 | TransLayer comm_packet; |
Navin | 0:7ce46d3f9f5d | 135 | MbedConsole cons; |
Navin | 0:7ce46d3f9f5d | 136 | MbedPerAccess per; |
Navin | 0:7ce46d3f9f5d | 137 | |
Navin | 0:7ce46d3f9f5d | 138 | Console *transCons; |
Navin | 0:7ce46d3f9f5d | 139 | PerAccess *transPer; |
Navin | 0:7ce46d3f9f5d | 140 | |
Navin | 0:7ce46d3f9f5d | 141 | transCons = &cons; |
Navin | 0:7ce46d3f9f5d | 142 | transPer = &per; |
Navin | 0:7ce46d3f9f5d | 143 | |
Navin | 0:7ce46d3f9f5d | 144 | |
Navin | 0:7ce46d3f9f5d | 145 | comm_packet.AddService(pin_control, 'P'); |
Navin | 0:7ce46d3f9f5d | 146 | comm_packet.AddService(analog_out, 'A'); |
Navin | 0:7ce46d3f9f5d | 147 | comm_packet.AddService(analog_in, 'I'); |
Navin | 0:7ce46d3f9f5d | 148 | comm_packet.AddService(read_pin, 'R'); |
Navin | 0:7ce46d3f9f5d | 149 | comm_packet.MainLoop(transCons, transPer); |
Navin | 0:7ce46d3f9f5d | 150 | |
Navin | 0:7ce46d3f9f5d | 151 | while(1); |
Navin | 0:7ce46d3f9f5d | 152 | } |