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 "drivers/Stream.h"
switches 0:5c4d7b2438d3 17
switches 0:5c4d7b2438d3 18 namespace mbed {
switches 0:5c4d7b2438d3 19
switches 0:5c4d7b2438d3 20 Stream::Stream(const char *name) : FileLike(name), _file(NULL) {
switches 0:5c4d7b2438d3 21 // No lock needed in constructor
switches 0:5c4d7b2438d3 22 /* open ourselves */
switches 0:5c4d7b2438d3 23 char buf[12]; /* :0x12345678 + null byte */
switches 0:5c4d7b2438d3 24 std::sprintf(buf, ":%p", this);
switches 0:5c4d7b2438d3 25 _file = std::fopen(buf, "w+");
switches 0:5c4d7b2438d3 26 mbed_set_unbuffered_stream(_file);
switches 0:5c4d7b2438d3 27 }
switches 0:5c4d7b2438d3 28
switches 0:5c4d7b2438d3 29 Stream::~Stream() {
switches 0:5c4d7b2438d3 30 // No lock can be used in destructor
switches 0:5c4d7b2438d3 31 fclose(_file);
switches 0:5c4d7b2438d3 32 }
switches 0:5c4d7b2438d3 33
switches 0:5c4d7b2438d3 34 int Stream::putc(int c) {
switches 0:5c4d7b2438d3 35 lock();
switches 0:5c4d7b2438d3 36 fflush(_file);
switches 0:5c4d7b2438d3 37 int ret = std::fputc(c, _file);
switches 0:5c4d7b2438d3 38 unlock();
switches 0:5c4d7b2438d3 39 return ret;
switches 0:5c4d7b2438d3 40 }
switches 0:5c4d7b2438d3 41 int Stream::puts(const char *s) {
switches 0:5c4d7b2438d3 42 lock();
switches 0:5c4d7b2438d3 43 fflush(_file);
switches 0:5c4d7b2438d3 44 int ret = std::fputs(s, _file);
switches 0:5c4d7b2438d3 45 unlock();
switches 0:5c4d7b2438d3 46 return ret;
switches 0:5c4d7b2438d3 47 }
switches 0:5c4d7b2438d3 48 int Stream::getc() {
switches 0:5c4d7b2438d3 49 lock();
switches 0:5c4d7b2438d3 50 fflush(_file);
switches 0:5c4d7b2438d3 51 int ret = mbed_getc(_file);
switches 0:5c4d7b2438d3 52 unlock();
switches 0:5c4d7b2438d3 53 return ret;
switches 0:5c4d7b2438d3 54 }
switches 0:5c4d7b2438d3 55 char* Stream::gets(char *s, int size) {
switches 0:5c4d7b2438d3 56 lock();
switches 0:5c4d7b2438d3 57 fflush(_file);
switches 0:5c4d7b2438d3 58 char *ret = mbed_gets(s,size,_file);
switches 0:5c4d7b2438d3 59 unlock();
switches 0:5c4d7b2438d3 60 return ret;
switches 0:5c4d7b2438d3 61 }
switches 0:5c4d7b2438d3 62
switches 0:5c4d7b2438d3 63 int Stream::close() {
switches 0:5c4d7b2438d3 64 return 0;
switches 0:5c4d7b2438d3 65 }
switches 0:5c4d7b2438d3 66
switches 0:5c4d7b2438d3 67 ssize_t Stream::write(const void* buffer, size_t length) {
switches 0:5c4d7b2438d3 68 const char* ptr = (const char*)buffer;
switches 0:5c4d7b2438d3 69 const char* end = ptr + length;
switches 0:5c4d7b2438d3 70
switches 0:5c4d7b2438d3 71 lock();
switches 0:5c4d7b2438d3 72 while (ptr != end) {
switches 0:5c4d7b2438d3 73 if (_putc(*ptr++) == EOF) {
switches 0:5c4d7b2438d3 74 break;
switches 0:5c4d7b2438d3 75 }
switches 0:5c4d7b2438d3 76 }
switches 0:5c4d7b2438d3 77 unlock();
switches 0:5c4d7b2438d3 78
switches 0:5c4d7b2438d3 79 return ptr - (const char*)buffer;
switches 0:5c4d7b2438d3 80 }
switches 0:5c4d7b2438d3 81
switches 0:5c4d7b2438d3 82 ssize_t Stream::read(void* buffer, size_t length) {
switches 0:5c4d7b2438d3 83 char* ptr = (char*)buffer;
switches 0:5c4d7b2438d3 84 char* end = ptr + length;
switches 0:5c4d7b2438d3 85
switches 0:5c4d7b2438d3 86 lock();
switches 0:5c4d7b2438d3 87 while (ptr != end) {
switches 0:5c4d7b2438d3 88 int c = _getc();
switches 0:5c4d7b2438d3 89 if (c==EOF) break;
switches 0:5c4d7b2438d3 90 *ptr++ = c;
switches 0:5c4d7b2438d3 91 }
switches 0:5c4d7b2438d3 92 unlock();
switches 0:5c4d7b2438d3 93
switches 0:5c4d7b2438d3 94 return ptr - (const char*)buffer;
switches 0:5c4d7b2438d3 95 }
switches 0:5c4d7b2438d3 96
switches 0:5c4d7b2438d3 97 off_t Stream::lseek(off_t offset, int whence) {
switches 0:5c4d7b2438d3 98 return 0;
switches 0:5c4d7b2438d3 99 }
switches 0:5c4d7b2438d3 100
switches 0:5c4d7b2438d3 101 int Stream::isatty() {
switches 0:5c4d7b2438d3 102 return 0;
switches 0:5c4d7b2438d3 103 }
switches 0:5c4d7b2438d3 104
switches 0:5c4d7b2438d3 105 int Stream::fsync() {
switches 0:5c4d7b2438d3 106 return 0;
switches 0:5c4d7b2438d3 107 }
switches 0:5c4d7b2438d3 108
switches 0:5c4d7b2438d3 109 off_t Stream::flen() {
switches 0:5c4d7b2438d3 110 return 0;
switches 0:5c4d7b2438d3 111 }
switches 0:5c4d7b2438d3 112
switches 0:5c4d7b2438d3 113 int Stream::printf(const char* format, ...) {
switches 0:5c4d7b2438d3 114 lock();
switches 0:5c4d7b2438d3 115 std::va_list arg;
switches 0:5c4d7b2438d3 116 va_start(arg, format);
switches 0:5c4d7b2438d3 117 fflush(_file);
switches 0:5c4d7b2438d3 118 int r = vfprintf(_file, format, arg);
switches 0:5c4d7b2438d3 119 va_end(arg);
switches 0:5c4d7b2438d3 120 unlock();
switches 0:5c4d7b2438d3 121 return r;
switches 0:5c4d7b2438d3 122 }
switches 0:5c4d7b2438d3 123
switches 0:5c4d7b2438d3 124 int Stream::scanf(const char* format, ...) {
switches 0:5c4d7b2438d3 125 lock();
switches 0:5c4d7b2438d3 126 std::va_list arg;
switches 0:5c4d7b2438d3 127 va_start(arg, format);
switches 0:5c4d7b2438d3 128 fflush(_file);
switches 0:5c4d7b2438d3 129 int r = vfscanf(_file, format, arg);
switches 0:5c4d7b2438d3 130 va_end(arg);
switches 0:5c4d7b2438d3 131 unlock();
switches 0:5c4d7b2438d3 132 return r;
switches 0:5c4d7b2438d3 133 }
switches 0:5c4d7b2438d3 134
switches 0:5c4d7b2438d3 135 int Stream::vprintf(const char* format, std::va_list args) {
switches 0:5c4d7b2438d3 136 lock();
switches 0:5c4d7b2438d3 137 fflush(_file);
switches 0:5c4d7b2438d3 138 int r = vfprintf(_file, format, args);
switches 0:5c4d7b2438d3 139 unlock();
switches 0:5c4d7b2438d3 140 return r;
switches 0:5c4d7b2438d3 141 }
switches 0:5c4d7b2438d3 142
switches 0:5c4d7b2438d3 143 int Stream::vscanf(const char* format, std::va_list args) {
switches 0:5c4d7b2438d3 144 lock();
switches 0:5c4d7b2438d3 145 fflush(_file);
switches 0:5c4d7b2438d3 146 int r = vfscanf(_file, format, args);
switches 0:5c4d7b2438d3 147 unlock();
switches 0:5c4d7b2438d3 148 return r;
switches 0:5c4d7b2438d3 149 }
switches 0:5c4d7b2438d3 150
switches 0:5c4d7b2438d3 151 } // namespace mbed