Jump to content

  • Log In with Google      Sign In   
  • Create Account

Photo

Writing a multi-plateform library with IF DEFINED


  • Please log in to reply
4 replies to this topic

#1 xv4y

xv4y

    Level 1

  • Members
  • 102 posts
  • LocationViêt-Nam

Posted 13 January 2013 - 11:15 AM

Hi,

 

I am trying to write a library that could compile with both Arduino and Energia (MSP430).

It should be easy because there are only a few changes involved in the .h header file (calls to different libraries) and the .cpp implementation file. I try to use the following preprocessor directives. 

#if defined (ARDUINO)

#elif defined (ENERGIA)

#endif

 

However this does not work as Energia still try to compile the arduino code.

Am I doing something wrong ?

Did someone experience the same ?

 

Thanks,

Yan.

 


---
Yannick DEVOS - XV4Y

http://xv4y.radioclub.asia/


#2 xv4y

xv4y

    Level 1

  • Members
  • 102 posts
  • LocationViêt-Nam

Posted 13 January 2013 - 03:07 PM

Well, I read a little bit more about GCC preprocessor directives and found that even if the code is not compiled, it has to be valid since it goes through transformations and tokenization.

That poses a problem because the AVR interrupt declaration are not valid for mspgcc...

SIGNAL(TIMER1_COMPA_vect)
{
...
}

 

I will have to dig in the AVR code a little bit more than I though.

 

Yan.


---
Yannick DEVOS - XV4Y

http://xv4y.radioclub.asia/


#3 xv4y

xv4y

    Level 1

  • Members
  • 102 posts
  • LocationViêt-Nam

Posted 13 January 2013 - 03:37 PM

Well, finally it is related to the inclusion of legacymsp430.h.

If I put it in the main code, it works. If I put it in a #if defined it does not work.

Please can someone have a look to my code at tell me if I am doing something wrong here :

#include "VirtualWire.h"
#include <util/crc16.h>

#if ARDUINO >= 100		// Recent Arduino IDE versions
#include <Arduino.h>
#elif ARDUINO < 100		// Older
#include <wiring.h>
#include <WProgram.h>
#elif defined(ENERGIA)	// Energia for LaunchPad (not tested on FraunchPad and StellarPad)
#include <Energia.h>
//#include <legacymsp430.h>
#define SIGNAL()
	void()
#else // error
#error Platform not supported
#endif

 

It is late now and I must go to sleep. Tomorrow kids get up at 5:30 at go to school at 7...

 

Thanks,

Yan.


---
Yannick DEVOS - XV4Y

http://xv4y.radioclub.asia/


#4 Rei Vilo

Rei Vilo

    Level 3

  • Members
  • 611 posts
  • LocationFrance

Posted 13 January 2013 - 08:59 PM

Energia uses both ARDUINO and ENERGIA variables to compile.

 

So you need to test ENERGIA first and ARDUINO after:

 

 

#if defined(ENERGIA)
...
#elif defined(ARDUINO) && (ARDUINO>100)
...
#endif

 

 

Please refer to this tutorial: Manage Code for Multiple Platforms with two approaches, MCU-based and IDE-based.

 

If you have a Mac computer, why not to try the template I've developed for Xcode? Have a look at embedXcode, embedded computing on Xcode.


  • xv4y likes this

#5 xv4y

xv4y

    Level 1

  • Members
  • 102 posts
  • LocationViêt-Nam

Posted 14 January 2013 - 03:18 AM

Hi Rei Vilo,

 

Once again you're a master.

You tutorial is really helping.

At first I took your 5110 lib as example, but going the IDE specific way is not the best since this library (VirtualWire) use Timers that are specific to processors.

Going with the MCU specific macros did the trick.

 

To be honest, yesterday right after turning off the computer and going downstair heading to the bed I found a solution with more macro def...

I tested it this morning and it was compiling ok. I have not checked it was running ok thought.

Anyhow, it was more a workaround than a neat solution.

 

Thanks,

Yan.


---
Yannick DEVOS - XV4Y

http://xv4y.radioclub.asia/





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users