I am working on a GLCD library for embedded devices. The idea is to split it into highlevel and lowlevel section. This allows the “user” to just write the lowlevel functions for his display controller, and use the highlevel functions like line-, cricle-, string drawing etc. without rewriting these functions.
To keep things easy, I decided that the user of the library just has to do the following, for example to use a display with SSD1289 controller, in his main.c:
#define LCD_USE_SSD1289
Example file ssd1289_lld.h:
#ifdef LCD_USE_SSD1289
lld_lcdInit(void);
#endif
Example file ssd1289_lld.c:
lld_lcdInit(void) {
// do some stuff for this controller
}
Example file s6d1121_lld.h:
#ifdef LCD_USE_S6D1121
lld_lcdInit(void);
#endif
Example file s6d1121_lld.c:
lld_lcdInit(void) {
// do some stuff for this controller
}
Inside the highlevel file, I’ll just do:
#include "drivers/ssd1289_lld.h"
#include "drivers/s6d1121_lld.h"
void lcdInit(void) {
lld_lcdInit();
}
But this does somehow not work:
- When I don’t do any #define LCD_USE_SSD1289 it does work without any problems
- After adding a second driver for a different type of controller, it still work without defining any type, and it also works when I define the wrong controller type.
What am I doing wrong?
Make sure the preprocessor puts the
#ifdef LCD_USE_SSD1289after the#define LCD_USE_SSD1289area. You said#define LCD_USE_SSD1289was in themain.cfile. You should really use a separate definitions.h file that is#included at the top of ssd1289_lld.h. Hope that helps.