fix for mbed lib issue 3 (i2c problem) see also https://mbed.org/users/mbed_official/code/mbed/issues/3 affected implementations: LPC812, LPC11U24, LPC1768, LPC2368, LPC4088
Fork of mbed-src by
Stream.cpp
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #include "Stream.h" 00017 00018 #include <cstdarg> 00019 00020 namespace mbed { 00021 00022 Stream::Stream(const char *name) : FileLike(name) { 00023 /* open ourselves */ 00024 char buf[12]; /* :0x12345678 + null byte */ 00025 std::sprintf(buf, ":%p", this); 00026 _file = std::fopen(buf, "w+"); 00027 setbuf(_file, NULL); 00028 } 00029 00030 Stream::~Stream() { 00031 fclose(_file); 00032 } 00033 00034 int Stream::putc(int c) { 00035 fflush(_file); 00036 return std::fputc(c, _file); 00037 } 00038 int Stream::puts(const char *s) { 00039 fflush(_file); 00040 return std::fputs(s, _file); 00041 } 00042 int Stream::getc() { 00043 fflush(_file); 00044 return std::fgetc(_file); 00045 } 00046 char* Stream::gets(char *s, int size) { 00047 fflush(_file); 00048 return std::fgets(s,size,_file); 00049 } 00050 00051 int Stream::close() { 00052 return 0; 00053 } 00054 00055 ssize_t Stream::write(const void* buffer, size_t length) { 00056 const char* ptr = (const char*)buffer; 00057 const char* end = ptr + length; 00058 while (ptr != end) { 00059 if (_putc(*ptr++) == EOF) { 00060 break; 00061 } 00062 } 00063 return ptr - (const char*)buffer; 00064 } 00065 00066 ssize_t Stream::read(void* buffer, size_t length) { 00067 char* ptr = (char*)buffer; 00068 char* end = ptr + length; 00069 while (ptr != end) { 00070 int c = _getc(); 00071 if (c==EOF) break; 00072 *ptr++ = c; 00073 } 00074 return ptr - (const char*)buffer; 00075 } 00076 00077 off_t Stream::lseek(off_t offset, int whence) { 00078 return 0; 00079 } 00080 00081 int Stream::isatty() { 00082 return 0; 00083 } 00084 00085 int Stream::fsync() { 00086 return 0; 00087 } 00088 00089 off_t Stream::flen() { 00090 return 0; 00091 } 00092 00093 int Stream::printf(const char* format, ...) { 00094 std::va_list arg; 00095 va_start(arg, format); 00096 fflush(_file); 00097 int r = vfprintf(_file, format, arg); 00098 va_end(arg); 00099 return r; 00100 } 00101 00102 int Stream::scanf(const char* format, ...) { 00103 std::va_list arg; 00104 va_start(arg, format); 00105 fflush(_file); 00106 int r = vfscanf(_file, format, arg); 00107 va_end(arg); 00108 return r; 00109 } 00110 00111 } // namespace mbed
Generated on Tue Jul 12 2022 13:47:02 by 1.7.2