Development mbed library for MAX32630FTHR

Dependents:   blinky_max32630fthr

Committer:
switches
Date:
Fri Dec 16 16:27:57 2016 +0000
Revision:
3:1198227e6421
Parent:
0:5c4d7b2438d3
Changed ADC scale for MAX32625 platforms to 1.2V full scale to match MAX32630 platforms

Who changed what in which revision?

UserRevisionLine numberNew contents of line
switches 0:5c4d7b2438d3 1 /* mbed Microcontroller Library
switches 0:5c4d7b2438d3 2 * Copyright (c) 2006-2013 ARM Limited
switches 0:5c4d7b2438d3 3 *
switches 0:5c4d7b2438d3 4 * Licensed under the Apache License, Version 2.0 (the "License");
switches 0:5c4d7b2438d3 5 * you may not use this file except in compliance with the License.
switches 0:5c4d7b2438d3 6 * You may obtain a copy of the License at
switches 0:5c4d7b2438d3 7 *
switches 0:5c4d7b2438d3 8 * http://www.apache.org/licenses/LICENSE-2.0
switches 0:5c4d7b2438d3 9 *
switches 0:5c4d7b2438d3 10 * Unless required by applicable law or agreed to in writing, software
switches 0:5c4d7b2438d3 11 * distributed under the License is distributed on an "AS IS" BASIS,
switches 0:5c4d7b2438d3 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
switches 0:5c4d7b2438d3 13 * See the License for the specific language governing permissions and
switches 0:5c4d7b2438d3 14 * limitations under the License.
switches 0:5c4d7b2438d3 15 */
switches 0:5c4d7b2438d3 16 #include "mbed.h"
switches 0:5c4d7b2438d3 17 #include "Arguments.h"
switches 0:5c4d7b2438d3 18 #include "pinmap.h"
switches 0:5c4d7b2438d3 19
switches 0:5c4d7b2438d3 20 using namespace std;
switches 0:5c4d7b2438d3 21
switches 0:5c4d7b2438d3 22 namespace mbed {
switches 0:5c4d7b2438d3 23
switches 0:5c4d7b2438d3 24 Arguments::Arguments(const char* rqs) {
switches 0:5c4d7b2438d3 25 obj_name = NULL;
switches 0:5c4d7b2438d3 26 method_name = NULL;
switches 0:5c4d7b2438d3 27 argc = 0;
switches 0:5c4d7b2438d3 28
switches 0:5c4d7b2438d3 29 // This copy can be removed if we can assume the request string is
switches 0:5c4d7b2438d3 30 // persistent and writable for the duration of the call
switches 0:5c4d7b2438d3 31 strcpy(request, rqs);
switches 0:5c4d7b2438d3 32
switches 0:5c4d7b2438d3 33 // Initial '/'
switches 0:5c4d7b2438d3 34 char* p = request;
switches 0:5c4d7b2438d3 35 if (*p != '/') return;
switches 0:5c4d7b2438d3 36 p++;
switches 0:5c4d7b2438d3 37
switches 0:5c4d7b2438d3 38 // Object Name
switches 0:5c4d7b2438d3 39 p = search_arg(&obj_name, p, '/');
switches 0:5c4d7b2438d3 40 if (p == NULL) return;
switches 0:5c4d7b2438d3 41
switches 0:5c4d7b2438d3 42 // Method Name
switches 0:5c4d7b2438d3 43 p = search_arg(&method_name, p, ' ');
switches 0:5c4d7b2438d3 44 if (p == NULL) return;
switches 0:5c4d7b2438d3 45
switches 0:5c4d7b2438d3 46 // Arguments
switches 0:5c4d7b2438d3 47 while (true) {
switches 0:5c4d7b2438d3 48 argv[argc] = NULL;
switches 0:5c4d7b2438d3 49 p = search_arg(&argv[argc], p, ' ');
switches 0:5c4d7b2438d3 50 if (argv[argc] != NULL) argc++;
switches 0:5c4d7b2438d3 51 if (p == NULL) break;
switches 0:5c4d7b2438d3 52 }
switches 0:5c4d7b2438d3 53
switches 0:5c4d7b2438d3 54 index = -1;
switches 0:5c4d7b2438d3 55 }
switches 0:5c4d7b2438d3 56
switches 0:5c4d7b2438d3 57 char* Arguments::search_arg(char **arg, char *p, char next_sep) {
switches 0:5c4d7b2438d3 58 char *s = p;
switches 0:5c4d7b2438d3 59 while (true) {
switches 0:5c4d7b2438d3 60 if ((*p == '/') || (*p == ' ') || (*p == '\n') || (*p == '\0')) break;
switches 0:5c4d7b2438d3 61 p++;
switches 0:5c4d7b2438d3 62 }
switches 0:5c4d7b2438d3 63 if (p == s) return NULL;
switches 0:5c4d7b2438d3 64 *arg = s;
switches 0:5c4d7b2438d3 65 char separator = *p;
switches 0:5c4d7b2438d3 66 *p = '\0';
switches 0:5c4d7b2438d3 67 p++;
switches 0:5c4d7b2438d3 68 return (separator == next_sep) ? (p) : (NULL);
switches 0:5c4d7b2438d3 69 }
switches 0:5c4d7b2438d3 70
switches 0:5c4d7b2438d3 71 template<> PinName Arguments::getArg<PinName>(void) {
switches 0:5c4d7b2438d3 72 index++;
switches 0:5c4d7b2438d3 73 return parse_pins(argv[index]);
switches 0:5c4d7b2438d3 74 }
switches 0:5c4d7b2438d3 75
switches 0:5c4d7b2438d3 76 template<> int Arguments::getArg<int>(void) {
switches 0:5c4d7b2438d3 77 index++;
switches 0:5c4d7b2438d3 78 char *pEnd;
switches 0:5c4d7b2438d3 79 return strtol(argv[index], &pEnd, 10);
switches 0:5c4d7b2438d3 80 }
switches 0:5c4d7b2438d3 81
switches 0:5c4d7b2438d3 82 template<> const char* Arguments::getArg<const char*>(void) {
switches 0:5c4d7b2438d3 83 index++;
switches 0:5c4d7b2438d3 84 return argv[index];
switches 0:5c4d7b2438d3 85 }
switches 0:5c4d7b2438d3 86
switches 0:5c4d7b2438d3 87 template<> char Arguments::getArg<char>(void) {
switches 0:5c4d7b2438d3 88 index++;
switches 0:5c4d7b2438d3 89 return *argv[index];
switches 0:5c4d7b2438d3 90 }
switches 0:5c4d7b2438d3 91
switches 0:5c4d7b2438d3 92 template<> double Arguments::getArg<double>(void) {
switches 0:5c4d7b2438d3 93 index++;
switches 0:5c4d7b2438d3 94 return atof(argv[index]);
switches 0:5c4d7b2438d3 95 }
switches 0:5c4d7b2438d3 96
switches 0:5c4d7b2438d3 97 template<> float Arguments::getArg<float>(void) {
switches 0:5c4d7b2438d3 98 index++;
switches 0:5c4d7b2438d3 99 return atof(argv[index]);
switches 0:5c4d7b2438d3 100 }
switches 0:5c4d7b2438d3 101
switches 0:5c4d7b2438d3 102 Reply::Reply(char* r) {
switches 0:5c4d7b2438d3 103 first = true;
switches 0:5c4d7b2438d3 104 *r = '\0';
switches 0:5c4d7b2438d3 105 reply = r;
switches 0:5c4d7b2438d3 106 }
switches 0:5c4d7b2438d3 107
switches 0:5c4d7b2438d3 108 void Reply::separator(void) {
switches 0:5c4d7b2438d3 109 if (first) {
switches 0:5c4d7b2438d3 110 first = false;
switches 0:5c4d7b2438d3 111 } else {
switches 0:5c4d7b2438d3 112 *reply = ' '; reply++;
switches 0:5c4d7b2438d3 113 }
switches 0:5c4d7b2438d3 114 }
switches 0:5c4d7b2438d3 115
switches 0:5c4d7b2438d3 116 template<> void Reply::putData<const char*>(const char* s) {
switches 0:5c4d7b2438d3 117 separator();
switches 0:5c4d7b2438d3 118 reply += sprintf(reply, "%s", s);
switches 0:5c4d7b2438d3 119 }
switches 0:5c4d7b2438d3 120
switches 0:5c4d7b2438d3 121 template<> void Reply::putData<char*>(char* s) {
switches 0:5c4d7b2438d3 122 separator();
switches 0:5c4d7b2438d3 123 reply += sprintf(reply, "%s", s);
switches 0:5c4d7b2438d3 124 }
switches 0:5c4d7b2438d3 125
switches 0:5c4d7b2438d3 126 template<> void Reply::putData<char>(char c) {
switches 0:5c4d7b2438d3 127 separator();
switches 0:5c4d7b2438d3 128 reply += sprintf(reply, "%c", c);
switches 0:5c4d7b2438d3 129 }
switches 0:5c4d7b2438d3 130
switches 0:5c4d7b2438d3 131 template<> void Reply::putData<int>(int v) {
switches 0:5c4d7b2438d3 132 separator();
switches 0:5c4d7b2438d3 133 reply += sprintf(reply, "%d", v);
switches 0:5c4d7b2438d3 134 }
switches 0:5c4d7b2438d3 135
switches 0:5c4d7b2438d3 136 template<> void Reply::putData<float>(float f) {
switches 0:5c4d7b2438d3 137 separator();
switches 0:5c4d7b2438d3 138 reply += sprintf(reply, "%.17g", f);
switches 0:5c4d7b2438d3 139 }
switches 0:5c4d7b2438d3 140
switches 0:5c4d7b2438d3 141 } // namespace mbed