Skip to content

Commit

Permalink
Merge pull request #1283 from spark/feature/arduino_compatibility_reg…
Browse files Browse the repository at this point in the history
…ression

Feature/arduino compatibility regression
  • Loading branch information
m-mcgowan authored Apr 5, 2017
2 parents 2ef3d73 + c3fe44e commit 724c359
Show file tree
Hide file tree
Showing 19 changed files with 629 additions and 310 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 0 additions & 10 deletions docs/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 0 additions & 8 deletions platform/import.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions system/inc/system_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
5 changes: 4 additions & 1 deletion system/inc/system_threading.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stddef.h>
#include <functional>
#include <mutex>
Expand All @@ -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
*/
Expand Down
269 changes: 269 additions & 0 deletions user/inc/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <math.h>
#else
#include <cmath>
#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<const __FlashStringHelper*>(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 */

11 changes: 4 additions & 7 deletions user/inc/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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_ */
Loading

0 comments on commit 724c359

Please sign in to comment.