From 083c8cdd105d5de316a592c58f01aff980e1270d Mon Sep 17 00:00:00 2001 From: Greg Mrozek Date: Wed, 31 Oct 2018 23:52:16 -0500 Subject: [PATCH 01/10] Change inline functions to macros in WCharacter.h --- api/WCharacter.h | 183 +++++------------------------------------------ 1 file changed, 18 insertions(+), 165 deletions(-) diff --git a/api/WCharacter.h b/api/WCharacter.h index 4ce89ee8..0c74424d 100644 --- a/api/WCharacter.h +++ b/api/WCharacter.h @@ -1,168 +1,21 @@ -/* - WCharacter.h - Character utility functions for Wiring & Arduino - Copyright (c) 2010 Hernando Barragan. 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 - */ - -#ifndef Character_h -#define Character_h +#pragma once #include -// WCharacter.h prototypes -inline bool isAlphaNumeric(int c) __attribute__((always_inline)); -inline bool isAlpha(int c) __attribute__((always_inline)); -inline bool isAscii(int c) __attribute__((always_inline)); -inline bool isWhitespace(int c) __attribute__((always_inline)); -inline bool isControl(int c) __attribute__((always_inline)); -inline bool isDigit(int c) __attribute__((always_inline)); -inline bool isGraph(int c) __attribute__((always_inline)); -inline bool isLowerCase(int c) __attribute__((always_inline)); -inline bool isPrintable(int c) __attribute__((always_inline)); -inline bool isPunct(int c) __attribute__((always_inline)); -inline bool isSpace(int c) __attribute__((always_inline)); -inline bool isUpperCase(int c) __attribute__((always_inline)); -inline bool isHexadecimalDigit(int c) __attribute__((always_inline)); -inline int toAscii(int c) __attribute__((always_inline)); -inline int toLowerCase(int c) __attribute__((always_inline)); -inline int toUpperCase(int c)__attribute__((always_inline)); - - -// Checks for an alphanumeric character. -// It is equivalent to (isalpha(c) || isdigit(c)). -inline bool isAlphaNumeric(int c) -{ - return ( isalnum(c) == 0 ? false : true); -} - - -// Checks for an alphabetic character. -// It is equivalent to (isupper(c) || islower(c)). -inline bool isAlpha(int c) -{ - return ( isalpha(c) == 0 ? false : true); -} - - -// Checks whether c is a 7-bit unsigned char value -// that fits into the ASCII character set. -inline bool isAscii(int c) -{ - return ( isascii (c) == 0 ? false : true); -} - - -// Checks for a blank character, that is, a space or a tab. -inline bool isWhitespace(int c) -{ - return ( isblank (c) == 0 ? false : true); -} - - -// Checks for a control character. -inline bool isControl(int c) -{ - return ( iscntrl (c) == 0 ? false : true); -} - - -// Checks for a digit (0 through 9). -inline bool isDigit(int c) -{ - return ( isdigit (c) == 0 ? false : true); -} - - -// Checks for any printable character except space. -inline bool isGraph(int c) -{ - return ( isgraph (c) == 0 ? false : true); -} - - -// Checks for a lower-case character. -inline bool isLowerCase(int c) -{ - return (islower (c) == 0 ? false : true); -} - - -// Checks for any printable character including space. -inline bool isPrintable(int c) -{ - return ( isprint (c) == 0 ? false : true); -} - - -// Checks for any printable character which is not a space -// or an alphanumeric character. -inline bool isPunct(int c) -{ - return ( ispunct (c) == 0 ? false : true); -} - - -// Checks for white-space characters. For the avr-libc library, -// these are: space, formfeed ('\f'), newline ('\n'), carriage -// return ('\r'), horizontal tab ('\t'), and vertical tab ('\v'). -inline bool isSpace(int c) -{ - return ( isspace (c) == 0 ? false : true); -} - - -// Checks for an uppercase letter. -inline bool isUpperCase(int c) -{ - return ( isupper (c) == 0 ? false : true); -} - - -// Checks for a hexadecimal digits, i.e. one of 0 1 2 3 4 5 6 7 -// 8 9 a b c d e f A B C D E F. -inline bool isHexadecimalDigit(int c) -{ - return ( isxdigit (c) == 0 ? false : true); -} - - -// Converts c to a 7-bit unsigned char value that fits into the -// ASCII character set, by clearing the high-order bits. -inline int toAscii(int c) -{ - return toascii (c); -} - - -// Warning: -// Many people will be unhappy if you use this function. -// This function will convert accented letters into random -// characters. - -// Converts the letter c to lower case, if possible. -inline int toLowerCase(int c) -{ - return tolower (c); -} - - -// Converts the letter c to upper case, if possible. -inline int toUpperCase(int c) -{ - return toupper (c); -} - -#endif \ No newline at end of file +#define isAlpha(c) (isalpha(c) ? true : false) +#define isAlphaNumeric(c) (isalnum(c) ? true : false) +#define isAscii(c) (isascii(c) ? true : false) +#define isControl(c) (iscntrl(c) ? true : false) +#define isDigit(c) (isdigit(c) ? true : false) +#define isGraph(c) (isgraph(c) ? true : false) +#define isHexadecimalDigit(c) (isxdigit(c) ? true : false) +#define isLowerCase(c) (islower(c) ? true : false) +#define isPrintable(c) (isprint(c) ? true : false) +#define isPunct(c) (ispunct(c) ? true : false) +#define isSpace(c) (isspace(c) ? true : false) +#define isUpperCase(c) (isupper(c) ? true : false) +#define isWhitespace(c) (isblank(c) ? true : false) + +#define toAscii(c) (toascii(c)) +#define toLowerCase(c) (tolower(c)) +#define toUpperCase(c) (toupper(c)) From 676527a10b3b7d85cebc3cb1183ea0a81b3fd215 Mon Sep 17 00:00:00 2001 From: Greg Mrozek Date: Wed, 31 Oct 2018 23:57:23 -0500 Subject: [PATCH 02/10] Reorganize common.h into separate module headers. --- api/ArduinoAPI.h | 26 ++++---- api/Common.cpp | 10 --- api/Common.h | 153 ---------------------------------------------- api/WAnalog.h | 18 ++++++ api/WDelay.h | 12 ++++ api/WDigital.h | 15 +++++ api/WInterrupts.h | 22 +++++++ api/WMath.cpp | 18 ++++++ api/WMath.h | 79 ++++++++++++++++++++++++ api/WMemory.cpp | 24 ++++++++ api/WMemory.h | 11 ++++ api/WPulse.h | 12 ++++ api/WRandom.cpp | 27 ++++++++ api/WRandom.h | 10 +++ api/WShift.c | 33 ++++++++++ api/WShift.h | 14 +++++ api/WTime.h | 12 ++++ api/WTone.h | 10 +++ api/WTypes.h | 44 +++++++++++++ 19 files changed, 376 insertions(+), 174 deletions(-) delete mode 100644 api/Common.cpp delete mode 100644 api/Common.h create mode 100644 api/WAnalog.h create mode 100644 api/WDelay.h create mode 100644 api/WDigital.h create mode 100644 api/WInterrupts.h create mode 100644 api/WMath.cpp create mode 100644 api/WMath.h create mode 100644 api/WMemory.cpp create mode 100644 api/WMemory.h create mode 100644 api/WPulse.h create mode 100644 api/WRandom.cpp create mode 100644 api/WRandom.h create mode 100644 api/WShift.c create mode 100644 api/WShift.h create mode 100644 api/WTime.h create mode 100644 api/WTone.h create mode 100644 api/WTypes.h diff --git a/api/ArduinoAPI.h b/api/ArduinoAPI.h index c70f2adb..b9f749f9 100644 --- a/api/ArduinoAPI.h +++ b/api/ArduinoAPI.h @@ -23,6 +23,21 @@ // version 1.0.0 #define ARDUINO_API_VERSION 10000 +#include "WTypes.h" + +#include "WAnalog.h" +#include "WCharacter.h" +#include "WDelay.h" +#include "WDigital.h" +#include "WInterrupts.h" +#include "WMath.h" +#include "WMemory.h" +#include "WPulse.h" +#include "WRandom.h" +#include "WShift.h" +#include "WTime.h" +#include "WTone.h" + #include "Binary.h" #ifdef __cplusplus @@ -39,17 +54,6 @@ #include "Stream.h" #include "Udp.h" #include "USBAPI.h" -#include "WCharacter.h" #endif -/* Standard C library includes */ -#include -#include -#include -#include -#include - -// Misc Arduino core functions -#include "Common.h" - #endif diff --git a/api/Common.cpp b/api/Common.cpp deleted file mode 100644 index d1f822c9..00000000 --- a/api/Common.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "Common.h" - -/* C++ prototypes */ -long map(long x, long in_min, long in_max, long out_min, long out_max) -{ - return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; -} - -uint16_t makeWord(uint16_t w) { return w; } -uint16_t makeWord(uint8_t h, uint8_t l) { return (h << 8) | l; } \ No newline at end of file diff --git a/api/Common.h b/api/Common.h deleted file mode 100644 index e638d3be..00000000 --- a/api/Common.h +++ /dev/null @@ -1,153 +0,0 @@ -#pragma once -#include - -#ifdef __cplusplus -extern "C"{ -#endif - -void yield(void); - -typedef enum { - LOW = 0, - HIGH = 1, - CHANGE = 2, - FALLING = 3, - RISING = 4, -} PinStatus; - -typedef enum { - INPUT = 0x0, - OUTPUT = 0x1, - INPUT_PULLUP = 0x2, - INPUT_PULLDOWN = 0x3, -} PinMode; - -typedef enum { - LSBFIRST = 0, - MSBFIRST = 1, -} BitOrder; - -#define PI 3.1415926535897932384626433832795 -#define HALF_PI 1.5707963267948966192313216916398 -#define TWO_PI 6.283185307179586476925286766559 -#define DEG_TO_RAD 0.017453292519943295769236907684886 -#define RAD_TO_DEG 57.295779513082320876798154814105 -#define EULER 2.718281828459045235360287471352 - -#define SERIAL 0x0 -#define DISPLAY 0x1 - -#ifndef min -#define min(a,b) \ - ({ __typeof__ (a) _a = (a); \ - __typeof__ (b) _b = (b); \ - _a < _b ? _a : _b; }) -#endif - -#ifndef max -#define max(a,b) \ - ({ __typeof__ (a) _a = (a); \ - __typeof__ (b) _b = (b); \ - _a > _b ? _a : _b; }) -#endif - -#ifndef constrain -#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) -#endif - -#ifndef radians -#define radians(deg) ((deg)*DEG_TO_RAD) -#endif - -#ifndef degrees -#define degrees(rad) ((rad)*RAD_TO_DEG) -#endif - -#ifndef sq -#define sq(x) ((x)*(x)) -#endif - -typedef void (*voidFuncPtr)(void); -typedef void (*voidFuncPtrParam)(void*); - -// interrupts() / noInterrupts() must be defined by the core - -#define lowByte(w) ((uint8_t) ((w) & 0xff)) -#define highByte(w) ((uint8_t) ((w) >> 8)) - -#define bitRead(value, bit) (((value) >> (bit)) & 0x01) -#define bitSet(value, bit) ((value) |= (1UL << (bit))) -#define bitClear(value, bit) ((value) &= ~(1UL << (bit))) -#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit)) - -#ifndef bit -#define bit(b) (1UL << (b)) -#endif - -/* TODO: request for removal */ -typedef bool boolean; -typedef uint8_t byte; -typedef uint16_t word; - -void init(void); -void initVariant(void); - -int atexit(void (*func)()) __attribute__((weak)); -int main() __attribute__((weak)); - -#ifdef EXTENDED_PIN_MODE -// Platforms who wnat to declare more than 256 pins need to define EXTENDED_PIN_MODE globally -typedef uint32_t pin_size_t; -#else -typedef uint8_t pin_size_t; -#endif - -void pinMode(pin_size_t pinNumber, PinMode pinMode); -void digitalWrite(pin_size_t pinNumber, PinStatus status); -PinStatus digitalRead(pin_size_t pinNumber); -int analogRead(pin_size_t pinNumber); -void analogReference(uint8_t mode); -void analogWrite(pin_size_t pinNumber, int value); - -unsigned long millis(void); -unsigned long micros(void); -void delay(unsigned long); -void delayMicroseconds(unsigned int us); -unsigned long pulseIn(pin_size_t pin, uint8_t state, unsigned long timeout); -unsigned long pulseInLong(pin_size_t pin, uint8_t state, unsigned long timeout); - -void shiftOut(pin_size_t dataPin, pin_size_t clockPin, BitOrder bitOrder, uint8_t val); -pin_size_t shiftIn(pin_size_t dataPin, pin_size_t clockPin, BitOrder bitOrder); - -void attachInterrupt(pin_size_t interruptNumber, voidFuncPtr callback, PinStatus mode); -void attachInterruptParam(pin_size_t interruptNumber, voidFuncPtrParam callback, PinStatus mode, void* param); -void detachInterrupt(pin_size_t interruptNumber); - -void setup(void); -void loop(void); - -#ifdef __cplusplus -} // extern "C" -#endif - -#ifdef __cplusplus - -/* C++ prototypes */ -uint16_t makeWord(uint16_t w); -uint16_t makeWord(byte h, byte l); - -#define word(...) makeWord(__VA_ARGS__) - -unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); -unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); - -void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0); -void noTone(uint8_t _pin); - -// WMath prototypes -long random(long); -long random(long, long); -void randomSeed(unsigned long); -long map(long, long, long, long, long); - -#endif // __cplusplus diff --git a/api/WAnalog.h b/api/WAnalog.h new file mode 100644 index 00000000..2ef06d9f --- /dev/null +++ b/api/WAnalog.h @@ -0,0 +1,18 @@ +#pragma once + +#include + +#ifdef __cplusplus +extern "C"{ +#endif + +int analogRead(pin_size_t pinNumber); +void analogReference(uint8_t mode); +void analogWrite(pin_size_t pinNumber, int value); + +void analogReadResolution(int bits); +void analogWriteResolution(int bits); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/api/WDelay.h b/api/WDelay.h new file mode 100644 index 00000000..5726286a --- /dev/null +++ b/api/WDelay.h @@ -0,0 +1,12 @@ +#pragma once + +#ifdef __cplusplus +extern "C"{ +#endif + +void delay(unsigned long ms); +void delayMicroseconds(unsigned int us); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/api/WDigital.h b/api/WDigital.h new file mode 100644 index 00000000..50b4228d --- /dev/null +++ b/api/WDigital.h @@ -0,0 +1,15 @@ +#pragma once + +#include "WTypes.h" + +#ifdef __cplusplus +extern "C"{ +#endif + +void pinMode(pin_size_t pinNumber, PinMode pinMode); +void digitalWrite(pin_size_t pinNumber, PinStatus status); +PinStatus digitalRead(pin_size_t pinNumber); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/api/WInterrupts.h b/api/WInterrupts.h new file mode 100644 index 00000000..d8c3a330 --- /dev/null +++ b/api/WInterrupts.h @@ -0,0 +1,22 @@ +#pragma once + +#include "WTypes.h" + +#include + +// interrupts() / noInterrupts() must be defined by the core + +#ifdef __cplusplus +extern "C"{ +#endif + +typedef void (*voidFuncPtr)(void); +typedef void (*voidFuncPtrParam)(void*); + +void attachInterrupt(pin_size_t interruptNumber, voidFuncPtr callback, PinStatus mode); +void attachInterruptParam(pin_size_t interruptNumber, voidFuncPtrParam callback, PinStatus mode, void* param); +void detachInterrupt(pin_size_t interruptNumber); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/api/WMath.cpp b/api/WMath.cpp new file mode 100644 index 00000000..19832efc --- /dev/null +++ b/api/WMath.cpp @@ -0,0 +1,18 @@ +#include "WMath.h" + +#include "WTypes.h" + +long map(long x, long in_min, long in_max, long out_min, long out_max) +{ + return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; +} + +word makeWord(unsigned int w) +{ + return w; +} + +word makeWord(unsigned char h, unsigned char l) +{ + return (h << 8) | l; +} diff --git a/api/WMath.h b/api/WMath.h new file mode 100644 index 00000000..9cdd794b --- /dev/null +++ b/api/WMath.h @@ -0,0 +1,79 @@ +#pragma once + +#include +#include "WTypes.h" + +#define PI 3.1415926535897932384626433832795 +#define HALF_PI 1.5707963267948966192313216916398 +#define TWO_PI 6.283185307179586476925286766559 + +#define EPSILON (0.0001) + +#define DEG_TO_RAD 0.017453292519943295769236907684886 +#define RAD_TO_DEG 57.295779513082320876798154814105 + +#define EULER 2.718281828459045235360287471352 + +// undefine stdlib's abs if encountered +#ifdef abs +#undef abs +#endif +#define abs(x) ((x)>0?(x):-(x)) + +#ifndef constrain +#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) +#endif + +long map(long x, long in_min, long in_max, long out_min, long out_max); + +#define min(a,b) ((a)<(b)?(a):(b)) +#define max(a,b) ((a)>(b)?(a):(b)) + +#ifndef min +#define min(a,b) \ + ({ __typeof__ (a) _a = (a); \ + __typeof__ (b) _b = (b); \ + _a < _b ? _a : _b; }) +#endif + +#ifndef max +#define max(a,b) \ + ({ __typeof__ (a) _a = (a); \ + __typeof__ (b) _b = (b); \ + _a > _b ? _a : _b; }) +#endif + +#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) + +#ifndef radians +#define radians(deg) ((deg)*DEG_TO_RAD) +#endif + +#ifndef degrees +#define degrees(rad) ((rad)*RAD_TO_DEG) +#endif + +#ifndef sq +#define sq(x) ((x)*(x)) +#endif + +#define lowByte(x) ((uint8_t)((x) & 0xff)) +#define highByte(x) ((uint8_t)((x) >> 8)) + +#define bitRead(value, bit) (((value) >> (bit)) & 0x01) +#define bitSet(value, bit) ((value) |= (1UL << (bit))) +#define bitClear(value, bit) ((value) &= ~(1UL << (bit))) +#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit)) + +#ifndef bit +#define bit(b) (1UL << (b)) +#endif + +#ifdef __cplusplus + +word makeWord(uint16_t w); +word makeWord(byte h, byte l); + +#define word(...) makeWord(__VA_ARGS__) + +#endif diff --git a/api/WMemory.cpp b/api/WMemory.cpp new file mode 100644 index 00000000..178fd6b1 --- /dev/null +++ b/api/WMemory.cpp @@ -0,0 +1,24 @@ +#include "WMemory.h" + +#include + + +void * operator new(size_t size) +{ + return malloc(size); +} + +void operator delete(void *ptr) +{ + free(ptr); +} + +void * operator new[](size_t size) +{ + return malloc(size); +} + +void operator delete[](void *ptr) +{ + free(ptr); +} diff --git a/api/WMemory.h b/api/WMemory.h new file mode 100644 index 00000000..9a2367dd --- /dev/null +++ b/api/WMemory.h @@ -0,0 +1,11 @@ +#pragma once + +#ifdef __cplusplus +#include + +void *operator new(size_t size); +void operator delete(void *ptr); +void *operator new[](size_t size); +void operator delete[](void *ptr); + +#endif diff --git a/api/WPulse.h b/api/WPulse.h new file mode 100644 index 00000000..8c8692f8 --- /dev/null +++ b/api/WPulse.h @@ -0,0 +1,12 @@ +#pragma once + +#ifdef __cplusplus +#include + +unsigned long pulseIn(pin_size_t pin, PinStatus state, unsigned long timeout = 1000000L); +unsigned long pulseInLong(pin_size_t pin, PinStatus state, unsigned long timeout = 1000000L); +unsigned long pulseIn(pin_size_t pin, PinStatus state, unsigned long timeout); +unsigned long pulseInLong(pin_size_t pin, PinStatus state, unsigned long timeout); + + +#endif diff --git a/api/WRandom.cpp b/api/WRandom.cpp new file mode 100644 index 00000000..aae0a7bc --- /dev/null +++ b/api/WRandom.cpp @@ -0,0 +1,27 @@ +extern "C" { + #include "stdlib.h" +} + +void randomSeed(unsigned long seed) +{ + if (seed != 0) { + srandom(seed); + } +} + +long random(long howbig) +{ + if (howbig == 0) { + return 0; + } + return random() % howbig; +} + +long random(long howsmall, long howbig) +{ + if (howsmall >= howbig) { + return howsmall; + } + long diff = howbig - howsmall; + return random(diff) + howsmall; +} diff --git a/api/WRandom.h b/api/WRandom.h new file mode 100644 index 00000000..99017a98 --- /dev/null +++ b/api/WRandom.h @@ -0,0 +1,10 @@ +#pragma once + +#ifdef __cplusplus + +long random(long max); +long random(long min, long max); + +void randomSeed(unsigned long seed); + +#endif diff --git a/api/WShift.c b/api/WShift.c new file mode 100644 index 00000000..f974a2d5 --- /dev/null +++ b/api/WShift.c @@ -0,0 +1,33 @@ +#include "WShift.h" + +#include "WTypes.h" + +uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) { + uint8_t value = 0; + uint8_t i; + + for (i = 0; i < 8; ++i) { + digitalWrite(clockPin, HIGH); + if (bitOrder == LSBFIRST) + value |= digitalRead(dataPin) << i; + else + value |= digitalRead(dataPin) << (7 - i); + digitalWrite(clockPin, LOW); + } + return value; +} + +void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t value) +{ + uint8_t i; + + for (i = 0; i < 8; i++) { + if (bitOrder == LSBFIRST) + digitalWrite(dataPin, !!(value & (1 << i))); + else + digitalWrite(dataPin, !!(value & (1 << (7 - i)))); + + digitalWrite(clockPin, HIGH); + digitalWrite(clockPin, LOW); + } +} diff --git a/api/WShift.h b/api/WShift.h new file mode 100644 index 00000000..20935f77 --- /dev/null +++ b/api/WShift.h @@ -0,0 +1,14 @@ +#pragma once + +#include "WTypes.h" + +#ifdef __cplusplus +extern "C"{ +#endif + +uint8_t shiftIn(pin_size_t dataPin, pin_size_t clockPin, BitOrder bitOrder); +void shiftOut(pin_size_t dataPin, pin_size_t clockPin, BitOrder bitOrder, uint8_t value); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/api/WTime.h b/api/WTime.h new file mode 100644 index 00000000..55832e3b --- /dev/null +++ b/api/WTime.h @@ -0,0 +1,12 @@ +#pragma once + +#ifdef __cplusplus +extern "C"{ +#endif + +unsigned long millis(void); +unsigned long micros(void); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/api/WTone.h b/api/WTone.h new file mode 100644 index 00000000..84375eef --- /dev/null +++ b/api/WTone.h @@ -0,0 +1,10 @@ +#pragma once + +#ifdef __cplusplus + +#include "WTypes.h" + +void tone(pin_size_t pin, unsigned int frequency, unsigned long duration = 0); +void noTone(pin_size_t pin); + +#endif diff --git a/api/WTypes.h b/api/WTypes.h new file mode 100644 index 00000000..3d647c20 --- /dev/null +++ b/api/WTypes.h @@ -0,0 +1,44 @@ +#pragma once + +#include +#include +#include + +#ifndef boolean +typedef bool boolean; +#endif + +#ifndef byte +typedef uint8_t byte; +#endif + +#ifndef word +typedef uint16_t word; +#endif + +#ifdef EXTENDED_PIN_MODE +// Platforms who wnat to declare more than 256 pins need to define EXTENDED_PIN_MODE globally +typedef uint32_t pin_size_t; +#else +typedef uint8_t pin_size_t; +#endif + +typedef enum { + LOW = 0, + HIGH = 1, + CHANGE = 2, + FALLING = 3, + RISING = 4, +} PinStatus; + +typedef enum { + INPUT = 0x0, + OUTPUT = 0x1, + INPUT_PULLUP = 0x2, + INPUT_PULLDOWN = 0x3, +} PinMode; + +typedef enum { + LSBFIRST = 0, + MSBFIRST = 1, +} BitOrder; From e33c48b878dba62bd50e6bd29476cef86a7b2119 Mon Sep 17 00:00:00 2001 From: Greg Mrozek Date: Fri, 2 Nov 2018 08:15:55 -0500 Subject: [PATCH 03/10] Additional cleanup to support removal of Common.h --- api/Interrupts.h | 1 - api/Stream.cpp | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api/Interrupts.h b/api/Interrupts.h index e13b54f4..8470f3ce 100644 --- a/api/Interrupts.h +++ b/api/Interrupts.h @@ -5,7 +5,6 @@ #include #include #include -#include "Common.h" template using voidTemplateFuncPtrParam = void (*)(T param); diff --git a/api/Stream.cpp b/api/Stream.cpp index b3f366f5..5442962f 100644 --- a/api/Stream.cpp +++ b/api/Stream.cpp @@ -22,9 +22,10 @@ findMulti/findUntil routines written by Jim Leonard/Xuth */ -#include "Common.h" #include "Stream.h" +#include "WTime.h" + #define PARSE_TIMEOUT 1000 // default number of milli-seconds to wait // private method to read stream with timeout From 42c32e4e522a57218b1e90fb7f0c29b2db44d1b3 Mon Sep 17 00:00:00 2001 From: Greg Mrozek Date: Fri, 2 Nov 2018 08:16:21 -0500 Subject: [PATCH 04/10] Remove extern from function prototypes --- api/itoa.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/api/itoa.h b/api/itoa.h index 55b28493..4ca00f35 100644 --- a/api/itoa.h +++ b/api/itoa.h @@ -26,12 +26,11 @@ extern "C" { #endif -extern char* itoa(int value, char *string, int radix); -extern char* ltoa(long value, char *string, int radix); -extern char* utoa(unsigned value, char *string, int radix); -extern char* ultoa(unsigned long value, char *string, int radix); +char* itoa(int value, char *string, int radix); +char* ltoa(long value, char *string, int radix); +char* utoa(unsigned value, char *string, int radix); +char* ultoa(unsigned long value, char *string, int radix); #ifdef __cplusplus } // extern "C" #endif - From f2832be5504a30c580973a0ba30567832b0d8f96 Mon Sep 17 00:00:00 2001 From: Greg Mrozek Date: Fri, 2 Nov 2018 09:03:19 -0500 Subject: [PATCH 05/10] Add FlashString abstract class to support extension of String and Print methods to core specific program memory implementation. --- api/Print.cpp | 42 ++------- api/Print.h | 4 +- api/String.cpp | 38 ++------ api/String.h | 40 +++++--- api/deprecated-avr-comp/avr/pgmspace.h | 122 ------------------------- 5 files changed, 46 insertions(+), 200 deletions(-) delete mode 100644 api/deprecated-avr-comp/avr/pgmspace.h diff --git a/api/Print.cpp b/api/Print.cpp index 4f0016c4..7938e9d3 100644 --- a/api/Print.cpp +++ b/api/Print.cpp @@ -36,23 +36,6 @@ size_t Print::write(const uint8_t *buffer, size_t size) return n; } -size_t Print::print(const __FlashStringHelper *ifsh) -{ -#if defined(__AVR__) - PGM_P p = reinterpret_cast(ifsh); - size_t n = 0; - while (1) { - unsigned char c = pgm_read_byte(p++); - if (c == 0) break; - if (write(c)) n++; - else break; - } - return n; -#else - return print(reinterpret_cast(ifsh)); -#endif -} - size_t Print::print(const String &s) { return write(s.c_str(), s.length()); @@ -132,13 +115,6 @@ size_t Print::print(double n, int digits) return printFloat(n, digits); } -size_t Print::println(const __FlashStringHelper *ifsh) -{ - size_t n = print(ifsh); - n += println(); - return n; -} - size_t Print::print(const Printable& x) { return x.printTo(*this); @@ -330,15 +306,15 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base) return bytes; } -size_t Print::printFloat(double number, uint8_t digits) -{ +size_t Print::printFloat(double number, uint8_t digits) +{ size_t n = 0; - + if (isnan(number)) return print("nan"); if (isinf(number)) return print("inf"); if (number > 4294967040.0) return print ("ovf"); // constant determined empirically if (number <-4294967040.0) return print ("ovf"); // constant determined empirically - + // Handle negative numbers if (number < 0.0) { @@ -350,7 +326,7 @@ size_t Print::printFloat(double number, uint8_t digits) double rounding = 0.5; for (uint8_t i=0; i 0) { - n += print("."); + n += print('.'); } // Extract digits from the remainder one at a time @@ -369,8 +345,8 @@ size_t Print::printFloat(double number, uint8_t digits) remainder *= 10.0; unsigned int toPrint = (unsigned int)remainder; n += print(toPrint); - remainder -= toPrint; - } - + remainder -= toPrint; + } + return n; } diff --git a/api/Print.h b/api/Print.h index 6a06bad6..4e435046 100644 --- a/api/Print.h +++ b/api/Print.h @@ -53,8 +53,7 @@ class Print size_t write(const char *buffer, size_t size) { return write((const uint8_t *)buffer, size); } - - size_t print(const __FlashStringHelper *); + size_t print(const String &); size_t print(const char[]); size_t print(char); @@ -68,7 +67,6 @@ class Print size_t print(double, int = 2); size_t print(const Printable&); - size_t println(const __FlashStringHelper *); size_t println(const String &s); size_t println(const char[]); size_t println(char); diff --git a/api/String.cpp b/api/String.cpp index 5eb0b2a2..22f8369c 100644 --- a/api/String.cpp +++ b/api/String.cpp @@ -39,10 +39,10 @@ String::String(const String &value) *this = value; } -String::String(const __FlashStringHelper *pstr) +String::String(const FlashString &fstr) { - init(); - *this = pstr; + init(); + *this = fstr; } #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) @@ -180,17 +180,6 @@ String & String::copy(const char *cstr, unsigned int length) return *this; } -String & String::copy(const __FlashStringHelper *pstr, unsigned int length) -{ - if (!reserve(length)) { - invalidate(); - return *this; - } - len = length; - strcpy_P(buffer, (PGM_P)pstr); - return *this; -} - #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) void String::move(String &rhs) { @@ -245,11 +234,9 @@ String & String::operator = (const char *cstr) return *this; } -String & String::operator = (const __FlashStringHelper *pstr) +String & String::operator = (const FlashString &fstr) { - if (pstr) copy(pstr, strlen_P((PGM_P)pstr)); - else invalidate(); - + *this = fstr.toString(); return *this; } @@ -336,16 +323,9 @@ unsigned char String::concat(double num) return concat(string, strlen(string)); } -unsigned char String::concat(const __FlashStringHelper * str) +unsigned char String::concat(const FlashString &fstr) { - if (!str) return 0; - int length = strlen_P((const char *) str); - if (length == 0) return 1; - unsigned int newlen = len + length; - if (!reserve(newlen)) return 0; - strcpy_P(buffer + len, (const char *) str); - len = newlen; - return 1; + return concat(fstr.toString()); } /*********************************************/ @@ -422,7 +402,7 @@ StringSumHelper & operator + (const StringSumHelper &lhs, double num) return a; } -StringSumHelper & operator + (const StringSumHelper &lhs, const __FlashStringHelper *rhs) +StringSumHelper & operator + (const StringSumHelper &lhs, const FlashString &rhs) { StringSumHelper &a = const_cast(lhs); if (!a.concat(rhs)) a.invalidate(); @@ -592,7 +572,7 @@ int String::lastIndexOf(const String &s2) const int String::lastIndexOf(const String &s2, unsigned int fromIndex) const { - if (s2.len == 0 || len == 0 || s2.len > len) return -1; + if (s2.len == 0 || len == 0 || s2.len > len) return -1; if (fromIndex >= len) fromIndex = len - 1; int found = -1; for (char *p = buffer; p <= buffer + fromIndex; p++) { diff --git a/api/String.h b/api/String.h index 8c6d2d39..a33adf4c 100644 --- a/api/String.h +++ b/api/String.h @@ -23,14 +23,12 @@ #ifdef __cplusplus +#include "Printable.h" + +#include #include #include #include -#if defined(__AVR__) -#include "avr/pgmspace.h" -#else -#include "deprecated-avr-comp/avr/pgmspace.h" -#endif // When compiling programs with this class, the following gcc parameters // dramatically increase performance and memory (RAM) efficiency, typically @@ -38,8 +36,25 @@ // -felide-constructors // -std=c++0x -class __FlashStringHelper; -#define F(string_literal) (reinterpret_cast(PSTR(string_literal))) +class String; + +// Default implemtation of 'F' macro for cores than can use +// string literals directly as (const char *). +// For cores that require special interface to program memory, +// the default 'F' macro can be undefined at core +// implementation level and redefined as needed. +#define F(string_literal) (string_literal) + +// Base Class for strings stored in program memory. +// For cores that require special interface to program memory, +// this class can be extended at the core implementation +// level in order to support String and Print operations from +// program memory. +class FlashString : public Printable +{ + public: + virtual String toString() const = 0; +}; // An inherited class for holding the result of a concatenation. These // result objects are assumed to be writable by subsequent concatenations. @@ -62,7 +77,7 @@ class String // be false). String(const char *cstr = ""); String(const String &str); - String(const __FlashStringHelper *str); + String(const FlashString &fstr); #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) String(String &&rval); String(StringSumHelper &&rval); @@ -89,7 +104,7 @@ class String // marked as invalid ("if (s)" will be false). String & operator = (const String &rhs); String & operator = (const char *cstr); - String & operator = (const __FlashStringHelper *str); + String & operator = (const FlashString &fstr); #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) String & operator = (String &&rval); String & operator = (StringSumHelper &&rval); @@ -110,7 +125,7 @@ class String unsigned char concat(unsigned long num); unsigned char concat(float num); unsigned char concat(double num); - unsigned char concat(const __FlashStringHelper * str); + unsigned char concat(const FlashString &fstr); // if there's not enough memory for the concatenated value, the string // will be left unchanged (but this isn't signalled in any way) @@ -124,7 +139,7 @@ class String String & operator += (unsigned long num) {concat(num); return (*this);} String & operator += (float num) {concat(num); return (*this);} String & operator += (double num) {concat(num); return (*this);} - String & operator += (const __FlashStringHelper *str){concat(str); return (*this);} + String & operator += (const FlashString &fstr){concat(fstr); return (*this);} friend StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs); friend StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr); @@ -136,7 +151,7 @@ class String friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned long num); friend StringSumHelper & operator + (const StringSumHelper &lhs, float num); friend StringSumHelper & operator + (const StringSumHelper &lhs, double num); - friend StringSumHelper & operator + (const StringSumHelper &lhs, const __FlashStringHelper *rhs); + friend StringSumHelper & operator + (const StringSumHelper &lhs, const FlashString &rhs); // comparison (only works w/ Strings and "strings") operator StringIfHelperType() const { return buffer ? &String::StringIfHelper : 0; } @@ -222,7 +237,6 @@ class String // copy and move String & copy(const char *cstr, unsigned int length); - String & copy(const __FlashStringHelper *pstr, unsigned int length); #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) void move(String &rhs); #endif diff --git a/api/deprecated-avr-comp/avr/pgmspace.h b/api/deprecated-avr-comp/avr/pgmspace.h deleted file mode 100644 index 0f732bba..00000000 --- a/api/deprecated-avr-comp/avr/pgmspace.h +++ /dev/null @@ -1,122 +0,0 @@ -/* - pgmspace.h - Definitions for compatibility with AVR pgmspace macros - - Copyright (c) 2015 Arduino LLC - - Based on work of Paul Stoffregen on Teensy 3 (http://pjrc.com) - - 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 __PGMSPACE_H_ -#define __PGMSPACE_H_ 1 - -#include - -#define PROGMEM -#define PGM_P const char * -#define PSTR(str) (str) - -#define _SFR_BYTE(n) (n) - -typedef void prog_void; -typedef char prog_char; -typedef unsigned char prog_uchar; -typedef int8_t prog_int8_t; -typedef uint8_t prog_uint8_t; -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; - -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 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 From 11a3d632c7f24d0e6356f6a780551a0720f34da1 Mon Sep 17 00:00:00 2001 From: Greg Mrozek Date: Fri, 2 Nov 2018 09:04:29 -0500 Subject: [PATCH 06/10] add .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..600d2d33 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vscode \ No newline at end of file From ff9a16a41bb6298265daf2a71118f14329b8b2e4 Mon Sep 17 00:00:00 2001 From: Greg Mrozek Date: Fri, 2 Nov 2018 09:13:44 -0500 Subject: [PATCH 07/10] Add FlashString abstract class to support extension of String and Print methods to core specific program memory implementation. --- api/Print.cpp | 42 ++------- api/Print.h | 4 +- api/String.cpp | 38 ++------ api/String.h | 39 +++++--- api/deprecated-avr-comp/avr/pgmspace.h | 122 ------------------------- 5 files changed, 45 insertions(+), 200 deletions(-) delete mode 100644 api/deprecated-avr-comp/avr/pgmspace.h diff --git a/api/Print.cpp b/api/Print.cpp index 4f0016c4..7938e9d3 100644 --- a/api/Print.cpp +++ b/api/Print.cpp @@ -36,23 +36,6 @@ size_t Print::write(const uint8_t *buffer, size_t size) return n; } -size_t Print::print(const __FlashStringHelper *ifsh) -{ -#if defined(__AVR__) - PGM_P p = reinterpret_cast(ifsh); - size_t n = 0; - while (1) { - unsigned char c = pgm_read_byte(p++); - if (c == 0) break; - if (write(c)) n++; - else break; - } - return n; -#else - return print(reinterpret_cast(ifsh)); -#endif -} - size_t Print::print(const String &s) { return write(s.c_str(), s.length()); @@ -132,13 +115,6 @@ size_t Print::print(double n, int digits) return printFloat(n, digits); } -size_t Print::println(const __FlashStringHelper *ifsh) -{ - size_t n = print(ifsh); - n += println(); - return n; -} - size_t Print::print(const Printable& x) { return x.printTo(*this); @@ -330,15 +306,15 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base) return bytes; } -size_t Print::printFloat(double number, uint8_t digits) -{ +size_t Print::printFloat(double number, uint8_t digits) +{ size_t n = 0; - + if (isnan(number)) return print("nan"); if (isinf(number)) return print("inf"); if (number > 4294967040.0) return print ("ovf"); // constant determined empirically if (number <-4294967040.0) return print ("ovf"); // constant determined empirically - + // Handle negative numbers if (number < 0.0) { @@ -350,7 +326,7 @@ size_t Print::printFloat(double number, uint8_t digits) double rounding = 0.5; for (uint8_t i=0; i 0) { - n += print("."); + n += print('.'); } // Extract digits from the remainder one at a time @@ -369,8 +345,8 @@ size_t Print::printFloat(double number, uint8_t digits) remainder *= 10.0; unsigned int toPrint = (unsigned int)remainder; n += print(toPrint); - remainder -= toPrint; - } - + remainder -= toPrint; + } + return n; } diff --git a/api/Print.h b/api/Print.h index 6a06bad6..4e435046 100644 --- a/api/Print.h +++ b/api/Print.h @@ -53,8 +53,7 @@ class Print size_t write(const char *buffer, size_t size) { return write((const uint8_t *)buffer, size); } - - size_t print(const __FlashStringHelper *); + size_t print(const String &); size_t print(const char[]); size_t print(char); @@ -68,7 +67,6 @@ class Print size_t print(double, int = 2); size_t print(const Printable&); - size_t println(const __FlashStringHelper *); size_t println(const String &s); size_t println(const char[]); size_t println(char); diff --git a/api/String.cpp b/api/String.cpp index 5eb0b2a2..22f8369c 100644 --- a/api/String.cpp +++ b/api/String.cpp @@ -39,10 +39,10 @@ String::String(const String &value) *this = value; } -String::String(const __FlashStringHelper *pstr) +String::String(const FlashString &fstr) { - init(); - *this = pstr; + init(); + *this = fstr; } #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) @@ -180,17 +180,6 @@ String & String::copy(const char *cstr, unsigned int length) return *this; } -String & String::copy(const __FlashStringHelper *pstr, unsigned int length) -{ - if (!reserve(length)) { - invalidate(); - return *this; - } - len = length; - strcpy_P(buffer, (PGM_P)pstr); - return *this; -} - #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) void String::move(String &rhs) { @@ -245,11 +234,9 @@ String & String::operator = (const char *cstr) return *this; } -String & String::operator = (const __FlashStringHelper *pstr) +String & String::operator = (const FlashString &fstr) { - if (pstr) copy(pstr, strlen_P((PGM_P)pstr)); - else invalidate(); - + *this = fstr.toString(); return *this; } @@ -336,16 +323,9 @@ unsigned char String::concat(double num) return concat(string, strlen(string)); } -unsigned char String::concat(const __FlashStringHelper * str) +unsigned char String::concat(const FlashString &fstr) { - if (!str) return 0; - int length = strlen_P((const char *) str); - if (length == 0) return 1; - unsigned int newlen = len + length; - if (!reserve(newlen)) return 0; - strcpy_P(buffer + len, (const char *) str); - len = newlen; - return 1; + return concat(fstr.toString()); } /*********************************************/ @@ -422,7 +402,7 @@ StringSumHelper & operator + (const StringSumHelper &lhs, double num) return a; } -StringSumHelper & operator + (const StringSumHelper &lhs, const __FlashStringHelper *rhs) +StringSumHelper & operator + (const StringSumHelper &lhs, const FlashString &rhs) { StringSumHelper &a = const_cast(lhs); if (!a.concat(rhs)) a.invalidate(); @@ -592,7 +572,7 @@ int String::lastIndexOf(const String &s2) const int String::lastIndexOf(const String &s2, unsigned int fromIndex) const { - if (s2.len == 0 || len == 0 || s2.len > len) return -1; + if (s2.len == 0 || len == 0 || s2.len > len) return -1; if (fromIndex >= len) fromIndex = len - 1; int found = -1; for (char *p = buffer; p <= buffer + fromIndex; p++) { diff --git a/api/String.h b/api/String.h index 8c6d2d39..5d3183c5 100644 --- a/api/String.h +++ b/api/String.h @@ -23,14 +23,11 @@ #ifdef __cplusplus +#include "Printable.h" + #include #include #include -#if defined(__AVR__) -#include "avr/pgmspace.h" -#else -#include "deprecated-avr-comp/avr/pgmspace.h" -#endif // When compiling programs with this class, the following gcc parameters // dramatically increase performance and memory (RAM) efficiency, typically @@ -38,8 +35,25 @@ // -felide-constructors // -std=c++0x -class __FlashStringHelper; -#define F(string_literal) (reinterpret_cast(PSTR(string_literal))) +class String; + +// Default implemtation of 'F' macro for cores than can use +// string literals directly as (const char *). +// For cores that require special interface to program memory, +// the default 'F' macro can be undefined at core +// implementation level and redefined as needed. +#define F(string_literal) (string_literal) + +// Base Class for strings stored in program memory. +// For cores that require special interface to program memory, +// this class can be extended at the core implementation +// level in order to support String and Print operations from +// program memory. +class FlashString : public Printable +{ + public: + virtual String toString() const = 0; +}; // An inherited class for holding the result of a concatenation. These // result objects are assumed to be writable by subsequent concatenations. @@ -62,7 +76,7 @@ class String // be false). String(const char *cstr = ""); String(const String &str); - String(const __FlashStringHelper *str); + String(const FlashString &fstr); #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) String(String &&rval); String(StringSumHelper &&rval); @@ -89,7 +103,7 @@ class String // marked as invalid ("if (s)" will be false). String & operator = (const String &rhs); String & operator = (const char *cstr); - String & operator = (const __FlashStringHelper *str); + String & operator = (const FlashString &fstr); #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) String & operator = (String &&rval); String & operator = (StringSumHelper &&rval); @@ -110,7 +124,7 @@ class String unsigned char concat(unsigned long num); unsigned char concat(float num); unsigned char concat(double num); - unsigned char concat(const __FlashStringHelper * str); + unsigned char concat(const FlashString &fstr); // if there's not enough memory for the concatenated value, the string // will be left unchanged (but this isn't signalled in any way) @@ -124,7 +138,7 @@ class String String & operator += (unsigned long num) {concat(num); return (*this);} String & operator += (float num) {concat(num); return (*this);} String & operator += (double num) {concat(num); return (*this);} - String & operator += (const __FlashStringHelper *str){concat(str); return (*this);} + String & operator += (const FlashString &fstr){concat(fstr); return (*this);} friend StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs); friend StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr); @@ -136,7 +150,7 @@ class String friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned long num); friend StringSumHelper & operator + (const StringSumHelper &lhs, float num); friend StringSumHelper & operator + (const StringSumHelper &lhs, double num); - friend StringSumHelper & operator + (const StringSumHelper &lhs, const __FlashStringHelper *rhs); + friend StringSumHelper & operator + (const StringSumHelper &lhs, const FlashString &rhs); // comparison (only works w/ Strings and "strings") operator StringIfHelperType() const { return buffer ? &String::StringIfHelper : 0; } @@ -222,7 +236,6 @@ class String // copy and move String & copy(const char *cstr, unsigned int length); - String & copy(const __FlashStringHelper *pstr, unsigned int length); #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) void move(String &rhs); #endif diff --git a/api/deprecated-avr-comp/avr/pgmspace.h b/api/deprecated-avr-comp/avr/pgmspace.h deleted file mode 100644 index 0f732bba..00000000 --- a/api/deprecated-avr-comp/avr/pgmspace.h +++ /dev/null @@ -1,122 +0,0 @@ -/* - pgmspace.h - Definitions for compatibility with AVR pgmspace macros - - Copyright (c) 2015 Arduino LLC - - Based on work of Paul Stoffregen on Teensy 3 (http://pjrc.com) - - 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 __PGMSPACE_H_ -#define __PGMSPACE_H_ 1 - -#include - -#define PROGMEM -#define PGM_P const char * -#define PSTR(str) (str) - -#define _SFR_BYTE(n) (n) - -typedef void prog_void; -typedef char prog_char; -typedef unsigned char prog_uchar; -typedef int8_t prog_int8_t; -typedef uint8_t prog_uint8_t; -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; - -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 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 From 67396b86d795e3206b0e70955f9c01bf7561e178 Mon Sep 17 00:00:00 2001 From: Greg Mrozek Date: Fri, 2 Nov 2018 16:03:16 -0500 Subject: [PATCH 08/10] Split Common.h into separate Wiring headers --- api/ArduinoAPI.h | 26 ++++---- api/Common.cpp | 10 --- api/Common.h | 153 ---------------------------------------------- api/Interrupts.h | 1 - api/Stream.cpp | 3 +- api/WAnalog.h | 18 ++++++ api/WDelay.h | 12 ++++ api/WDigital.h | 15 +++++ api/WInterrupts.h | 22 +++++++ api/WMath.h | 79 ++++++++++++++++++++++++ api/WMemory.h | 11 ++++ api/WPulse.h | 12 ++++ api/WRandom.h | 10 +++ api/WShift.h | 14 +++++ api/WTime.h | 12 ++++ api/WTone.h | 10 +++ api/WTypes.h | 44 +++++++++++++ 17 files changed, 276 insertions(+), 176 deletions(-) delete mode 100644 api/Common.cpp delete mode 100644 api/Common.h create mode 100644 api/WAnalog.h create mode 100644 api/WDelay.h create mode 100644 api/WDigital.h create mode 100644 api/WInterrupts.h create mode 100644 api/WMath.h create mode 100644 api/WMemory.h create mode 100644 api/WPulse.h create mode 100644 api/WRandom.h create mode 100644 api/WShift.h create mode 100644 api/WTime.h create mode 100644 api/WTone.h create mode 100644 api/WTypes.h diff --git a/api/ArduinoAPI.h b/api/ArduinoAPI.h index c70f2adb..b9f749f9 100644 --- a/api/ArduinoAPI.h +++ b/api/ArduinoAPI.h @@ -23,6 +23,21 @@ // version 1.0.0 #define ARDUINO_API_VERSION 10000 +#include "WTypes.h" + +#include "WAnalog.h" +#include "WCharacter.h" +#include "WDelay.h" +#include "WDigital.h" +#include "WInterrupts.h" +#include "WMath.h" +#include "WMemory.h" +#include "WPulse.h" +#include "WRandom.h" +#include "WShift.h" +#include "WTime.h" +#include "WTone.h" + #include "Binary.h" #ifdef __cplusplus @@ -39,17 +54,6 @@ #include "Stream.h" #include "Udp.h" #include "USBAPI.h" -#include "WCharacter.h" #endif -/* Standard C library includes */ -#include -#include -#include -#include -#include - -// Misc Arduino core functions -#include "Common.h" - #endif diff --git a/api/Common.cpp b/api/Common.cpp deleted file mode 100644 index d1f822c9..00000000 --- a/api/Common.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "Common.h" - -/* C++ prototypes */ -long map(long x, long in_min, long in_max, long out_min, long out_max) -{ - return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; -} - -uint16_t makeWord(uint16_t w) { return w; } -uint16_t makeWord(uint8_t h, uint8_t l) { return (h << 8) | l; } \ No newline at end of file diff --git a/api/Common.h b/api/Common.h deleted file mode 100644 index e638d3be..00000000 --- a/api/Common.h +++ /dev/null @@ -1,153 +0,0 @@ -#pragma once -#include - -#ifdef __cplusplus -extern "C"{ -#endif - -void yield(void); - -typedef enum { - LOW = 0, - HIGH = 1, - CHANGE = 2, - FALLING = 3, - RISING = 4, -} PinStatus; - -typedef enum { - INPUT = 0x0, - OUTPUT = 0x1, - INPUT_PULLUP = 0x2, - INPUT_PULLDOWN = 0x3, -} PinMode; - -typedef enum { - LSBFIRST = 0, - MSBFIRST = 1, -} BitOrder; - -#define PI 3.1415926535897932384626433832795 -#define HALF_PI 1.5707963267948966192313216916398 -#define TWO_PI 6.283185307179586476925286766559 -#define DEG_TO_RAD 0.017453292519943295769236907684886 -#define RAD_TO_DEG 57.295779513082320876798154814105 -#define EULER 2.718281828459045235360287471352 - -#define SERIAL 0x0 -#define DISPLAY 0x1 - -#ifndef min -#define min(a,b) \ - ({ __typeof__ (a) _a = (a); \ - __typeof__ (b) _b = (b); \ - _a < _b ? _a : _b; }) -#endif - -#ifndef max -#define max(a,b) \ - ({ __typeof__ (a) _a = (a); \ - __typeof__ (b) _b = (b); \ - _a > _b ? _a : _b; }) -#endif - -#ifndef constrain -#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) -#endif - -#ifndef radians -#define radians(deg) ((deg)*DEG_TO_RAD) -#endif - -#ifndef degrees -#define degrees(rad) ((rad)*RAD_TO_DEG) -#endif - -#ifndef sq -#define sq(x) ((x)*(x)) -#endif - -typedef void (*voidFuncPtr)(void); -typedef void (*voidFuncPtrParam)(void*); - -// interrupts() / noInterrupts() must be defined by the core - -#define lowByte(w) ((uint8_t) ((w) & 0xff)) -#define highByte(w) ((uint8_t) ((w) >> 8)) - -#define bitRead(value, bit) (((value) >> (bit)) & 0x01) -#define bitSet(value, bit) ((value) |= (1UL << (bit))) -#define bitClear(value, bit) ((value) &= ~(1UL << (bit))) -#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit)) - -#ifndef bit -#define bit(b) (1UL << (b)) -#endif - -/* TODO: request for removal */ -typedef bool boolean; -typedef uint8_t byte; -typedef uint16_t word; - -void init(void); -void initVariant(void); - -int atexit(void (*func)()) __attribute__((weak)); -int main() __attribute__((weak)); - -#ifdef EXTENDED_PIN_MODE -// Platforms who wnat to declare more than 256 pins need to define EXTENDED_PIN_MODE globally -typedef uint32_t pin_size_t; -#else -typedef uint8_t pin_size_t; -#endif - -void pinMode(pin_size_t pinNumber, PinMode pinMode); -void digitalWrite(pin_size_t pinNumber, PinStatus status); -PinStatus digitalRead(pin_size_t pinNumber); -int analogRead(pin_size_t pinNumber); -void analogReference(uint8_t mode); -void analogWrite(pin_size_t pinNumber, int value); - -unsigned long millis(void); -unsigned long micros(void); -void delay(unsigned long); -void delayMicroseconds(unsigned int us); -unsigned long pulseIn(pin_size_t pin, uint8_t state, unsigned long timeout); -unsigned long pulseInLong(pin_size_t pin, uint8_t state, unsigned long timeout); - -void shiftOut(pin_size_t dataPin, pin_size_t clockPin, BitOrder bitOrder, uint8_t val); -pin_size_t shiftIn(pin_size_t dataPin, pin_size_t clockPin, BitOrder bitOrder); - -void attachInterrupt(pin_size_t interruptNumber, voidFuncPtr callback, PinStatus mode); -void attachInterruptParam(pin_size_t interruptNumber, voidFuncPtrParam callback, PinStatus mode, void* param); -void detachInterrupt(pin_size_t interruptNumber); - -void setup(void); -void loop(void); - -#ifdef __cplusplus -} // extern "C" -#endif - -#ifdef __cplusplus - -/* C++ prototypes */ -uint16_t makeWord(uint16_t w); -uint16_t makeWord(byte h, byte l); - -#define word(...) makeWord(__VA_ARGS__) - -unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); -unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); - -void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0); -void noTone(uint8_t _pin); - -// WMath prototypes -long random(long); -long random(long, long); -void randomSeed(unsigned long); -long map(long, long, long, long, long); - -#endif // __cplusplus diff --git a/api/Interrupts.h b/api/Interrupts.h index e13b54f4..8470f3ce 100644 --- a/api/Interrupts.h +++ b/api/Interrupts.h @@ -5,7 +5,6 @@ #include #include #include -#include "Common.h" template using voidTemplateFuncPtrParam = void (*)(T param); diff --git a/api/Stream.cpp b/api/Stream.cpp index b3f366f5..5442962f 100644 --- a/api/Stream.cpp +++ b/api/Stream.cpp @@ -22,9 +22,10 @@ findMulti/findUntil routines written by Jim Leonard/Xuth */ -#include "Common.h" #include "Stream.h" +#include "WTime.h" + #define PARSE_TIMEOUT 1000 // default number of milli-seconds to wait // private method to read stream with timeout diff --git a/api/WAnalog.h b/api/WAnalog.h new file mode 100644 index 00000000..2ef06d9f --- /dev/null +++ b/api/WAnalog.h @@ -0,0 +1,18 @@ +#pragma once + +#include + +#ifdef __cplusplus +extern "C"{ +#endif + +int analogRead(pin_size_t pinNumber); +void analogReference(uint8_t mode); +void analogWrite(pin_size_t pinNumber, int value); + +void analogReadResolution(int bits); +void analogWriteResolution(int bits); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/api/WDelay.h b/api/WDelay.h new file mode 100644 index 00000000..5726286a --- /dev/null +++ b/api/WDelay.h @@ -0,0 +1,12 @@ +#pragma once + +#ifdef __cplusplus +extern "C"{ +#endif + +void delay(unsigned long ms); +void delayMicroseconds(unsigned int us); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/api/WDigital.h b/api/WDigital.h new file mode 100644 index 00000000..50b4228d --- /dev/null +++ b/api/WDigital.h @@ -0,0 +1,15 @@ +#pragma once + +#include "WTypes.h" + +#ifdef __cplusplus +extern "C"{ +#endif + +void pinMode(pin_size_t pinNumber, PinMode pinMode); +void digitalWrite(pin_size_t pinNumber, PinStatus status); +PinStatus digitalRead(pin_size_t pinNumber); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/api/WInterrupts.h b/api/WInterrupts.h new file mode 100644 index 00000000..d8c3a330 --- /dev/null +++ b/api/WInterrupts.h @@ -0,0 +1,22 @@ +#pragma once + +#include "WTypes.h" + +#include + +// interrupts() / noInterrupts() must be defined by the core + +#ifdef __cplusplus +extern "C"{ +#endif + +typedef void (*voidFuncPtr)(void); +typedef void (*voidFuncPtrParam)(void*); + +void attachInterrupt(pin_size_t interruptNumber, voidFuncPtr callback, PinStatus mode); +void attachInterruptParam(pin_size_t interruptNumber, voidFuncPtrParam callback, PinStatus mode, void* param); +void detachInterrupt(pin_size_t interruptNumber); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/api/WMath.h b/api/WMath.h new file mode 100644 index 00000000..9cdd794b --- /dev/null +++ b/api/WMath.h @@ -0,0 +1,79 @@ +#pragma once + +#include +#include "WTypes.h" + +#define PI 3.1415926535897932384626433832795 +#define HALF_PI 1.5707963267948966192313216916398 +#define TWO_PI 6.283185307179586476925286766559 + +#define EPSILON (0.0001) + +#define DEG_TO_RAD 0.017453292519943295769236907684886 +#define RAD_TO_DEG 57.295779513082320876798154814105 + +#define EULER 2.718281828459045235360287471352 + +// undefine stdlib's abs if encountered +#ifdef abs +#undef abs +#endif +#define abs(x) ((x)>0?(x):-(x)) + +#ifndef constrain +#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) +#endif + +long map(long x, long in_min, long in_max, long out_min, long out_max); + +#define min(a,b) ((a)<(b)?(a):(b)) +#define max(a,b) ((a)>(b)?(a):(b)) + +#ifndef min +#define min(a,b) \ + ({ __typeof__ (a) _a = (a); \ + __typeof__ (b) _b = (b); \ + _a < _b ? _a : _b; }) +#endif + +#ifndef max +#define max(a,b) \ + ({ __typeof__ (a) _a = (a); \ + __typeof__ (b) _b = (b); \ + _a > _b ? _a : _b; }) +#endif + +#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) + +#ifndef radians +#define radians(deg) ((deg)*DEG_TO_RAD) +#endif + +#ifndef degrees +#define degrees(rad) ((rad)*RAD_TO_DEG) +#endif + +#ifndef sq +#define sq(x) ((x)*(x)) +#endif + +#define lowByte(x) ((uint8_t)((x) & 0xff)) +#define highByte(x) ((uint8_t)((x) >> 8)) + +#define bitRead(value, bit) (((value) >> (bit)) & 0x01) +#define bitSet(value, bit) ((value) |= (1UL << (bit))) +#define bitClear(value, bit) ((value) &= ~(1UL << (bit))) +#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit)) + +#ifndef bit +#define bit(b) (1UL << (b)) +#endif + +#ifdef __cplusplus + +word makeWord(uint16_t w); +word makeWord(byte h, byte l); + +#define word(...) makeWord(__VA_ARGS__) + +#endif diff --git a/api/WMemory.h b/api/WMemory.h new file mode 100644 index 00000000..9a2367dd --- /dev/null +++ b/api/WMemory.h @@ -0,0 +1,11 @@ +#pragma once + +#ifdef __cplusplus +#include + +void *operator new(size_t size); +void operator delete(void *ptr); +void *operator new[](size_t size); +void operator delete[](void *ptr); + +#endif diff --git a/api/WPulse.h b/api/WPulse.h new file mode 100644 index 00000000..8c8692f8 --- /dev/null +++ b/api/WPulse.h @@ -0,0 +1,12 @@ +#pragma once + +#ifdef __cplusplus +#include + +unsigned long pulseIn(pin_size_t pin, PinStatus state, unsigned long timeout = 1000000L); +unsigned long pulseInLong(pin_size_t pin, PinStatus state, unsigned long timeout = 1000000L); +unsigned long pulseIn(pin_size_t pin, PinStatus state, unsigned long timeout); +unsigned long pulseInLong(pin_size_t pin, PinStatus state, unsigned long timeout); + + +#endif diff --git a/api/WRandom.h b/api/WRandom.h new file mode 100644 index 00000000..99017a98 --- /dev/null +++ b/api/WRandom.h @@ -0,0 +1,10 @@ +#pragma once + +#ifdef __cplusplus + +long random(long max); +long random(long min, long max); + +void randomSeed(unsigned long seed); + +#endif diff --git a/api/WShift.h b/api/WShift.h new file mode 100644 index 00000000..20935f77 --- /dev/null +++ b/api/WShift.h @@ -0,0 +1,14 @@ +#pragma once + +#include "WTypes.h" + +#ifdef __cplusplus +extern "C"{ +#endif + +uint8_t shiftIn(pin_size_t dataPin, pin_size_t clockPin, BitOrder bitOrder); +void shiftOut(pin_size_t dataPin, pin_size_t clockPin, BitOrder bitOrder, uint8_t value); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/api/WTime.h b/api/WTime.h new file mode 100644 index 00000000..55832e3b --- /dev/null +++ b/api/WTime.h @@ -0,0 +1,12 @@ +#pragma once + +#ifdef __cplusplus +extern "C"{ +#endif + +unsigned long millis(void); +unsigned long micros(void); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/api/WTone.h b/api/WTone.h new file mode 100644 index 00000000..84375eef --- /dev/null +++ b/api/WTone.h @@ -0,0 +1,10 @@ +#pragma once + +#ifdef __cplusplus + +#include "WTypes.h" + +void tone(pin_size_t pin, unsigned int frequency, unsigned long duration = 0); +void noTone(pin_size_t pin); + +#endif diff --git a/api/WTypes.h b/api/WTypes.h new file mode 100644 index 00000000..3d647c20 --- /dev/null +++ b/api/WTypes.h @@ -0,0 +1,44 @@ +#pragma once + +#include +#include +#include + +#ifndef boolean +typedef bool boolean; +#endif + +#ifndef byte +typedef uint8_t byte; +#endif + +#ifndef word +typedef uint16_t word; +#endif + +#ifdef EXTENDED_PIN_MODE +// Platforms who wnat to declare more than 256 pins need to define EXTENDED_PIN_MODE globally +typedef uint32_t pin_size_t; +#else +typedef uint8_t pin_size_t; +#endif + +typedef enum { + LOW = 0, + HIGH = 1, + CHANGE = 2, + FALLING = 3, + RISING = 4, +} PinStatus; + +typedef enum { + INPUT = 0x0, + OUTPUT = 0x1, + INPUT_PULLUP = 0x2, + INPUT_PULLDOWN = 0x3, +} PinMode; + +typedef enum { + LSBFIRST = 0, + MSBFIRST = 1, +} BitOrder; From dcda3cece6fced7a648cfe8a41a70f818175be01 Mon Sep 17 00:00:00 2001 From: Greg Mrozek Date: Sun, 4 Nov 2018 16:29:46 -0600 Subject: [PATCH 09/10] Fix stdlib function names --- api/WRandom.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/WRandom.cpp b/api/WRandom.cpp index aae0a7bc..ae400fee 100644 --- a/api/WRandom.cpp +++ b/api/WRandom.cpp @@ -5,7 +5,7 @@ extern "C" { void randomSeed(unsigned long seed) { if (seed != 0) { - srandom(seed); + srand(seed); } } @@ -14,7 +14,7 @@ long random(long howbig) if (howbig == 0) { return 0; } - return random() % howbig; + return rand() % howbig; } long random(long howsmall, long howbig) From 30805ba014e201a0210c794a37bbe5dd91b23858 Mon Sep 17 00:00:00 2001 From: Greg Mrozek Date: Thu, 8 Nov 2018 06:48:16 -0600 Subject: [PATCH 10/10] Rename of arduino headers to A_ prefix. Reorg file structure. --- api/{WAnalog.h => A_Analog.h} | 7 +- api/{WCharacter.h => A_Character.h} | 5 +- api/{Client.h => A_Client.h} | 15 ++- api/{WDelay.h => A_Delay.h} | 5 +- api/{WDigital.h => A_Digital.h} | 9 +- api/{HardwareI2C.h => A_HardwareI2C.h} | 16 ++- api/{HardwareSerial.h => A_HardwareSerial.h} | 13 +- api/{IPAddress.h => A_IPAddress.h} | 13 +- api/{WInterrupts.h => A_Interrupts.h} | 9 +- api/{WMath.h => A_Math.h} | 11 +- api/{WMemory.h => A_Memory.h} | 10 +- api/{PluggableUSB.h => A_PluggableUSB.h} | 15 ++- api/{Print.h => A_Print.h} | 14 +- api/{Printable.h => A_Printable.h} | 10 +- api/{WPulse.h => A_Pulse.h} | 14 +- api/{WRandom.h => A_Random.h} | 7 +- api/{RingBuffer.h => A_RingBuffer.h} | 10 +- api/{Server.h => A_Server.h} | 10 +- api/{WShift.h => A_Shift.h} | 9 +- api/{Stream.h => A_Stream.h} | 11 +- api/{String.h => A_String.h} | 13 +- api/{WTime.h => A_Time.h} | 5 +- api/{WTone.h => A_Tone.h} | 9 +- api/{WTypes.h => A_Types.h} | 6 +- api/{USBAPI.h => A_USBAPI.h} | 10 +- api/{Udp.h => A_Udp.h} | 15 ++- api/ArduinoAPI.h | 89 +++++-------- api/deprecated-avr/README.md | 1 + .../avr/dtostrf.c.impl | 0 .../avr/dtostrf.h | 0 .../avr/interrupt.h | 0 api/deprecated-avr/avr/pgmspace.h | 122 ++++++++++++++++++ api/deprecated-include/Client.h | 1 + api/deprecated-include/HardwareI2C.h | 1 + api/deprecated-include/HardwareSerial.h | 1 + api/deprecated-include/IPAddress.h | 1 + api/{ => deprecated-include}/Interrupts.h | 0 api/deprecated-include/PluggableUSB.h | 1 + api/deprecated-include/Print.h | 1 + api/deprecated-include/Printable.h | 1 + api/deprecated-include/README.md | 1 + api/deprecated-include/RingBuffer.h | 1 + api/deprecated-include/Server.h | 1 + api/deprecated-include/Stream.h | 1 + api/deprecated-include/USBAPI.h | 1 + api/deprecated-include/Udp.h | 1 + api/deprecated-include/WCharacter.h | 1 + api/deprecated-include/WString.h | 1 + api/{Binary.h => deprecated-include/binary.h} | 0 api/{ => deprecated-include}/itoa.h | 0 api/deprecated-include/new.h | 1 + api/deprecated-include/wiring.h | 0 api/deprecated/Client.h | 25 ---- api/deprecated/HardwareSerial.h | 25 ---- api/deprecated/IPAddress.h | 25 ---- api/deprecated/Print.h | 24 ---- api/deprecated/Printable.h | 24 ---- api/deprecated/Server.h | 25 ---- api/deprecated/Stream.h | 25 ---- api/deprecated/Udp.h | 25 ---- api/deprecated/WString.h | 24 ---- api/{IPAddress.cpp => src/A_IPAddress.cpp} | 5 +- api/{WMath.cpp => src/A_Math.cpp} | 4 +- api/{WMemory.cpp => src/A_Memory.cpp} | 3 +- .../A_PluggableUSB.cpp} | 7 +- api/{Print.cpp => src/A_Print.cpp} | 6 +- api/{WRandom.cpp => src/A_Random.cpp} | 2 + api/{WShift.c => src/A_Shift.c} | 4 +- api/{Stream.cpp => src/A_Stream.cpp} | 4 +- api/{String.cpp => src/A_String.cpp} | 9 +- api/src/README.md | 1 + 71 files changed, 393 insertions(+), 373 deletions(-) rename api/{WAnalog.h => A_Analog.h} (75%) rename api/{WCharacter.h => A_Character.h} (91%) rename api/{Client.h => A_Client.h} (87%) rename api/{WDelay.h => A_Delay.h} (66%) rename api/{WDigital.h => A_Digital.h} (52%) rename api/{HardwareI2C.h => A_HardwareI2C.h} (87%) rename api/{HardwareSerial.h => A_HardwareSerial.h} (96%) rename api/{IPAddress.h => A_IPAddress.h} (94%) rename api/{WInterrupts.h => A_Interrupts.h} (80%) rename api/{WMath.h => A_Math.h} (92%) rename api/{WMemory.h => A_Memory.h} (56%) rename api/{PluggableUSB.h => A_PluggableUSB.h} (92%) rename api/{Print.h => A_Print.h} (93%) rename api/{Printable.h => A_Printable.h} (88%) rename api/{WPulse.h => A_Pulse.h} (75%) rename api/{WRandom.h => A_Random.h} (53%) rename api/{RingBuffer.h => A_RingBuffer.h} (96%) rename api/{Server.h => A_Server.h} (86%) rename api/{WShift.h => A_Shift.h} (68%) rename api/{Stream.h => A_Stream.h} (97%) rename api/{String.h => A_String.h} (98%) rename api/{WTime.h => A_Time.h} (65%) rename api/{WTone.h => A_Tone.h} (52%) rename api/{WTypes.h => A_Types.h} (89%) rename api/{USBAPI.h => A_USBAPI.h} (93%) rename api/{Udp.h => A_Udp.h} (95%) create mode 100644 api/deprecated-avr/README.md rename api/{deprecated-avr-comp => deprecated-avr}/avr/dtostrf.c.impl (100%) rename api/{deprecated-avr-comp => deprecated-avr}/avr/dtostrf.h (100%) rename api/{deprecated-avr-comp => deprecated-avr}/avr/interrupt.h (100%) create mode 100644 api/deprecated-avr/avr/pgmspace.h create mode 100644 api/deprecated-include/Client.h create mode 100644 api/deprecated-include/HardwareI2C.h create mode 100644 api/deprecated-include/HardwareSerial.h create mode 100644 api/deprecated-include/IPAddress.h rename api/{ => deprecated-include}/Interrupts.h (100%) create mode 100644 api/deprecated-include/PluggableUSB.h create mode 100644 api/deprecated-include/Print.h create mode 100644 api/deprecated-include/Printable.h create mode 100644 api/deprecated-include/README.md create mode 100644 api/deprecated-include/RingBuffer.h create mode 100644 api/deprecated-include/Server.h create mode 100644 api/deprecated-include/Stream.h create mode 100644 api/deprecated-include/USBAPI.h create mode 100644 api/deprecated-include/Udp.h create mode 100644 api/deprecated-include/WCharacter.h create mode 100644 api/deprecated-include/WString.h rename api/{Binary.h => deprecated-include/binary.h} (100%) rename api/{ => deprecated-include}/itoa.h (100%) create mode 100644 api/deprecated-include/new.h create mode 100644 api/deprecated-include/wiring.h delete mode 100644 api/deprecated/Client.h delete mode 100644 api/deprecated/HardwareSerial.h delete mode 100644 api/deprecated/IPAddress.h delete mode 100644 api/deprecated/Print.h delete mode 100644 api/deprecated/Printable.h delete mode 100644 api/deprecated/Server.h delete mode 100644 api/deprecated/Stream.h delete mode 100644 api/deprecated/Udp.h delete mode 100644 api/deprecated/WString.h rename api/{IPAddress.cpp => src/A_IPAddress.cpp} (98%) rename api/{WMath.cpp => src/A_Math.cpp} (85%) rename api/{WMemory.cpp => src/A_Memory.cpp} (85%) rename api/{PluggableUSB.cpp => src/A_PluggableUSB.cpp} (96%) rename api/{Print.cpp => src/A_Print.cpp} (99%) rename api/{WRandom.cpp => src/A_Random.cpp} (93%) rename api/{WShift.c => src/A_Shift.c} (93%) rename api/{Stream.cpp => src/A_Stream.cpp} (99%) rename api/{String.cpp => src/A_String.cpp} (99%) create mode 100644 api/src/README.md diff --git a/api/WAnalog.h b/api/A_Analog.h similarity index 75% rename from api/WAnalog.h rename to api/A_Analog.h index 2ef06d9f..38c7c7d2 100644 --- a/api/WAnalog.h +++ b/api/A_Analog.h @@ -1,7 +1,10 @@ -#pragma once +#ifndef ARDUINO_ANALOG_H +#define ARDUINO_ANALOG_H #include +#include "A_Types.h" + #ifdef __cplusplus extern "C"{ #endif @@ -16,3 +19,5 @@ void analogWriteResolution(int bits); #ifdef __cplusplus } // extern "C" #endif + +#endif // ARDUINO_ANALOG_H diff --git a/api/WCharacter.h b/api/A_Character.h similarity index 91% rename from api/WCharacter.h rename to api/A_Character.h index 0c74424d..a235b0be 100644 --- a/api/WCharacter.h +++ b/api/A_Character.h @@ -1,4 +1,5 @@ -#pragma once +#ifndef ARDUINO_CHARACTER_H +#define ARDUINO_CHARACTER_H #include @@ -19,3 +20,5 @@ #define toAscii(c) (toascii(c)) #define toLowerCase(c) (tolower(c)) #define toUpperCase(c) (toupper(c)) + +#endif // ARDUINO_CHARACTER_H diff --git a/api/Client.h b/api/A_Client.h similarity index 87% rename from api/Client.h rename to api/A_Client.h index c8ebc9fe..e2fef18e 100644 --- a/api/Client.h +++ b/api/A_Client.h @@ -17,10 +17,16 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#pragma once +#ifndef ARDUINO_CLIENT_H +#define ARDUINO_CLIENT_H -#include "Stream.h" -#include "IPAddress.h" +#ifdef __cplusplus + +#include +#include + +#include "A_IPAddress.h" +#include "A_Stream.h" class Client : public Stream { @@ -41,3 +47,6 @@ class Client : public Stream { uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); }; }; +#endif // __cplusplus + +#endif // ARDUINO_CLIENT_H diff --git a/api/WDelay.h b/api/A_Delay.h similarity index 66% rename from api/WDelay.h rename to api/A_Delay.h index 5726286a..d20d3a55 100644 --- a/api/WDelay.h +++ b/api/A_Delay.h @@ -1,4 +1,5 @@ -#pragma once +#ifndef ARDUINO_DELAY_H +#define ARDUINO_DELAY_H #ifdef __cplusplus extern "C"{ @@ -10,3 +11,5 @@ void delayMicroseconds(unsigned int us); #ifdef __cplusplus } // extern "C" #endif + +#endif // ARDUINO_DELAY_H diff --git a/api/WDigital.h b/api/A_Digital.h similarity index 52% rename from api/WDigital.h rename to api/A_Digital.h index 50b4228d..02dc42a9 100644 --- a/api/WDigital.h +++ b/api/A_Digital.h @@ -1,15 +1,18 @@ -#pragma once +#ifndef ARDUINO_DIGITAL_H +#define ARDUINO_DIGITAL_H -#include "WTypes.h" +#include "A_Types.h" #ifdef __cplusplus extern "C"{ #endif void pinMode(pin_size_t pinNumber, PinMode pinMode); -void digitalWrite(pin_size_t pinNumber, PinStatus status); +//void digitalWrite(pin_size_t pinNumber, PinStatus status); PinStatus digitalRead(pin_size_t pinNumber); #ifdef __cplusplus } // extern "C" #endif + +#endif // ARDUINO_DIGITAL_H diff --git a/api/HardwareI2C.h b/api/A_HardwareI2C.h similarity index 87% rename from api/HardwareI2C.h rename to api/A_HardwareI2C.h index 25bf40e5..2f7b31bf 100644 --- a/api/HardwareI2C.h +++ b/api/A_HardwareI2C.h @@ -16,10 +16,15 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#pragma once +#ifndef ARDUINO_HARDWARE_I2C_H +#define ARDUINO_HARDWARE_I2C_H -#include -#include "Stream.h" +#ifdef __cplusplus + +#include +#include + +#include "A_Stream.h" class HardwareI2C : public Stream { @@ -29,7 +34,7 @@ class HardwareI2C : public Stream virtual void end() = 0; virtual void setClock(uint32_t freq) = 0; - + virtual void beginTransmission(uint8_t address) = 0; virtual uint8_t endTransmission(bool stopBit) = 0; virtual uint8_t endTransmission(void) = 0; @@ -41,3 +46,6 @@ class HardwareI2C : public Stream virtual void onRequest(void(*)(void)) = 0; }; +#endif // __cplusplus + +#endif // ARDUINO_HARDWARE_I2C_H \ No newline at end of file diff --git a/api/HardwareSerial.h b/api/A_HardwareSerial.h similarity index 96% rename from api/HardwareSerial.h rename to api/A_HardwareSerial.h index e3b0b278..8524ee1c 100644 --- a/api/HardwareSerial.h +++ b/api/A_HardwareSerial.h @@ -16,10 +16,14 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#pragma once +#ifndef ARDUINO_HARDWARE_SERIAL_H +#define ARDUINO_HARDWARE_SERIAL_H -#include -#include "Stream.h" +#ifdef __cplusplus + +#include + +#include "A_Stream.h" // XXX: Those constants should be defined as const int / enums? // XXX: shall we use namespaces too? @@ -100,3 +104,6 @@ class HardwareSerial : public Stream // XXX: Are we keeping the serialEvent API? extern void serialEventRun(void) __attribute__((weak)); +#endif // __cplusplus + +#endif // ARDUINO_HARDWARE_SERIAL_H diff --git a/api/IPAddress.h b/api/A_IPAddress.h similarity index 94% rename from api/IPAddress.h rename to api/A_IPAddress.h index c8df92d7..c8fb2d40 100644 --- a/api/IPAddress.h +++ b/api/A_IPAddress.h @@ -17,11 +17,15 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#pragma once +#ifndef ARDUINO_IP_ADDRESS_H +#define ARDUINO_IP_ADDRESS_H + +#ifdef __cplusplus #include -#include "Printable.h" -#include "String.h" + +#include "A_Printable.h" +#include "A_String.h" // A class to make it easier to handle and pass around IP addresses @@ -75,3 +79,6 @@ class IPAddress : public Printable { extern const IPAddress INADDR_NONE; +#endif // __cplusplus + +#endif // ARDUINO_IP_ADDRESS_H diff --git a/api/WInterrupts.h b/api/A_Interrupts.h similarity index 80% rename from api/WInterrupts.h rename to api/A_Interrupts.h index d8c3a330..578a67fa 100644 --- a/api/WInterrupts.h +++ b/api/A_Interrupts.h @@ -1,8 +1,7 @@ -#pragma once +#ifndef ARDUINO_INTERRUPTS_H +#define ARDUINO_INTERRUPTS_H -#include "WTypes.h" - -#include +#include "A_Types.h" // interrupts() / noInterrupts() must be defined by the core @@ -20,3 +19,5 @@ void detachInterrupt(pin_size_t interruptNumber); #ifdef __cplusplus } // extern "C" #endif + +#endif // ARDUINO_INTERRUPTS_H diff --git a/api/WMath.h b/api/A_Math.h similarity index 92% rename from api/WMath.h rename to api/A_Math.h index 9cdd794b..2a6bf989 100644 --- a/api/WMath.h +++ b/api/A_Math.h @@ -1,7 +1,10 @@ -#pragma once +#ifndef ARDUINO_MATH_H +#define ARDUINO_MATH_H #include -#include "WTypes.h" +#include + +#include "A_Types.h" #define PI 3.1415926535897932384626433832795 #define HALF_PI 1.5707963267948966192313216916398 @@ -76,4 +79,6 @@ word makeWord(byte h, byte l); #define word(...) makeWord(__VA_ARGS__) -#endif +#endif // __cplusplus + +#endif // ARDUINO_MATH_H diff --git a/api/WMemory.h b/api/A_Memory.h similarity index 56% rename from api/WMemory.h rename to api/A_Memory.h index 9a2367dd..9e7a10a1 100644 --- a/api/WMemory.h +++ b/api/A_Memory.h @@ -1,11 +1,15 @@ -#pragma once +#ifndef ARDUINO_MEMORY_H +#define ARDUINO_MEMORY_H #ifdef __cplusplus -#include + +#include void *operator new(size_t size); void operator delete(void *ptr); void *operator new[](size_t size); void operator delete[](void *ptr); -#endif +#endif // __cplusplus + +#endif // ARDUINO_MEMORY_H diff --git a/api/PluggableUSB.h b/api/A_PluggableUSB.h similarity index 92% rename from api/PluggableUSB.h rename to api/A_PluggableUSB.h index 09b5fed5..c50ff65b 100644 --- a/api/PluggableUSB.h +++ b/api/A_PluggableUSB.h @@ -17,12 +17,15 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef PUSB_h -#define PUSB_h +#ifndef ARDUINO_PLUGGABLE_USB_H +#define ARDUINO_PLUGGABLE_USB_H + +#ifdef __cplusplus -#include "USBAPI.h" -#include #include +#include + +#include "A_USBAPI.h" // core need to define void* epBuffer(unsigned int n); // -> returns a poointer to the Nth element of the EP buffer structure @@ -72,4 +75,6 @@ class PluggableUSB_ { // https://isocpp.org/wiki/faq/ctors#static-init-order-on-first-use PluggableUSB_& PluggableUSB(); -#endif \ No newline at end of file +#endif // __cplusplus + +#endif // ARDUINO_PLUGGABLE_USB_H diff --git a/api/Print.h b/api/A_Print.h similarity index 93% rename from api/Print.h rename to api/A_Print.h index 4e435046..1472544c 100644 --- a/api/Print.h +++ b/api/A_Print.h @@ -16,13 +16,16 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#pragma once +#ifndef ARDUINO_PRINT_H +#define ARDUINO_PRINT_H + +#ifdef __cplusplus #include -#include // for size_t +#include -#include "String.h" -#include "Printable.h" +#include "A_Printable.h" +#include "A_String.h" #define DEC 10 #define HEX 16 @@ -82,3 +85,6 @@ class Print size_t println(void); }; +#endif // __cplusplus + +#endif // ARDUINO_PRINT_H diff --git a/api/Printable.h b/api/A_Printable.h similarity index 88% rename from api/Printable.h rename to api/A_Printable.h index de45907d..559a6f1f 100644 --- a/api/Printable.h +++ b/api/A_Printable.h @@ -16,9 +16,12 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#pragma once +#ifndef ARDUINO_PRINTABLE_H +#define ARDUINO_PRINTABLE_H -#include +#ifdef __cplusplus + +#include class Print; @@ -34,3 +37,6 @@ class Printable virtual size_t printTo(Print& p) const = 0; }; +#endif // __cplusplus + +#endif // ARDUINO_PRINTABLE_H diff --git a/api/WPulse.h b/api/A_Pulse.h similarity index 75% rename from api/WPulse.h rename to api/A_Pulse.h index 8c8692f8..38abf3f8 100644 --- a/api/WPulse.h +++ b/api/A_Pulse.h @@ -1,12 +1,16 @@ -#pragma once +#ifndef ARDUINO_PULSE_H +#define ARDUINO_PULSE_H + +#include "A_Types.h" + +unsigned long pulseIn(pin_size_t pin, PinStatus state, unsigned long timeout); +unsigned long pulseInLong(pin_size_t pin, PinStatus state, unsigned long timeout); #ifdef __cplusplus -#include unsigned long pulseIn(pin_size_t pin, PinStatus state, unsigned long timeout = 1000000L); unsigned long pulseInLong(pin_size_t pin, PinStatus state, unsigned long timeout = 1000000L); -unsigned long pulseIn(pin_size_t pin, PinStatus state, unsigned long timeout); -unsigned long pulseInLong(pin_size_t pin, PinStatus state, unsigned long timeout); +#endif // __cplusplus -#endif +#endif // ARDUINO_PULSE_H diff --git a/api/WRandom.h b/api/A_Random.h similarity index 53% rename from api/WRandom.h rename to api/A_Random.h index 99017a98..4b2b50d8 100644 --- a/api/WRandom.h +++ b/api/A_Random.h @@ -1,4 +1,5 @@ -#pragma once +#ifndef ARDUINO_RANDOM_H +#define ARDUINO_RANDOM_H #ifdef __cplusplus @@ -7,4 +8,6 @@ long random(long min, long max); void randomSeed(unsigned long seed); -#endif +#endif // __cplusplus + +#endif // ARDUINO_RANDOM_H diff --git a/api/RingBuffer.h b/api/A_RingBuffer.h similarity index 96% rename from api/RingBuffer.h rename to api/A_RingBuffer.h index 2d58dca5..d003d393 100644 --- a/api/RingBuffer.h +++ b/api/A_RingBuffer.h @@ -16,10 +16,10 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifdef __cplusplus +#ifndef ARDUINO_RING_BUFFER_H +#define ARDUINO_RING_BUFFER_H -#ifndef _RING_BUFFER_ -#define _RING_BUFFER_ +#ifdef __cplusplus #include @@ -137,6 +137,6 @@ bool RingBufferN::isFull() return (nextIndex(_iHead) == _iTail); } -#endif /* _RING_BUFFER_ */ +#endif // __cplusplus -#endif /* __cplusplus */ \ No newline at end of file +#endif // ARDUINO_RING_BUFFER_H diff --git a/api/Server.h b/api/A_Server.h similarity index 86% rename from api/Server.h rename to api/A_Server.h index 86756825..f66b08bd 100644 --- a/api/Server.h +++ b/api/A_Server.h @@ -17,12 +17,18 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#pragma once +#ifndef ARDUINO_SERVER_H +#define ARDUINO_SERVER_H -#include "Print.h" +#ifdef __cplusplus + +#include "A_Print.h" class Server : public Print { public: virtual void begin() = 0; }; +#endif // __cplusplus + +#endif // ARDUINO_SERVER_H diff --git a/api/WShift.h b/api/A_Shift.h similarity index 68% rename from api/WShift.h rename to api/A_Shift.h index 20935f77..c8b5c1a7 100644 --- a/api/WShift.h +++ b/api/A_Shift.h @@ -1,6 +1,9 @@ -#pragma once +#ifndef ARDUINO_SHIFT_H +#define ARDUINO_SHIFT_H -#include "WTypes.h" +#include + +#include "A_Types.h" #ifdef __cplusplus extern "C"{ @@ -12,3 +15,5 @@ void shiftOut(pin_size_t dataPin, pin_size_t clockPin, BitOrder bitOrder, uint8_ #ifdef __cplusplus } // extern "C" #endif + +#endif // ARDUINO_SHIFT_H diff --git a/api/Stream.h b/api/A_Stream.h similarity index 97% rename from api/Stream.h rename to api/A_Stream.h index 0576ba87..f99be303 100644 --- a/api/Stream.h +++ b/api/A_Stream.h @@ -19,10 +19,13 @@ parsing functions based on TextFinder library by Michael Margolis */ -#pragma once +#ifndef ARDUINO_STREAM_H +#define ARDUINO_STREAM_H + +#ifdef __cplusplus #include -#include "Print.h" +#include "A_Print.h" // compatability macros for testing /* @@ -126,3 +129,7 @@ class Stream : public Print }; #undef NO_IGNORE_CHAR + +#endif // __cplusplus + +#endif // ARDUINO_STREAM_H diff --git a/api/String.h b/api/A_String.h similarity index 98% rename from api/String.h rename to api/A_String.h index 5d3183c5..32fd9476 100644 --- a/api/String.h +++ b/api/A_String.h @@ -19,15 +19,16 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#pragma once +#ifndef ARDUINO_STRING_H +#define ARDUINO_STRING_H #ifdef __cplusplus -#include "Printable.h" - -#include -#include #include +//#include +#include + +#include "A_Printable.h" // When compiling programs with this class, the following gcc parameters // dramatically increase performance and memory (RAM) efficiency, typically @@ -257,3 +258,5 @@ class StringSumHelper : public String }; #endif // __cplusplus + +#endif // ARDUINO_STRING_H diff --git a/api/WTime.h b/api/A_Time.h similarity index 65% rename from api/WTime.h rename to api/A_Time.h index 55832e3b..440e4e47 100644 --- a/api/WTime.h +++ b/api/A_Time.h @@ -1,4 +1,5 @@ -#pragma once +#ifndef ARDUINO_TIME_H +#define ARDUINO_TIME_H #ifdef __cplusplus extern "C"{ @@ -10,3 +11,5 @@ unsigned long micros(void); #ifdef __cplusplus } // extern "C" #endif + +#endif // ARDUINO_TIME_H diff --git a/api/WTone.h b/api/A_Tone.h similarity index 52% rename from api/WTone.h rename to api/A_Tone.h index 84375eef..34031877 100644 --- a/api/WTone.h +++ b/api/A_Tone.h @@ -1,10 +1,13 @@ -#pragma once +#ifndef ARDUINO_TONE_H +#define ARDUINO_TONE_H #ifdef __cplusplus -#include "WTypes.h" +#include "A_Types.h" void tone(pin_size_t pin, unsigned int frequency, unsigned long duration = 0); void noTone(pin_size_t pin); -#endif +#endif // __cplusplus + +#endif // ARDUINO_TONE_H diff --git a/api/WTypes.h b/api/A_Types.h similarity index 89% rename from api/WTypes.h rename to api/A_Types.h index 3d647c20..ab59ad6f 100644 --- a/api/WTypes.h +++ b/api/A_Types.h @@ -1,8 +1,8 @@ -#pragma once +#ifndef ARDUINO_TYPES_H +#define ARDUINO_TYPES_H #include #include -#include #ifndef boolean typedef bool boolean; @@ -42,3 +42,5 @@ typedef enum { LSBFIRST = 0, MSBFIRST = 1, } BitOrder; + +#endif // ARDUINO_TYPES_H diff --git a/api/USBAPI.h b/api/A_USBAPI.h similarity index 93% rename from api/USBAPI.h rename to api/A_USBAPI.h index 8743ab4b..6685b2a5 100644 --- a/api/USBAPI.h +++ b/api/A_USBAPI.h @@ -17,8 +17,10 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef __USBAPI__ -#define __USBAPI__ +#ifndef ARDUINO_USB_API_H +#define ARDUINO_USB_API_H + +#ifdef __cplusplus #include @@ -57,4 +59,6 @@ int USB_Recv(uint8_t ep, void* data, int len); // non-blocking int USB_Recv(uint8_t ep); // non-blocking void USB_Flush(uint8_t ep); -#endif \ No newline at end of file +#endif // __cplusplus + +#endif // ARDUINO_USB_API_H diff --git a/api/Udp.h b/api/A_Udp.h similarity index 95% rename from api/Udp.h rename to api/A_Udp.h index 90581653..2ad75394 100644 --- a/api/Udp.h +++ b/api/A_Udp.h @@ -32,10 +32,16 @@ * bjoern@cs.stanford.edu 12/30/2008 */ -#pragma once +#ifndef ARDUINO_UDP_H +#define ARDUINO_UDP_H -#include "Stream.h" -#include "IPAddress.h" +#ifdef __cplusplus + +#include +#include + +#include "A_Stream.h" +#include "A_IPAddress.h" class UDP : public Stream { @@ -84,3 +90,6 @@ class UDP : public Stream { uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); }; }; +#endif __cplusplus + +#endif ARDUINO_UDP_H diff --git a/api/ArduinoAPI.h b/api/ArduinoAPI.h index b9f749f9..e92c4f64 100644 --- a/api/ArduinoAPI.h +++ b/api/ArduinoAPI.h @@ -1,59 +1,30 @@ -/* - Arduino API main include - Copyright (c) 2016 Arduino LLC. 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 -*/ - -#ifndef ARDUINO_API_H -#define ARDUINO_API_H - -// version 1.0.0 -#define ARDUINO_API_VERSION 10000 - -#include "WTypes.h" - -#include "WAnalog.h" -#include "WCharacter.h" -#include "WDelay.h" -#include "WDigital.h" -#include "WInterrupts.h" -#include "WMath.h" -#include "WMemory.h" -#include "WPulse.h" -#include "WRandom.h" -#include "WShift.h" -#include "WTime.h" -#include "WTone.h" - -#include "Binary.h" - -#ifdef __cplusplus -#include "Client.h" -#include "HardwareI2C.h" -#include "HardwareSerial.h" -#include "Interrupts.h" -#include "IPAddress.h" -#include "Print.h" -#include "Printable.h" -#include "PluggableUSB.h" -#include "Server.h" -#include "String.h" -#include "Stream.h" -#include "Udp.h" -#include "USBAPI.h" -#endif - -#endif +#ifndef ARDUINO_API_H_ +#define ARDUINO_API_H_ + +#include "A_Analog.h" +#include "A_Character.h" +#include "A_Client.h" +#include "A_Delay.h" +#include "A_Digital.h" +#include "A_HardwareI2C.h" +#include "A_HardwareSerial.h" +#include "A_Interrupts.h" +#include "A_Math.h"å +#include "A_Memory.h" +#include "A_PluggableUSB.h" +#include "A_Print.h" +#include "A_Printable.h" +#include "A_Pulse.h" +#include "A_Random.h" +#include "A_RingBuffer.h" +#include "A_Server.h" +#include "A_Shift.h" +#include "A_Stream.h" +#include "A_String.h" +#include "A_Time.h" +#include "A_Tone.h" +#include "A_Types.h" +#include "A_Udp.h" +#include "A_USBAPI.h" + +#endif // ARDUINO_API_H_ diff --git a/api/deprecated-avr/README.md b/api/deprecated-avr/README.md new file mode 100644 index 00000000..abd54853 --- /dev/null +++ b/api/deprecated-avr/README.md @@ -0,0 +1 @@ +Deprecated include files for support of existing sketches that may have included them directly. diff --git a/api/deprecated-avr-comp/avr/dtostrf.c.impl b/api/deprecated-avr/avr/dtostrf.c.impl similarity index 100% rename from api/deprecated-avr-comp/avr/dtostrf.c.impl rename to api/deprecated-avr/avr/dtostrf.c.impl diff --git a/api/deprecated-avr-comp/avr/dtostrf.h b/api/deprecated-avr/avr/dtostrf.h similarity index 100% rename from api/deprecated-avr-comp/avr/dtostrf.h rename to api/deprecated-avr/avr/dtostrf.h diff --git a/api/deprecated-avr-comp/avr/interrupt.h b/api/deprecated-avr/avr/interrupt.h similarity index 100% rename from api/deprecated-avr-comp/avr/interrupt.h rename to api/deprecated-avr/avr/interrupt.h diff --git a/api/deprecated-avr/avr/pgmspace.h b/api/deprecated-avr/avr/pgmspace.h new file mode 100644 index 00000000..de92051a --- /dev/null +++ b/api/deprecated-avr/avr/pgmspace.h @@ -0,0 +1,122 @@ +/* + pgmspace.h - Definitions for compatibility with AVR pgmspace macros + + Copyright (c) 2015 Arduino LLC + + Based on work of Paul Stoffregen on Teensy 3 (http://pjrc.com) + + 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 __PGMSPACE_H_ +#define __PGMSPACE_H_ 1 + +#include + +#define PROGMEM +#define PGM_P const char * +#define PSTR(str) (str) + +#define _SFR_BYTE(n) (n) + +typedef void prog_void; +typedef char prog_char; +typedef unsigned char prog_uchar; +typedef int8_t prog_int8_t; +typedef uint8_t prog_uint8_t; +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; + +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 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/api/deprecated-include/Client.h b/api/deprecated-include/Client.h new file mode 100644 index 00000000..cee1d3f9 --- /dev/null +++ b/api/deprecated-include/Client.h @@ -0,0 +1 @@ +#include "../A_Client.h" diff --git a/api/deprecated-include/HardwareI2C.h b/api/deprecated-include/HardwareI2C.h new file mode 100644 index 00000000..03741a66 --- /dev/null +++ b/api/deprecated-include/HardwareI2C.h @@ -0,0 +1 @@ +#include "../A_HardwareI2C.h" diff --git a/api/deprecated-include/HardwareSerial.h b/api/deprecated-include/HardwareSerial.h new file mode 100644 index 00000000..26a8d554 --- /dev/null +++ b/api/deprecated-include/HardwareSerial.h @@ -0,0 +1 @@ +#include "../A_HardwareSerial.h" diff --git a/api/deprecated-include/IPAddress.h b/api/deprecated-include/IPAddress.h new file mode 100644 index 00000000..382c005a --- /dev/null +++ b/api/deprecated-include/IPAddress.h @@ -0,0 +1 @@ +#include "../A_IPAddress.h" diff --git a/api/Interrupts.h b/api/deprecated-include/Interrupts.h similarity index 100% rename from api/Interrupts.h rename to api/deprecated-include/Interrupts.h diff --git a/api/deprecated-include/PluggableUSB.h b/api/deprecated-include/PluggableUSB.h new file mode 100644 index 00000000..9ce8f44a --- /dev/null +++ b/api/deprecated-include/PluggableUSB.h @@ -0,0 +1 @@ +#include "../A_PluggableUSB.h" diff --git a/api/deprecated-include/Print.h b/api/deprecated-include/Print.h new file mode 100644 index 00000000..b0a3e6bb --- /dev/null +++ b/api/deprecated-include/Print.h @@ -0,0 +1 @@ +#include "../A_Print.h" diff --git a/api/deprecated-include/Printable.h b/api/deprecated-include/Printable.h new file mode 100644 index 00000000..f2281d8d --- /dev/null +++ b/api/deprecated-include/Printable.h @@ -0,0 +1 @@ +#include "../A_Printable.h" diff --git a/api/deprecated-include/README.md b/api/deprecated-include/README.md new file mode 100644 index 00000000..abd54853 --- /dev/null +++ b/api/deprecated-include/README.md @@ -0,0 +1 @@ +Deprecated include files for support of existing sketches that may have included them directly. diff --git a/api/deprecated-include/RingBuffer.h b/api/deprecated-include/RingBuffer.h new file mode 100644 index 00000000..d0a2a5c0 --- /dev/null +++ b/api/deprecated-include/RingBuffer.h @@ -0,0 +1 @@ +#include "../A_RingBuffer.h" diff --git a/api/deprecated-include/Server.h b/api/deprecated-include/Server.h new file mode 100644 index 00000000..51410658 --- /dev/null +++ b/api/deprecated-include/Server.h @@ -0,0 +1 @@ +#include "../A_Server.h" diff --git a/api/deprecated-include/Stream.h b/api/deprecated-include/Stream.h new file mode 100644 index 00000000..ff364a21 --- /dev/null +++ b/api/deprecated-include/Stream.h @@ -0,0 +1 @@ +#include "../A_Stream.h" diff --git a/api/deprecated-include/USBAPI.h b/api/deprecated-include/USBAPI.h new file mode 100644 index 00000000..1e62d397 --- /dev/null +++ b/api/deprecated-include/USBAPI.h @@ -0,0 +1 @@ +#include "../USBAPI.h" diff --git a/api/deprecated-include/Udp.h b/api/deprecated-include/Udp.h new file mode 100644 index 00000000..afd36097 --- /dev/null +++ b/api/deprecated-include/Udp.h @@ -0,0 +1 @@ +#include "../A_Udp.h" diff --git a/api/deprecated-include/WCharacter.h b/api/deprecated-include/WCharacter.h new file mode 100644 index 00000000..431c2cf4 --- /dev/null +++ b/api/deprecated-include/WCharacter.h @@ -0,0 +1 @@ +#include "../A_Character.h" diff --git a/api/deprecated-include/WString.h b/api/deprecated-include/WString.h new file mode 100644 index 00000000..6d8d7b8f --- /dev/null +++ b/api/deprecated-include/WString.h @@ -0,0 +1 @@ +#include "../A_String.h" diff --git a/api/Binary.h b/api/deprecated-include/binary.h similarity index 100% rename from api/Binary.h rename to api/deprecated-include/binary.h diff --git a/api/itoa.h b/api/deprecated-include/itoa.h similarity index 100% rename from api/itoa.h rename to api/deprecated-include/itoa.h diff --git a/api/deprecated-include/new.h b/api/deprecated-include/new.h new file mode 100644 index 00000000..c6db3ba7 --- /dev/null +++ b/api/deprecated-include/new.h @@ -0,0 +1 @@ +#include "../A_Memory.h" diff --git a/api/deprecated-include/wiring.h b/api/deprecated-include/wiring.h new file mode 100644 index 00000000..e69de29b diff --git a/api/deprecated/Client.h b/api/deprecated/Client.h deleted file mode 100644 index 5f8d4be9..00000000 --- a/api/deprecated/Client.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - Copyright (c) 2016 Arduino LLC. 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 -*/ - -// including Client.h is deprecated, for all future projects use Arduino.h instead - -// This include is added for compatibility, it will be remove on the next -// major release of the API -#include "../Client.h" - - diff --git a/api/deprecated/HardwareSerial.h b/api/deprecated/HardwareSerial.h deleted file mode 100644 index 19d77c78..00000000 --- a/api/deprecated/HardwareSerial.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - Copyright (c) 2016 Arduino LLC. 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 -*/ - -// including HardwareSerial.h is deprecated, for all future projects use Arduino.h instead - -// This include is added for compatibility, it will be remove on the next -// major release of the API -#include "../HardwareSerial.h" - - diff --git a/api/deprecated/IPAddress.h b/api/deprecated/IPAddress.h deleted file mode 100644 index bf7fb7f0..00000000 --- a/api/deprecated/IPAddress.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - Copyright (c) 2016 Arduino LLC. 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 -*/ - -// including IPAddress.h is deprecated, for all future projects use Arduino.h instead - -// This include is added for compatibility, it will be remove on the next -// major release of the API -#include "../IPAddress.h" - - diff --git a/api/deprecated/Print.h b/api/deprecated/Print.h deleted file mode 100644 index 2ac088d8..00000000 --- a/api/deprecated/Print.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - Copyright (c) 2016 Arduino LLC. 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 -*/ - -// including Print.h is deprecated, for all future projects use Arduino.h instead - -// This include is added for compatibility, it will be remove on the next -// major release of the API -#include "../Print.h" - diff --git a/api/deprecated/Printable.h b/api/deprecated/Printable.h deleted file mode 100644 index bd721264..00000000 --- a/api/deprecated/Printable.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - Copyright (c) 2016 Arduino LLC. 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 -*/ - -// including Printable.h is deprecated, for all future projects use Arduino.h instead - -// This include is added for compatibility, it will be remove on the next -// major release of the API -#include "../Printable.h" - diff --git a/api/deprecated/Server.h b/api/deprecated/Server.h deleted file mode 100644 index f3b02c16..00000000 --- a/api/deprecated/Server.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - Copyright (c) 2016 Arduino LLC. 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 -*/ - -// including Server.h is deprecated, for all future projects use Arduino.h instead - -// This include is added for compatibility, it will be remove on the next -// major release of the API -#include "../Server.h" - - diff --git a/api/deprecated/Stream.h b/api/deprecated/Stream.h deleted file mode 100644 index aa5dc8e0..00000000 --- a/api/deprecated/Stream.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - Copyright (c) 2016 Arduino LLC. 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 -*/ - -// including Stream.h is deprecated, for all future projects use Arduino.h instead - -// This include is added for compatibility, it will be remove on the next -// major release of the API -#include "../Stream.h" - - diff --git a/api/deprecated/Udp.h b/api/deprecated/Udp.h deleted file mode 100644 index 56980603..00000000 --- a/api/deprecated/Udp.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - Copyright (c) 2016 Arduino LLC. 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 -*/ - -// including Udp.h is deprecated, for all future projects use Arduino.h instead - -// This include is added for compatibility, it will be remove on the next -// major release of the API -#include "../Udp.h" - - diff --git a/api/deprecated/WString.h b/api/deprecated/WString.h deleted file mode 100644 index 072323e0..00000000 --- a/api/deprecated/WString.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - Copyright 2016, Arduino LLC. 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 -*/ - -// including WString.h is deprecated, for all future projects use Arduino.h instead - -// This include is added for compatibility, it will be remove on the next -// major release of the API -#include "../String.h" - diff --git a/api/IPAddress.cpp b/api/src/A_IPAddress.cpp similarity index 98% rename from api/IPAddress.cpp rename to api/src/A_IPAddress.cpp index 62244d6b..e2af7e8e 100644 --- a/api/IPAddress.cpp +++ b/api/src/A_IPAddress.cpp @@ -17,8 +17,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "IPAddress.h" -#include "Print.h" +#include "../A_IPAddress.h" + +#include "../A_Print.h" IPAddress::IPAddress() { diff --git a/api/WMath.cpp b/api/src/A_Math.cpp similarity index 85% rename from api/WMath.cpp rename to api/src/A_Math.cpp index 19832efc..7c684e0f 100644 --- a/api/WMath.cpp +++ b/api/src/A_Math.cpp @@ -1,6 +1,6 @@ -#include "WMath.h" +#include "../A_Math.h" -#include "WTypes.h" +#include "../A_Types.h" long map(long x, long in_min, long in_max, long out_min, long out_max) { diff --git a/api/WMemory.cpp b/api/src/A_Memory.cpp similarity index 85% rename from api/WMemory.cpp rename to api/src/A_Memory.cpp index 178fd6b1..af7ece13 100644 --- a/api/WMemory.cpp +++ b/api/src/A_Memory.cpp @@ -1,5 +1,6 @@ -#include "WMemory.h" +#include "../A_Memory.h" +#include #include diff --git a/api/PluggableUSB.cpp b/api/src/A_PluggableUSB.cpp similarity index 96% rename from api/PluggableUSB.cpp rename to api/src/A_PluggableUSB.cpp index f0c45f01..2a6cffd3 100644 --- a/api/PluggableUSB.cpp +++ b/api/src/A_PluggableUSB.cpp @@ -17,8 +17,11 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "USBAPI.h" -#include "PluggableUSB.h" +#include "../A_PluggableUSB.h" + +#include "../A_USBAPI.h" + +#include int PluggableUSB_::getInterface(uint8_t* interfaceCount) { diff --git a/api/Print.cpp b/api/src/A_Print.cpp similarity index 99% rename from api/Print.cpp rename to api/src/A_Print.cpp index 7938e9d3..28bbd3c8 100644 --- a/api/Print.cpp +++ b/api/src/A_Print.cpp @@ -16,12 +16,12 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "../A_Print.h" + +#include #include #include #include -#include - -#include "Print.h" // Public Methods ////////////////////////////////////////////////////////////// diff --git a/api/WRandom.cpp b/api/src/A_Random.cpp similarity index 93% rename from api/WRandom.cpp rename to api/src/A_Random.cpp index ae400fee..862ea953 100644 --- a/api/WRandom.cpp +++ b/api/src/A_Random.cpp @@ -1,3 +1,5 @@ +#include "../A_Random.h" + extern "C" { #include "stdlib.h" } diff --git a/api/WShift.c b/api/src/A_Shift.c similarity index 93% rename from api/WShift.c rename to api/src/A_Shift.c index f974a2d5..640c5132 100644 --- a/api/WShift.c +++ b/api/src/A_Shift.c @@ -1,6 +1,6 @@ -#include "WShift.h" +#include "../A_Shift.h" -#include "WTypes.h" +#include "../A_Types.h" uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) { uint8_t value = 0; diff --git a/api/Stream.cpp b/api/src/A_Stream.cpp similarity index 99% rename from api/Stream.cpp rename to api/src/A_Stream.cpp index 5442962f..e4f5f5f7 100644 --- a/api/Stream.cpp +++ b/api/src/A_Stream.cpp @@ -22,9 +22,9 @@ findMulti/findUntil routines written by Jim Leonard/Xuth */ -#include "Stream.h" +#include "../A_Stream.h" -#include "WTime.h" +#include "../A_Time.h" #define PARSE_TIMEOUT 1000 // default number of milli-seconds to wait diff --git a/api/String.cpp b/api/src/A_String.cpp similarity index 99% rename from api/String.cpp rename to api/src/A_String.cpp index 22f8369c..ed975605 100644 --- a/api/String.cpp +++ b/api/src/A_String.cpp @@ -19,9 +19,12 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "String.h" -#include "itoa.h" -#include "deprecated-avr-comp/avr/dtostrf.h" +#include "../A_String.h" + +#include "../deprecated-include/itoa.h" +#include "../deprecated-avr/avr/dtostrf.h" + +#include /*********************************************/ /* Constructors */ diff --git a/api/src/README.md b/api/src/README.md new file mode 100644 index 00000000..ac145ff8 --- /dev/null +++ b/api/src/README.md @@ -0,0 +1 @@ +Platform independent Arduino source files