Modification of mbed-src library only for STM32F030F4, very cheap microcontroller in 20-Pin TSSOP package, with 16Kbytes of Flash and 4Kbytes of Ram. **Target for online compilator must be Nucleo 32F030R8.** 01.02.2018 Acosinwork: Fork of mbed-STM32F030F4 library. Support for Troyka GPIO expander by Amperka. http://amperka.ru/product/troyka-gpio-expander

Fork of mbed-STM32F030F4 by Nothing Special

Committer:
acosinwork
Date:
Thu Feb 01 10:37:10 2018 +0000
Revision:
12:6f07dd7cbe47
Parent:
0:38ccae254a29
Change pin mapping and set internall oscillator as default. Fork to support Troyka GPIO expander (I2C I/O); http://amperka.ru/product/troyka-gpio-expander

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mega64 0:38ccae254a29 1 /* mbed Microcontroller Library
mega64 0:38ccae254a29 2 * Copyright (c) 2006-2013 ARM Limited
mega64 0:38ccae254a29 3 *
mega64 0:38ccae254a29 4 * Licensed under the Apache License, Version 2.0 (the "License");
mega64 0:38ccae254a29 5 * you may not use this file except in compliance with the License.
mega64 0:38ccae254a29 6 * You may obtain a copy of the License at
mega64 0:38ccae254a29 7 *
mega64 0:38ccae254a29 8 * http://www.apache.org/licenses/LICENSE-2.0
mega64 0:38ccae254a29 9 *
mega64 0:38ccae254a29 10 * Unless required by applicable law or agreed to in writing, software
mega64 0:38ccae254a29 11 * distributed under the License is distributed on an "AS IS" BASIS,
mega64 0:38ccae254a29 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mega64 0:38ccae254a29 13 * See the License for the specific language governing permissions and
mega64 0:38ccae254a29 14 * limitations under the License.
mega64 0:38ccae254a29 15 */
mega64 0:38ccae254a29 16 #include "Stream.h"
mega64 0:38ccae254a29 17
mega64 0:38ccae254a29 18 #include <cstdarg>
mega64 0:38ccae254a29 19
mega64 0:38ccae254a29 20 namespace mbed {
mega64 0:38ccae254a29 21
mega64 0:38ccae254a29 22 Stream::Stream(const char *name) : FileLike(name), _file(NULL) {
mega64 0:38ccae254a29 23 /* open ourselves */
mega64 0:38ccae254a29 24 char buf[12]; /* :0x12345678 + null byte */
mega64 0:38ccae254a29 25 std::sprintf(buf, ":%p", this);
mega64 0:38ccae254a29 26 _file = std::fopen(buf, "w+");
mega64 0:38ccae254a29 27 setbuf(_file, NULL);
mega64 0:38ccae254a29 28 }
mega64 0:38ccae254a29 29
mega64 0:38ccae254a29 30 Stream::~Stream() {
mega64 0:38ccae254a29 31 fclose(_file);
mega64 0:38ccae254a29 32 }
mega64 0:38ccae254a29 33
mega64 0:38ccae254a29 34 int Stream::putc(int c) {
mega64 0:38ccae254a29 35 fflush(_file);
mega64 0:38ccae254a29 36 return std::fputc(c, _file);
mega64 0:38ccae254a29 37 }
mega64 0:38ccae254a29 38 int Stream::puts(const char *s) {
mega64 0:38ccae254a29 39 fflush(_file);
mega64 0:38ccae254a29 40 return std::fputs(s, _file);
mega64 0:38ccae254a29 41 }
mega64 0:38ccae254a29 42 int Stream::getc() {
mega64 0:38ccae254a29 43 fflush(_file);
mega64 0:38ccae254a29 44 return std::fgetc(_file);
mega64 0:38ccae254a29 45 }
mega64 0:38ccae254a29 46 char* Stream::gets(char *s, int size) {
mega64 0:38ccae254a29 47 fflush(_file);
mega64 0:38ccae254a29 48 return std::fgets(s,size,_file);
mega64 0:38ccae254a29 49 }
mega64 0:38ccae254a29 50
mega64 0:38ccae254a29 51 int Stream::close() {
mega64 0:38ccae254a29 52 return 0;
mega64 0:38ccae254a29 53 }
mega64 0:38ccae254a29 54
mega64 0:38ccae254a29 55 ssize_t Stream::write(const void* buffer, size_t length) {
mega64 0:38ccae254a29 56 const char* ptr = (const char*)buffer;
mega64 0:38ccae254a29 57 const char* end = ptr + length;
mega64 0:38ccae254a29 58 while (ptr != end) {
mega64 0:38ccae254a29 59 if (_putc(*ptr++) == EOF) {
mega64 0:38ccae254a29 60 break;
mega64 0:38ccae254a29 61 }
mega64 0:38ccae254a29 62 }
mega64 0:38ccae254a29 63 return ptr - (const char*)buffer;
mega64 0:38ccae254a29 64 }
mega64 0:38ccae254a29 65
mega64 0:38ccae254a29 66 ssize_t Stream::read(void* buffer, size_t length) {
mega64 0:38ccae254a29 67 char* ptr = (char*)buffer;
mega64 0:38ccae254a29 68 char* end = ptr + length;
mega64 0:38ccae254a29 69 while (ptr != end) {
mega64 0:38ccae254a29 70 int c = _getc();
mega64 0:38ccae254a29 71 if (c==EOF) break;
mega64 0:38ccae254a29 72 *ptr++ = c;
mega64 0:38ccae254a29 73 }
mega64 0:38ccae254a29 74 return ptr - (const char*)buffer;
mega64 0:38ccae254a29 75 }
mega64 0:38ccae254a29 76
mega64 0:38ccae254a29 77 off_t Stream::lseek(off_t offset, int whence) {
mega64 0:38ccae254a29 78 return 0;
mega64 0:38ccae254a29 79 }
mega64 0:38ccae254a29 80
mega64 0:38ccae254a29 81 int Stream::isatty() {
mega64 0:38ccae254a29 82 return 0;
mega64 0:38ccae254a29 83 }
mega64 0:38ccae254a29 84
mega64 0:38ccae254a29 85 int Stream::fsync() {
mega64 0:38ccae254a29 86 return 0;
mega64 0:38ccae254a29 87 }
mega64 0:38ccae254a29 88
mega64 0:38ccae254a29 89 off_t Stream::flen() {
mega64 0:38ccae254a29 90 return 0;
mega64 0:38ccae254a29 91 }
mega64 0:38ccae254a29 92
mega64 0:38ccae254a29 93 int Stream::printf(const char* format, ...) {
mega64 0:38ccae254a29 94 std::va_list arg;
mega64 0:38ccae254a29 95 va_start(arg, format);
mega64 0:38ccae254a29 96 fflush(_file);
mega64 0:38ccae254a29 97 int r = vfprintf(_file, format, arg);
mega64 0:38ccae254a29 98 va_end(arg);
mega64 0:38ccae254a29 99 return r;
mega64 0:38ccae254a29 100 }
mega64 0:38ccae254a29 101
mega64 0:38ccae254a29 102 int Stream::scanf(const char* format, ...) {
mega64 0:38ccae254a29 103 std::va_list arg;
mega64 0:38ccae254a29 104 va_start(arg, format);
mega64 0:38ccae254a29 105 fflush(_file);
mega64 0:38ccae254a29 106 int r = vfscanf(_file, format, arg);
mega64 0:38ccae254a29 107 va_end(arg);
mega64 0:38ccae254a29 108 return r;
mega64 0:38ccae254a29 109 }
mega64 0:38ccae254a29 110
mega64 0:38ccae254a29 111 } // namespace mbed