diff --git a/cores/arduino/Arduino.h b/cores/arduino/Arduino.h index c374c964b..32e99a3e1 100644 --- a/cores/arduino/Arduino.h +++ b/cores/arduino/Arduino.h @@ -20,25 +20,11 @@ #ifndef Arduino_h #define Arduino_h -#include -#include -#include -#include -#include - -typedef bool boolean; -typedef uint8_t byte; -typedef uint16_t word; - -// some libraries and sketches depend on this AVR stuff, -// assuming Arduino.h or WProgram.h automatically includes it... -// -#include "avr/pgmspace.h" -#include "avr/interrupt.h" -#include "avr/io.h" - -#include "binary.h" -#include "itoa.h" +#include "api/ArduinoAPI.h" + +#define RAMSTART (HMCRAMC0_ADDR) +#define RAMSIZE (HMCRAMC0_SIZE) +#define RAMEND (RAMSTART + RAMSIZE - 1) #ifdef __cplusplus extern "C"{ @@ -47,86 +33,73 @@ extern "C"{ // Include Atmel headers #include "sam.h" -#include "wiring_constants.h" - #define clockCyclesPerMicrosecond() ( SystemCoreClock / 1000000L ) #define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (SystemCoreClock / 1000L) ) #define microsecondsToClockCycles(a) ( (a) * (SystemCoreClock / 1000000L) ) -void yield( void ) ; - -/* system functions */ -int main( void ); -void init( void ); - -/* sketch */ -void setup( void ) ; -void loop( void ) ; - #include "WVariant.h" #ifdef __cplusplus } // extern "C" #endif -// The following headers are for C++ only compilation -#ifdef __cplusplus - #include "WCharacter.h" - #include "WString.h" - #include "Tone.h" - #include "WMath.h" - #include "HardwareSerial.h" - #include "pulse.h" -#endif -#include "delay.h" -#ifdef __cplusplus - #include "Uart.h" -#endif - // Include board variant #include "variant.h" -#include "wiring.h" -#include "wiring_digital.h" -#include "wiring_analog.h" -#include "wiring_shift.h" -#include "WInterrupts.h" +#define interrupts() __enable_irq() +#define noInterrupts() __disable_irq() + +#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606) +// Interrupts +#define digitalPinToInterrupt(P) ( P ) +#endif // undefine stdlib's abs if encountered #ifdef abs #undef abs #endif // abs -#define min(a,b) ((a)<(b)?(a):(b)) -#define max(a,b) ((a)>(b)?(a):(b)) #define abs(x) ((x)>0?(x):-(x)) -#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) -#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) -#define radians(deg) ((deg)*DEG_TO_RAD) -#define degrees(rad) ((rad)*RAD_TO_DEG) -#define sq(x) ((x)*(x)) -#define interrupts() __enable_irq() -#define noInterrupts() __disable_irq() +// Allows publishing the Beta core under samd-beta / arduino organization +#ifndef ARDUINO_ARCH_SAMD +#define ARDUINO_ARCH_SAMD +#endif -#define lowByte(w) ((uint8_t) ((w) & 0xff)) -#define highByte(w) ((uint8_t) ((w) >> 8)) +#ifdef __cplusplus +extern "C" { +#endif +/* + * \brief SAMD products have only one reference for ADC + */ +typedef enum _eAnalogReference +{ + AR_DEFAULT, + AR_INTERNAL, + AR_EXTERNAL, + AR_INTERNAL1V0, + AR_INTERNAL1V65, + AR_INTERNAL2V23 +} eAnalogReference ; -#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)) +/* + * \brief Set the resolution of analogRead return values. Default is 10 bits (range from 0 to 1023). + * + * \param res + */ +extern void analogReadResolution(int res); -#define bit(b) (1UL << (b)) +/* + * \brief Set the resolution of analogWrite parameters. Default is 8 bits (range from 0 to 255). + * + * \param res + */ +extern void analogWriteResolution(int res); -#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606) -// Interrupts -#define digitalPinToInterrupt(P) ( P ) -#endif +extern void analogOutputInit( void ) ; -// Allows publishing the Beta core under samd-beta / arduino organization -#ifndef ARDUINO_ARCH_SAMD -#define ARDUINO_ARCH_SAMD +#ifdef __cplusplus +} #endif // USB Device @@ -135,8 +108,7 @@ void loop( void ) ; #include "USB/USBAPI.h" #include "USB/USB_host.h" -#ifdef __cplusplus - #include "USB/CDC.h" -#endif +// ARM toolchain doesn't provide itoa etc, provide them +#include "api/itoa.h" #endif // Arduino_h diff --git a/cores/arduino/Client.h b/cores/arduino/Client.h deleted file mode 100644 index b8e5d935f..000000000 --- a/cores/arduino/Client.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - Client.h - Base class that provides Client - Copyright (c) 2011 Adrian McEwen. 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 client_h -#define client_h -#include "Print.h" -#include "Stream.h" -#include "IPAddress.h" - -class Client : public Stream { - -public: - virtual int connect(IPAddress ip, uint16_t port) =0; - virtual int connect(const char *host, uint16_t port) =0; - virtual size_t write(uint8_t) =0; - virtual size_t write(const uint8_t *buf, size_t size) =0; - virtual int available() = 0; - virtual int read() = 0; - virtual int read(uint8_t *buf, size_t size) = 0; - virtual int peek() = 0; - virtual void flush() = 0; - virtual void stop() = 0; - virtual uint8_t connected() = 0; - virtual operator bool() = 0; -protected: - uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); }; -}; - -#endif diff --git a/cores/arduino/HardwareSerial.h b/cores/arduino/HardwareSerial.h deleted file mode 100644 index 62508e786..000000000 --- a/cores/arduino/HardwareSerial.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - Copyright (c) 2015 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 HardwareSerial_h -#define HardwareSerial_h - -#include - -#include "Stream.h" - -#define HARDSER_PARITY_EVEN (0x1ul) -#define HARDSER_PARITY_ODD (0x2ul) -#define HARDSER_PARITY_NONE (0x3ul) -#define HARDSER_PARITY_MASK (0xFul) - -#define HARDSER_STOP_BIT_1 (0x10ul) -#define HARDSER_STOP_BIT_1_5 (0x20ul) -#define HARDSER_STOP_BIT_2 (0x30ul) -#define HARDSER_STOP_BIT_MASK (0xF0ul) - -#define HARDSER_DATA_5 (0x100ul) -#define HARDSER_DATA_6 (0x200ul) -#define HARDSER_DATA_7 (0x300ul) -#define HARDSER_DATA_8 (0x400ul) -#define HARDSER_DATA_MASK (0xF00ul) - -#define SERIAL_5N1 (HARDSER_STOP_BIT_1 | HARDSER_PARITY_NONE | HARDSER_DATA_5) -#define SERIAL_6N1 (HARDSER_STOP_BIT_1 | HARDSER_PARITY_NONE | HARDSER_DATA_6) -#define SERIAL_7N1 (HARDSER_STOP_BIT_1 | HARDSER_PARITY_NONE | HARDSER_DATA_7) -#define SERIAL_8N1 (HARDSER_STOP_BIT_1 | HARDSER_PARITY_NONE | HARDSER_DATA_8) -#define SERIAL_5N2 (HARDSER_STOP_BIT_2 | HARDSER_PARITY_NONE | HARDSER_DATA_5) -#define SERIAL_6N2 (HARDSER_STOP_BIT_2 | HARDSER_PARITY_NONE | HARDSER_DATA_6) -#define SERIAL_7N2 (HARDSER_STOP_BIT_2 | HARDSER_PARITY_NONE | HARDSER_DATA_7) -#define SERIAL_8N2 (HARDSER_STOP_BIT_2 | HARDSER_PARITY_NONE | HARDSER_DATA_8) -#define SERIAL_5E1 (HARDSER_STOP_BIT_1 | HARDSER_PARITY_EVEN | HARDSER_DATA_5) -#define SERIAL_6E1 (HARDSER_STOP_BIT_1 | HARDSER_PARITY_EVEN | HARDSER_DATA_6) -#define SERIAL_7E1 (HARDSER_STOP_BIT_1 | HARDSER_PARITY_EVEN | HARDSER_DATA_7) -#define SERIAL_8E1 (HARDSER_STOP_BIT_1 | HARDSER_PARITY_EVEN | HARDSER_DATA_8) -#define SERIAL_5E2 (HARDSER_STOP_BIT_2 | HARDSER_PARITY_EVEN | HARDSER_DATA_5) -#define SERIAL_6E2 (HARDSER_STOP_BIT_2 | HARDSER_PARITY_EVEN | HARDSER_DATA_6) -#define SERIAL_7E2 (HARDSER_STOP_BIT_2 | HARDSER_PARITY_EVEN | HARDSER_DATA_7) -#define SERIAL_8E2 (HARDSER_STOP_BIT_2 | HARDSER_PARITY_EVEN | HARDSER_DATA_8) -#define SERIAL_5O1 (HARDSER_STOP_BIT_1 | HARDSER_PARITY_ODD | HARDSER_DATA_5) -#define SERIAL_6O1 (HARDSER_STOP_BIT_1 | HARDSER_PARITY_ODD | HARDSER_DATA_6) -#define SERIAL_7O1 (HARDSER_STOP_BIT_1 | HARDSER_PARITY_ODD | HARDSER_DATA_7) -#define SERIAL_8O1 (HARDSER_STOP_BIT_1 | HARDSER_PARITY_ODD | HARDSER_DATA_8) -#define SERIAL_5O2 (HARDSER_STOP_BIT_2 | HARDSER_PARITY_ODD | HARDSER_DATA_5) -#define SERIAL_6O2 (HARDSER_STOP_BIT_2 | HARDSER_PARITY_ODD | HARDSER_DATA_6) -#define SERIAL_7O2 (HARDSER_STOP_BIT_2 | HARDSER_PARITY_ODD | HARDSER_DATA_7) -#define SERIAL_8O2 (HARDSER_STOP_BIT_2 | HARDSER_PARITY_ODD | HARDSER_DATA_8) - -class HardwareSerial : public Stream -{ - public: - virtual void begin(unsigned long); - virtual void begin(unsigned long baudrate, uint16_t config); - virtual void end(); - virtual int available(void) = 0; - virtual int peek(void) = 0; - virtual int read(void) = 0; - virtual void flush(void) = 0; - virtual size_t write(uint8_t) = 0; - using Print::write; // pull in write(str) and write(buf, size) from Print - virtual operator bool() = 0; -}; - -extern void serialEventRun(void) __attribute__((weak)); - -#endif diff --git a/cores/arduino/IPAddress.cpp b/cores/arduino/IPAddress.cpp deleted file mode 100644 index 76aefa8b2..000000000 --- a/cores/arduino/IPAddress.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/* - IPAddress.cpp - Base class that provides IPAddress - Copyright (c) 2011 Adrian McEwen. 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 -*/ - -#include -#include - -IPAddress::IPAddress() -{ - _address.dword = 0; -} - -IPAddress::IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet) -{ - _address.bytes[0] = first_octet; - _address.bytes[1] = second_octet; - _address.bytes[2] = third_octet; - _address.bytes[3] = fourth_octet; -} - -IPAddress::IPAddress(uint32_t address) -{ - _address.dword = address; -} - -IPAddress::IPAddress(const uint8_t *address) -{ - memcpy(_address.bytes, address, sizeof(_address.bytes)); -} - -bool IPAddress::fromString(const char *address) -{ - // TODO: add support for "a", "a.b", "a.b.c" formats - - uint16_t acc = 0; // Accumulator - uint8_t dots = 0; - - while (*address) - { - char c = *address++; - if (c >= '0' && c <= '9') - { - acc = acc * 10 + (c - '0'); - if (acc > 255) { - // Value out of [0..255] range - return false; - } - } - else if (c == '.') - { - if (dots == 3) { - // Too much dots (there must be 3 dots) - return false; - } - _address.bytes[dots++] = acc; - acc = 0; - } - else - { - // Invalid char - return false; - } - } - - if (dots != 3) { - // Too few dots (there must be 3 dots) - return false; - } - _address.bytes[3] = acc; - return true; -} - -IPAddress& IPAddress::operator=(const uint8_t *address) -{ - memcpy(_address.bytes, address, sizeof(_address.bytes)); - return *this; -} - -IPAddress& IPAddress::operator=(uint32_t address) -{ - _address.dword = address; - return *this; -} - -bool IPAddress::operator==(const uint8_t* addr) const -{ - return memcmp(addr, _address.bytes, sizeof(_address.bytes)) == 0; -} - -size_t IPAddress::printTo(Print& p) const -{ - size_t n = 0; - for (int i =0; i < 3; i++) - { - n += p.print(_address.bytes[i], DEC); - n += p.print('.'); - } - n += p.print(_address.bytes[3], DEC); - return n; -} - diff --git a/cores/arduino/IPAddress.h b/cores/arduino/IPAddress.h deleted file mode 100644 index d762f2c02..000000000 --- a/cores/arduino/IPAddress.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - IPAddress.h - Base class that provides IPAddress - Copyright (c) 2011 Adrian McEwen. 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 IPAddress_h -#define IPAddress_h - -#include -#include "Printable.h" -#include "WString.h" - -// A class to make it easier to handle and pass around IP addresses - -class IPAddress : public Printable { -private: - union { - uint8_t bytes[4]; // IPv4 address - uint32_t dword; - } _address; - - // Access the raw byte array containing the address. Because this returns a pointer - // to the internal structure rather than a copy of the address this function should only - // be used when you know that the usage of the returned uint8_t* will be transient and not - // stored. - uint8_t* raw_address() { return _address.bytes; }; - -public: - // Constructors - IPAddress(); - IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet); - IPAddress(uint32_t address); - IPAddress(const uint8_t *address); - - bool fromString(const char *address); - bool fromString(const String &address) { return fromString(address.c_str()); } - - // Overloaded cast operator to allow IPAddress objects to be used where a pointer - // to a four-byte uint8_t array is expected - operator uint32_t() const { return _address.dword; }; - bool operator==(const IPAddress& addr) const { return _address.dword == addr._address.dword; }; - bool operator==(const uint8_t* addr) const; - - // Overloaded index operator to allow getting and setting individual octets of the address - uint8_t operator[](int index) const { return _address.bytes[index]; }; - uint8_t& operator[](int index) { return _address.bytes[index]; }; - - // Overloaded copy operators to allow initialisation of IPAddress objects from other types - IPAddress& operator=(const uint8_t *address); - IPAddress& operator=(uint32_t address); - - virtual size_t printTo(Print& p) const; - - friend class EthernetClass; - friend class UDP; - friend class Client; - friend class Server; - friend class DhcpClass; - friend class DNSClient; -}; - -const IPAddress INADDR_NONE(0,0,0,0); - -#endif diff --git a/cores/arduino/Print.cpp b/cores/arduino/Print.cpp deleted file mode 100644 index 9fc5c3116..000000000 --- a/cores/arduino/Print.cpp +++ /dev/null @@ -1,251 +0,0 @@ -/* - Copyright (c) 2014 Arduino. 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 -*/ - -#include -#include "Arduino.h" - -#include "Print.h" - -// Public Methods ////////////////////////////////////////////////////////////// - -/* default implementation: may be overridden */ -size_t Print::write(const uint8_t *buffer, size_t size) -{ - size_t n = 0; - while (size--) { - if (write(*buffer++)) n++; - else break; - } - return n; -} - -size_t Print::print(const __FlashStringHelper *ifsh) -{ - return print(reinterpret_cast(ifsh)); -} - -size_t Print::print(const String &s) -{ - return write(s.c_str(), s.length()); -} - -size_t Print::print(const char str[]) -{ - return write(str); -} - -size_t Print::print(char c) -{ - return write(c); -} - -size_t Print::print(unsigned char b, int base) -{ - return print((unsigned long) b, base); -} - -size_t Print::print(int n, int base) -{ - return print((long) n, base); -} - -size_t Print::print(unsigned int n, int base) -{ - return print((unsigned long) n, base); -} - -size_t Print::print(long n, int base) -{ - if (base == 0) { - return write(n); - } else if (base == 10) { - if (n < 0) { - int t = print('-'); - n = -n; - return printNumber(n, 10) + t; - } - return printNumber(n, 10); - } else { - return printNumber(n, base); - } -} - -size_t Print::print(unsigned long n, int base) -{ - if (base == 0) return write(n); - else return printNumber(n, base); -} - -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); -} - -size_t Print::println(void) -{ - return write("\r\n"); -} - -size_t Print::println(const String &s) -{ - size_t n = print(s); - n += println(); - return n; -} - -size_t Print::println(const char c[]) -{ - size_t n = print(c); - n += println(); - return n; -} - -size_t Print::println(char c) -{ - size_t n = print(c); - n += println(); - return n; -} - -size_t Print::println(unsigned char b, int base) -{ - size_t n = print(b, base); - n += println(); - return n; -} - -size_t Print::println(int num, int base) -{ - size_t n = print(num, base); - n += println(); - return n; -} - -size_t Print::println(unsigned int num, int base) -{ - size_t n = print(num, base); - n += println(); - return n; -} - -size_t Print::println(long num, int base) -{ - size_t n = print(num, base); - n += println(); - return n; -} - -size_t Print::println(unsigned long num, int base) -{ - size_t n = print(num, base); - n += println(); - return n; -} - -size_t Print::println(double num, int digits) -{ - size_t n = print(num, digits); - n += println(); - return n; -} - -size_t Print::println(const Printable& x) -{ - size_t n = print(x); - n += println(); - return n; -} - -// Private Methods ///////////////////////////////////////////////////////////// - -size_t Print::printNumber(unsigned long n, uint8_t base) -{ - char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte. - char *str = &buf[sizeof(buf) - 1]; - - *str = '\0'; - - // prevent crash if called with base == 1 - if (base < 2) base = 10; - - do { - char c = n % base; - n /= base; - - *--str = c < 10 ? c + '0' : c + 'A' - 10; - } while(n); - - return write(str); -} - -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) - { - n += print('-'); - number = -number; - } - - // Round correctly so that print(1.999, 2) prints as "2.00" - double rounding = 0.5; - for (uint8_t i=0; i 0) { - n += print('.'); - } - - // Extract digits from the remainder one at a time - while (digits-- > 0) - { - remainder *= 10.0; - unsigned int toPrint = (unsigned int)(remainder); - n += print(toPrint); - remainder -= toPrint; - } - - return n; -} diff --git a/cores/arduino/Print.h b/cores/arduino/Print.h deleted file mode 100644 index dfb645cbb..000000000 --- a/cores/arduino/Print.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - Copyright (c) 2014 Arduino. 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 Print_h -#define Print_h - -#include -#include // for size_t - -#include "WString.h" -#include "Printable.h" - -#define DEC 10 -#define HEX 16 -#define OCT 8 -#ifdef BIN // Prevent warnings if BIN is previously defined in "iotnx4.h" or similar -#undef BIN -#endif -#define BIN 2 - -class Print -{ - private: - int write_error; - size_t printNumber(unsigned long, uint8_t); - size_t printFloat(double, uint8_t); - protected: - void setWriteError(int err = 1) { write_error = err; } - public: - Print() : write_error(0) {} - - int getWriteError() { return write_error; } - void clearWriteError() { setWriteError(0); } - - virtual size_t write(uint8_t) = 0; - size_t write(const char *str) { - if (str == NULL) return 0; - return write((const uint8_t *)str, strlen(str)); - } - virtual size_t write(const uint8_t *buffer, size_t size); - size_t write(const char *buffer, size_t size) { - return write((const uint8_t *)buffer, size); - } - - // default to zero, meaning "a single write may block" - // should be overriden by subclasses with buffering - virtual int availableForWrite() { return 0; } - - size_t print(const __FlashStringHelper *); - size_t print(const String &); - size_t print(const char[]); - size_t print(char); - size_t print(unsigned char, int = DEC); - size_t print(int, int = DEC); - size_t print(unsigned int, int = DEC); - size_t print(long, int = DEC); - size_t print(unsigned long, int = DEC); - 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); - size_t println(unsigned char, int = DEC); - size_t println(int, int = DEC); - size_t println(unsigned int, int = DEC); - size_t println(long, int = DEC); - size_t println(unsigned long, int = DEC); - size_t println(double, int = 2); - size_t println(const Printable&); - size_t println(void); - - virtual void flush() { /* Empty implementation for backward compatibility */ } -}; - -#endif diff --git a/cores/arduino/Printable.h b/cores/arduino/Printable.h deleted file mode 100644 index 34ad5b4dc..000000000 --- a/cores/arduino/Printable.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - Copyright (c) 2014 Arduino. 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 Printable_h -#define Printable_h - -#include - -class Print; - -/** The Printable class provides a way for new classes to allow themselves to be printed. - By deriving from Printable and implementing the printTo method, it will then be possible - for users to print out instances of this class by passing them into the usual - Print::print and Print::println methods. -*/ - -class Printable -{ - public: - virtual size_t printTo(Print& p) const = 0; -}; - -#endif - diff --git a/cores/arduino/Server.h b/cores/arduino/Server.h deleted file mode 100644 index 69e3e39fe..000000000 --- a/cores/arduino/Server.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - Server.h - Base class that provides Server - Copyright (c) 2011 Adrian McEwen. 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 server_h -#define server_h - -#include "Print.h" - -class Server : public Print { -public: - virtual void begin() =0; -}; - -#endif diff --git a/cores/arduino/Stream.cpp b/cores/arduino/Stream.cpp deleted file mode 100644 index d2846316d..000000000 --- a/cores/arduino/Stream.cpp +++ /dev/null @@ -1,319 +0,0 @@ -/* - Stream.cpp - adds parsing methods to Stream class - Copyright (c) 2008 David A. Mellis. 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 - - Created July 2011 - parsing functions based on TextFinder library by Michael Margolis - - findMulti/findUntil routines written by Jim Leonard/Xuth - */ - -#include "Arduino.h" -#include "Stream.h" - -#define PARSE_TIMEOUT 1000 // default number of milli-seconds to wait - -// protected method to read stream with timeout -int Stream::timedRead() -{ - int c; - _startMillis = millis(); - do { - c = read(); - if (c >= 0) return c; - } while(millis() - _startMillis < _timeout); - return -1; // -1 indicates timeout -} - -// protected method to peek stream with timeout -int Stream::timedPeek() -{ - int c; - _startMillis = millis(); - do { - c = peek(); - if (c >= 0) return c; - } while(millis() - _startMillis < _timeout); - return -1; // -1 indicates timeout -} - -// returns peek of the next digit in the stream or -1 if timeout -// discards non-numeric characters -int Stream::peekNextDigit(LookaheadMode lookahead, bool detectDecimal) -{ - int c; - while (1) { - c = timedPeek(); - - if( c < 0 || - c == '-' || - (c >= '0' && c <= '9') || - (detectDecimal && c == '.')) return c; - - switch( lookahead ){ - case SKIP_NONE: return -1; // Fail code. - case SKIP_WHITESPACE: - switch( c ){ - case ' ': - case '\t': - case '\r': - case '\n': break; - default: return -1; // Fail code. - } - case SKIP_ALL: - break; - } - read(); // discard non-numeric - } -} - -// Public Methods -////////////////////////////////////////////////////////////// - -void Stream::setTimeout(unsigned long timeout) // sets the maximum number of milliseconds to wait -{ - _timeout = timeout; -} - - // find returns true if the target string is found -bool Stream::find(char *target) -{ - return findUntil(target, strlen(target), NULL, 0); -} - -// reads data from the stream until the target string of given length is found -// returns true if target string is found, false if timed out -bool Stream::find(char *target, size_t length) -{ - return findUntil(target, length, NULL, 0); -} - -// as find but search ends if the terminator string is found -bool Stream::findUntil(char *target, char *terminator) -{ - return findUntil(target, strlen(target), terminator, strlen(terminator)); -} - -// reads data from the stream until the target string of the given length is found -// search terminated if the terminator string is found -// returns true if target string is found, false if terminated or timed out -bool Stream::findUntil(char *target, size_t targetLen, char *terminator, size_t termLen) -{ - if (terminator == NULL) { - MultiTarget t[1] = {{target, targetLen, 0}}; - return findMulti(t, 1) == 0 ? true : false; - } else { - MultiTarget t[2] = {{target, targetLen, 0}, {terminator, termLen, 0}}; - return findMulti(t, 2) == 0 ? true : false; - } -} - -// returns the first valid (long) integer value from the current position. -// lookahead determines how parseInt looks ahead in the stream. -// See LookaheadMode enumeration at the top of the file. -// Lookahead is terminated by the first character that is not a valid part of an integer. -// Once parsing commences, 'ignore' will be skipped in the stream. -long Stream::parseInt(LookaheadMode lookahead, char ignore) -{ - bool isNegative = false; - long value = 0; - int c; - - c = peekNextDigit(lookahead, false); - // ignore non numeric leading characters - if(c < 0) - return 0; // zero returned if timeout - - do{ - if(c == ignore) - ; // ignore this character - else if(c == '-') - isNegative = true; - else if(c >= '0' && c <= '9') // is c a digit? - value = value * 10 + c - '0'; - read(); // consume the character we got with peek - c = timedPeek(); - } - while( (c >= '0' && c <= '9') || c == ignore ); - - if(isNegative) - value = -value; - return value; -} - -// as parseInt but returns a floating point value -float Stream::parseFloat(LookaheadMode lookahead, char ignore) -{ - bool isNegative = false; - bool isFraction = false; - long value = 0; - int c; - float fraction = 1.0; - - c = peekNextDigit(lookahead, true); - // ignore non numeric leading characters - if(c < 0) - return 0; // zero returned if timeout - - do{ - if(c == ignore) - ; // ignore - else if(c == '-') - isNegative = true; - else if (c == '.') - isFraction = true; - else if(c >= '0' && c <= '9') { // is c a digit? - value = value * 10 + c - '0'; - if(isFraction) - fraction *= 0.1; - } - read(); // consume the character we got with peek - c = timedPeek(); - } - while( (c >= '0' && c <= '9') || (c == '.' && !isFraction) || c == ignore ); - - if(isNegative) - value = -value; - if(isFraction) - return value * fraction; - else - return value; -} - -// read characters from stream into buffer -// terminates if length characters have been read, or timeout (see setTimeout) -// returns the number of characters placed in the buffer -// the buffer is NOT null terminated. -// -size_t Stream::readBytes(char *buffer, size_t length) -{ - size_t count = 0; - while (count < length) { - int c = timedRead(); - if (c < 0) break; - *buffer++ = (char)c; - count++; - } - return count; -} - - -// as readBytes with terminator character -// terminates if length characters have been read, timeout, or if the terminator character detected -// returns the number of characters placed in the buffer (0 means no valid data found) - -size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length) -{ - if (length < 1) return 0; - size_t index = 0; - while (index < length) { - int c = timedRead(); - if (c < 0 || c == terminator) break; - *buffer++ = (char)c; - index++; - } - return index; // return number of characters, not including null terminator -} - -String Stream::readString() -{ - String ret; - int c = timedRead(); - while (c >= 0) - { - ret += (char)c; - c = timedRead(); - } - return ret; -} - -String Stream::readStringUntil(char terminator) -{ - String ret; - int c = timedRead(); - while (c >= 0 && c != terminator) - { - ret += (char)c; - c = timedRead(); - } - return ret; -} - -int Stream::findMulti( struct Stream::MultiTarget *targets, int tCount) { - // any zero length target string automatically matches and would make - // a mess of the rest of the algorithm. - for (struct MultiTarget *t = targets; t < targets+tCount; ++t) { - if (t->len <= 0) - return t - targets; - } - - while (1) { - int c = timedRead(); - if (c < 0) - return -1; - - for (struct MultiTarget *t = targets; t < targets+tCount; ++t) { - // the simple case is if we match, deal with that first. - if (c == t->str[t->index]) { - if (++t->index == t->len) - return t - targets; - else - continue; - } - - // if not we need to walk back and see if we could have matched further - // down the stream (ie '1112' doesn't match the first position in '11112' - // but it will match the second position so we can't just reset the current - // index to 0 when we find a mismatch. - if (t->index == 0) - continue; - - int origIndex = t->index; - do { - --t->index; - // first check if current char works against the new current index - if (c != t->str[t->index]) - continue; - - // if it's the only char then we're good, nothing more to check - if (t->index == 0) { - t->index++; - break; - } - - // otherwise we need to check the rest of the found string - int diff = origIndex - t->index; - size_t i; - for (i = 0; i < t->index; ++i) { - if (t->str[i] != t->str[i + diff]) - break; - } - - // if we successfully got through the previous loop then our current - // index is good. - if (i == t->index) { - t->index++; - break; - } - - // otherwise we just try the next index - } while (t->index); - } - } - // unreachable - return -1; -} diff --git a/cores/arduino/Stream.h b/cores/arduino/Stream.h deleted file mode 100644 index c3311c3cd..000000000 --- a/cores/arduino/Stream.h +++ /dev/null @@ -1,129 +0,0 @@ -/* - Stream.h - base class for character-based streams. - Copyright (c) 2010 David A. Mellis. 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 - - parsing functions based on TextFinder library by Michael Margolis -*/ - -#ifndef Stream_h -#define Stream_h - -#include -#include "Print.h" - -// compatability macros for testing -/* -#define getInt() parseInt() -#define getInt(ignore) parseInt(ignore) -#define getFloat() parseFloat() -#define getFloat(ignore) parseFloat(ignore) -#define getString( pre_string, post_string, buffer, length) -readBytesBetween( pre_string, terminator, buffer, length) -*/ - -// This enumeration provides the lookahead options for parseInt(), parseFloat() -// The rules set out here are used until either the first valid character is found -// or a time out occurs due to lack of input. -enum LookaheadMode{ - SKIP_ALL, // All invalid characters are ignored. - SKIP_NONE, // Nothing is skipped, and the stream is not touched unless the first waiting character is valid. - SKIP_WHITESPACE // Only tabs, spaces, line feeds & carriage returns are skipped. -}; - -#define NO_IGNORE_CHAR '\x01' // a char not found in a valid ASCII numeric field - -class Stream : public Print -{ - protected: - unsigned long _timeout; // number of milliseconds to wait for the next char before aborting timed read - unsigned long _startMillis; // used for timeout measurement - int timedRead(); // read stream with timeout - int timedPeek(); // peek stream with timeout - int peekNextDigit(LookaheadMode lookahead, bool detectDecimal); // returns the next numeric digit in the stream or -1 if timeout - - public: - virtual int available() = 0; - virtual int read() = 0; - virtual int peek() = 0; - - Stream() {_timeout=1000;} - -// parsing methods - - void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second - unsigned long getTimeout(void) { return _timeout; } - - bool find(char *target); // reads data from the stream until the target string is found - bool find(uint8_t *target) { return find ((char *)target); } - // returns true if target string is found, false if timed out (see setTimeout) - - bool find(char *target, size_t length); // reads data from the stream until the target string of given length is found - bool find(uint8_t *target, size_t length) { return find ((char *)target, length); } - // returns true if target string is found, false if timed out - - bool find(char target) { return find (&target, 1); } - - bool findUntil(char *target, char *terminator); // as find but search ends if the terminator string is found - bool findUntil(uint8_t *target, char *terminator) { return findUntil((char *)target, terminator); } - - bool findUntil(char *target, size_t targetLen, char *terminate, size_t termLen); // as above but search ends if the terminate string is found - bool findUntil(uint8_t *target, size_t targetLen, char *terminate, size_t termLen) {return findUntil((char *)target, targetLen, terminate, termLen); } - - long parseInt(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR); - // returns the first valid (long) integer value from the current position. - // lookahead determines how parseInt looks ahead in the stream. - // See LookaheadMode enumeration at the top of the file. - // Lookahead is terminated by the first character that is not a valid part of an integer. - // Once parsing commences, 'ignore' will be skipped in the stream. - - float parseFloat(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR); - // float version of parseInt - - size_t readBytes( char *buffer, size_t length); // read chars from stream into buffer - size_t readBytes( uint8_t *buffer, size_t length) { return readBytes((char *)buffer, length); } - // terminates if length characters have been read or timeout (see setTimeout) - // returns the number of characters placed in the buffer (0 means no valid data found) - - size_t readBytesUntil( char terminator, char *buffer, size_t length); // as readBytes with terminator character - size_t readBytesUntil( char terminator, uint8_t *buffer, size_t length) { return readBytesUntil(terminator, (char *)buffer, length); } - // terminates if length characters have been read, timeout, or if the terminator character detected - // returns the number of characters placed in the buffer (0 means no valid data found) - - // Arduino String functions to be added here - String readString(); - String readStringUntil(char terminator); - - protected: - long parseInt(char ignore) { return parseInt(SKIP_ALL, ignore); } - float parseFloat(char ignore) { return parseFloat(SKIP_ALL, ignore); } - // These overload exists for compatibility with any class that has derived - // Stream and used parseFloat/Int with a custom ignore character. To keep - // the public API simple, these overload remains protected. - - struct MultiTarget { - const char *str; // string you're searching for - size_t len; // length of string you're searching for - size_t index; // index used by the search routine. - }; - - // This allows you to search for an arbitrary number of strings. - // Returns index of the target that is found first or -1 if timeout occurs. - int findMulti(struct MultiTarget *targets, int tCount); -}; - -#undef NO_IGNORE_CHAR -#endif diff --git a/cores/arduino/Tone.cpp b/cores/arduino/Tone.cpp index d427d6075..37b6b0b0d 100644 --- a/cores/arduino/Tone.cpp +++ b/cores/arduino/Tone.cpp @@ -16,7 +16,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "Tone.h" +#include "Arduino.h" #include "variant.h" #define WAIT_TC16_REGS_SYNC(x) while(x->COUNT16.STATUS.bit.SYNCBUSY); @@ -55,7 +55,7 @@ void toneAccurateClock (uint32_t accurateSystemCoreClockFrequency) toneMaxFrequency = accurateSystemCoreClockFrequency / 2; } -void tone (uint32_t outputPin, uint32_t frequency, uint32_t duration) +void tone (unsigned char outputPin, unsigned int frequency, unsigned long duration) { // Avoid divide by zero error by calling 'noTone' instead @@ -158,7 +158,7 @@ void tone (uint32_t outputPin, uint32_t frequency, uint32_t duration) NVIC_EnableIRQ(TONE_TC_IRQn); } -void noTone (uint32_t outputPin) +void noTone (uint8_t outputPin) { /* 'tone' need to run at least once in order to enable GCLK for * the timers used for the tone-functionality. If 'noTone' is called diff --git a/cores/arduino/Tone.h b/cores/arduino/Tone.h deleted file mode 100644 index cf2705160..000000000 --- a/cores/arduino/Tone.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - Copyright (c) 2015 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 -*/ - -#pragma once - -#ifdef __cplusplus - -#include "Arduino.h" - -void tone(uint32_t _pin, uint32_t frequency, uint32_t duration = 0); -void noTone(uint32_t _pin); - -#endif diff --git a/cores/arduino/USB/CDC.cpp b/cores/arduino/USB/CDC.cpp index 890b67367..e1a133ca8 100644 --- a/cores/arduino/USB/CDC.cpp +++ b/cores/arduino/USB/CDC.cpp @@ -19,6 +19,7 @@ #include #include // Needed for auto-reset with 1200bps port touch #include "CDC.h" +#include "USBAPI.h" #include "SAMD21_USBDevice.h" #include @@ -37,7 +38,9 @@ extern USBDevice_SAMD21G18x usbd; #define CDC_LINESTATE_READY (CDC_LINESTATE_RTS | CDC_LINESTATE_DTR) -typedef struct __attribute__((packed)) { +extern USBDeviceClass USBDevice; + +typedef struct { uint32_t dwDTERate; uint8_t bCharFormat; uint8_t bParityType; diff --git a/cores/arduino/USB/CDC.h b/cores/arduino/USB/CDC.h index a19f588f3..8e88db5b5 100644 --- a/cores/arduino/USB/CDC.h +++ b/cores/arduino/USB/CDC.h @@ -5,7 +5,7 @@ #include "USBDesc.h" #include "USBAPI.h" -#include "PluggableUSB.h" +#include "api/PluggableUSB.h" #define CDC_V1_10 0x0110 @@ -74,88 +74,5 @@ typedef struct } CDCDescriptor; -//================================================================================ -// Serial over CDC (Serial1 is the physical port) - -class Serial_ : public Stream, public PluggableUSBModule { -public: - Serial_(USBDeviceClass &_usb); - - void begin(uint32_t baud_count); - void begin(unsigned long, uint8_t); - void end(void); - - virtual int available(void); - virtual int availableForWrite(void); - virtual int peek(void); - virtual int read(void); - virtual void flush(void); - virtual void clear(void); - virtual size_t write(uint8_t); - virtual size_t write(const uint8_t *buffer, size_t size); - using Print::write; // pull in write(str) from Print - operator bool(); - - size_t readBytes(char *buffer, size_t length); - - // This method allows processing "SEND_BREAK" requests sent by - // the USB host. Those requests indicate that the host wants to - // send a BREAK signal and are accompanied by a single uint16_t - // value, specifying the duration of the break. The value 0 - // means to end any current break, while the value 0xffff means - // to start an indefinite break. - // readBreak() will return the value of the most recent break - // request, but will return it at most once, returning -1 when - // readBreak() is called again (until another break request is - // received, which is again returned once). - // This also mean that if two break requests are received - // without readBreak() being called in between, the value of the - // first request is lost. - // Note that the value returned is a long, so it can return - // 0-0xffff as well as -1. - int32_t readBreak(); - - // These return the settings specified by the USB host for the - // serial port. These aren't really used, but are offered here - // in case a sketch wants to act on these settings. - uint32_t baud(); - uint8_t stopbits(); - uint8_t paritytype(); - uint8_t numbits(); - bool dtr(); - bool rts(); - enum { - ONE_STOP_BIT = 0, - ONE_AND_HALF_STOP_BIT = 1, - TWO_STOP_BITS = 2, - }; - enum { - NO_PARITY = 0, - ODD_PARITY = 1, - EVEN_PARITY = 2, - MARK_PARITY = 3, - SPACE_PARITY = 4, - }; - -protected: - // Implementation of the PUSBListNode - int getInterface(uint8_t* interfaceNum); - int getDescriptor(USBSetup& setup); - bool setup(USBSetup& setup); - uint8_t getShortName(char* name); - void handleEndpoint(int ep); - void enableInterrupt(); - -friend USBDeviceClass; - -private: - int availableForStore(void); - - USBDeviceClass &usb; - bool stalled; - uint32_t epType[3]; -}; -extern Serial_ SerialUSB; - #endif #endif \ No newline at end of file diff --git a/cores/arduino/USB/PluggableUSB.cpp b/cores/arduino/USB/PluggableUSB.cpp deleted file mode 100644 index d90ff2c50..000000000 --- a/cores/arduino/USB/PluggableUSB.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* - PluggableUSB.cpp - Copyright (c) 2015 Arduino LLC - - 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 -*/ - -#include "USBAPI.h" -#include "USBDesc.h" -#include "USBCore.h" -#include "PluggableUSB.h" - -#if defined(USBCON) && defined(PLUGGABLE_USB_ENABLED) - -extern uint32_t EndPoints[]; - -int PluggableUSB_::getInterface(uint8_t* interfaceCount) -{ - int sent = 0; - PluggableUSBModule* node; - for (node = rootNode; node; node = node->next) { - int res = node->getInterface(interfaceCount); - if (res < 0) - return -1; - sent += res; - } - return sent; -} - -int PluggableUSB_::getDescriptor(USBSetup& setup) -{ - PluggableUSBModule* node; - for (node = rootNode; node; node = node->next) { - int ret = node->getDescriptor(setup); - // ret!=0 -> request has been processed - if (ret) - return ret; - } - return 0; -} - -uint8_t PluggableUSB_::getShortName(char *iSerialNum) -{ - PluggableUSBModule* node; - uint8_t size = 0; - for (node = rootNode; node; node = node->next) { - uint8_t len = node->getShortName(iSerialNum); - iSerialNum += len; - size += len; - } - *iSerialNum = 0; - return size; -} - -bool PluggableUSB_::setup(USBSetup& setup) -{ - PluggableUSBModule* node; - for (node = rootNode; node; node = node->next) { - if (node->setup(setup)) { - return true; - } - } - return false; -} - -void PluggableUSB_::handleEndpoint(int ep) -{ - PluggableUSBModule* node; - for (node = rootNode; node; node = node->next) { - node->handleEndpoint(ep); - } -} - -bool PluggableUSB_::plug(PluggableUSBModule *node) -{ - if ((lastEp + node->numEndpoints) > USB_ENDPOINTS) { - return false; - } - - if (!rootNode) { - rootNode = node; - } else { - PluggableUSBModule *current = rootNode; - while (current->next) { - current = current->next; - } - current->next = node; - } - - node->pluggedInterface = lastIf; - node->pluggedEndpoint = lastEp; - lastIf += node->numInterfaces; - for (uint8_t i = 0; i < node->numEndpoints; i++) { - EndPoints[lastEp] = node->endpointType[i]; - lastEp++; - } - return true; - // restart USB layer??? -} - -PluggableUSB_& PluggableUSB() -{ - static PluggableUSB_ obj; - return obj; -} - -PluggableUSB_::PluggableUSB_() : lastIf(0), lastEp(1), rootNode(NULL) -{ - // Empty -} - -#endif \ No newline at end of file diff --git a/cores/arduino/USB/PluggableUSB.h b/cores/arduino/USB/PluggableUSB.h deleted file mode 100644 index e1d8cfa3a..000000000 --- a/cores/arduino/USB/PluggableUSB.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - PluggableUSB.h - Copyright (c) 2015 Arduino LLC - - 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 PUSB_h -#define PUSB_h - -#include "USBAPI.h" -#include - -#if defined(USBCON) - -class PluggableUSBModule { -public: - PluggableUSBModule(uint8_t numEps, uint8_t numIfs, uint32_t *epType) : - numEndpoints(numEps), numInterfaces(numIfs), endpointType(epType) - { } - -protected: - virtual bool setup(USBSetup& setup) = 0; - virtual int getInterface(uint8_t* interfaceCount) = 0; - virtual int getDescriptor(USBSetup& setup) = 0; - virtual void handleEndpoint(int /* ep */) { /* Do nothing */ } - virtual uint8_t getShortName(char *name) { name[0] = 'A'+pluggedInterface; return 1; } - - uint8_t pluggedInterface; - uint8_t pluggedEndpoint; - - const uint8_t numEndpoints; - const uint8_t numInterfaces; - const uint32_t *endpointType; - - PluggableUSBModule *next = NULL; - - friend class PluggableUSB_; -}; - -class PluggableUSB_ { -public: - PluggableUSB_(); - bool plug(PluggableUSBModule *node); - int getInterface(uint8_t* interfaceCount); - int getDescriptor(USBSetup& setup); - bool setup(USBSetup& setup); - void handleEndpoint(int ep); - uint8_t getShortName(char *iSerialNum); - -private: - uint8_t lastIf; - uint8_t lastEp; - PluggableUSBModule* rootNode; -}; - -// Replacement for global singleton. -// This function prevents static-initialization-order-fiasco -// https://isocpp.org/wiki/faq/ctors#static-init-order-on-first-use -PluggableUSB_& PluggableUSB(); - -#endif - -#endif diff --git a/cores/arduino/USB/SAMD21_USBDevice.h b/cores/arduino/USB/SAMD21_USBDevice.h index d1ef4f161..3fff6e1b8 100644 --- a/cores/arduino/USB/SAMD21_USBDevice.h +++ b/cores/arduino/USB/SAMD21_USBDevice.h @@ -24,6 +24,8 @@ #include #include +#include "sync.h" + typedef uint8_t ep_t; class USBDevice_SAMD21G18x { @@ -219,32 +221,6 @@ void USBDevice_SAMD21G18x::calibrate() { usb.PADCAL.bit.TRIM = pad_trim; } -/* - * Synchronization primitives. - * TODO: Move into a separate header file and make an API out of it - */ - -class __Guard { -public: - __Guard() : primask(__get_PRIMASK()), loops(1) { - __disable_irq(); - } - ~__Guard() { - if (primask == 0) { - __enable_irq(); - // http://infocenter.arm.com/help/topic/com.arm.doc.dai0321a/BIHBFEIB.html - __ISB(); - } - } - uint32_t enter() { return loops--; } -private: - uint32_t primask; - uint32_t loops; -}; - -#define synchronized for (__Guard __guard; __guard.enter(); ) - - /* * USB EP generic handlers. */ diff --git a/cores/arduino/USB/USBAPI.h b/cores/arduino/USB/USBAPI.h index 30455acfc..c5cec6257 100644 --- a/cores/arduino/USB/USBAPI.h +++ b/cores/arduino/USB/USBAPI.h @@ -29,29 +29,19 @@ #if defined __cplusplus -#include "Stream.h" -#include "RingBuffer.h" +#include "Arduino.h" +#include "api/Stream.h" +#include "api/RingBuffer.h" +#include "api/USBAPI.h" +#include "CDC.h" + +#if ARDUINO_API_VERSION > 10000 +using namespace arduino; +#endif //================================================================================ // USB -// Low level API -typedef struct __attribute__((packed)) { - union { - uint8_t bmRequestType; - struct { - uint8_t direction : 5; - uint8_t type : 2; - uint8_t transferDirection : 1; - }; - }; - uint8_t bRequest; - uint8_t wValueL; - uint8_t wValueH; - uint16_t wIndex; - uint16_t wLength; -} USBSetup; - class USBDeviceClass { public: USBDeviceClass() {}; @@ -105,16 +95,90 @@ class USBDeviceClass { private: bool initialized; }; - extern USBDeviceClass USBDevice; //================================================================================ -//================================================================================ -// MSC 'Driver' +// Serial over CDC (Serial1 is the physical port) -uint32_t MSC_GetInterface(uint8_t* interfaceNum); -uint32_t MSC_GetDescriptor(uint32_t i); -bool MSC_Setup(USBSetup& setup); -bool MSC_Data(uint8_t rx,uint8_t tx); +class Serial_ : public Stream, public arduino::PluggableUSBModule +{ +public: + Serial_(USBDeviceClass &_usb); + void begin(uint32_t baud_count); + void begin(unsigned long, uint8_t); + void end(void); + + virtual int available(void); + virtual int availableForWrite(void); + virtual int peek(void); + virtual int read(void); + virtual void flush(void); + virtual void clear(void); + virtual size_t write(uint8_t); + virtual size_t write(const uint8_t *buffer, size_t size); + using Print::write; // pull in write(str) from Print + operator bool(); + + size_t readBytes(char *buffer, size_t length); + + // This method allows processing "SEND_BREAK" requests sent by + // the USB host. Those requests indicate that the host wants to + // send a BREAK signal and are accompanied by a single uint16_t + // value, specifying the duration of the break. The value 0 + // means to end any current break, while the value 0xffff means + // to start an indefinite break. + // readBreak() will return the value of the most recent break + // request, but will return it at most once, returning -1 when + // readBreak() is called again (until another break request is + // received, which is again returned once). + // This also mean that if two break requests are received + // without readBreak() being called in between, the value of the + // first request is lost. + // Note that the value returned is a long, so it can return + // 0-0xffff as well as -1. + int32_t readBreak(); + + // These return the settings specified by the USB host for the + // serial port. These aren't really used, but are offered here + // in case a sketch wants to act on these settings. + uint32_t baud(); + uint8_t stopbits(); + uint8_t paritytype(); + uint8_t numbits(); + bool dtr(); + bool rts(); + enum { + ONE_STOP_BIT = 0, + ONE_AND_HALF_STOP_BIT = 1, + TWO_STOP_BITS = 2, + }; + enum { + NO_PARITY = 0, + ODD_PARITY = 1, + EVEN_PARITY = 2, + MARK_PARITY = 3, + SPACE_PARITY = 4, + }; + +protected: + // Implementation of the PUSBListNode + int getInterface(uint8_t* interfaceNum); + int getDescriptor(USBSetup& setup); + bool setup(USBSetup& setup); + uint8_t getShortName(char* name); + void handleEndpoint(int ep); + void enableInterrupt(); + +friend USBDeviceClass; + +private: + int availableForStore(void); + + USBDeviceClass &usb; + bool stalled; + unsigned int epType[3]; + +}; +extern Serial_ SerialUSB; #endif // __cplusplus diff --git a/cores/arduino/USB/USBCore.cpp b/cores/arduino/USB/USBCore.cpp index bf7888acb..e6f33cf94 100644 --- a/cores/arduino/USB/USBCore.cpp +++ b/cores/arduino/USB/USBCore.cpp @@ -20,16 +20,25 @@ #include +#include "api/USBAPI.h" +#include "USBAPI.h" #include "SAMD21_USBDevice.h" -#include "PluggableUSB.h" #include "CDC.h" +#include "api/PluggableUSB.h" #include #include #include #include + +/* + * USB Device instance + * ------------------- + */ + USBDevice_SAMD21G18x usbd; +USBDeviceClass USBDevice; /** Pulse generation counters to keep track of the number of milliseconds remaining for each pulse type */ #define TX_RX_LED_PULSE_MS 100 @@ -223,11 +232,9 @@ bool USBDeviceClass::sendDescriptor(USBSetup &setup) memset(name, 0, sizeof(name)); uint8_t idx = 0; #ifdef PLUGGABLE_USB_ENABLED - idx += PluggableUSB().getShortName(&name[idx]); + PluggableUSB().getShortName(name); + return sendStringDescriptor((uint8_t*)name, setup.wLength); #endif - if (idx > 0) { - return sendStringDescriptor((uint8_t*)name, setup.wLength); - } } else { return false; @@ -911,7 +918,7 @@ void USBDeviceClass::ISRHandler() epHandlers[ep]->handleEndpoint(); } else { #if defined(PLUGGABLE_USB_ENABLED) - PluggableUSB().handleEndpoint(ep); + SerialUSB.handleEndpoint(ep); usbd.epAckPendingInterrupts(ep); #endif } @@ -919,12 +926,16 @@ void USBDeviceClass::ISRHandler() } } -/* - * USB Device instance - * ------------------- - */ +// PluggableUSB contructor +PluggableUSB_::PluggableUSB_() : lastIf(0), + lastEp(1), + rootNode(NULL), totalEP(USB_ENDPOINTS) +{ + // Empty +} -// USBDevice class instance -USBDeviceClass USBDevice; +void* epBuffer(unsigned int lastEp) { + return &(EndPoints[lastEp]); +} #endif diff --git a/cores/arduino/USB/samd21_host.c b/cores/arduino/USB/samd21_host.c index 64255c04f..4066d62f5 100644 --- a/cores/arduino/USB/samd21_host.c +++ b/cores/arduino/USB/samd21_host.c @@ -16,9 +16,16 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include +#include +#include + #include "Arduino.h" +#include "variant.h" #include "USB_host.h" #include "samd21_host.h" +#include "sam.h" #include "wiring_private.h" #define HOST_DEFINED diff --git a/cores/arduino/Uart.cpp b/cores/arduino/Uart.cpp index e7d3adcd4..5f7b3d8fd 100644 --- a/cores/arduino/Uart.cpp +++ b/cores/arduino/Uart.cpp @@ -192,31 +192,31 @@ size_t Uart::write(const uint8_t data) SercomNumberStopBit Uart::extractNbStopBit(uint16_t config) { - switch(config & HARDSER_STOP_BIT_MASK) + switch(config & SERIAL_STOP_BIT_MASK) { - case HARDSER_STOP_BIT_1: + case SERIAL_STOP_BIT_1: default: return SERCOM_STOP_BIT_1; - case HARDSER_STOP_BIT_2: + case SERIAL_STOP_BIT_2: return SERCOM_STOP_BITS_2; } } SercomUartCharSize Uart::extractCharSize(uint16_t config) { - switch(config & HARDSER_DATA_MASK) + switch(config & SERIAL_DATA_MASK) { - case HARDSER_DATA_5: + case SERIAL_DATA_5: return UART_CHAR_SIZE_5_BITS; - case HARDSER_DATA_6: + case SERIAL_DATA_6: return UART_CHAR_SIZE_6_BITS; - case HARDSER_DATA_7: + case SERIAL_DATA_7: return UART_CHAR_SIZE_7_BITS; - case HARDSER_DATA_8: + case SERIAL_DATA_8: default: return UART_CHAR_SIZE_8_BITS; @@ -225,16 +225,16 @@ SercomUartCharSize Uart::extractCharSize(uint16_t config) SercomParityMode Uart::extractParity(uint16_t config) { - switch(config & HARDSER_PARITY_MASK) + switch(config & SERIAL_PARITY_MASK) { - case HARDSER_PARITY_NONE: + case SERIAL_PARITY_NONE: default: return SERCOM_NO_PARITY; - case HARDSER_PARITY_EVEN: + case SERIAL_PARITY_EVEN: return SERCOM_EVEN_PARITY; - case HARDSER_PARITY_ODD: + case SERIAL_PARITY_ODD: return SERCOM_ODD_PARITY; } } diff --git a/cores/arduino/Uart.h b/cores/arduino/Uart.h index 8f80ea9ce..62ed3bbb8 100644 --- a/cores/arduino/Uart.h +++ b/cores/arduino/Uart.h @@ -18,11 +18,11 @@ #pragma once -#include "HardwareSerial.h" +#include "api/HardwareSerial.h" #include "SERCOM.h" -#include "RingBuffer.h" +#include "api/RingBuffer.h" -#include +#define SERIAL_BUFFER_SIZE 64 class Uart : public HardwareSerial { diff --git a/cores/arduino/WCharacter.h b/cores/arduino/WCharacter.h deleted file mode 100644 index c0cbec7ae..000000000 --- a/cores/arduino/WCharacter.h +++ /dev/null @@ -1,179 +0,0 @@ -/* - Copyright (c) 2014 Arduino. 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 - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -// WCharacter.h prototypes -#if defined ( __GNUC__ ) -inline boolean isAlphaNumeric(int c) __attribute__((always_inline)); -inline boolean isAlpha(int c) __attribute__((always_inline)); -inline boolean isAscii(int c) __attribute__((always_inline)); -inline boolean isWhitespace(int c) __attribute__((always_inline)); -inline boolean isControl(int c) __attribute__((always_inline)); -inline boolean isDigit(int c) __attribute__((always_inline)); -inline boolean isGraph(int c) __attribute__((always_inline)); -inline boolean isLowerCase(int c) __attribute__((always_inline)); -inline boolean isPrintable(int c) __attribute__((always_inline)); -inline boolean isPunct(int c) __attribute__((always_inline)); -inline boolean isSpace(int c) __attribute__((always_inline)); -inline boolean isUpperCase(int c) __attribute__((always_inline)); -inline boolean 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)); -#elif defined ( __ICCARM__ ) -#endif - -// Checks for an alphanumeric character. -// It is equivalent to (isalpha(c) || isdigit(c)). -inline boolean isAlphaNumeric(int c) -{ - return ( isalnum(c) == 0 ? false : true); -} - - -// Checks for an alphabetic character. -// It is equivalent to (isupper(c) || islower(c)). -inline boolean 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 boolean isAscii(int c) -{ -/* return ( isascii(c) == 0 ? false : true); */ - return ( (c & ~0x7f) != 0 ? false : true); -} - - -// Checks for a blank character, that is, a space or a tab. -inline boolean isWhitespace(int c) -{ - return ( isblank (c) == 0 ? false : true); -} - - -// Checks for a control character. -inline boolean isControl(int c) -{ - return ( iscntrl (c) == 0 ? false : true); -} - - -// Checks for a digit (0 through 9). -inline boolean isDigit(int c) -{ - return ( isdigit (c) == 0 ? false : true); -} - - -// Checks for any printable character except space. -inline boolean isGraph(int c) -{ - return ( isgraph (c) == 0 ? false : true); -} - - -// Checks for a lower-case character. -inline boolean isLowerCase(int c) -{ - return (islower (c) == 0 ? false : true); -} - - -// Checks for any printable character including space. -inline boolean isPrintable(int c) -{ - return ( isprint (c) == 0 ? false : true); -} - - -// Checks for any printable character which is not a space -// or an alphanumeric character. -inline boolean 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 boolean isSpace(int c) -{ - return ( isspace (c) == 0 ? false : true); -} - - -// Checks for an uppercase letter. -inline boolean 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 boolean 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); */ - return (c & 0x7f); -} - - -// 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); -} - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/cores/arduino/WInterrupts.c b/cores/arduino/WInterrupts.c index c78ddf62b..9b542a297 100644 --- a/cores/arduino/WInterrupts.c +++ b/cores/arduino/WInterrupts.c @@ -25,7 +25,6 @@ static voidFuncPtr ISRcallback[EXTERNAL_NUM_INTERRUPTS]; static uint32_t ISRlist[EXTERNAL_NUM_INTERRUPTS]; static uint32_t nints; // Stores total number of attached interrupts - /* Configure I/O interrupt sources */ static void __initialize() { @@ -56,7 +55,7 @@ static void __initialize() * \brief Specifies a named Interrupt Service Routine (ISR) to call when an interrupt occurs. * Replaces any previous function that was attached to the interrupt. */ -void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode) +void attachInterrupt(pin_size_t pin, voidFuncPtr callback, PinStatus mode) { static int enabled = 0; uint32_t config; @@ -145,7 +144,7 @@ void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode) /* * \brief Turns off the given interrupt. */ -void detachInterrupt(uint32_t pin) +void detachInterrupt(pin_size_t pin) { #if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606) EExt_Interrupts in = g_APinDescription[pin].ulExtInt; diff --git a/cores/arduino/WInterrupts.h b/cores/arduino/WInterrupts.h deleted file mode 100644 index 5d2b24a0d..000000000 --- a/cores/arduino/WInterrupts.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - Copyright (c) 2015 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 _WIRING_INTERRUPTS_ -#define _WIRING_INTERRUPTS_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -// LOW 0 -// HIGH 1 -#define CHANGE 2 -#define FALLING 3 -#define RISING 4 - -#define DEFAULT 1 -#define EXTERNAL 0 - -typedef void (*voidFuncPtr)(void); - -/* - * \brief Specifies a named Interrupt Service Routine (ISR) to call when an interrupt occurs. - * Replaces any previous function that was attached to the interrupt. - */ -void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode); - -/* - * \brief Turns off the given interrupt. - */ -void detachInterrupt(uint32_t pin); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/cores/arduino/WMath.cpp b/cores/arduino/WMath.cpp index 55caddd62..2c6cdc3fe 100644 --- a/cores/arduino/WMath.cpp +++ b/cores/arduino/WMath.cpp @@ -20,9 +20,8 @@ extern "C" { #include "stdlib.h" #include "stdint.h" } -#include "WMath.h" -extern void randomSeed( uint32_t dwSeed ) +void randomSeed( uint32_t dwSeed ) { if ( dwSeed != 0 ) { @@ -30,7 +29,7 @@ extern void randomSeed( uint32_t dwSeed ) } } -extern long random( long howbig ) +long random( long howbig ) { if ( howbig == 0 ) { @@ -40,7 +39,7 @@ extern long random( long howbig ) return rand() % howbig; } -extern long random( long howsmall, long howbig ) +long random( long howsmall, long howbig ) { if (howsmall >= howbig) { @@ -51,18 +50,3 @@ extern long random( long howsmall, long howbig ) return random(diff) + howsmall; } - -extern 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; -} - -extern uint16_t makeWord( uint16_t w ) -{ - return w ; -} - -extern uint16_t makeWord( uint8_t h, uint8_t l ) -{ - return (h << 8) | l ; -} diff --git a/cores/arduino/WMath.h b/cores/arduino/WMath.h deleted file mode 100644 index 1893955cb..000000000 --- a/cores/arduino/WMath.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - Copyright (c) 2014 Arduino. 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 _WIRING_MATH_ -#define _WIRING_MATH_ - -extern long random( long ) ; -extern long random( long, long ) ; -extern void randomSeed( uint32_t dwSeed ) ; -extern long map( long, long, long, long, long ) ; - -extern uint16_t makeWord( uint16_t w ) ; -extern uint16_t makeWord( uint8_t h, uint8_t l ) ; - -#define word(...) makeWord(__VA_ARGS__) - - -#endif /* _WIRING_MATH_ */ diff --git a/cores/arduino/WString.cpp b/cores/arduino/WString.cpp deleted file mode 100644 index 4c0155998..000000000 --- a/cores/arduino/WString.cpp +++ /dev/null @@ -1,752 +0,0 @@ -/* - WString.cpp - String library for Wiring & Arduino - ...mostly rewritten by Paul Stoffregen... - Copyright (c) 2009-10 Hernando Barragan. All rights reserved. - Copyright 2011, Paul Stoffregen, paul@pjrc.com - - 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 -*/ - -#include "WString.h" -#include "itoa.h" -#include "avr/dtostrf.h" - -/*********************************************/ -/* Constructors */ -/*********************************************/ - -String::String(const char *cstr) -{ - init(); - if (cstr) copy(cstr, strlen(cstr)); -} - -String::String(const String &value) -{ - init(); - *this = value; -} - -String::String(const __FlashStringHelper *pstr) -{ - init(); - *this = pstr; -} - -#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) -String::String(String &&rval) -{ - init(); - move(rval); -} -String::String(StringSumHelper &&rval) -{ - init(); - move(rval); -} -#endif - -String::String(char c) -{ - init(); - char buf[2]; - buf[0] = c; - buf[1] = 0; - *this = buf; -} - -String::String(unsigned char value, unsigned char base) -{ - init(); - char buf[1 + 8 * sizeof(unsigned char)]; - utoa(value, buf, base); - *this = buf; -} - -String::String(int value, unsigned char base) -{ - init(); - char buf[2 + 8 * sizeof(int)]; - itoa(value, buf, base); - *this = buf; -} - -String::String(unsigned int value, unsigned char base) -{ - init(); - char buf[1 + 8 * sizeof(unsigned int)]; - utoa(value, buf, base); - *this = buf; -} - -String::String(long value, unsigned char base) -{ - init(); - char buf[2 + 8 * sizeof(long)]; - ltoa(value, buf, base); - *this = buf; -} - -String::String(unsigned long value, unsigned char base) -{ - init(); - char buf[1 + 8 * sizeof(unsigned long)]; - ultoa(value, buf, base); - *this = buf; -} - -String::String(float value, unsigned char decimalPlaces) -{ - init(); - char buf[33]; - *this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf); -} - -String::String(double value, unsigned char decimalPlaces) -{ - init(); - char buf[33]; - *this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf); -} - -String::~String() -{ - if (buffer) free(buffer); -} - -/*********************************************/ -/* Memory Management */ -/*********************************************/ - -inline void String::init(void) -{ - buffer = NULL; - capacity = 0; - len = 0; -} - -void String::invalidate(void) -{ - if (buffer) free(buffer); - buffer = NULL; - capacity = len = 0; -} - -unsigned char String::reserve(unsigned int size) -{ - if (buffer && capacity >= size) return 1; - if (changeBuffer(size)) { - if (len == 0) buffer[0] = 0; - return 1; - } - return 0; -} - -unsigned char String::changeBuffer(unsigned int maxStrLen) -{ - char *newbuffer = (char *)realloc(buffer, maxStrLen + 1); - if (newbuffer) { - buffer = newbuffer; - capacity = maxStrLen; - return 1; - } - return 0; -} - -/*********************************************/ -/* Copy and Move */ -/*********************************************/ - -String & String::copy(const char *cstr, unsigned int length) -{ - if (!reserve(length)) { - invalidate(); - return *this; - } - len = length; - strcpy(buffer, cstr); - 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) -{ - if (buffer) { - if (rhs && capacity >= rhs.len) { - strcpy(buffer, rhs.buffer); - len = rhs.len; - rhs.len = 0; - return; - } else { - free(buffer); - } - } - buffer = rhs.buffer; - capacity = rhs.capacity; - len = rhs.len; - rhs.buffer = NULL; - rhs.capacity = 0; - rhs.len = 0; -} -#endif - -String & String::operator = (const String &rhs) -{ - if (this == &rhs) return *this; - - if (rhs.buffer) copy(rhs.buffer, rhs.len); - else invalidate(); - - return *this; -} - -#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) -String & String::operator = (String &&rval) -{ - if (this != &rval) move(rval); - return *this; -} - -String & String::operator = (StringSumHelper &&rval) -{ - if (this != &rval) move(rval); - return *this; -} -#endif - -String & String::operator = (const char *cstr) -{ - if (cstr) copy(cstr, strlen(cstr)); - else invalidate(); - - return *this; -} - -String & String::operator = (const __FlashStringHelper *pstr) -{ - if (pstr) copy(pstr, strlen_P((PGM_P)pstr)); - else invalidate(); - - return *this; -} - -/*********************************************/ -/* concat */ -/*********************************************/ - -unsigned char String::concat(const String &s) -{ - return concat(s.buffer, s.len); -} - -unsigned char String::concat(const char *cstr, unsigned int length) -{ - unsigned int newlen = len + length; - if (!cstr) return 0; - if (length == 0) return 1; - if (!reserve(newlen)) return 0; - strcpy(buffer + len, cstr); - len = newlen; - return 1; -} - -unsigned char String::concat(const char *cstr) -{ - if (!cstr) return 0; - return concat(cstr, strlen(cstr)); -} - -unsigned char String::concat(char c) -{ - char buf[2]; - buf[0] = c; - buf[1] = 0; - return concat(buf, 1); -} - -unsigned char String::concat(unsigned char num) -{ - char buf[1 + 3 * sizeof(unsigned char)]; - itoa(num, buf, 10); - return concat(buf, strlen(buf)); -} - -unsigned char String::concat(int num) -{ - char buf[2 + 3 * sizeof(int)]; - itoa(num, buf, 10); - return concat(buf, strlen(buf)); -} - -unsigned char String::concat(unsigned int num) -{ - char buf[1 + 3 * sizeof(unsigned int)]; - utoa(num, buf, 10); - return concat(buf, strlen(buf)); -} - -unsigned char String::concat(long num) -{ - char buf[2 + 3 * sizeof(long)]; - ltoa(num, buf, 10); - return concat(buf, strlen(buf)); -} - -unsigned char String::concat(unsigned long num) -{ - char buf[1 + 3 * sizeof(unsigned long)]; - ultoa(num, buf, 10); - return concat(buf, strlen(buf)); -} - -unsigned char String::concat(float num) -{ - char buf[20]; - char* string = dtostrf(num, 4, 2, buf); - return concat(string, strlen(string)); -} - -unsigned char String::concat(double num) -{ - char buf[20]; - char* string = dtostrf(num, 4, 2, buf); - return concat(string, strlen(string)); -} - -unsigned char String::concat(const __FlashStringHelper * str) -{ - 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; -} - -/*********************************************/ -/* Concatenate */ -/*********************************************/ - -StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs) -{ - StringSumHelper &a = const_cast(lhs); - if (!a.concat(rhs.buffer, rhs.len)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr) -{ - StringSumHelper &a = const_cast(lhs); - if (!cstr || !a.concat(cstr, strlen(cstr))) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, char c) -{ - StringSumHelper &a = const_cast(lhs); - if (!a.concat(c)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, unsigned char num) -{ - StringSumHelper &a = const_cast(lhs); - if (!a.concat(num)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, int num) -{ - StringSumHelper &a = const_cast(lhs); - if (!a.concat(num)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, unsigned int num) -{ - StringSumHelper &a = const_cast(lhs); - if (!a.concat(num)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, long num) -{ - StringSumHelper &a = const_cast(lhs); - if (!a.concat(num)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, unsigned long num) -{ - StringSumHelper &a = const_cast(lhs); - if (!a.concat(num)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, float num) -{ - StringSumHelper &a = const_cast(lhs); - if (!a.concat(num)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, double num) -{ - StringSumHelper &a = const_cast(lhs); - if (!a.concat(num)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, const __FlashStringHelper *rhs) -{ - StringSumHelper &a = const_cast(lhs); - if (!a.concat(rhs)) a.invalidate(); - return a; -} - -/*********************************************/ -/* Comparison */ -/*********************************************/ - -int String::compareTo(const String &s) const -{ - if (!buffer || !s.buffer) { - if (s.buffer && s.len > 0) return 0 - *(unsigned char *)s.buffer; - if (buffer && len > 0) return *(unsigned char *)buffer; - return 0; - } - return strcmp(buffer, s.buffer); -} - -unsigned char String::equals(const String &s2) const -{ - return (len == s2.len && compareTo(s2) == 0); -} - -unsigned char String::equals(const char *cstr) const -{ - if (len == 0) return (cstr == NULL || *cstr == 0); - if (cstr == NULL) return buffer[0] == 0; - return strcmp(buffer, cstr) == 0; -} - -unsigned char String::operator<(const String &rhs) const -{ - return compareTo(rhs) < 0; -} - -unsigned char String::operator>(const String &rhs) const -{ - return compareTo(rhs) > 0; -} - -unsigned char String::operator<=(const String &rhs) const -{ - return compareTo(rhs) <= 0; -} - -unsigned char String::operator>=(const String &rhs) const -{ - return compareTo(rhs) >= 0; -} - -unsigned char String::equalsIgnoreCase( const String &s2 ) const -{ - if (this == &s2) return 1; - if (len != s2.len) return 0; - if (len == 0) return 1; - const char *p1 = buffer; - const char *p2 = s2.buffer; - while (*p1) { - if (tolower(*p1++) != tolower(*p2++)) return 0; - } - return 1; -} - -unsigned char String::startsWith( const String &s2 ) const -{ - if (len < s2.len) return 0; - return startsWith(s2, 0); -} - -unsigned char String::startsWith( const String &s2, unsigned int offset ) const -{ - if (offset > len - s2.len || !buffer || !s2.buffer) return 0; - return strncmp( &buffer[offset], s2.buffer, s2.len ) == 0; -} - -unsigned char String::endsWith( const String &s2 ) const -{ - if ( len < s2.len || !buffer || !s2.buffer) return 0; - return strcmp(&buffer[len - s2.len], s2.buffer) == 0; -} - -/*********************************************/ -/* Character Access */ -/*********************************************/ - -char String::charAt(unsigned int loc) const -{ - return operator[](loc); -} - -void String::setCharAt(unsigned int loc, char c) -{ - if (loc < len) buffer[loc] = c; -} - -char & String::operator[](unsigned int index) -{ - static char dummy_writable_char; - if (index >= len || !buffer) { - dummy_writable_char = 0; - return dummy_writable_char; - } - return buffer[index]; -} - -char String::operator[]( unsigned int index ) const -{ - if (index >= len || !buffer) return 0; - return buffer[index]; -} - -void String::getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index) const -{ - if (!bufsize || !buf) return; - if (index >= len) { - buf[0] = 0; - return; - } - unsigned int n = bufsize - 1; - if (n > len - index) n = len - index; - strncpy((char *)buf, buffer + index, n); - buf[n] = 0; -} - -/*********************************************/ -/* Search */ -/*********************************************/ - -int String::indexOf(char c) const -{ - return indexOf(c, 0); -} - -int String::indexOf( char ch, unsigned int fromIndex ) const -{ - if (fromIndex >= len) return -1; - const char* temp = strchr(buffer + fromIndex, ch); - if (temp == NULL) return -1; - return temp - buffer; -} - -int String::indexOf(const String &s2) const -{ - return indexOf(s2, 0); -} - -int String::indexOf(const String &s2, unsigned int fromIndex) const -{ - if (fromIndex >= len) return -1; - const char *found = strstr(buffer + fromIndex, s2.buffer); - if (found == NULL) return -1; - return found - buffer; -} - -int String::lastIndexOf( char theChar ) const -{ - return lastIndexOf(theChar, len - 1); -} - -int String::lastIndexOf(char ch, unsigned int fromIndex) const -{ - if (fromIndex >= len) return -1; - char tempchar = buffer[fromIndex + 1]; - buffer[fromIndex + 1] = '\0'; - char* temp = strrchr( buffer, ch ); - buffer[fromIndex + 1] = tempchar; - if (temp == NULL) return -1; - return temp - buffer; -} - -int String::lastIndexOf(const String &s2) const -{ - return lastIndexOf(s2, len - s2.len); -} - -int String::lastIndexOf(const String &s2, unsigned int fromIndex) const -{ - 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++) { - p = strstr(p, s2.buffer); - if (!p) break; - if ((unsigned int)(p - buffer) <= fromIndex) found = p - buffer; - } - return found; -} - -String String::substring(unsigned int left, unsigned int right) const -{ - if (left > right) { - unsigned int temp = right; - right = left; - left = temp; - } - String out; - if (left >= len) return out; - if (right > len) right = len; - char temp = buffer[right]; // save the replaced character - buffer[right] = '\0'; - out = buffer + left; // pointer arithmetic - buffer[right] = temp; //restore character - return out; -} - -/*********************************************/ -/* Modification */ -/*********************************************/ - -void String::replace(char find, char replace) -{ - if (!buffer) return; - for (char *p = buffer; *p; p++) { - if (*p == find) *p = replace; - } -} - -void String::replace(const String& find, const String& replace) -{ - if (len == 0 || find.len == 0) return; - int diff = replace.len - find.len; - char *readFrom = buffer; - char *foundAt; - if (diff == 0) { - while ((foundAt = strstr(readFrom, find.buffer)) != NULL) { - memcpy(foundAt, replace.buffer, replace.len); - readFrom = foundAt + replace.len; - } - } else if (diff < 0) { - char *writeTo = buffer; - while ((foundAt = strstr(readFrom, find.buffer)) != NULL) { - unsigned int n = foundAt - readFrom; - memcpy(writeTo, readFrom, n); - writeTo += n; - memcpy(writeTo, replace.buffer, replace.len); - writeTo += replace.len; - readFrom = foundAt + find.len; - len += diff; - } - strcpy(writeTo, readFrom); - } else { - unsigned int size = len; // compute size needed for result - while ((foundAt = strstr(readFrom, find.buffer)) != NULL) { - readFrom = foundAt + find.len; - size += diff; - } - if (size == len) return; - if (size > capacity && !changeBuffer(size)) return; // XXX: tell user! - int index = len - 1; - while (index >= 0 && (index = lastIndexOf(find, index)) >= 0) { - readFrom = buffer + index + find.len; - memmove(readFrom + diff, readFrom, len - (readFrom - buffer)); - len += diff; - buffer[len] = 0; - memcpy(buffer + index, replace.buffer, replace.len); - index--; - } - } -} - -void String::remove(unsigned int index){ - // Pass the biggest integer as the count. The remove method - // below will take care of truncating it at the end of the - // string. - remove(index, (unsigned int)-1); -} - -void String::remove(unsigned int index, unsigned int count){ - if (index >= len) { return; } - if (count <= 0) { return; } - if (count > len - index) { count = len - index; } - char *writeTo = buffer + index; - len = len - count; - strncpy(writeTo, buffer + index + count,len - index); - buffer[len] = 0; -} - -void String::toLowerCase(void) -{ - if (!buffer) return; - for (char *p = buffer; *p; p++) { - *p = tolower(*p); - } -} - -void String::toUpperCase(void) -{ - if (!buffer) return; - for (char *p = buffer; *p; p++) { - *p = toupper(*p); - } -} - -void String::trim(void) -{ - if (!buffer || len == 0) return; - char *begin = buffer; - while (isspace(*begin)) begin++; - char *end = buffer + len - 1; - while (isspace(*end) && end >= begin) end--; - len = end + 1 - begin; - if (begin > buffer) memcpy(buffer, begin, len); - buffer[len] = 0; -} - -/*********************************************/ -/* Parsing / Conversion */ -/*********************************************/ - -long String::toInt(void) const -{ - if (buffer) return atol(buffer); - return 0; -} - -float String::toFloat(void) const -{ - return float(toDouble()); -} - -double String::toDouble(void) const -{ - if (buffer) return atof(buffer); - return 0; -} diff --git a/cores/arduino/WString.h b/cores/arduino/WString.h deleted file mode 100644 index 77709c3ba..000000000 --- a/cores/arduino/WString.h +++ /dev/null @@ -1,229 +0,0 @@ -/* - WString.h - String library for Wiring & Arduino - ...mostly rewritten by Paul Stoffregen... - Copyright (c) 2009-10 Hernando Barragan. All right reserved. - Copyright 2011, Paul Stoffregen, paul@pjrc.com - - 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 String_class_h -#define String_class_h -#ifdef __cplusplus - -#include -#include -#include -#include - -// When compiling programs with this class, the following gcc parameters -// dramatically increase performance and memory (RAM) efficiency, typically -// with little or no increase in code size. -// -felide-constructors -// -std=c++0x - -class __FlashStringHelper; -#define F(string_literal) (reinterpret_cast(PSTR(string_literal))) - -// An inherited class for holding the result of a concatenation. These -// result objects are assumed to be writable by subsequent concatenations. -class StringSumHelper; - -// The string class -class String -{ - // use a function pointer to allow for "if (s)" without the - // complications of an operator bool(). for more information, see: - // http://www.artima.com/cppsource/safebool.html - typedef void (String::*StringIfHelperType)() const; - void StringIfHelper() const {} - -public: - // constructors - // creates a copy of the initial value. - // if the initial value is null or invalid, or if memory allocation - // fails, the string will be marked as invalid (i.e. "if (s)" will - // be false). - String(const char *cstr = ""); - String(const String &str); - String(const __FlashStringHelper *str); - #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) - String(String &&rval); - String(StringSumHelper &&rval); - #endif - explicit String(char c); - explicit String(unsigned char, unsigned char base=10); - explicit String(int, unsigned char base=10); - explicit String(unsigned int, unsigned char base=10); - explicit String(long, unsigned char base=10); - explicit String(unsigned long, unsigned char base=10); - explicit String(float, unsigned char decimalPlaces=2); - explicit String(double, unsigned char decimalPlaces=2); - ~String(void); - - // memory management - // return true on success, false on failure (in which case, the string - // is left unchanged). reserve(0), if successful, will validate an - // invalid string (i.e., "if (s)" will be true afterwards) - unsigned char reserve(unsigned int size); - inline unsigned int length(void) const {return len;} - - // creates a copy of the assigned value. if the value is null or - // invalid, or if the memory allocation fails, the string will be - // marked as invalid ("if (s)" will be false). - String & operator = (const String &rhs); - String & operator = (const char *cstr); - String & operator = (const __FlashStringHelper *str); - #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) - String & operator = (String &&rval); - String & operator = (StringSumHelper &&rval); - #endif - - // concatenate (works w/ built-in types) - - // returns true on success, false on failure (in which case, the string - // is left unchanged). if the argument is null or invalid, the - // concatenation is considered unsucessful. - unsigned char concat(const String &str); - unsigned char concat(const char *cstr); - unsigned char concat(char c); - unsigned char concat(unsigned char c); - unsigned char concat(int num); - unsigned char concat(unsigned int num); - unsigned char concat(long num); - unsigned char concat(unsigned long num); - unsigned char concat(float num); - unsigned char concat(double num); - unsigned char concat(const __FlashStringHelper * str); - - // if there's not enough memory for the concatenated value, the string - // will be left unchanged (but this isn't signalled in any way) - String & operator += (const String &rhs) {concat(rhs); return (*this);} - String & operator += (const char *cstr) {concat(cstr); return (*this);} - String & operator += (char c) {concat(c); return (*this);} - String & operator += (unsigned char num) {concat(num); return (*this);} - String & operator += (int num) {concat(num); return (*this);} - String & operator += (unsigned int num) {concat(num); return (*this);} - String & operator += (long num) {concat(num); return (*this);} - 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);} - - friend StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs); - friend StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr); - friend StringSumHelper & operator + (const StringSumHelper &lhs, char c); - friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned char num); - friend StringSumHelper & operator + (const StringSumHelper &lhs, int num); - friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned int num); - friend StringSumHelper & operator + (const StringSumHelper &lhs, long num); - 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); - - // comparison (only works w/ Strings and "strings") - operator StringIfHelperType() const { return buffer ? &String::StringIfHelper : 0; } - int compareTo(const String &s) const; - unsigned char equals(const String &s) const; - unsigned char equals(const char *cstr) const; - unsigned char operator == (const String &rhs) const {return equals(rhs);} - unsigned char operator == (const char *cstr) const {return equals(cstr);} - unsigned char operator != (const String &rhs) const {return !equals(rhs);} - unsigned char operator != (const char *cstr) const {return !equals(cstr);} - unsigned char operator < (const String &rhs) const; - unsigned char operator > (const String &rhs) const; - unsigned char operator <= (const String &rhs) const; - unsigned char operator >= (const String &rhs) const; - unsigned char equalsIgnoreCase(const String &s) const; - unsigned char startsWith( const String &prefix) const; - unsigned char startsWith(const String &prefix, unsigned int offset) const; - unsigned char endsWith(const String &suffix) const; - - // character acccess - char charAt(unsigned int index) const; - void setCharAt(unsigned int index, char c); - char operator [] (unsigned int index) const; - char& operator [] (unsigned int index); - void getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index=0) const; - void toCharArray(char *buf, unsigned int bufsize, unsigned int index=0) const - { getBytes((unsigned char *)buf, bufsize, index); } - const char* c_str() const { return buffer; } - char* begin() { return buffer; } - char* end() { return buffer + length(); } - const char* begin() const { return c_str(); } - const char* end() const { return c_str() + length(); } - - // search - int indexOf( char ch ) const; - int indexOf( char ch, unsigned int fromIndex ) const; - int indexOf( const String &str ) const; - int indexOf( const String &str, unsigned int fromIndex ) const; - int lastIndexOf( char ch ) const; - int lastIndexOf( char ch, unsigned int fromIndex ) const; - int lastIndexOf( const String &str ) const; - int lastIndexOf( const String &str, unsigned int fromIndex ) const; - String substring( unsigned int beginIndex ) const { return substring(beginIndex, len); }; - String substring( unsigned int beginIndex, unsigned int endIndex ) const; - - // modification - void replace(char find, char replace); - void replace(const String& find, const String& replace); - void remove(unsigned int index); - void remove(unsigned int index, unsigned int count); - void toLowerCase(void); - void toUpperCase(void); - void trim(void); - - // parsing/conversion - long toInt(void) const; - float toFloat(void) const; - double toDouble(void) const; - -protected: - char *buffer; // the actual char array - unsigned int capacity; // the array length minus one (for the '\0') - unsigned int len; // the String length (not counting the '\0') -protected: - void init(void); - void invalidate(void); - unsigned char changeBuffer(unsigned int maxStrLen); - unsigned char concat(const char *cstr, unsigned int length); - - // 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 -}; - -class StringSumHelper : public String -{ -public: - StringSumHelper(const String &s) : String(s) {} - StringSumHelper(const char *p) : String(p) {} - StringSumHelper(char c) : String(c) {} - StringSumHelper(unsigned char num) : String(num) {} - StringSumHelper(int num) : String(num) {} - StringSumHelper(unsigned int num) : String(num) {} - StringSumHelper(long num) : String(num) {} - StringSumHelper(unsigned long num) : String(num) {} - StringSumHelper(float num) : String(num) {} - StringSumHelper(double num) : String(num) {} -}; - -#endif // __cplusplus -#endif // String_class_h diff --git a/cores/arduino/avr/dtostrf.c b/cores/arduino/avr/dtostrf.c deleted file mode 100644 index de164277b..000000000 --- a/cores/arduino/avr/dtostrf.c +++ /dev/null @@ -1,30 +0,0 @@ -/* - dtostrf - Emulation for dtostrf function from avr-libc - Copyright (c) 2015 Arduino LLC. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - 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 -*/ - -#include - -char *dtostrf (double val, signed char width, unsigned char prec, char *sout) { - asm(".global _printf_float"); - - char fmt[20]; - sprintf(fmt, "%%%d.%df", width, prec); - sprintf(sout, fmt, val); - return sout; -} - diff --git a/cores/arduino/avr/dtostrf.h b/cores/arduino/avr/dtostrf.h deleted file mode 100644 index 762a8864a..000000000 --- a/cores/arduino/avr/dtostrf.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - dtostrf - Emulation for dtostrf function from avr-libc - Copyright (c) 2015 Arduino LLC. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - 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 -*/ - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -char *dtostrf(double val, signed char width, unsigned char prec, char *sout); - -#ifdef __cplusplus -} -#endif diff --git a/cores/arduino/avr/interrupt.h b/cores/arduino/avr/interrupt.h deleted file mode 100644 index 950509dde..000000000 --- a/cores/arduino/avr/interrupt.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - Copyright (c) 2015 Arduino LCC. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -/* - Empty file. - This file is here to allow compatibility with sketches (made for AVR) - that includes -*/ diff --git a/cores/arduino/avr/io.h b/cores/arduino/avr/io.h deleted file mode 100644 index 33d20cdd2..000000000 --- a/cores/arduino/avr/io.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - io.h - Definitions for compatibility with AVR io macros - - Copyright (c) 2016 Arduino LLC - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE -*/ - -#ifndef _IO_H_ -#define _IO_H_ - -#define RAMSTART (HMCRAMC0_ADDR) -#define RAMSIZE (HMCRAMC0_SIZE) -#define RAMEND (RAMSTART + RAMSIZE - 1) - -#endif diff --git a/cores/arduino/avr/pgmspace.h b/cores/arduino/avr/pgmspace.h deleted file mode 100644 index de92051a9..000000000 --- a/cores/arduino/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 diff --git a/cores/arduino/binary.h b/cores/arduino/binary.h deleted file mode 100644 index aec4c733d..000000000 --- a/cores/arduino/binary.h +++ /dev/null @@ -1,534 +0,0 @@ -/* - binary.h - Definitions for binary constants - Copyright (c) 2006 David A. Mellis. 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 Binary_h -#define Binary_h - -#define B0 0 -#define B00 0 -#define B000 0 -#define B0000 0 -#define B00000 0 -#define B000000 0 -#define B0000000 0 -#define B00000000 0 -#define B1 1 -#define B01 1 -#define B001 1 -#define B0001 1 -#define B00001 1 -#define B000001 1 -#define B0000001 1 -#define B00000001 1 -#define B10 2 -#define B010 2 -#define B0010 2 -#define B00010 2 -#define B000010 2 -#define B0000010 2 -#define B00000010 2 -#define B11 3 -#define B011 3 -#define B0011 3 -#define B00011 3 -#define B000011 3 -#define B0000011 3 -#define B00000011 3 -#define B100 4 -#define B0100 4 -#define B00100 4 -#define B000100 4 -#define B0000100 4 -#define B00000100 4 -#define B101 5 -#define B0101 5 -#define B00101 5 -#define B000101 5 -#define B0000101 5 -#define B00000101 5 -#define B110 6 -#define B0110 6 -#define B00110 6 -#define B000110 6 -#define B0000110 6 -#define B00000110 6 -#define B111 7 -#define B0111 7 -#define B00111 7 -#define B000111 7 -#define B0000111 7 -#define B00000111 7 -#define B1000 8 -#define B01000 8 -#define B001000 8 -#define B0001000 8 -#define B00001000 8 -#define B1001 9 -#define B01001 9 -#define B001001 9 -#define B0001001 9 -#define B00001001 9 -#define B1010 10 -#define B01010 10 -#define B001010 10 -#define B0001010 10 -#define B00001010 10 -#define B1011 11 -#define B01011 11 -#define B001011 11 -#define B0001011 11 -#define B00001011 11 -#define B1100 12 -#define B01100 12 -#define B001100 12 -#define B0001100 12 -#define B00001100 12 -#define B1101 13 -#define B01101 13 -#define B001101 13 -#define B0001101 13 -#define B00001101 13 -#define B1110 14 -#define B01110 14 -#define B001110 14 -#define B0001110 14 -#define B00001110 14 -#define B1111 15 -#define B01111 15 -#define B001111 15 -#define B0001111 15 -#define B00001111 15 -#define B10000 16 -#define B010000 16 -#define B0010000 16 -#define B00010000 16 -#define B10001 17 -#define B010001 17 -#define B0010001 17 -#define B00010001 17 -#define B10010 18 -#define B010010 18 -#define B0010010 18 -#define B00010010 18 -#define B10011 19 -#define B010011 19 -#define B0010011 19 -#define B00010011 19 -#define B10100 20 -#define B010100 20 -#define B0010100 20 -#define B00010100 20 -#define B10101 21 -#define B010101 21 -#define B0010101 21 -#define B00010101 21 -#define B10110 22 -#define B010110 22 -#define B0010110 22 -#define B00010110 22 -#define B10111 23 -#define B010111 23 -#define B0010111 23 -#define B00010111 23 -#define B11000 24 -#define B011000 24 -#define B0011000 24 -#define B00011000 24 -#define B11001 25 -#define B011001 25 -#define B0011001 25 -#define B00011001 25 -#define B11010 26 -#define B011010 26 -#define B0011010 26 -#define B00011010 26 -#define B11011 27 -#define B011011 27 -#define B0011011 27 -#define B00011011 27 -#define B11100 28 -#define B011100 28 -#define B0011100 28 -#define B00011100 28 -#define B11101 29 -#define B011101 29 -#define B0011101 29 -#define B00011101 29 -#define B11110 30 -#define B011110 30 -#define B0011110 30 -#define B00011110 30 -#define B11111 31 -#define B011111 31 -#define B0011111 31 -#define B00011111 31 -#define B100000 32 -#define B0100000 32 -#define B00100000 32 -#define B100001 33 -#define B0100001 33 -#define B00100001 33 -#define B100010 34 -#define B0100010 34 -#define B00100010 34 -#define B100011 35 -#define B0100011 35 -#define B00100011 35 -#define B100100 36 -#define B0100100 36 -#define B00100100 36 -#define B100101 37 -#define B0100101 37 -#define B00100101 37 -#define B100110 38 -#define B0100110 38 -#define B00100110 38 -#define B100111 39 -#define B0100111 39 -#define B00100111 39 -#define B101000 40 -#define B0101000 40 -#define B00101000 40 -#define B101001 41 -#define B0101001 41 -#define B00101001 41 -#define B101010 42 -#define B0101010 42 -#define B00101010 42 -#define B101011 43 -#define B0101011 43 -#define B00101011 43 -#define B101100 44 -#define B0101100 44 -#define B00101100 44 -#define B101101 45 -#define B0101101 45 -#define B00101101 45 -#define B101110 46 -#define B0101110 46 -#define B00101110 46 -#define B101111 47 -#define B0101111 47 -#define B00101111 47 -#define B110000 48 -#define B0110000 48 -#define B00110000 48 -#define B110001 49 -#define B0110001 49 -#define B00110001 49 -#define B110010 50 -#define B0110010 50 -#define B00110010 50 -#define B110011 51 -#define B0110011 51 -#define B00110011 51 -#define B110100 52 -#define B0110100 52 -#define B00110100 52 -#define B110101 53 -#define B0110101 53 -#define B00110101 53 -#define B110110 54 -#define B0110110 54 -#define B00110110 54 -#define B110111 55 -#define B0110111 55 -#define B00110111 55 -#define B111000 56 -#define B0111000 56 -#define B00111000 56 -#define B111001 57 -#define B0111001 57 -#define B00111001 57 -#define B111010 58 -#define B0111010 58 -#define B00111010 58 -#define B111011 59 -#define B0111011 59 -#define B00111011 59 -#define B111100 60 -#define B0111100 60 -#define B00111100 60 -#define B111101 61 -#define B0111101 61 -#define B00111101 61 -#define B111110 62 -#define B0111110 62 -#define B00111110 62 -#define B111111 63 -#define B0111111 63 -#define B00111111 63 -#define B1000000 64 -#define B01000000 64 -#define B1000001 65 -#define B01000001 65 -#define B1000010 66 -#define B01000010 66 -#define B1000011 67 -#define B01000011 67 -#define B1000100 68 -#define B01000100 68 -#define B1000101 69 -#define B01000101 69 -#define B1000110 70 -#define B01000110 70 -#define B1000111 71 -#define B01000111 71 -#define B1001000 72 -#define B01001000 72 -#define B1001001 73 -#define B01001001 73 -#define B1001010 74 -#define B01001010 74 -#define B1001011 75 -#define B01001011 75 -#define B1001100 76 -#define B01001100 76 -#define B1001101 77 -#define B01001101 77 -#define B1001110 78 -#define B01001110 78 -#define B1001111 79 -#define B01001111 79 -#define B1010000 80 -#define B01010000 80 -#define B1010001 81 -#define B01010001 81 -#define B1010010 82 -#define B01010010 82 -#define B1010011 83 -#define B01010011 83 -#define B1010100 84 -#define B01010100 84 -#define B1010101 85 -#define B01010101 85 -#define B1010110 86 -#define B01010110 86 -#define B1010111 87 -#define B01010111 87 -#define B1011000 88 -#define B01011000 88 -#define B1011001 89 -#define B01011001 89 -#define B1011010 90 -#define B01011010 90 -#define B1011011 91 -#define B01011011 91 -#define B1011100 92 -#define B01011100 92 -#define B1011101 93 -#define B01011101 93 -#define B1011110 94 -#define B01011110 94 -#define B1011111 95 -#define B01011111 95 -#define B1100000 96 -#define B01100000 96 -#define B1100001 97 -#define B01100001 97 -#define B1100010 98 -#define B01100010 98 -#define B1100011 99 -#define B01100011 99 -#define B1100100 100 -#define B01100100 100 -#define B1100101 101 -#define B01100101 101 -#define B1100110 102 -#define B01100110 102 -#define B1100111 103 -#define B01100111 103 -#define B1101000 104 -#define B01101000 104 -#define B1101001 105 -#define B01101001 105 -#define B1101010 106 -#define B01101010 106 -#define B1101011 107 -#define B01101011 107 -#define B1101100 108 -#define B01101100 108 -#define B1101101 109 -#define B01101101 109 -#define B1101110 110 -#define B01101110 110 -#define B1101111 111 -#define B01101111 111 -#define B1110000 112 -#define B01110000 112 -#define B1110001 113 -#define B01110001 113 -#define B1110010 114 -#define B01110010 114 -#define B1110011 115 -#define B01110011 115 -#define B1110100 116 -#define B01110100 116 -#define B1110101 117 -#define B01110101 117 -#define B1110110 118 -#define B01110110 118 -#define B1110111 119 -#define B01110111 119 -#define B1111000 120 -#define B01111000 120 -#define B1111001 121 -#define B01111001 121 -#define B1111010 122 -#define B01111010 122 -#define B1111011 123 -#define B01111011 123 -#define B1111100 124 -#define B01111100 124 -#define B1111101 125 -#define B01111101 125 -#define B1111110 126 -#define B01111110 126 -#define B1111111 127 -#define B01111111 127 -#define B10000000 128 -#define B10000001 129 -#define B10000010 130 -#define B10000011 131 -#define B10000100 132 -#define B10000101 133 -#define B10000110 134 -#define B10000111 135 -#define B10001000 136 -#define B10001001 137 -#define B10001010 138 -#define B10001011 139 -#define B10001100 140 -#define B10001101 141 -#define B10001110 142 -#define B10001111 143 -#define B10010000 144 -#define B10010001 145 -#define B10010010 146 -#define B10010011 147 -#define B10010100 148 -#define B10010101 149 -#define B10010110 150 -#define B10010111 151 -#define B10011000 152 -#define B10011001 153 -#define B10011010 154 -#define B10011011 155 -#define B10011100 156 -#define B10011101 157 -#define B10011110 158 -#define B10011111 159 -#define B10100000 160 -#define B10100001 161 -#define B10100010 162 -#define B10100011 163 -#define B10100100 164 -#define B10100101 165 -#define B10100110 166 -#define B10100111 167 -#define B10101000 168 -#define B10101001 169 -#define B10101010 170 -#define B10101011 171 -#define B10101100 172 -#define B10101101 173 -#define B10101110 174 -#define B10101111 175 -#define B10110000 176 -#define B10110001 177 -#define B10110010 178 -#define B10110011 179 -#define B10110100 180 -#define B10110101 181 -#define B10110110 182 -#define B10110111 183 -#define B10111000 184 -#define B10111001 185 -#define B10111010 186 -#define B10111011 187 -#define B10111100 188 -#define B10111101 189 -#define B10111110 190 -#define B10111111 191 -#define B11000000 192 -#define B11000001 193 -#define B11000010 194 -#define B11000011 195 -#define B11000100 196 -#define B11000101 197 -#define B11000110 198 -#define B11000111 199 -#define B11001000 200 -#define B11001001 201 -#define B11001010 202 -#define B11001011 203 -#define B11001100 204 -#define B11001101 205 -#define B11001110 206 -#define B11001111 207 -#define B11010000 208 -#define B11010001 209 -#define B11010010 210 -#define B11010011 211 -#define B11010100 212 -#define B11010101 213 -#define B11010110 214 -#define B11010111 215 -#define B11011000 216 -#define B11011001 217 -#define B11011010 218 -#define B11011011 219 -#define B11011100 220 -#define B11011101 221 -#define B11011110 222 -#define B11011111 223 -#define B11100000 224 -#define B11100001 225 -#define B11100010 226 -#define B11100011 227 -#define B11100100 228 -#define B11100101 229 -#define B11100110 230 -#define B11100111 231 -#define B11101000 232 -#define B11101001 233 -#define B11101010 234 -#define B11101011 235 -#define B11101100 236 -#define B11101101 237 -#define B11101110 238 -#define B11101111 239 -#define B11110000 240 -#define B11110001 241 -#define B11110010 242 -#define B11110011 243 -#define B11110100 244 -#define B11110101 245 -#define B11110110 246 -#define B11110111 247 -#define B11111000 248 -#define B11111001 249 -#define B11111010 250 -#define B11111011 251 -#define B11111100 252 -#define B11111101 253 -#define B11111110 254 -#define B11111111 255 - -#endif diff --git a/cores/arduino/compact/dtostrf.c b/cores/arduino/compact/dtostrf.c new file mode 100644 index 000000000..c0d62ab9e --- /dev/null +++ b/cores/arduino/compact/dtostrf.c @@ -0,0 +1 @@ +#include "../api/deprecated-avr-comp/avr/dtostrf.c.impl" \ No newline at end of file diff --git a/cores/arduino/delay.c b/cores/arduino/delay.c index 84c8ea7e4..bf6db0ef7 100644 --- a/cores/arduino/delay.c +++ b/cores/arduino/delay.c @@ -16,7 +16,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "delay.h" #include "Arduino.h" #ifdef __cplusplus @@ -90,6 +89,47 @@ void SysTick_DefaultHandler(void) tickReset(); } +/** + * \brief Pauses the program for the amount of time (in microseconds) specified as parameter. + * + * \param dwUs the number of microseconds to pause (uint32_t) + */ +void delayMicroseconds( unsigned int usec ) +{ + if ( usec == 0 ) + { + return ; + } + + /* + * The following loop: + * + * for (; ul; ul--) { + * __asm__ volatile(""); + * } + * + * produce the following assembly code: + * + * loop: + * subs r3, #1 // 1 Core cycle + * bne.n loop // 1 Core cycle + 1 if branch is taken + */ + + // VARIANT_MCK / 1000000 == cycles needed to delay 1uS + // 3 == cycles used in a loop + uint32_t n = usec * (VARIANT_MCK / 1000000) / 3; + __asm__ __volatile__( + "1: \n" + " sub %0, #1 \n" // substract 1 from %0 (n) + " bne 1b \n" // if result is not 0 jump to 1 + : "+r" (n) // '%0' is n variable with RW constraints + : // no input + : // no clobber + ); + // https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html + // https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Volatile +} + #ifdef __cplusplus } #endif diff --git a/cores/arduino/delay.h b/cores/arduino/delay.h deleted file mode 100644 index 64f39b13f..000000000 --- a/cores/arduino/delay.h +++ /dev/null @@ -1,104 +0,0 @@ -/* - Copyright (c) 2015 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 _DELAY_ -#define _DELAY_ - -#include -#include "variant.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * \brief Returns the number of milliseconds since the Arduino board began running the current program. - * - * This number will overflow (go back to zero), after approximately 50 days. - * - * \return Number of milliseconds since the program started (uint32_t) - */ -extern unsigned long millis( void ) ; - -/** - * \brief Returns the number of microseconds since the Arduino board began running the current program. - * - * This number will overflow (go back to zero), after approximately 70 minutes. On 16 MHz Arduino boards - * (e.g. Duemilanove and Nano), this function has a resolution of four microseconds (i.e. the value returned is - * always a multiple of four). On 8 MHz Arduino boards (e.g. the LilyPad), this function has a resolution - * of eight microseconds. - * - * \note There are 1,000 microseconds in a millisecond and 1,000,000 microseconds in a second. - */ -extern unsigned long micros( void ) ; - -/** - * \brief Pauses the program for the amount of time (in miliseconds) specified as parameter. - * (There are 1000 milliseconds in a second.) - * - * \param dwMs the number of milliseconds to pause (uint32_t) - */ -extern void delay( unsigned long dwMs ) ; - -/** - * \brief Pauses the program for the amount of time (in microseconds) specified as parameter. - * - * \param dwUs the number of microseconds to pause (uint32_t) - */ -static __inline__ void delayMicroseconds( unsigned int ) __attribute__((always_inline, unused)) ; -static __inline__ void delayMicroseconds( unsigned int usec ) -{ - if ( usec == 0 ) - { - return ; - } - - /* - * The following loop: - * - * for (; ul; ul--) { - * __asm__ volatile(""); - * } - * - * produce the following assembly code: - * - * loop: - * subs r3, #1 // 1 Core cycle - * bne.n loop // 1 Core cycle + 1 if branch is taken - */ - - // VARIANT_MCK / 1000000 == cycles needed to delay 1uS - // 3 == cycles used in a loop - uint32_t n = usec * (VARIANT_MCK / 1000000) / 3; - __asm__ __volatile__( - "1: \n" - " sub %0, #1 \n" // substract 1 from %0 (n) - " bne 1b \n" // if result is not 0 jump to 1 - : "+r" (n) // '%0' is n variable with RW constraints - : // no input - : // no clobber - ); - // https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html - // https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Volatile -} - -#ifdef __cplusplus -} -#endif - -#endif /* _DELAY_ */ diff --git a/cores/arduino/itoa.c b/cores/arduino/itoa.c index cb30a47c6..fb468dcce 100644 --- a/cores/arduino/itoa.c +++ b/cores/arduino/itoa.c @@ -16,63 +16,13 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "itoa.h" #include #ifdef __cplusplus extern "C" { #endif -/* reverse: reverse string s in place */ -/* -static void reverse( char s[] ) -{ - int i, j ; - char c ; - - for ( i = 0, j = strlen(s)-1 ; i < j ; i++, j-- ) - { - c = s[i] ; - s[i] = s[j] ; - s[j] = c ; - } -} -*/ - -/* itoa: convert n to characters in s */ -/* -extern void itoa( int n, char s[] ) -{ - int i, sign ; - - if ( (sign = n) < 0 ) // record sign - { - n = -n; // make n positive - } - - i = 0; - do - { // generate digits in reverse order - s[i++] = n % 10 + '0'; // get next digit - } while ((n /= 10) > 0) ; // delete it - - if (sign < 0 ) - { - s[i++] = '-'; - } - - s[i] = '\0'; - - reverse( s ) ; -} -*/ - -extern char* itoa( int value, char *string, int radix ) -{ - return ltoa( value, string, radix ) ; -} - -extern char* ltoa( long value, char *string, int radix ) +char* ltoa( long value, char *string, int radix ) { char tmp[33]; char *tp = tmp; @@ -122,12 +72,7 @@ extern char* ltoa( long value, char *string, int radix ) return string; } -extern char* utoa( unsigned int value, char *string, int radix ) -{ - return ultoa( value, string, radix ) ; -} - -extern char* ultoa( unsigned long value, char *string, int radix ) +char* ultoa( unsigned long value, char *string, int radix ) { char tmp[33]; char *tp = tmp; @@ -165,6 +110,16 @@ extern char* ultoa( unsigned long value, char *string, int radix ) return string; } +char* itoa( int value, char *string, int radix ) +{ + return ltoa( value, string, radix ) ; +} + +char* utoa( unsigned int value, char *string, int radix ) +{ + return ultoa( value, string, radix ) ; +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/cores/arduino/itoa.h b/cores/arduino/itoa.h deleted file mode 100644 index 1057d11a5..000000000 --- a/cores/arduino/itoa.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - Copyright (c) 2015 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 -*/ - -#pragma once - -#ifdef __cplusplus -extern "C"{ -#endif - -//extern void itoa( int n, char s[] ) ; - -extern char* itoa( int value, char *string, int radix ) ; -extern char* ltoa( long value, char *string, int radix ) ; -extern char* utoa( unsigned int value, char *string, int radix ) ; -extern char* ultoa( unsigned long value, char *string, int radix ) ; - -#ifdef __cplusplus -} // extern "C" -#endif - diff --git a/cores/arduino/main.cpp b/cores/arduino/main.cpp index 49ebc27f5..5a59884f6 100644 --- a/cores/arduino/main.cpp +++ b/cores/arduino/main.cpp @@ -24,6 +24,8 @@ void initVariant() __attribute__((weak)); void initVariant() { } +extern USBDeviceClass USBDevice; + // Initialize C library extern "C" void __libc_init_array(void); diff --git a/cores/arduino/pulse.c b/cores/arduino/pulse.c index 2dd03bf47..89bdf6840 100644 --- a/cores/arduino/pulse.c +++ b/cores/arduino/pulse.c @@ -25,7 +25,7 @@ extern unsigned long countPulseASM(const volatile uint32_t *port, uint32_t bit, * or LOW, the type of pulse to measure. Works on pulses from 2-3 microseconds * to 3 minutes in length, but must be called at least a few dozen microseconds * before the start of the pulse. */ -uint32_t pulseIn(uint32_t pin, uint32_t state, uint32_t timeout) +uint32_t pulseIn(pin_size_t pin, uint8_t state, uint32_t timeout) { // cache the port and bit of the pin in order to speed up the // pulse width measuring loop and achieve finer resolution. calling diff --git a/cores/arduino/pulse.h b/cores/arduino/pulse.h deleted file mode 100644 index 9c620f12a..000000000 --- a/cores/arduino/pulse.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - Copyright (c) 2015 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 -*/ - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * \brief Measures the length (in microseconds) of a pulse on the pin; state is HIGH - * or LOW, the type of pulse to measure. Works on pulses from 2-3 microseconds - * to 3 minutes in length, but must be called at least a few dozen microseconds - * before the start of the pulse. - */ -uint32_t pulseIn(uint32_t pin, uint32_t state, uint32_t timeout); - -#ifdef __cplusplus -// Provides a version of pulseIn with a default argument (C++ only) -uint32_t pulseIn(uint32_t pin, uint32_t state, uint32_t timeout = 1000000L); - -} // extern "C" -#endif - diff --git a/cores/arduino/sync.h b/cores/arduino/sync.h new file mode 100644 index 000000000..2750a2911 --- /dev/null +++ b/cores/arduino/sync.h @@ -0,0 +1,30 @@ +#include + +#ifndef _SYNC_H_ +#define _SYNC_H_ +/* + * Synchronization primitives. + * TODO: Move into a separate header file and make an API out of it + */ + +class __Guard { +public: + __Guard() : primask(__get_PRIMASK()), loops(1) { + __disable_irq(); + } + ~__Guard() { + if (primask == 0) { + __enable_irq(); + // http://infocenter.arm.com/help/topic/com.arm.doc.dai0321a/BIHBFEIB.html + __ISB(); + } + } + uint32_t enter() { return loops--; } +private: + uint32_t primask; + uint32_t loops; +}; + +#define synchronized for (__Guard __guard; __guard.enter(); ) + +#endif \ No newline at end of file diff --git a/cores/arduino/wiring.h b/cores/arduino/wiring.h deleted file mode 100644 index 55e4e6a81..000000000 --- a/cores/arduino/wiring.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - Copyright (c) 2015 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 -*/ - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -extern void init(void); - -#ifdef __cplusplus -} -#endif diff --git a/cores/arduino/wiring_analog.c b/cores/arduino/wiring_analog.c index 8655f6ecf..2476e0105 100644 --- a/cores/arduino/wiring_analog.c +++ b/cores/arduino/wiring_analog.c @@ -125,7 +125,7 @@ void analogReference(eAnalogReference mode) } } -uint32_t analogRead(uint32_t pin) +int analogRead(pin_size_t pin) { uint32_t valueRead = 0; @@ -191,7 +191,7 @@ uint32_t analogRead(uint32_t pin) // hardware support. These are defined in the appropriate // pins_*.c file. For the rest of the pins, we default // to digital output. -void analogWrite(uint32_t pin, uint32_t value) +void analogWrite(pin_size_t pin, int value) { PinDescription pinDesc = g_APinDescription[pin]; uint32_t attr = pinDesc.ulPinAttribute; diff --git a/cores/arduino/wiring_analog.h b/cores/arduino/wiring_analog.h deleted file mode 100644 index cca46359c..000000000 --- a/cores/arduino/wiring_analog.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - Copyright (c) 2015 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 -*/ - -#pragma once - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * \brief SAMD products have only one reference for ADC - */ -typedef enum _eAnalogReference -{ - AR_DEFAULT, - AR_INTERNAL, - AR_EXTERNAL, - AR_INTERNAL1V0, - AR_INTERNAL1V65, - AR_INTERNAL2V23 -} eAnalogReference ; - - -/* - * \brief Configures the reference voltage used for analog input (i.e. the value used as the top of the input range). - * This function is kept only for compatibility with existing AVR based API. - * - * \param ulMmode Should be set to AR_DEFAULT. - */ -extern void analogReference( eAnalogReference ulMode ) ; - -/* - * \brief Writes an analog value (PWM wave) to a pin. - * - * \param ulPin - * \param ulValue - */ -extern void analogWrite( uint32_t ulPin, uint32_t ulValue ) ; - -/* - * \brief Reads the value from the specified analog pin. - * - * \param ulPin - * - * \return Read value from selected pin, if no error. - */ -extern uint32_t analogRead( uint32_t ulPin ) ; - -/* - * \brief Set the resolution of analogRead return values. Default is 10 bits (range from 0 to 1023). - * - * \param res - */ -extern void analogReadResolution(int res); - -/* - * \brief Set the resolution of analogWrite parameters. Default is 8 bits (range from 0 to 255). - * - * \param res - */ -extern void analogWriteResolution(int res); - -extern void analogOutputInit( void ) ; - -#ifdef __cplusplus -} -#endif diff --git a/cores/arduino/wiring_constants.h b/cores/arduino/wiring_constants.h deleted file mode 100644 index e8573aeda..000000000 --- a/cores/arduino/wiring_constants.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - Copyright (c) 2014 Arduino. 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 _WIRING_CONSTANTS_ -#define _WIRING_CONSTANTS_ - -#ifdef __cplusplus -extern "C"{ -#endif // __cplusplus - -#define LOW (0x0) -#define HIGH (0x1) - -#define INPUT (0x0) -#define OUTPUT (0x1) -#define INPUT_PULLUP (0x2) -#define INPUT_PULLDOWN (0x3) - -#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 - -enum BitOrder { - LSBFIRST = 0, - MSBFIRST = 1 -}; - -// moved to WInterrupts.h -//// LOW 0 -//// HIGH 1 -//#define CHANGE 2 -//#define FALLING 3 -//#define RISING 4 -// -//#define DEFAULT 1 -//#define EXTERNAL 0 - -#ifdef __cplusplus -} // extern "C" -#endif // __cplusplus - -#endif /* _WIRING_CONSTANTS_ */ diff --git a/cores/arduino/wiring_digital.c b/cores/arduino/wiring_digital.c index 026af80df..f9d8b68b1 100644 --- a/cores/arduino/wiring_digital.c +++ b/cores/arduino/wiring_digital.c @@ -22,7 +22,7 @@ extern "C" { #endif -void pinMode( uint32_t ulPin, uint32_t ulMode ) +void pinMode( pin_size_t ulPin, PinMode ulMode ) { // Handle the case the pin isn't usable as PIO if ( g_APinDescription[ulPin].ulPinType == PIO_NOT_A_PIN ) @@ -71,7 +71,7 @@ void pinMode( uint32_t ulPin, uint32_t ulMode ) } } -void digitalWrite( uint32_t ulPin, uint32_t ulVal ) +void digitalWrite( pin_size_t ulPin, PinStatus ulVal ) { // Handle the case the pin isn't usable as PIO if ( g_APinDescription[ulPin].ulPinType == PIO_NOT_A_PIN ) @@ -102,7 +102,7 @@ void digitalWrite( uint32_t ulPin, uint32_t ulVal ) return ; } -int digitalRead( uint32_t ulPin ) +PinStatus digitalRead( pin_size_t ulPin ) { // Handle the case the pin isn't usable as PIO if ( g_APinDescription[ulPin].ulPinType == PIO_NOT_A_PIN ) diff --git a/cores/arduino/wiring_digital.h b/cores/arduino/wiring_digital.h deleted file mode 100644 index 9895390f2..000000000 --- a/cores/arduino/wiring_digital.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - Copyright (c) 2014 Arduino. 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 _WIRING_DIGITAL_ -#define _WIRING_DIGITAL_ - -#ifdef __cplusplus - extern "C" { -#endif - -#include "WVariant.h" - -/** - * \brief Configures the specified pin to behave either as an input or an output. See the description of digital pins for details. - * - * \param ulPin The number of the pin whose mode you wish to set - * \param ulMode Can be INPUT, OUTPUT, INPUT_PULLUP or INPUT_PULLDOWN - */ -extern void pinMode( uint32_t dwPin, uint32_t dwMode ) ; - -/** - * \brief Write a HIGH or a LOW value to a digital pin. - * - * If the pin has been configured as an OUTPUT with pinMode(), its voltage will be set to the - * corresponding value: 5V (or 3.3V on 3.3V boards) for HIGH, 0V (ground) for LOW. - * - * If the pin is configured as an INPUT, writing a HIGH value with digitalWrite() will enable an internal - * 20K pullup resistor (see the tutorial on digital pins). Writing LOW will disable the pullup. The pullup - * resistor is enough to light an LED dimly, so if LEDs appear to work, but very dimly, this is a likely - * cause. The remedy is to set the pin to an output with the pinMode() function. - * - * \note Digital pin PIN_LED is harder to use as a digital input than the other digital pins because it has an LED - * and resistor attached to it that's soldered to the board on most boards. If you enable its internal 20k pull-up - * resistor, it will hang at around 1.7 V instead of the expected 5V because the onboard LED and series resistor - * pull the voltage level down, meaning it always returns LOW. If you must use pin PIN_LED as a digital input, use an - * external pull down resistor. - * - * \param dwPin the pin number - * \param dwVal HIGH or LOW - */ -extern void digitalWrite( uint32_t dwPin, uint32_t dwVal ) ; - -/** - * \brief Reads the value from a specified digital pin, either HIGH or LOW. - * - * \param ulPin The number of the digital pin you want to read (int) - * - * \return HIGH or LOW - */ -extern int digitalRead( uint32_t ulPin ) ; - -#ifdef __cplusplus -} -#endif - -#endif /* _WIRING_DIGITAL_ */ diff --git a/cores/arduino/wiring_private.h b/cores/arduino/wiring_private.h index ce64e2def..be1babd92 100644 --- a/cores/arduino/wiring_private.h +++ b/cores/arduino/wiring_private.h @@ -29,13 +29,9 @@ extern "C" { // Includes Atmel CMSIS #include "sam.h" -#include "wiring_constants.h" - int pinPeripheral( uint32_t ulPin, EPioType ulPeripheral ); #ifdef __cplusplus } // extern "C" -#include "HardwareSerial.h" - #endif diff --git a/cores/arduino/wiring_shift.c b/cores/arduino/wiring_shift.c index 3260d2b12..7a855ee57 100644 --- a/cores/arduino/wiring_shift.c +++ b/cores/arduino/wiring_shift.c @@ -17,15 +17,14 @@ */ #include -#include "wiring_shift.h" -#include "wiring_digital.h" +#include #include "wiring_private.h" #ifdef __cplusplus extern "C"{ #endif -uint32_t shiftIn( uint32_t ulDataPin, uint32_t ulClockPin, uint32_t ulBitOrder ) +uint8_t shiftIn( pin_size_t ulDataPin, pin_size_t ulClockPin, BitOrder ulBitOrder ) { uint8_t value = 0 ; uint8_t i ; @@ -49,7 +48,7 @@ uint32_t shiftIn( uint32_t ulDataPin, uint32_t ulClockPin, uint32_t ulBitOrder ) return value ; } -void shiftOut( uint32_t ulDataPin, uint32_t ulClockPin, uint32_t ulBitOrder, uint32_t ulVal ) +void shiftOut( pin_size_t ulDataPin, pin_size_t ulClockPin, BitOrder ulBitOrder, uint8_t ulVal ) { uint8_t i ; diff --git a/cores/arduino/wiring_shift.h b/cores/arduino/wiring_shift.h deleted file mode 100644 index 6026bdc61..000000000 --- a/cores/arduino/wiring_shift.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - Copyright (c) 2014 Arduino. 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 _WIRING_SHIFT_ -#define _WIRING_SHIFT_ - -#ifdef __cplusplus - extern "C" { -#endif - -/* - * \brief - */ -extern uint32_t shiftIn( uint32_t ulDataPin, uint32_t ulClockPin, uint32_t ulBitOrder ) ; - - -/* - * \brief - */ -extern void shiftOut( uint32_t ulDataPin, uint32_t ulClockPin, uint32_t ulBitOrder, uint32_t ulVal ) ; - - -#ifdef __cplusplus -} -#endif - -#endif /* _WIRING_SHIFT_ */ diff --git a/libraries/HID/HID.cpp b/libraries/HID/HID.cpp index a2f1382b2..f4cffc5ae 100644 --- a/libraries/HID/HID.cpp +++ b/libraries/HID/HID.cpp @@ -16,11 +16,13 @@ ** SOFTWARE. */ -#include "USB/PluggableUSB.h" +#include "api/PluggableUSB.h" #include "HID.h" #if defined(USBCON) +extern USBDeviceClass USBDevice; + HID_& HID() { static HID_ obj; diff --git a/libraries/HID/HID.h b/libraries/HID/HID.h index d086593b6..0148daeaf 100644 --- a/libraries/HID/HID.h +++ b/libraries/HID/HID.h @@ -21,7 +21,7 @@ #include #include -#include "USB/PluggableUSB.h" +#include "api/PluggableUSB.h" #if defined(USBCON) @@ -99,7 +99,7 @@ class HID_ : public PluggableUSBModule uint8_t getShortName(char* name); private: - uint32_t epType[1]; + unsigned int epType[1]; HIDSubDescriptor* rootNode; uint16_t descriptorSize; diff --git a/libraries/SPI/SPI.cpp b/libraries/SPI/SPI.cpp index ff3a36106..6b34e13de 100644 --- a/libraries/SPI/SPI.cpp +++ b/libraries/SPI/SPI.cpp @@ -26,7 +26,30 @@ #define SPI_IMODE_EXTINT 1 #define SPI_IMODE_GLOBAL 2 -SPIClass::SPIClass(SERCOM *p_sercom, uint8_t uc_pinMISO, uint8_t uc_pinSCK, uint8_t uc_pinMOSI, SercomSpiTXPad PadTx, SercomRXPad PadRx) : settings(SPISettings(0, MSBFIRST, SPI_MODE0)) +//const SPISettings DEFAULT_SPI_SETTINGS = SPISettings(); + +static inline SercomDataOrder getBitOrder(SPISettings& settings) { + return (settings.getBitOrder() == MSBFIRST ? MSB_FIRST : LSB_FIRST); +} + +static inline SercomSpiClockMode getDataMode(SPISettings& settings) { + switch (settings.getDataMode()) + { + case SPI_MODE0: + return SERCOM_SPI_MODE_0; break; + case SPI_MODE1: + return SERCOM_SPI_MODE_1; break; + case SPI_MODE2: + return SERCOM_SPI_MODE_2; break; + case SPI_MODE3: + return SERCOM_SPI_MODE_3; break; + default: + return SERCOM_SPI_MODE_0; break; + } +} + +SPIClass::SPIClass(SERCOM *p_sercom, uint8_t uc_pinMISO, uint8_t uc_pinSCK, uint8_t uc_pinMOSI, SercomSpiTXPad PadTx, SercomRXPad PadRx) +: settings(0, MSBFIRST, SPI_MODE0) { initialized = false; assert(p_sercom != NULL); @@ -70,8 +93,8 @@ void SPIClass::config(SPISettings settings) this->settings = settings; _p_sercom->disableSPI(); - _p_sercom->initSPI(_padTx, _padRx, SPI_CHAR_SIZE_8_BITS, settings.bitOrder); - _p_sercom->initSPIClock(settings.dataMode, settings.clockFreq); + _p_sercom->initSPI(_padTx, _padRx, SPI_CHAR_SIZE_8_BITS, getBitOrder(settings)); + _p_sercom->initSPIClock(getDataMode(settings), settings.getClockFreq()); _p_sercom->enableSPI(); } diff --git a/libraries/SPI/SPI.h b/libraries/SPI/SPI.h index 99d971704..fcb56ca8a 100644 --- a/libraries/SPI/SPI.h +++ b/libraries/SPI/SPI.h @@ -21,6 +21,7 @@ #define _SPI_H_INCLUDED #include +#include // SPI_HAS_TRANSACTION means SPI has // - beginTransaction() @@ -32,11 +33,6 @@ // SPI_HAS_NOTUSINGINTERRUPT means that SPI has notUsingInterrupt() method #define SPI_HAS_NOTUSINGINTERRUPT 1 -#define SPI_MODE0 0x02 -#define SPI_MODE1 0x00 -#define SPI_MODE2 0x03 -#define SPI_MODE3 0x01 - #if defined(ARDUINO_ARCH_SAMD) // The datasheet specifies a typical SPI SCK period (tSCK) of 42 ns, // see "Table 36-48. SPI Timing Characteristics and Requirements", @@ -45,75 +41,9 @@ #define SPI_MIN_CLOCK_DIVIDER (uint8_t)(1 + ((F_CPU - 1) / 12000000)) #endif -class SPISettings { - public: - SPISettings(uint32_t clock, BitOrder bitOrder, uint8_t dataMode) { - if (__builtin_constant_p(clock)) { - init_AlwaysInline(clock, bitOrder, dataMode); - } else { - init_MightInline(clock, bitOrder, dataMode); - } - } - - // Default speed set to 4MHz, SPI mode set to MODE 0 and Bit order set to MSB first. - SPISettings() { init_AlwaysInline(4000000, MSBFIRST, SPI_MODE0); } - - bool operator==(const SPISettings& rhs) const - { - if ((this->clockFreq == rhs.clockFreq) && - (this->bitOrder == rhs.bitOrder) && - (this->dataMode == rhs.dataMode)) { - return true; - } - return false; - } - - bool operator!=(const SPISettings& rhs) const - { - return !(*this == rhs); - } - - uint32_t getClockFreq() const {return clockFreq;} - uint8_t getDataMode() const {return (uint8_t)dataMode;} - BitOrder getBitOrder() const {return (bitOrder == MSB_FIRST ? MSBFIRST : LSBFIRST);} - - private: - void init_MightInline(uint32_t clock, BitOrder bitOrder, uint8_t dataMode) { - init_AlwaysInline(clock, bitOrder, dataMode); - } - - void init_AlwaysInline(uint32_t clock, BitOrder bitOrder, uint8_t dataMode) __attribute__((__always_inline__)) { - this->clockFreq = (clock >= (F_CPU / SPI_MIN_CLOCK_DIVIDER) ? F_CPU / SPI_MIN_CLOCK_DIVIDER : clock); - - this->bitOrder = (bitOrder == MSBFIRST ? MSB_FIRST : LSB_FIRST); - - switch (dataMode) - { - case SPI_MODE0: - this->dataMode = SERCOM_SPI_MODE_0; break; - case SPI_MODE1: - this->dataMode = SERCOM_SPI_MODE_1; break; - case SPI_MODE2: - this->dataMode = SERCOM_SPI_MODE_2; break; - case SPI_MODE3: - this->dataMode = SERCOM_SPI_MODE_3; break; - default: - this->dataMode = SERCOM_SPI_MODE_0; break; - } - } - - uint32_t clockFreq; - SercomSpiClockMode dataMode; - SercomDataOrder bitOrder; - - friend class SPIClass; -}; - -const SPISettings DEFAULT_SPI_SETTINGS = SPISettings(); - -class SPIClass { +class SPIClassSAMD : public arduino::HardwareSPI { public: - SPIClass(SERCOM *p_sercom, uint8_t uc_pinMISO, uint8_t uc_pinSCK, uint8_t uc_pinMOSI, SercomSpiTXPad, SercomRXPad); + SPIClassSAMD(SERCOM *p_sercom, uint8_t uc_pinMISO, uint8_t uc_pinSCK, uint8_t uc_pinMOSI, SercomSpiTXPad, SercomRXPad); byte transfer(uint8_t data); uint16_t transfer16(uint16_t data); @@ -156,6 +86,8 @@ class SPIClass { uint32_t interruptMask; }; +#define SPIClass SPIClassSAMD + #if SPI_INTERFACES_COUNT > 0 extern SPIClass SPI; #endif diff --git a/libraries/USBHost/examples/USB_desc/USB_desc.ino b/libraries/USBHost/examples/USB_desc/USB_desc.ino index a7ede046c..de9ab09f4 100644 --- a/libraries/USBHost/examples/USB_desc/USB_desc.ino +++ b/libraries/USBHost/examples/USB_desc/USB_desc.ino @@ -2,7 +2,6 @@ #include "Arduino.h" #include -#include "wiring_constants.h" #include "pgmstrings.h" // Satisfy IDE, which only needs to see the include statment in the ino. #ifdef dobogusinclude diff --git a/libraries/USBHost/src/usbhub.cpp b/libraries/USBHost/src/usbhub.cpp index 670c848c5..f79a60bc8 100644 --- a/libraries/USBHost/src/usbhub.cpp +++ b/libraries/USBHost/src/usbhub.cpp @@ -15,7 +15,7 @@ Web : http://www.circuitsathome.com e-mail : support@circuitsathome.com */ #include "usbhub.h" -#include "delay.h" +#include "api/Common.h" bool USBHub::bResetInitiated = false; diff --git a/libraries/Wire/Wire.cpp b/libraries/Wire/Wire.cpp index c56381911..cfc621616 100644 --- a/libraries/Wire/Wire.cpp +++ b/libraries/Wire/Wire.cpp @@ -26,6 +26,8 @@ extern "C" { #include "Wire.h" +using namespace arduino; + TwoWire::TwoWire(SERCOM * s, uint8_t pinSDA, uint8_t pinSCL) { this->sercom = s; @@ -288,7 +290,7 @@ void TwoWire::onService(void) #define PERIPH_WIRE sercom3 #define WIRE_IT_HANDLER SERCOM3_Handler #endif // PERIPH_WIRE - TwoWire Wire(&PERIPH_WIRE, PIN_WIRE_SDA, PIN_WIRE_SCL); + arduino::TwoWire Wire(&PERIPH_WIRE, PIN_WIRE_SDA, PIN_WIRE_SCL); void WIRE_IT_HANDLER(void) { Wire.onService(); @@ -296,7 +298,7 @@ void TwoWire::onService(void) #endif #if WIRE_INTERFACES_COUNT > 1 - TwoWire Wire1(&PERIPH_WIRE1, PIN_WIRE1_SDA, PIN_WIRE1_SCL); + arduino::TwoWire Wire1(&PERIPH_WIRE1, PIN_WIRE1_SDA, PIN_WIRE1_SCL); void WIRE1_IT_HANDLER(void) { Wire1.onService(); @@ -304,7 +306,7 @@ void TwoWire::onService(void) #endif #if WIRE_INTERFACES_COUNT > 2 - TwoWire Wire2(&PERIPH_WIRE2, PIN_WIRE2_SDA, PIN_WIRE2_SCL); + arduino::TwoWire Wire2(&PERIPH_WIRE2, PIN_WIRE2_SDA, PIN_WIRE2_SCL); void WIRE2_IT_HANDLER(void) { Wire2.onService(); @@ -312,7 +314,7 @@ void TwoWire::onService(void) #endif #if WIRE_INTERFACES_COUNT > 3 - TwoWire Wire3(&PERIPH_WIRE3, PIN_WIRE3_SDA, PIN_WIRE3_SCL); + arduino::TwoWire Wire3(&PERIPH_WIRE3, PIN_WIRE3_SDA, PIN_WIRE3_SCL); void WIRE3_IT_HANDLER(void) { Wire3.onService(); @@ -320,7 +322,7 @@ void TwoWire::onService(void) #endif #if WIRE_INTERFACES_COUNT > 4 - TwoWire Wire4(&PERIPH_WIRE4, PIN_WIRE4_SDA, PIN_WIRE4_SCL); + arduino::TwoWire Wire4(&PERIPH_WIRE4, PIN_WIRE4_SDA, PIN_WIRE4_SCL); void WIRE4_IT_HANDLER(void) { Wire4.onService(); @@ -328,7 +330,7 @@ void TwoWire::onService(void) #endif #if WIRE_INTERFACES_COUNT > 5 - TwoWire Wire5(&PERIPH_WIRE5, PIN_WIRE5_SDA, PIN_WIRE5_SCL); + arduino::TwoWire Wire5(&PERIPH_WIRE5, PIN_WIRE5_SDA, PIN_WIRE5_SCL); void WIRE5_IT_HANDLER(void) { Wire5.onService(); diff --git a/libraries/Wire/Wire.h b/libraries/Wire/Wire.h index db2ae646e..6474eb37c 100644 --- a/libraries/Wire/Wire.h +++ b/libraries/Wire/Wire.h @@ -20,21 +20,24 @@ #ifndef TwoWire_h #define TwoWire_h -#include "Stream.h" +#include "api/HardwareI2C.h" #include "variant.h" - #include "SERCOM.h" -#include "RingBuffer.h" // WIRE_HAS_END means Wire has end() #define WIRE_HAS_END 1 -class TwoWire : public Stream +namespace arduino { + +class TwoWire : public HardwareI2C { public: TwoWire(SERCOM *s, uint8_t pinSDA, uint8_t pinSCL); void begin(); - void begin(uint8_t, bool enableGeneralCall = false); + void begin(uint8_t address, bool enableGeneralCall); + void begin(uint8_t address) { + begin(address, false); + } void end(); void setClock(uint32_t); @@ -71,10 +74,10 @@ class TwoWire : public Stream bool transmissionBegun; // RX Buffer - RingBufferN<256> rxBuffer; + arduino::RingBufferN<256> rxBuffer; //TX buffer - RingBufferN<256> txBuffer; + arduino::RingBufferN<256> txBuffer; uint8_t txAddress; // Callback user functions @@ -85,23 +88,25 @@ class TwoWire : public Stream static const uint32_t TWI_CLOCK = 100000; }; +} + #if WIRE_INTERFACES_COUNT > 0 - extern TwoWire Wire; + extern arduino::TwoWire Wire; #endif #if WIRE_INTERFACES_COUNT > 1 - extern TwoWire Wire1; + extern arduino::TwoWire Wire1; #endif #if WIRE_INTERFACES_COUNT > 2 - extern TwoWire Wire2; + extern arduino::TwoWire Wire2; #endif #if WIRE_INTERFACES_COUNT > 3 - extern TwoWire Wire3; + extern arduino::TwoWire Wire3; #endif #if WIRE_INTERFACES_COUNT > 4 - extern TwoWire Wire4; + extern arduino::TwoWire Wire4; #endif #if WIRE_INTERFACES_COUNT > 5 - extern TwoWire Wire5; + extern arduino::TwoWire Wire5; #endif #endif diff --git a/platform.txt b/platform.txt index 319a8c0c5..bdf152186 100644 --- a/platform.txt +++ b/platform.txt @@ -87,13 +87,13 @@ build.usb_manufacturer="Unknown" # ---------------- ## Compile c files -recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {compiler.arm.cmsis.c.flags} {includes} "{source_file}" -o "{object_file}" +recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {compiler.arm.cmsis.c.flags} "-I{build.core.path}/api/deprecated" {includes} "{source_file}" -o "{object_file}" ## Compile c++ files -recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {compiler.arm.cmsis.c.flags} {includes} "{source_file}" -o "{object_file}" +recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {compiler.arm.cmsis.c.flags} "-I{build.core.path}/api/deprecated" {includes} "{source_file}" -o "{object_file}" ## Compile S files -recipe.S.o.pattern="{compiler.path}{compiler.S.cmd}" {compiler.S.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.S.extra_flags} {build.extra_flags} {compiler.arm.cmsis.c.flags} {includes} "{source_file}" -o "{object_file}" +recipe.S.o.pattern="{compiler.path}{compiler.S.cmd}" {compiler.S.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.S.extra_flags} {build.extra_flags} {compiler.arm.cmsis.c.flags} "-I{build.core.path}/api/deprecated" {includes} "{source_file}" -o "{object_file}" ## Create archives # archive_file_path is needed for backwards compatibility with IDE 1.6.5 or older, IDE 1.6.6 or newer overrides this value diff --git a/variants/mkrwan1300/variant.cpp b/variants/mkrwan1300/variant.cpp index 447393d06..8e07454fb 100644 --- a/variants/mkrwan1300/variant.cpp +++ b/variants/mkrwan1300/variant.cpp @@ -177,7 +177,7 @@ const void* g_apTCInstances[TCC_INST_NUM + TC_INST_NUM]={ TCC0, TCC1, TCC2, TC3, #if defined(USE_BQ24195L_PMIC) #include "wiring_private.h" -#include "delay.h" +#include "../Common.h" #define PMIC_ADDRESS 0x6B #define PMIC_REG01 0x01