Joel Bodenmann
Joel Bodenmann

Reputation: 2282

use #ifdef for custom drivers

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:

What am I doing wrong?

Upvotes: 1

Views: 284

Answers (1)

Hans Z
Hans Z

Reputation: 4744

Make sure the preprocessor puts the #ifdef LCD_USE_SSD1289 after the #define LCD_USE_SSD1289 area. You said #define LCD_USE_SSD1289 was in the main.c file. You should really use a separate definitions.h file that is #included at the top of ssd1289_lld.h. Hope that helps.

Upvotes: 1

Related Questions