Problem making a third part library: works on Micro but not on Due

Hi everybody!
I'm trying to create new library and I've followed the instructions posted here: Arduino IDE 1.5: Library specification · arduino/Arduino Wiki · GitHub.
Since this library should work for Due and Micro, I've used the pre-compiler instruction

#if defined(ARDUINO_ARCH_SAM)

to identify special code for Arduino Due, and

#if defined(__AVR_ATmega32U4__)

to identify special code for Micro.

The library needs as support others libraries, such as "AltSoftSerial" (to create new RX/TX pins simulated via software for Micro) and "DueFlashStorage" (so Due can store some data in his code memory).
So, I make the inclusion of AltSoftSerial only for Micro, and DueFlashStorage only for Due.

As inticated in the above link, I create a folder named as my library (QBMicroController) which has the subfolders:

  • src: contains QBMicroController.h and .cpp and other subfolers with others files
  • examples
  • deviceSpecificLibrary: contains AltSoftSerial and DueFlashStorage subfolders

Then, I tried to compile the mainLoop.ino example in the folder "examples":
If I select "Micro" as Board in Arduino IDE every thing is fine and the compilation works well.
If I select "Due" as Board, then I have the following errors:

Arduino: 1.5.6-r2 (Windows 7), Board: "Arduino Due (Programming Port)"

In file included from C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp:25:
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\/config/known_boards.h:101: error: #error "Please define your board timer and pins"
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp: In static member function 'static void AltSoftSerial::init(uint32_t)':
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp:64: error: 'CONFIG_TIMER_NOPRESCALE' was not declared in this scope
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp:68: error: 'CONFIG_TIMER_PRESCALE_8' was not declared in this scope
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp:75: error: 'INPUT_CAPTURE_PIN' was not declared in this scope
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp:76: error: 'OUTPUT_COMPARE_A_PIN' was not declared in this scope
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp:85: error: 'ENABLE_INT_INPUT_CAPTURE' was not declared in this scope
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp: In static member function 'static void AltSoftSerial::end()':
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp:90: error: 'DISABLE_INT_COMPARE_B' was not declared in this scope
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp:91: error: 'DISABLE_INT_INPUT_CAPTURE' was not declared in this scope
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp:94: error: 'DISABLE_INT_COMPARE_A' was not declared in this scope
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp: In static member function 'static void AltSoftSerial::writeByte(uint8_t)':
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp:110: error: 'SREG' was not declared in this scope
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp:111: error: 'cli' was not declared in this scope
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp:119: error: 'ENABLE_INT_COMPARE_A' was not declared in this scope
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp:120: error: 'CONFIG_MATCH_CLEAR' was not declared in this scope
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp:121: error: 'GET_TIMER_COUNT' was not declared in this scope
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp:121: error: 'SET_COMPARE_A' was not declared in this scope
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp: In function 'void COMPARE_A_INTERRUPT()':
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp:134: error: 'GET_COMPARE_A' was not declared in this scope
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp:142: error: 'CONFIG_MATCH_SET' was not declared in this scope
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp:144: error: 'CONFIG_MATCH_CLEAR' was not declared in this scope
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp:146: error: 'SET_COMPARE_A' was not declared in this scope
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp:156: error: 'CONFIG_MATCH_SET' was not declared in this scope
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp:157: error: 'SET_COMPARE_A' was not declared in this scope
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp:164: error: 'CONFIG_MATCH_NORMAL' was not declared in this scope
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp:165: error: 'DISABLE_INT_COMPARE_A' was not declared in this scope
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp:172: error: 'CONFIG_MATCH_CLEAR' was not declared in this scope
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp:173: error: 'SET_COMPARE_A' was not declared in this scope
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp: In function 'void CAPTURE_INTERRUPT()':
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp:197: error: 'GET_INPUT_CAPTURE' was not declared in this scope
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp:200: error: 'CONFIG_CAPTURE_FALLING_EDGE' was not declared in this scope
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp:203: error: 'CONFIG_CAPTURE_RISING_EDGE' was not declared in this scope
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp:209: error: 'SET_COMPARE_B' was not declared in this scope
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp:210: error: 'ENABLE_INT_COMPARE_B' was not declared in this scope
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp:225: error: 'DISABLE_INT_COMPARE_B' was not declared in this scope
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp:232: error: 'CONFIG_CAPTURE_FALLING_EDGE' was not declared in this scope
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp: In function 'void COMPARE_B_INTERRUPT()':
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp:250: error: 'DISABLE_INT_COMPARE_B' was not declared in this scope
C:\Users\Marco\Documents\Arduino\libraries\AltSoftSerial\AltSoftSerial.cpp:251: error: 'CONFIG_CAPTURE_FALLING_EDGE' was not declared in this scope

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

I don't understand why when compiling for Arduino Due the compiler includes a library (AltSoftSerial) that I've told it not to include.

I attach the library folder, if someone has any ideas on that, I'd appreciate if you could let me know ...

Marco.

QBMicroController.zip (61.1 KB)

The IDE determines what needs to be compiled by scanning your sketch, and copying things that are included in the sketch - NOT those things included in the cpp file that is ultimately compiled.

Since your sketch necessarily includes AltSoftSerial.h, AltSoftSerial.cpp is copied to the build directory, and will be compiled, even though the resulting .o file will not be used on the Due.

You'll need to make AltSoftSerial compile successfully (even though it does nothing) when the board type is Due.

Hi Paul,
thanks for your replay!

Does the IDE include AltSoftSerial even if in mainLoop.ino I use

#if defined(__AVR_ATmega32U4__)//#ifdef ARDUINO MICRO

  #include <EEPROM.h>
  #include "AltSoftSerial.h"
  #include <SoftwareSerial.h>

#endif

in order to avoid the inclusion if I'm compiling for Due?

I can't make AltSoftSerial compile successfully because it uses some definitions that aren't available when compiling for Due ... Do you think there is anyway to handle this problem instead of changing most of the AltSoftSerial library?

Thanks,
Marco.

Does the IDE include AltSoftSerial even if in mainLoop.ino I use

Yes, it odes. When the IDE scans the code it is looking for #include statements. It does NOT care that they will not actually be part of the cpp file that the compiler will see.

Do you think there is anyway to handle this problem instead of changing most of the AltSoftSerial library?

Don't use the IDE. If you do, you must make AltSoftSerial compile when the board is the Due. It really isn't that hard.

In the header file, inside the inclusion guard, add:
#if !defined (whatever makes it a due)

At the bottom, before the #endif, add another #endif.

Do the same in the source file. When the compiler sees the AltSoftSerial.cpp file, it will appear to be empty, and the class definition in the header file won't exist. Empty files compile easily.

Great!!!

You're right, after a few additional changes I can compile both for Micro and Due ... I had to remember the KISS philosophy!

Thank you very much Paul!

Marco.