This may be a general C question and not an Atmel Studio question per se. I am using Atmel Studio 7.0.1188 so I will post in this forum.
I have created a library that I want to reuse. The library exists on it's own as a "GCC C Static Library Project." It is critical to its function that the library makes use of utils/delay.h. As we are all aware, delay.h requires the definition of the macro F_CPU.
I would like to use the library on multiple projects that run on different devices operating at different speeds. However, to my understanding, this requires that that I either:
- Define F_CPU in the library code and change it each time I compile for a new device,
- Define F_CPU in the project's tool chain properties and change it each time I compile for a new device, or
- Copy the code into each project where it will be used and set up a header file that defines the marcos that want to use for the target device (like the tutorial on "Modularizing C Code: Managing large projects").
None of these seems ideal. Options 1 and 2 lends themselves to errors (forgetting to change the macros) and Option 2 presents a configuration management issue with multiple copies of the same code (making a change to the library).
Is there a way that I can define F_CPU at compile time based on the project? Is there any other options that you can think of that I have overlooked?
Thanks in advance for any assistance.