I am going to build a simple library (.a file) in IAR Workbench for STM8. In this library, I want to implement both hardware SPI and software SPI for users to choose.
In my library.c, I wrote:
#include "library.h"
void LibraryInit()
{
#ifdef HARDWARE_SPI
funcToInitHardwareSPI();
#else
funcToInitSoftwareSPI();
#endif
}
And in my library.h, I wrote:
#ifndef __LIB_H
#define __LIB_H
#define HARDWARE_SPI
void LibraryInit();
#endif
Then I think if user define #define HARDWARE_SPI
in the target project, the library will run hardware SPI part. If not, software SPI should be in use.
But after I build the project and added library.a and library.h into testing project, with library.h has no #define HARDWARE_SPI
, the routine is still going into hardware SPI part. How can I build the library.a that can let user choose the function by writing #define
in the header file?