diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d2aec54ba..d548a2fc67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 0.6.2-rc.1 + +### ENHANCEMENT / BUG FIX + +- [[PR #1283]](https://github.com/spark/firmware/pull/1283) [[Implements #1278]](https://github.com/spark/firmware/issues/1278) Restores 0.6.0-style Arduino compatibility by default, full Arduino compatibility when including Arduino.h + ## 0.6.1 (same as 0.6.1-rc.2) ### FEATURES diff --git a/docs/build.md b/docs/build.md index a3385b09bf..e7ee5e8bfd 100644 --- a/docs/build.md +++ b/docs/build.md @@ -470,16 +470,6 @@ USE_SWD=y and perform a clean build. For more details on SWD-only debugging see https://github.com/spark/firmware/pull/337 - -## Compilation without Arduino Compatibility Support - -Arduino compatibility defines are included by default to support hundreds of libraries that have been ported from Arduino to Particle. If those defines should cause an issue with your build, you may remove them by adding - -PARTICLE_NO_ARDUINO_COMPATIBILITY=y to the make command line. This requires a clean build. - -There should be no difference in FLASH or RAM allocation with or without these defines. - - ## Compilation without Cloud Support [Core only] diff --git a/platform/import.mk b/platform/import.mk index 51a685875b..365063542f 100644 --- a/platform/import.mk +++ b/platform/import.mk @@ -21,14 +21,6 @@ ifeq ("$(USE_SWD)","y") CFLAGS += -DUSE_SWD endif -ifeq ("$(PARTICLE_NO_ARDUINO_COMPATIBILITY)","y") -PARTICLE_NO_ARDUINO_COMPATIBILITY_VALUE=1 -else -PARTICLE_NO_ARDUINO_COMPATIBILITY_VALUE=0 -endif - -CFLAGS += -DPARTICLE_NO_ARDUINO_COMPATIBILITY=${PARTICLE_NO_ARDUINO_COMPATIBILITY_VALUE} - # pull in the includes/sources corresponding to the target platform INCLUDE_DIRS += $(PLATFORM_MODULE_PATH)/shared/inc diff --git a/system/inc/system_task.h b/system/inc/system_task.h index 8a44ddcd2b..5799cde2b3 100644 --- a/system/inc/system_task.h +++ b/system/inc/system_task.h @@ -30,9 +30,6 @@ #include "socket_hal.h" #include "system_cloud.h" #include "wlan_hal.h" -#include "active_object.h" - -extern ISRTaskQueue SystemISRTaskQueue; #ifdef __cplusplus extern "C" { diff --git a/system/inc/system_threading.h b/system/inc/system_threading.h index de9a8a49ab..fa37a458fb 100644 --- a/system/inc/system_threading.h +++ b/system/inc/system_threading.h @@ -19,10 +19,12 @@ #ifndef SYSTEM_THREADING_H #define SYSTEM_THREADING_H +#include "active_object.h" +extern ISRTaskQueue SystemISRTaskQueue; + #if PLATFORM_THREADING #include "concurrent_hal.h" -#include "active_object.h" #include #include #include @@ -32,6 +34,7 @@ #error "GTHREAD header not included. This is required for correct mutex implementation on embedded platforms." #endif + /** * System thread runs on a separate thread */ diff --git a/user/inc/Arduino.h b/user/inc/Arduino.h index 4b306f376c..35b2fb88c5 100644 --- a/user/inc/Arduino.h +++ b/user/inc/Arduino.h @@ -2,7 +2,276 @@ #ifndef ARDUINO_H #define ARDUINO_H +#ifdef PARTICLE_WIRING_ARDUINO_COMPATIBILTY +#undef PARTICLE_WIRING_ARDUINO_COMPATIBILTY +#endif + +#define PARTICLE_WIRING_ARDUINO_COMPATIBILTY 1 + #include "Particle.h" +#if PARTICLE_WIRING_ARDUINO_COMPATIBILTY == 1 + +#ifndef ARDUINO +#define ARDUINO 10800 +#endif + +#ifndef __cplusplus +#include +#else +#include +#endif // __cplusplus + +#include "avr/pgmspace.h" +#include "spark_wiring_arduino_constants.h" +#include "spark_wiring_arduino_binary.h" + +typedef particle::__SPISettings SPISettings; + +#undef F +#define F(X) (reinterpret_cast(X)) + +#ifndef makeWord +inline uint16_t makeWord(uint16_t w) { + return w; +} + +inline uint16_t makeWord(uint8_t h, uint8_t l) { + return ((uint16_t)h << 8) | ((uint16_t)l); +} +#endif + +#ifndef word +#define word(...) makeWord(__VA_ARGS__) +#endif + +#ifndef WEAK +#define WEAK __attribute__ ((weak)) +#endif + +#ifndef SYSTEM_CORE_CLOCK +#define SYSTEM_CORE_CLOCK SystemCoreClock +#endif + +#ifndef clockCyclesPerMicrosecond +#define clockCyclesPerMicrosecond() (SystemCoreClock / 1000000L) +#endif + +#ifndef clockCyclesToMicroseconds +#define clockCyclesToMicroseconds(a) (((a) * 1000L) / (SystemCoreClock / 1000L)) +#endif + +#ifndef microsecondsToClockCycles +#define microsecondsToClockCycles(a) ((a) * (SystemCoreClock / 1000000L)) +#endif + +#ifndef digitalPinToInterrupt +#define digitalPinToInterrupt(P) (P) +#endif + +inline void yield() { +#if PLATFORM_THREADING + os_thread_yield(); +#endif // PLATFORM_THREADING +} + +#ifndef PINS_COUNT +#define PINS_COUNT TOTAL_PINS +#endif + +#ifndef NUM_DIGITAL_PINS +#define NUM_DIGITAL_PINS TOTAL_PINS +#endif + +#ifndef NUM_ANALOG_INPUTS +#define NUM_ANALOG_INPUTS TOTAL_ANALOG_PINS +#endif + +#ifndef NUM_ANALOG_OUTPUTS +#define NUM_ANALOG_OUTPUTS TOTAL_DAC_PINS +#endif + +#ifndef analogInputToDigitalPin +#define analogInputToDigitalPin(p) (((p < TOTAL_ANALOG_PINS) && (p >= 0)) ? (p) + FIRST_ANALOG_PIN : -1) +#endif + +// XXX +#if PLATFORM_ID == PLATFORM_SPARK_CORE || PLATFORM_ID == PLATFORM_PHOTON_PRODUCTION || PLATFORM_ID == PLATFORM_P1 || PLATFORM_ID == PLATFORM_ELECTRON_PRODUCTION + +# ifndef digitalPinToPort +# define digitalPinToPort(P) ( HAL_Pin_Map()[P].gpio_peripheral ) +# endif + +# ifndef digitalPinToBitMask +# define digitalPinToBitMask(P) ( HAL_Pin_Map()[P].gpio_pin ) +# endif +//#define analogInPinToBit(P) ( ) +# ifndef portOutputRegister +# define portOutputRegister(port) ( &(port->ODR) ) +# endif + +# ifndef portInputRegister +# define portInputRegister(port) ( &(port->IDR) ) +# endif + +//#define portModeRegister(port) ( &(port->CRL) ) +# ifndef digitalPinHasPWM +# define digitalPinHasPWM(P) ( HAL_Validate_Pin_Function(P, PF_TIMER) == PF_TIMER ) +# endif + +#endif // PLATFORM_ID == PLATFORM_SPARK_CORE || PLATFORM_ID == PLATFORM_PHOTON_PRODUCTION || PLATFORM_ID == PLATFORM_P1 || PLATFORM_ID == PLATFORM_ELECTRON_PRODUCTION + +#ifndef _BV +#define _BV(x) (((uint32_t)1) << (x)) +#endif + +// XXX +#ifndef sei +#define sei() HAL_enable_irq(0) +#endif + +// XXX +#ifndef cli +#define cli() (void)HAL_disable_irq() +#endif + +#ifndef cbi +#define cbi(sfr, bit) ((sfr) &= ~_BV(bit)) +#endif +#ifndef sbi +#define sbi(sfr, bit) ((sfr) |= _BV(bit)) +#endif + +// XXX +#ifndef RwReg +typedef volatile uint32_t RwReg; +#endif + +// Pins + +// LED +#if PLATFORM_ID == PLATFORM_SPARK_CORE || PLATFORM_ID == PLATFORM_PHOTON_PRODUCTION || PLATFORM_ID == PLATFORM_P1 || PLATFORM_ID == PLATFORM_ELECTRON_PRODUCTION +# ifndef LED_BUILTIN +# define LED_BUILTIN D7 +# endif + +# ifndef ATN +# define ATN SS +# endif + +#endif // PLATFORM_ID == PLATFORM_SPARK_CORE || PLATFORM_ID == PLATFORM_PHOTON_PRODUCTION || PLATFORM_ID == PLATFORM_P1 || PLATFORM_ID == PLATFORM_ELECTRON_PRODUCTION + +// C++ only +#ifdef __cplusplus + +#ifndef isnan +#define isnan std::isnan +#endif + +#ifndef isinf +#define isinf std::isinf +#endif + + +// Hardware serial defines + +#ifndef UBRRH +#define UBRRH +#endif + +#ifndef UBRR1H +#define UBRR1H +#endif + +#if Wiring_Serial2 +#ifndef UBRR2H +#define UBRR2H +#endif +#endif + +#if Wiring_Serial3 +#ifndef UBRR3H +#define UBRR3H +#endif +#endif + +#if Wiring_Serial4 +#ifndef UBRR4H +#define UBRR4H +#endif +#endif +#if Wiring_Serial5 +#ifndef UBRR5H +#define UBRR5H +#endif +#endif + +typedef USARTSerial HardwareSerial; + +#ifndef SERIAL_PORT_MONITOR +#define SERIAL_PORT_MONITOR Serial +#endif + +#ifndef SERIAL_PORT_USBVIRTUAL +#define SERIAL_PORT_USBVIRTUAL Serial +#endif + +#ifndef SERIAL_PORT_HARDWARE_OPEN +#define SERIAL_PORT_HARDWARE_OPEN Serial1 +#endif + +#ifndef SERIAL_PORT_HARDWARE_OPEN1 +#define SERIAL_PORT_HARDWARE_OPEN1 Serial1 +#endif + +#if !defined(SERIAL_PORT_HARDWARE_OPEN2) && Wiring_Serial2 +#define SERIAL_PORT_HARDWARE_OPEN2 Serial2 +#endif + +#if !defined(SERIAL_PORT_HARDWARE_OPEN3) && Wiring_Serial3 +#define SERIAL_PORT_HARDWARE_OPEN3 Serial3 +#endif + +#if !defined(SERIAL_PORT_HARDWARE_OPEN4) && Wiring_Serial4 +#define SERIAL_PORT_HARDWARE_OPEN4 Serial4 +#endif + +#if !defined(SERIAL_PORT_HARDWARE_OPEN5) && Wiring_Serial5 +#define SERIAL_PORT_HARDWARE_OPEN5 Serial5 +#endif + +#ifndef SERIAL_PORT_HARDWARE +#define SERIAL_PORT_HARDWARE Serial1 +#endif + +#ifndef SERIAL_PORT_HARDWARE1 +#define SERIAL_PORT_HARDWARE1 Serial1 +#endif + +#if !defined(SERIAL_PORT_HARDWARE2) && Wiring_Serial2 +#define SERIAL_PORT_HARDWARE2 Serial2 +#endif + +#if !defined(SERIAL_PORT_HARDWARE3) && Wiring_Serial3 +#define SERIAL_PORT_HARDWARE3 Serial3 +#endif + +#if !defined(SERIAL_PORT_HARDWARE4) && Wiring_Serial4 +#define SERIAL_PORT_HARDWARE4 Serial4 +#endif + +#if !defined(SERIAL_PORT_HARDWARE5) && Wiring_Serial5 +#define SERIAL_PORT_HARDWARE5 Serial5 +#endif + +#ifndef SerialUSB +#define SerialUSB Serial +#endif + +#endif // __cplusplus + +#endif // PARTICLE_WIRING_ARDUINO_COMPATIBILTY + + #endif /* ARDUINO_H */ diff --git a/user/inc/application.h b/user/inc/application.h index abbe044d6f..be14937399 100644 --- a/user/inc/application.h +++ b/user/inc/application.h @@ -26,6 +26,10 @@ #ifndef APPLICATION_H_ #define APPLICATION_H_ +#ifndef PARTICLE_WIRING_ARDUINO_COMPATIBILTY +#define PARTICLE_WIRING_ARDUINO_COMPATIBILTY 0 +#endif + #include "system_version.h" #ifdef SPARK_PLATFORM @@ -82,13 +86,6 @@ using namespace spark; using namespace particle; -#ifndef PARTICLE_NO_ARDUINO_COMPATIBILITY -#define PARTICLE_NO_ARDUINO_COMPATIBILITY 0 -#endif -#if !PARTICLE_NO_ARDUINO_COMPATIBILITY -#undef PARTICLE_ARDUINO_COMPATIBILITY -#define PARTICLE_ARDUINO_COMPATIBILITY 1 -#endif #include "spark_wiring_arduino.h" #endif /* APPLICATION_H_ */ diff --git a/user/tests/wiring/api/arduino.cpp b/user/tests/wiring/api/arduino.cpp new file mode 100644 index 0000000000..35c159f924 --- /dev/null +++ b/user/tests/wiring/api/arduino.cpp @@ -0,0 +1,125 @@ +// including particle first should not stop the arduino chnages being added later +// the one exception is the template functinos min/max/constrain/range - these become the C++ +// template version when Arduino.h is included after particle.h + +#include "Particle.h" +#include "Arduino.h" + +#include "testapi.h" + +// SPISettings part of the API +void somefunc(SPISettings& s) { + +} + +test(has_min_and_max) { + min(0L, short(3)); + max(0L, short(3)); +} + +test(has_sq) { + (void)sq(5); +} + +test(abs) { + (void)abs(5.0); +} + +// FlashStringHelper +// construct, assign, copy, concat, +, +test(String_FlashStringHelper) { + const __FlashStringHelper* flash = reinterpret_cast("hello"); + + String s(flash); + s = flash; + String s2 = s + flash; + String s3 = String(flash); + s.concat(flash); +} + +class ShowThatFlashStringHelperIsDistinctType { + void f(const char* s) { + + } + + void f(const __FlashStringHelper* s) { + + } +}; + +test(character_analysis) { + isAlphaNumeric('c'); + isAlpha('c'); + isAscii('c'); + isWhitespace('c'); + isControl('c'); + isDigit('c'); + isGraph('c'); + isLowerCase('c'); + isPrintable('c'); + isPunct('c'); + isSpace('c'); + isUpperCase('c'); + isHexadecimalDigit('c'); + toAscii('c'); + toLowerCase('c'); + toUpperCase('c'); +} + +test(Wire_setClock) { + Wire.setClock(4000000); + Wire.setSpeed(4000000); +} + +test(SPI_usingInterrupt) { + SPI.usingInterrupt(3); +} + +test(ifSerial) { + if (Serial) { + + } +} + +test(pow) { + pow(3.0, 5.0); +} + +test(map) { + map(1,2,3,4,5); +} + +test(trigs) { + sin(0.5); + cos(0.5); + tan(0.5); +} + +test(LED_BUILTIN) { + if (LED_BUILTIN>0) { + + } +} + +test(sqrt) { + sqrt(2.0); +} + +test(word) { + if (word(2)>2) { + + } +} + + +test(bytes) { + (void)(lowByte(0x0304)); + (void)(highByte(0x0343)); + int x = 0; + bitRead(x, 4); + bitWrite(x, 4, false); + bitSet(x,4); + bitClear(x,4); + (void)x; + bit(3); +} diff --git a/user/tests/wiring/api/spi.cpp b/user/tests/wiring/api/spi.cpp index e49b610300..31c64615a5 100644 --- a/user/tests/wiring/api/spi.cpp +++ b/user/tests/wiring/api/spi.cpp @@ -15,4 +15,7 @@ test(spi_transfer) API_COMPILE(SPI.transfer(0)); API_COMPILE(SPI.transfer(NULL, NULL, 1, NULL)); API_COMPILE(SPI.transferCancel()); -} \ No newline at end of file +} + +// without Arduino.h we should not get a clash redefining SPISettings +class SPISettings {}; diff --git a/user/tests/wiring/no_fixture/spi.cpp b/user/tests/wiring/no_fixture/spi.cpp index 4db3961744..9f844d52a0 100644 --- a/user/tests/wiring/no_fixture/spi.cpp +++ b/user/tests/wiring/no_fixture/spi.cpp @@ -6,6 +6,8 @@ static volatile uint8_t DMA_Completed_Flag = 0; static uint8_t tempBuf[256]; static uint8_t tempBuf1[256]; +using particle::__SPISettings; + static void querySpiInfo(HAL_SPI_Interface spi, hal_spi_info_t* info) { memset(info, 0, sizeof(hal_spi_info_t)); @@ -13,14 +15,14 @@ static void querySpiInfo(HAL_SPI_Interface spi, hal_spi_info_t* info) HAL_SPI_Info(spi, info, nullptr); } -static SPISettings spiSettingsFromSpiInfo(hal_spi_info_t* info) +static __SPISettings spiSettingsFromSpiInfo(hal_spi_info_t* info) { if (!info->enabled || info->default_settings) - return SPISettings(); - return SPISettings(info->clock, info->bit_order, info->data_mode); + return __SPISettings(); + return __SPISettings(info->clock, info->bit_order, info->data_mode); } -static bool spiSettingsApplyCheck(SPIClass& spi, const SPISettings& settings, HAL_SPI_Interface interface = HAL_SPI_INTERFACE1) +static bool spiSettingsApplyCheck(SPIClass& spi, const __SPISettings& settings, HAL_SPI_Interface interface = HAL_SPI_INTERFACE1) { hal_spi_info_t info; spi.beginTransaction(settings); @@ -218,28 +220,28 @@ test(SPI_07_SPI_Settings_Are_Applied_In_Begin_Transaction) // Get current SPISettings hal_spi_info_t info; - SPISettings current, settings; + __SPISettings current, settings; querySpiInfo(HAL_SPI_INTERFACE1, &info); settings = spiSettingsFromSpiInfo(&info); // Configure SPI with default settings - SPI.beginTransaction(SPISettings()); + SPI.beginTransaction(__SPISettings()); querySpiInfo(HAL_SPI_INTERFACE1, &info); current = spiSettingsFromSpiInfo(&info); assertEqual(current, settings); SPI.endTransaction(); - assertTrue(spiSettingsApplyCheck(SPI, SPISettings(15*MHZ, MSBFIRST, SPI_MODE0))); - assertTrue(spiSettingsApplyCheck(SPI, SPISettings(10*MHZ, LSBFIRST, SPI_MODE1))); - assertTrue(spiSettingsApplyCheck(SPI, SPISettings(15*MHZ, MSBFIRST, SPI_MODE2))); - assertTrue(spiSettingsApplyCheck(SPI, SPISettings(10*MHZ, LSBFIRST, SPI_MODE3))); + assertTrue(spiSettingsApplyCheck(SPI, __SPISettings(15*MHZ, MSBFIRST, SPI_MODE0))); + assertTrue(spiSettingsApplyCheck(SPI, __SPISettings(10*MHZ, LSBFIRST, SPI_MODE1))); + assertTrue(spiSettingsApplyCheck(SPI, __SPISettings(15*MHZ, MSBFIRST, SPI_MODE2))); + assertTrue(spiSettingsApplyCheck(SPI, __SPISettings(10*MHZ, LSBFIRST, SPI_MODE3))); - assertTrue(spiSettingsApplyCheck(SPI, SPISettings(15*MHZ, MSBFIRST, SPI_MODE0))); - assertTrue(spiSettingsApplyCheck(SPI, SPISettings(10*MHZ, LSBFIRST, SPI_MODE1))); - assertTrue(spiSettingsApplyCheck(SPI, SPISettings(15*MHZ, MSBFIRST, SPI_MODE2))); - assertTrue(spiSettingsApplyCheck(SPI, SPISettings(10*MHZ, LSBFIRST, SPI_MODE3))); + assertTrue(spiSettingsApplyCheck(SPI, __SPISettings(15*MHZ, MSBFIRST, SPI_MODE0))); + assertTrue(spiSettingsApplyCheck(SPI, __SPISettings(10*MHZ, LSBFIRST, SPI_MODE1))); + assertTrue(spiSettingsApplyCheck(SPI, __SPISettings(15*MHZ, MSBFIRST, SPI_MODE2))); + assertTrue(spiSettingsApplyCheck(SPI, __SPISettings(10*MHZ, LSBFIRST, SPI_MODE3))); - assertTrue(spiSettingsApplyCheck(SPI, SPISettings())); + assertTrue(spiSettingsApplyCheck(SPI, __SPISettings())); SPI.end(); } @@ -254,29 +256,29 @@ test(SPI_08_SPI1_Settings_Are_Applied_In_Begin_Transaction) // Get current SPISettings hal_spi_info_t info; - SPISettings current, settings; + __SPISettings current, settings; querySpiInfo(HAL_SPI_INTERFACE2, &info); settings = spiSettingsFromSpiInfo(&info); // Configure SPI with default settings - SPI1.beginTransaction(SPISettings()); + SPI1.beginTransaction(__SPISettings()); querySpiInfo(HAL_SPI_INTERFACE2, &info); current = spiSettingsFromSpiInfo(&info); assertEqual(current, settings); SPI1.endTransaction(); - assertTrue(spiSettingsApplyCheck(SPI1, SPISettings(15*MHZ, MSBFIRST, SPI_MODE0), HAL_SPI_INTERFACE2)); - assertTrue(spiSettingsApplyCheck(SPI1, SPISettings(10*MHZ, LSBFIRST, SPI_MODE1), HAL_SPI_INTERFACE2)); - assertTrue(spiSettingsApplyCheck(SPI1, SPISettings(15*MHZ, MSBFIRST, SPI_MODE2), HAL_SPI_INTERFACE2)); - assertTrue(spiSettingsApplyCheck(SPI1, SPISettings(10*MHZ, LSBFIRST, SPI_MODE3), HAL_SPI_INTERFACE2)); + assertTrue(spiSettingsApplyCheck(SPI1, __SPISettings(15*MHZ, MSBFIRST, SPI_MODE0), HAL_SPI_INTERFACE2)); + assertTrue(spiSettingsApplyCheck(SPI1, __SPISettings(10*MHZ, LSBFIRST, SPI_MODE1), HAL_SPI_INTERFACE2)); + assertTrue(spiSettingsApplyCheck(SPI1, __SPISettings(15*MHZ, MSBFIRST, SPI_MODE2), HAL_SPI_INTERFACE2)); + assertTrue(spiSettingsApplyCheck(SPI1, __SPISettings(10*MHZ, LSBFIRST, SPI_MODE3), HAL_SPI_INTERFACE2)); - assertTrue(spiSettingsApplyCheck(SPI1, SPISettings(15*MHZ, MSBFIRST, SPI_MODE0), HAL_SPI_INTERFACE2)); - assertTrue(spiSettingsApplyCheck(SPI1, SPISettings(10*MHZ, LSBFIRST, SPI_MODE1), HAL_SPI_INTERFACE2)); - assertTrue(spiSettingsApplyCheck(SPI1, SPISettings(15*MHZ, MSBFIRST, SPI_MODE2), HAL_SPI_INTERFACE2)); - assertTrue(spiSettingsApplyCheck(SPI1, SPISettings(10*MHZ, LSBFIRST, SPI_MODE3), HAL_SPI_INTERFACE2)); + assertTrue(spiSettingsApplyCheck(SPI1, __SPISettings(15*MHZ, MSBFIRST, SPI_MODE0), HAL_SPI_INTERFACE2)); + assertTrue(spiSettingsApplyCheck(SPI1, __SPISettings(10*MHZ, LSBFIRST, SPI_MODE1), HAL_SPI_INTERFACE2)); + assertTrue(spiSettingsApplyCheck(SPI1, __SPISettings(15*MHZ, MSBFIRST, SPI_MODE2), HAL_SPI_INTERFACE2)); + assertTrue(spiSettingsApplyCheck(SPI1, __SPISettings(10*MHZ, LSBFIRST, SPI_MODE3), HAL_SPI_INTERFACE2)); - assertTrue(spiSettingsApplyCheck(SPI1, SPISettings(), HAL_SPI_INTERFACE2)); + assertTrue(spiSettingsApplyCheck(SPI1, __SPISettings(), HAL_SPI_INTERFACE2)); SPI1.end(); } @@ -292,29 +294,29 @@ test(SPI_09_SPI2_Settings_Are_Applied_In_Begin_Transaction) // Get current SPISettings hal_spi_info_t info; - SPISettings current, settings; + __SPISettings current, settings; querySpiInfo(HAL_SPI_INTERFACE3, &info); settings = spiSettingsFromSpiInfo(&info); // Configure SPI with default settings - SPI2.beginTransaction(SPISettings()); + SPI2.beginTransaction(__SPISettings()); querySpiInfo(HAL_SPI_INTERFACE3, &info); current = spiSettingsFromSpiInfo(&info); assertEqual(current, settings); SPI2.endTransaction(); - assertTrue(spiSettingsApplyCheck(SPI2, SPISettings(15*MHZ, MSBFIRST, SPI_MODE0), HAL_SPI_INTERFACE3)); - assertTrue(spiSettingsApplyCheck(SPI2, SPISettings(10*MHZ, LSBFIRST, SPI_MODE1), HAL_SPI_INTERFACE3)); - assertTrue(spiSettingsApplyCheck(SPI2, SPISettings(15*MHZ, MSBFIRST, SPI_MODE2), HAL_SPI_INTERFACE3)); - assertTrue(spiSettingsApplyCheck(SPI2, SPISettings(10*MHZ, LSBFIRST, SPI_MODE3), HAL_SPI_INTERFACE3)); + assertTrue(spiSettingsApplyCheck(SPI2, __SPISettings(15*MHZ, MSBFIRST, SPI_MODE0), HAL_SPI_INTERFACE3)); + assertTrue(spiSettingsApplyCheck(SPI2, __SPISettings(10*MHZ, LSBFIRST, SPI_MODE1), HAL_SPI_INTERFACE3)); + assertTrue(spiSettingsApplyCheck(SPI2, __SPISettings(15*MHZ, MSBFIRST, SPI_MODE2), HAL_SPI_INTERFACE3)); + assertTrue(spiSettingsApplyCheck(SPI2, __SPISettings(10*MHZ, LSBFIRST, SPI_MODE3), HAL_SPI_INTERFACE3)); - assertTrue(spiSettingsApplyCheck(SPI2, SPISettings(15*MHZ, MSBFIRST, SPI_MODE0), HAL_SPI_INTERFACE3)); - assertTrue(spiSettingsApplyCheck(SPI2, SPISettings(10*MHZ, LSBFIRST, SPI_MODE1), HAL_SPI_INTERFACE3)); - assertTrue(spiSettingsApplyCheck(SPI2, SPISettings(15*MHZ, MSBFIRST, SPI_MODE2), HAL_SPI_INTERFACE3)); - assertTrue(spiSettingsApplyCheck(SPI2, SPISettings(10*MHZ, LSBFIRST, SPI_MODE3), HAL_SPI_INTERFACE3)); + assertTrue(spiSettingsApplyCheck(SPI2, __SPISettings(15*MHZ, MSBFIRST, SPI_MODE0), HAL_SPI_INTERFACE3)); + assertTrue(spiSettingsApplyCheck(SPI2, __SPISettings(10*MHZ, LSBFIRST, SPI_MODE1), HAL_SPI_INTERFACE3)); + assertTrue(spiSettingsApplyCheck(SPI2, __SPISettings(15*MHZ, MSBFIRST, SPI_MODE2), HAL_SPI_INTERFACE3)); + assertTrue(spiSettingsApplyCheck(SPI2, __SPISettings(10*MHZ, LSBFIRST, SPI_MODE3), HAL_SPI_INTERFACE3)); - assertTrue(spiSettingsApplyCheck(SPI2, SPISettings(), HAL_SPI_INTERFACE3)); + assertTrue(spiSettingsApplyCheck(SPI2, __SPISettings(), HAL_SPI_INTERFACE3)); SPI2.end(); } @@ -329,7 +331,7 @@ test(SPI_10_SPI_Begin_Transaction_Locks) SPI.begin(); assertTrue(SPI.trylock()); SPI.unlock(); - SPI.beginTransaction(SPISettings()); + SPI.beginTransaction(__SPISettings()); assertFalse(SPI.trylock()); SPI.endTransaction(); assertTrue(SPI.trylock()); @@ -346,7 +348,7 @@ test(SPI_11_SPI1_Begin_Transaction_Locks) SPI1.begin(); assertTrue(SPI1.trylock()); SPI1.unlock(); - SPI1.beginTransaction(SPISettings()); + SPI1.beginTransaction(__SPISettings()); assertFalse(SPI1.trylock()); SPI1.endTransaction(); assertTrue(SPI1.trylock()); @@ -364,7 +366,7 @@ test(SPI_12_SPI2_Begin_Transaction_Locks) SPI2.begin(); assertTrue(SPI2.trylock()); SPI2.unlock(); - SPI2.beginTransaction(SPISettings()); + SPI2.beginTransaction(__SPISettings()); assertFalse(SPI2.trylock()); SPI2.endTransaction(); assertTrue(SPI2.trylock()); diff --git a/wiring/inc/avr/pgmspace.h b/wiring/inc/avr/pgmspace.h index 6567457508..f7884bf019 100644 --- a/wiring/inc/avr/pgmspace.h +++ b/wiring/inc/avr/pgmspace.h @@ -25,11 +25,21 @@ #include +#ifndef PROGMEM #define PROGMEM +#endif + +#ifndef PGM_P #define PGM_P const char * +#endif + +#ifndef PSTR #define PSTR(str) (str) +#endif +#ifndef _SFR_BYTE #define _SFR_BYTE(n) (n) +#endif typedef void prog_void; typedef char prog_char; @@ -49,20 +59,43 @@ 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)) + +#ifdef memcpy_P +#undef memcpy_P +#endif #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)) + +#ifdef strcmp_P +#undef strcmp_P +#endif #define strcmp_P(a, b) strcmp((a), (b)) + +#ifdef strcpy_P +#undef strcpy_P +#endif #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)) + +#ifdef strlcpy_P +#undef strlcpy_P +#endif #define strlcpy_P(s1, s2, n) strlcpy((s1), (s2), (n)) + +#ifdef strlen_P +#undef strlen_P +#endif #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)) @@ -92,17 +125,38 @@ typedef const void* uint_farptr_t; #define strlcpy_PF(dest, src, n) strlcpy((dest), (src), (n)) #define memcmp_PF(s1, s2, n) memcmp((s1), (s2), (n)) +#ifdef sprintf_P +#undef sprintf_P +#endif + #define sprintf_P(s, f, ...) sprintf((s), (f), __VA_ARGS__) + #define snprintf_P(s, f, ...) snprintf((s), (f), __VA_ARGS__) +#ifdef pgm_read_byte +#undef pgm_read_byte +#endif #define pgm_read_byte(addr) (*(const unsigned char *)(addr)) + +#ifdef pgm_read_word +#undef pgm_read_word +#endif #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)) +#ifdef pgm_read_byte_near +#undef pgm_read_byte_near +#endif #define pgm_read_byte_near(addr) pgm_read_byte(addr) + +#ifdef pgm_read_word_near +#undef pgm_read_word_near +#endif #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) diff --git a/wiring/inc/spark_wiring_arduino.h b/wiring/inc/spark_wiring_arduino.h index bcce5497ce..07c5ddcdde 100644 --- a/wiring/inc/spark_wiring_arduino.h +++ b/wiring/inc/spark_wiring_arduino.h @@ -20,246 +20,62 @@ #ifndef SPARK_WIRING_ARDUINO_H #define SPARK_WIRING_ARDUINO_H -#if PARTICLE_ARDUINO_COMPATIBILITY == 1 - -#ifndef ARDUINO -#define ARDUINO 10800 -#endif - -#ifndef __cplusplus -#include -#else -#include -#endif // __cplusplus - -#include "avr/pgmspace.h" -#include "spark_wiring_arduino_constants.h" -#include "spark_wiring_arduino_binary.h" - -#undef F -#define F(X) (reinterpret_cast(X)) - -#ifndef makeWord -inline uint16_t makeWord(uint16_t w) { - return w; -} - -inline uint16_t makeWord(uint8_t h, uint8_t l) { - return ((uint16_t)h << 8) | ((uint16_t)l); -} -#endif - -#ifndef word -#define word(...) makeWord(__VA_ARGS__) +#ifndef strcpy_P +#define strcpy_P strcpy #endif -#ifndef WEAK -#define WEAK __attribute__ ((weak)) +#ifndef strlcpy_P +#define strlcpy_P strncpy #endif -#ifndef SYSTEM_CORE_CLOCK -#define SYSTEM_CORE_CLOCK SystemCoreClock +#ifndef sprintf_P +#define sprintf_P sprintf #endif -#ifndef clockCyclesPerMicrosecond -#define clockCyclesPerMicrosecond() (SystemCoreClock / 1000000L) +#ifndef strlen_P +#define strlen_P strlen #endif -#ifndef clockCyclesToMicroseconds -#define clockCyclesToMicroseconds(a) (((a) * 1000L) / (SystemCoreClock / 1000L)) +#ifndef strcmp_P +#define strcmp_P strcmp #endif -#ifndef microsecondsToClockCycles -#define microsecondsToClockCycles(a) ((a) * (SystemCoreClock / 1000000L)) +#ifndef memcpy_P +#define memcpy_P memcpy #endif -#define digitalPinToInterrupt(P) (P) - -inline void yield() { -#if PLATFORM_THREADING - os_thread_yield(); -#endif // PLATFORM_THREADING -} - -#ifndef PINS_COUNT -#define PINS_COUNT TOTAL_PINS +#ifndef vsnprintf_P +#define vsnprintf_P vsnprintf #endif -#ifndef NUM_DIGITAL_PINS -#define NUM_DIGITAL_PINS TOTAL_PINS +#ifndef PROGMEM +#define PROGMEM #endif -#ifndef NUM_ANALOG_INPUTS -#define NUM_ANALOG_INPUTS TOTAL_ANALOG_PINS +#ifndef PSTR +#define PSTR(x) (x) #endif -#ifndef NUM_ANALOG_OUTPUTS -#define NUM_ANALOG_OUTPUTS TOTAL_DAC_PINS +#ifndef pgm_read_byte +#define pgm_read_byte(x) (*(x)) #endif -#ifndef analogInputToDigitalPin -#define analogInputToDigitalPin(p) (((p < TOTAL_ANALOG_PINS) && (p >= 0)) ? (p) + FIRST_ANALOG_PIN : -1) +#ifndef pgm_read_word +#define pgm_read_word(x) ((uint16_t)(*(x))) #endif -// XXX -#if PLATFORM_ID == PLATFORM_SPARK_CORE || PLATFORM_ID == PLATFORM_PHOTON_PRODUCTION || PLATFORM_ID == PLATFORM_P1 || PLATFORM_ID == PLATFORM_ELECTRON_PRODUCTION - -# ifndef digitalPinToPort -# define digitalPinToPort(P) ( HAL_Pin_Map()[P].gpio_peripheral ) -# endif - -# ifndef digitalPinToBitMask -# define digitalPinToBitMask(P) ( HAL_Pin_Map()[P].gpio_pin ) -# endif -//#define analogInPinToBit(P) ( ) -# ifndef portOutputRegister -# define portOutputRegister(port) ( &(port->ODR) ) -# endif - -# ifndef portInputRegister -# define portInputRegister(port) ( &(port->IDR) ) -# endif - -//#define portModeRegister(port) ( &(port->CRL) ) -# ifndef digitalPinHasPWM -# define digitalPinHasPWM(P) ( HAL_Validate_Pin_Function(P, PF_TIMER) == PF_TIMER ) -# endif - -#endif // PLATFORM_ID == PLATFORM_SPARK_CORE || PLATFORM_ID == PLATFORM_PHOTON_PRODUCTION || PLATFORM_ID == PLATFORM_P1 || PLATFORM_ID == PLATFORM_ELECTRON_PRODUCTION - -#ifndef _BV -#define _BV(x) (((uint32_t)1) << (x)) +#ifndef pgm_read_byte_near +#define pgm_read_byte_near(x) (*(x)) #endif -// XXX -#ifndef sei -#define sei() HAL_enable_irq(0) +#ifndef pgm_read_word_near +#define pgm_read_word_near(x) ((uint16_t)(*(x))) #endif -// XXX -#ifndef cli -#define cli() (void)HAL_disable_irq() -#endif - -#ifndef cbi -#define cbi(sfr, bit) ((sfr) &= ~_BV(bit)) -#endif -#ifndef sbi -#define sbi(sfr, bit) ((sfr) |= _BV(bit)) -#endif - -// XXX -#ifndef RwReg -typedef volatile uint32_t RwReg; -#endif - -// Pins - -// LED -#if PLATFORM_ID == PLATFORM_SPARK_CORE || PLATFORM_ID == PLATFORM_PHOTON_PRODUCTION || PLATFORM_ID == PLATFORM_P1 || PLATFORM_ID == PLATFORM_ELECTRON_PRODUCTION -# ifndef LED_BUILTIN -# define LED_BUILTIN D7 -# endif - -# ifndef ATN -# define ATN SS -# endif - -#endif // PLATFORM_ID == PLATFORM_SPARK_CORE || PLATFORM_ID == PLATFORM_PHOTON_PRODUCTION || PLATFORM_ID == PLATFORM_P1 || PLATFORM_ID == PLATFORM_ELECTRON_PRODUCTION - -// C++ only -#ifdef __cplusplus +#include "math.h" #ifndef isnan -#define isnan std::isnan -#endif - -#ifndef isinf -#define isinf std::isinf -#endif - - -// Hardware serial defines - -#define UBRRH -#define UBRR1H -#if Wiring_Serial2 -#define UBRR2H -#endif -#if Wiring_Serial3 -#define UBRR3H +#error isnan is not defined #endif -#if Wiring_Serial4 -#define UBRR4H -#endif -#if Wiring_Serial5 -#define UBRR5H -#endif - -typedef USARTSerial HardwareSerial; - -#ifndef SERIAL_PORT_MONITOR -#define SERIAL_PORT_MONITOR Serial -#endif - -#ifndef SERIAL_PORT_USBVIRTUAL -#define SERIAL_PORT_USBVIRTUAL Serial -#endif - -#ifndef SERIAL_PORT_HARDWARE_OPEN -#define SERIAL_PORT_HARDWARE_OPEN Serial1 -#endif - -#ifndef SERIAL_PORT_HARDWARE_OPEN1 -#define SERIAL_PORT_HARDWARE_OPEN1 Serial1 -#endif - -#if !defined(SERIAL_PORT_HARDWARE_OPEN2) && Wiring_Serial2 -#define SERIAL_PORT_HARDWARE_OPEN2 Serial2 -#endif - -#if !defined(SERIAL_PORT_HARDWARE_OPEN3) && Wiring_Serial3 -#define SERIAL_PORT_HARDWARE_OPEN3 Serial3 -#endif - -#if !defined(SERIAL_PORT_HARDWARE_OPEN4) && Wiring_Serial4 -#define SERIAL_PORT_HARDWARE_OPEN4 Serial4 -#endif - -#if !defined(SERIAL_PORT_HARDWARE_OPEN5) && Wiring_Serial5 -#define SERIAL_PORT_HARDWARE_OPEN5 Serial5 -#endif - -#ifndef SERIAL_PORT_HARDWARE -#define SERIAL_PORT_HARDWARE Serial1 -#endif - -#ifndef SERIAL_PORT_HARDWARE1 -#define SERIAL_PORT_HARDWARE1 Serial1 -#endif - -#if !defined(SERIAL_PORT_HARDWARE2) && Wiring_Serial2 -#define SERIAL_PORT_HARDWARE2 Serial2 -#endif - -#if !defined(SERIAL_PORT_HARDWARE3) && Wiring_Serial3 -#define SERIAL_PORT_HARDWARE3 Serial3 -#endif - -#if !defined(SERIAL_PORT_HARDWARE4) && Wiring_Serial4 -#define SERIAL_PORT_HARDWARE4 Serial4 -#endif - -#if !defined(SERIAL_PORT_HARDWARE5) && Wiring_Serial5 -#define SERIAL_PORT_HARDWARE5 Serial5 -#endif - -#ifndef SerialUSB -#define SerialUSB Serial -#endif - -#endif // __cplusplus - -#endif // PARTICLE_ARDUINO_COMPATIBILITY #endif /* SPARK_WIRING_ARDUINO_H */ diff --git a/wiring/inc/spark_wiring_arduino_constants.h b/wiring/inc/spark_wiring_arduino_constants.h index a5a925fab5..4a2cbd3887 100644 --- a/wiring/inc/spark_wiring_arduino_constants.h +++ b/wiring/inc/spark_wiring_arduino_constants.h @@ -68,20 +68,8 @@ #define EULER 2.718281828459045235360287471352 #endif -#ifdef abs -#undef abs -#endif - #ifndef abs -#define abs(x) ((x)>0?(x):-(x)) -#endif - -#ifndef constrain -#define constrain(amt, low, high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) -#endif - -#ifndef round -#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) +#define abs(x) ((x)>0?(x):-(x)) #endif #ifndef radians @@ -96,6 +84,43 @@ #define sq(x) ((x)*(x)) #endif + +#if PARTICLE_WIRING_ARDUINO_TEMPLATES +#ifdef min +#undef min +#endif + +#ifdef max +#undef max +#endif + +#ifdef constrain +#undef constrain +#endif + +#ifdef round +#undef round +#endif + +#else +#ifndef min +#define min(a,b) ((a)<(b)?(a):(b)) +#endif + +#ifndef max +#define max(a,b) ((a)>(b)?(a):(b)) +#endif + +#ifndef constrain +#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) +#endif + +#ifndef round +#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) +#endif + +#endif // #ifdef PARTICLE_WIRING_ARDUINO_TEMPLATES + #ifndef lowByte #define lowByte(w) ((uint8_t) ((w) & 0xff)) #endif diff --git a/wiring/inc/spark_wiring_constants.h b/wiring/inc/spark_wiring_constants.h index 4eacefb62f..4a093eb640 100644 --- a/wiring/inc/spark_wiring_constants.h +++ b/wiring/inc/spark_wiring_constants.h @@ -35,6 +35,9 @@ enum PinState { HIGH = 1 }; +#if !defined(PARTICLE_WIRING_ARDUINO_COMPATIBILTY) || !PARTICLE_WIRING_ARDUINO_COMPATIBILTY +#define PARTICLE_WIRING_ARDUINO_TEMPLATES 1 + template static inline typename std::common_type::type @@ -52,6 +55,9 @@ T constrain (T amt, U low, V high) { return ((amt)<(low)?(low):((amt)>(high)?(hi template static inline T round (T x) { return ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)); } +#else +#define PARTICLE_WIRING_ARDUINO_TEMPLATES 0 +#endif // #ifndef PARTICLE_WIRING_ARDUINO_COMPATIBILTY typedef bool boolean; typedef uint8_t byte; diff --git a/wiring/inc/spark_wiring_i2c.h b/wiring/inc/spark_wiring_i2c.h index a577a854a1..879ccf98df 100644 --- a/wiring/inc/spark_wiring_i2c.h +++ b/wiring/inc/spark_wiring_i2c.h @@ -40,7 +40,9 @@ class TwoWire : public Stream public: TwoWire(HAL_I2C_Interface i2c); virtual ~TwoWire() {}; - + inline void setClock(uint32_t speed) { + setSpeed(speed); + } void setSpeed(uint32_t); void enableDMAMode(bool); void stretchClock(bool); diff --git a/wiring/inc/spark_wiring_spi.h b/wiring/inc/spark_wiring_spi.h index 9f7ac266f2..491c7f5931 100644 --- a/wiring/inc/spark_wiring_spi.h +++ b/wiring/inc/spark_wiring_spi.h @@ -47,9 +47,10 @@ enum FrequencyScale SPI_CLK_PHOTON = 60*MHZ }; -class SPISettings : public Printable { +namespace particle { +class __SPISettings : public Printable { public: - SPISettings(uint32_t clock, uint8_t bitOrder, uint8_t dataMode) + __SPISettings(uint32_t clock, uint8_t bitOrder, uint8_t dataMode) : default_{false}, clock_{clock}, bitOrder_{bitOrder}, @@ -57,11 +58,11 @@ class SPISettings : public Printable { { } - SPISettings() + __SPISettings() { } - bool operator==(const SPISettings& other) const + bool operator==(const __SPISettings& other) const { if (default_ && other.default_) return true; @@ -77,7 +78,7 @@ class SPISettings : public Printable { return false; } - bool operator>=(const SPISettings& other) const + bool operator>=(const __SPISettings& other) const { if (default_ && other.default_) return true; @@ -93,7 +94,7 @@ class SPISettings : public Printable { return false; } - bool operator<=(const SPISettings& other) const + bool operator<=(const __SPISettings& other) const { if (default_ && other.default_) return true; @@ -109,7 +110,7 @@ class SPISettings : public Printable { return false; } - bool operator!=(const SPISettings& other) const + bool operator!=(const __SPISettings& other) const { return !(other == *this); } @@ -127,12 +128,13 @@ class SPISettings : public Printable { } private: - friend class SPIClass; + friend class ::SPIClass; bool default_ = true; uint32_t clock_ = 0; uint8_t bitOrder_ = 0; uint8_t dataMode_ = 0; }; +} class SPIClass { private: @@ -160,8 +162,10 @@ class SPIClass { void setBitOrder(uint8_t); void setDataMode(uint8_t); + static void usingInterrupt(uint8_t) {}; + int32_t beginTransaction(); - int32_t beginTransaction(const SPISettings& settings); + int32_t beginTransaction(const particle::__SPISettings& settings); void endTransaction(); /** diff --git a/wiring/inc/spark_wiring_string.h b/wiring/inc/spark_wiring_string.h index 27cf35b748..fc9671c9c7 100644 --- a/wiring/inc/spark_wiring_string.h +++ b/wiring/inc/spark_wiring_string.h @@ -65,6 +65,7 @@ class String String(const char *cstr = ""); String(const char *cstr, unsigned int length); String(const String &str); + String(const __FlashStringHelper *pstr); String(const Printable& printable); #ifdef __GXX_EXPERIMENTAL_CXX0X__ String(String &&rval); @@ -92,6 +93,7 @@ class String // marked as invalid ("if (s)" will be false). String & operator = (const String &rhs); String & operator = (const char *cstr); + String & operator = (const __FlashStringHelper *pstr); #ifdef __GXX_EXPERIMENTAL_CXX0X__ String & operator = (String &&rval); String & operator = (StringSumHelper &&rval); @@ -106,6 +108,7 @@ class String // concatenation is considered unsucessful. unsigned char concat(const String &str); unsigned char concat(const char *cstr); + unsigned char concat(const __FlashStringHelper * str); unsigned char concat(char c); unsigned char concat(unsigned char c); unsigned char concat(int num); @@ -205,6 +208,8 @@ class String // copy and move String & copy(const char *cstr, unsigned int length); + String & copy(const __FlashStringHelper *pstr, unsigned int length); + #ifdef __GXX_EXPERIMENTAL_CXX0X__ void move(String &rhs); #endif diff --git a/wiring/src/spark_wiring_spi.cpp b/wiring/src/spark_wiring_spi.cpp index eaaf8c740f..6a10d0a891 100644 --- a/wiring/src/spark_wiring_spi.cpp +++ b/wiring/src/spark_wiring_spi.cpp @@ -35,11 +35,11 @@ static void querySpiInfo(HAL_SPI_Interface spi, hal_spi_info_t* info) HAL_SPI_Info(spi, info, nullptr); } -static SPISettings spiSettingsFromSpiInfo(hal_spi_info_t* info) +static particle::__SPISettings spiSettingsFromSpiInfo(hal_spi_info_t* info) { if (!info->enabled || info->default_settings) - return SPISettings(); - return SPISettings(info->clock, info->bit_order, info->data_mode); + return particle::__SPISettings(); + return particle::__SPISettings(info->clock, info->bit_order, info->data_mode); } SPIClass::SPIClass(HAL_SPI_Interface spi) @@ -98,13 +98,13 @@ int32_t SPIClass::beginTransaction() return 0; } -int32_t SPIClass::beginTransaction(const SPISettings& settings) +int32_t SPIClass::beginTransaction(const particle::__SPISettings& settings) { lock(); // Get Current SPISettings hal_spi_info_t info; querySpiInfo(_spi, &info); - SPISettings current = spiSettingsFromSpiInfo(&info); + particle::__SPISettings current = spiSettingsFromSpiInfo(&info); // If they differ, reconfigure SPI peripheral if (settings != current) { diff --git a/wiring/src/spark_wiring_string.cpp b/wiring/src/spark_wiring_string.cpp index b1ee0b7223..13b5dded2d 100644 --- a/wiring/src/spark_wiring_string.cpp +++ b/wiring/src/spark_wiring_string.cpp @@ -84,6 +84,13 @@ String::String(const String &value) *this = value; } +String::String(const __FlashStringHelper *pstr) +{ + init(); + const char* cstr = reinterpret_cast(pstr); + if (cstr) copy(cstr, strlen(cstr)); +} + #ifdef __GXX_EXPERIMENTAL_CXX0X__ String::String(String &&rval) { @@ -222,6 +229,10 @@ String & String::copy(const char *cstr, unsigned int length) return *this; } +String & String::copy(const __FlashStringHelper *pstr, unsigned int length) { + return copy(reinterpret_cast(pstr), length); +} + #ifdef __GXX_EXPERIMENTAL_CXX0X__ void String::move(String &rhs) { @@ -254,6 +265,14 @@ String & String::operator = (const String &rhs) return *this; } +String & String::operator = (const __FlashStringHelper *pstr) +{ + const char* cstr = reinterpret_cast(pstr); + if (cstr) copy(cstr, strlen(cstr)); + else invalidate(); + return *this; +} + #ifdef __GXX_EXPERIMENTAL_CXX0X__ String & String::operator = (String &&rval) { @@ -302,6 +321,10 @@ unsigned char String::concat(const char *cstr) return concat(cstr, strlen(cstr)); } +unsigned char String::concat(const __FlashStringHelper * str) { + return concat(reinterpret_cast(str)); +} + unsigned char String::concat(char c) { char buf[2];