With the
embedXcode template, I'm dealing with 6 different Processing-based IDEs with Wiring-derived frameworks: Arduino 0023 and 1.0, Wiring, Maple IDE, chipKIT MPIDE and LaunchPad MSP430 Energia.
Needless to say none is fully compatible. So when I develop a library I want to use on different boards, as the
Serial_LCD library suite, I need to test the MCU, ending in such inelegant code

as:
// Core library
#if defined (__AVR_ATmega328P__) || defined(__AVR_ATmega2560__) // Arduino specific
#include "WProgram.h"
#elif defined(__32MX320F128H__) || defined(__32MX795F512L__) // chipKIT specific
#include "WProgram.h"
#elif defined(__AVR_ATmega644P__) // Wiring specific
#include "Wiring.h"
#elif defined(__MSP430G2452__) || defined(__MSP430G2553__) || defined(__MSP430G2231__) // LaunchPad specific
#include "Energia.h"
#elif defined(MCU_STM32F103RB) || defined(MCU_STM32F103ZE) || defined(MCU_STM32F103CB) || defined(MCU_STM32F103RE) // Maple specific
#include "WProgram.h"
#else // error
#error Platform not defined
#endif
As at today, some of the IDEs have specific definitions passed on as arguments to the compiler and linker:
- Arduino uses -DARDUINO=23 or -DARDUINO=100,
- Wiring has -DWIRING=100
- and MapleIDE uses -DMAPLE_IDE.
- Energia for LaunchPad is considering -DENERGIA=6
- and chipKIT sticks with -DARDUINO=23 -Danything_you_want -Danything=1.
The question is, in the new Wiring framework, is there a clean way for identifying the platform and its corresponding framework?
The main benefit is a more readable code, as:
// Core library
#if defined(WIRING) // Wiring specific
#include "Wiring.h"
#if defined(MPIDE) // chipKIT specific
#include "WProgram.h"
#elif defined(ENERGIA) // LaunchPad specific
#include "Energia.h"
#elif defined(MAPLE_IDE) // Maple specific
#include "WProgram.h"
#elif defined(ARDUINO) && (ARDUINO >= 100) // Arduino 1.0 specific
#include "Arduino.h"
#elif defined(ARDUINO) && (ARDUINO < 100) // Arduino 23 specific
#include "WProgram.h"
#else // error
#error Platform not defined
#endif
The test on
ARDUINO comes last as some IDE may use two definitions.