From ec615a4690de74afa9647c4e371f30cbaa95471f Mon Sep 17 00:00:00 2001 From: soburi Date: Sat, 15 Oct 2016 23:06:20 +0900 Subject: [PATCH] Cache up base source updating until SAMD-1.6.9 --- cores/arduino/Arduino.h | 6 ++++ cores/arduino/Print.cpp | 2 +- cores/arduino/Stream.h | 3 +- cores/arduino/Uart.cpp | 5 +++ cores/arduino/Uart.h | 1 + cores/arduino/WString.cpp | 9 ++++-- cores/arduino/WString.h | 19 +++++++----- cores/arduino/avr/dtostrf.h | 7 +++-- cores/arduino/avr/interrupt.h | 23 ++++++++++++++ cores/arduino/avr/io.h | 32 +++++++++++++++++++ cores/arduino/avr/pgmspace.h | 58 +++++++++++++++++++++++++++++++++-- cores/arduino/delay.h | 2 +- 12 files changed, 149 insertions(+), 18 deletions(-) mode change 100644 => 100755 cores/arduino/avr/dtostrf.h mode change 100644 => 100755 cores/arduino/avr/interrupt.h create mode 100755 cores/arduino/avr/io.h mode change 100644 => 100755 cores/arduino/avr/pgmspace.h mode change 100644 => 100755 cores/arduino/delay.h diff --git a/cores/arduino/Arduino.h b/cores/arduino/Arduino.h index 6f0282a..a8f79d9 100644 --- a/cores/arduino/Arduino.h +++ b/cores/arduino/Arduino.h @@ -35,6 +35,7 @@ typedef uint16_t word; // #include "avr/pgmspace.h" #include "avr/interrupt.h" +#include "avr/io.h" #include "binary.h" #include "itoa.h" @@ -114,6 +115,11 @@ void loop( void ) ; #define bit(b) (1UL << (b)) +#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606) +// Interrupts +#define digitalPinToInterrupt(P) ( P ) +#endif + // USB Device #include "USB/USBDesc.h" #include "USB/USBCore.h" diff --git a/cores/arduino/Print.cpp b/cores/arduino/Print.cpp index 05a1f18..33ee721 100644 --- a/cores/arduino/Print.cpp +++ b/cores/arduino/Print.cpp @@ -245,7 +245,7 @@ size_t Print::printFloat(double number, uint8_t digits) while (digits-- > 0) { remainder *= 10.0; - int toPrint = int(remainder); + unsigned int toPrint = (unsigned int)remainder; n += print(toPrint); remainder -= toPrint; } diff --git a/cores/arduino/Stream.h b/cores/arduino/Stream.h index 684aa7e..dd54e8c 100644 --- a/cores/arduino/Stream.h +++ b/cores/arduino/Stream.h @@ -66,7 +66,8 @@ class Stream : public Print // parsing methods void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second - + unsigned long getTimeout(void) { return _timeout; } + bool find(char *target); // reads data from the stream until the target string is found bool find(uint8_t *target) { return find ((char *)target); } // returns true if target string is found, false if timed out (see setTimeout) diff --git a/cores/arduino/Uart.cpp b/cores/arduino/Uart.cpp index 8397fbc..97fe73a 100644 --- a/cores/arduino/Uart.cpp +++ b/cores/arduino/Uart.cpp @@ -62,6 +62,11 @@ int Uart::available() return (uint32_t)(SERIAL_BUFFER_SIZE + rxBuffer._iHead - rxBuffer._iTail) % SERIAL_BUFFER_SIZE; } +int Uart::availableForWrite() +{ + return 0; //TODO +} + int Uart::peek() { return rxBuffer.peek(); diff --git a/cores/arduino/Uart.h b/cores/arduino/Uart.h index 2a1e0e1..4537349 100644 --- a/cores/arduino/Uart.h +++ b/cores/arduino/Uart.h @@ -33,6 +33,7 @@ class Uart : public HardwareSerial void begin(unsigned long baudrate, uint32_t config); void end(); int available(); + int availableForWrite(); int peek(); int read(); void flush(); diff --git a/cores/arduino/WString.cpp b/cores/arduino/WString.cpp index e1d60f4..71bbc07 100644 --- a/cores/arduino/WString.cpp +++ b/cores/arduino/WString.cpp @@ -195,7 +195,7 @@ String & String::copy(const __FlashStringHelper *pstr, unsigned int length) void String::move(String &rhs) { if (buffer) { - if (capacity >= rhs.len) { + if (rhs && capacity >= rhs.len) { strcpy(buffer, rhs.buffer); len = rhs.len; rhs.len = 0; @@ -742,6 +742,11 @@ long String::toInt(void) const float String::toFloat(void) const { - if (buffer) return float(atof(buffer)); + return float(toDouble()); +} + +double String::toDouble(void) const +{ + if (buffer) return atof(buffer); return 0; } diff --git a/cores/arduino/WString.h b/cores/arduino/WString.h index b047980..77709c3 100644 --- a/cores/arduino/WString.h +++ b/cores/arduino/WString.h @@ -81,7 +81,7 @@ class String inline unsigned int length(void) const {return len;} // creates a copy of the assigned value. if the value is null or - // invalid, or if the memory allocation fails, the string will be + // invalid, or if the memory allocation fails, the string will be // marked as invalid ("if (s)" will be false). String & operator = (const String &rhs); String & operator = (const char *cstr); @@ -92,10 +92,10 @@ class String #endif // concatenate (works w/ built-in types) - + // returns true on success, false on failure (in which case, the string - // is left unchanged). if the argument is null or invalid, the - // concatenation is considered unsucessful. + // is left unchanged). if the argument is null or invalid, the + // concatenation is considered unsucessful. unsigned char concat(const String &str); unsigned char concat(const char *cstr); unsigned char concat(char c); @@ -107,7 +107,7 @@ class String unsigned char concat(float num); unsigned char concat(double num); unsigned char concat(const __FlashStringHelper * str); - + // if there's not enough memory for the concatenated value, the string // will be left unchanged (but this isn't signalled in any way) String & operator += (const String &rhs) {concat(rhs); return (*this);} @@ -159,8 +159,12 @@ class String char& operator [] (unsigned int index); void getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index=0) const; void toCharArray(char *buf, unsigned int bufsize, unsigned int index=0) const - {getBytes((unsigned char *)buf, bufsize, index);} - const char * c_str() const { return buffer; } + { getBytes((unsigned char *)buf, bufsize, index); } + const char* c_str() const { return buffer; } + char* begin() { return buffer; } + char* end() { return buffer + length(); } + const char* begin() const { return c_str(); } + const char* end() const { return c_str() + length(); } // search int indexOf( char ch ) const; @@ -186,6 +190,7 @@ class String // parsing/conversion long toInt(void) const; float toFloat(void) const; + double toDouble(void) const; protected: char *buffer; // the actual char array diff --git a/cores/arduino/avr/dtostrf.h b/cores/arduino/avr/dtostrf.h old mode 100644 new mode 100755 index e4317c1..762a886 --- a/cores/arduino/avr/dtostrf.h +++ b/cores/arduino/avr/dtostrf.h @@ -1,7 +1,6 @@ /* dtostrf - Emulation for dtostrf function from avr-libc - Copyright (c) 2013 Arduino. All rights reserved. - Written by Cristian Maglie + Copyright (c) 2015 Arduino LLC. All rights reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -18,11 +17,13 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#pragma once + #ifdef __cplusplus extern "C" { #endif -char *dtostrf (double val, signed char width, unsigned char prec, char *sout); +char *dtostrf(double val, signed char width, unsigned char prec, char *sout); #ifdef __cplusplus } diff --git a/cores/arduino/avr/interrupt.h b/cores/arduino/avr/interrupt.h old mode 100644 new mode 100755 index e69de29..950509d --- a/cores/arduino/avr/interrupt.h +++ b/cores/arduino/avr/interrupt.h @@ -0,0 +1,23 @@ +/* + Copyright (c) 2015 Arduino LCC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +/* + Empty file. + This file is here to allow compatibility with sketches (made for AVR) + that includes +*/ diff --git a/cores/arduino/avr/io.h b/cores/arduino/avr/io.h new file mode 100755 index 0000000..33d20cd --- /dev/null +++ b/cores/arduino/avr/io.h @@ -0,0 +1,32 @@ +/* + io.h - Definitions for compatibility with AVR io macros + + Copyright (c) 2016 Arduino LLC + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE +*/ + +#ifndef _IO_H_ +#define _IO_H_ + +#define RAMSTART (HMCRAMC0_ADDR) +#define RAMSIZE (HMCRAMC0_SIZE) +#define RAMEND (RAMSTART + RAMSIZE - 1) + +#endif diff --git a/cores/arduino/avr/pgmspace.h b/cores/arduino/avr/pgmspace.h old mode 100644 new mode 100755 index 1a88e30..0f732bb --- a/cores/arduino/avr/pgmspace.h +++ b/cores/arduino/avr/pgmspace.h @@ -44,27 +44,79 @@ typedef int16_t prog_int16_t; typedef uint16_t prog_uint16_t; typedef int32_t prog_int32_t; typedef uint32_t prog_uint32_t; +typedef int64_t prog_int64_t; +typedef uint64_t prog_uint64_t; -#define memcpy_P(dest, src, num) memcpy((dest), (src), (num)) -#define strcpy_P(dest, src) strcpy((dest), (src)) +typedef const void* int_farptr_t; +typedef const void* uint_farptr_t; + +#define memchr_P(s, c, n) memchr((s), (c), (n)) +#define memcmp_P(s1, s2, n) memcmp((s1), (s2), (n)) +#define memccpy_P(dest, src, c, n) memccpy((dest), (src), (c), (n)) +#define memcpy_P(dest, src, n) memcpy((dest), (src), (n)) +#define memmem_P(haystack, haystacklen, needle, needlelen) memmem((haystack), (haystacklen), (needle), (needlelen)) +#define memrchr_P(s, c, n) memrchr((s), (c), (n)) #define strcat_P(dest, src) strcat((dest), (src)) +#define strchr_P(s, c) strchr((s), (c)) +#define strchrnul_P(s, c) strchrnul((s), (c)) #define strcmp_P(a, b) strcmp((a), (b)) -#define strstr_P(a, b) strstr((a), (b)) +#define strcpy_P(dest, src) strcpy((dest), (src)) +#define strcasecmp_P(s1, s2) strcasecmp((s1), (s2)) +#define strcasestr_P(haystack, needle) strcasestr((haystack), (needle)) +#define strcspn_P(s, accept) strcspn((s), (accept)) +#define strlcat_P(s1, s2, n) strlcat((s1), (s2), (n)) +#define strlcpy_P(s1, s2, n) strlcpy((s1), (s2), (n)) #define strlen_P(a) strlen((a)) +#define strnlen_P(s, n) strnlen((s), (n)) +#define strncmp_P(s1, s2, n) strncmp((s1), (s2), (n)) +#define strncasecmp_P(s1, s2, n) strncasecmp((s1), (s2), (n)) +#define strncat_P(s1, s2, n) strncat((s1), (s2), (n)) +#define strncpy_P(s1, s2, n) strncpy((s1), (s2), (n)) +#define strpbrk_P(s, accept) strpbrk((s), (accept)) +#define strrchr_P(s, c) strrchr((s), (c)) +#define strsep_P(sp, delim) strsep((sp), (delim)) +#define strspn_P(s, accept) strspn((s), (accept)) +#define strstr_P(a, b) strstr((a), (b)) +#define strtok_P(s, delim) strtok((s), (delim)) +#define strtok_rP(s, delim, last) strtok((s), (delim), (last)) + +#define strlen_PF(a) strlen((a)) +#define strnlen_PF(src, len) strnlen((src), (len)) +#define memcpy_PF(dest, src, len) memcpy((dest), (src), (len)) +#define strcpy_PF(dest, src) strcpy((dest), (src)) +#define strncpy_PF(dest, src, len) strncpy((dest), (src), (len)) +#define strcat_PF(dest, src) strcat((dest), (src)) +#define strlcat_PF(dest, src, len) strlcat((dest), (src), (len)) +#define strncat_PF(dest, src, len) strncat((dest), (src), (len)) +#define strcmp_PF(s1, s2) strcmp((s1), (s2)) +#define strncmp_PF(s1, s2, n) strncmp((s1), (s2), (n)) +#define strcasecmp_PF(s1, s2) strcasecmp((s1), (s2)) +#define strncasecmp_PF(s1, s2, n) strncasecmp((s1), (s2), (n)) +#define strstr_PF(s1, s2) strstr((s1), (s2)) +#define strlcpy_PF(dest, src, n) strlcpy((dest), (src), (n)) +#define memcmp_PF(s1, s2, n) memcmp((s1), (s2), (n)) + #define sprintf_P(s, f, ...) sprintf((s), (f), __VA_ARGS__) +#define snprintf_P(s, f, ...) snprintf((s), (f), __VA_ARGS__) #define pgm_read_byte(addr) (*(const unsigned char *)(addr)) #define pgm_read_word(addr) (*(const unsigned short *)(addr)) #define pgm_read_dword(addr) (*(const unsigned long *)(addr)) #define pgm_read_float(addr) (*(const float *)(addr)) +#define pgm_read_ptr(addr) (*(const void *)(addr)) #define pgm_read_byte_near(addr) pgm_read_byte(addr) #define pgm_read_word_near(addr) pgm_read_word(addr) #define pgm_read_dword_near(addr) pgm_read_dword(addr) #define pgm_read_float_near(addr) pgm_read_float(addr) +#define pgm_read_ptr_near(addr) pgm_read_ptr(addr) + #define pgm_read_byte_far(addr) pgm_read_byte(addr) #define pgm_read_word_far(addr) pgm_read_word(addr) #define pgm_read_dword_far(addr) pgm_read_dword(addr) #define pgm_read_float_far(addr) pgm_read_float(addr) +#define pgm_read_ptr_far(addr) pgm_read_ptr(addr) + +#define pgm_get_far_address(addr) (&(addr)) #endif diff --git a/cores/arduino/delay.h b/cores/arduino/delay.h old mode 100644 new mode 100755 index 4a5803a..e9c5204 --- a/cores/arduino/delay.h +++ b/cores/arduino/delay.h @@ -55,12 +55,12 @@ extern uint32_t micros( void ) ; */ extern void delay( uint32_t dwMs ) ; -#ifndef OVERLOAD_DELAYMICROSECONDS /** * \brief Pauses the program for the amount of time (in microseconds) specified as parameter. * * \param dwUs the number of microseconds to pause (uint32_t) */ +#ifndef OVERLOAD_DELAYMICROSECONDS extern void delayMicroseconds( uint32_t usec ); #endif