diff --git a/font.c b/font.c new file mode 100644 index 0000000..b714447 --- /dev/null +++ b/font.c @@ -0,0 +1,16 @@ + +/** \file + + \brief Font broker. + + Here we map generic font variables to the actually used font. This is done in + a rather primitive way by having the same variable name in all font variants + and wrapping each font in the corresponding #ifdef. +*/ + +#include "font.h" + +#define TEACUP_C_INCLUDE +#include "font_8x4.c" +//#include "font_ another.c" +#undef TEACUP_C_INCLUDE diff --git a/font.h b/font.h new file mode 100644 index 0000000..5b5f2b4 --- /dev/null +++ b/font.h @@ -0,0 +1,35 @@ + +#ifndef _FONT_H +#define _FONT_H + +#include +#include "arduino.h" // For PROGMEM. + +/** + So far we have only one font and no choice for fonts in Configtool, + so just paraphrase handling of distinct fonts. +*/ + +//#if defined DISPLAY_FONT_8X4 + + #define FONT_ROWS 8 + #define FONT_COLUMNS 4 + #define FONT_SYMBOL_SPACE 1 + #define FONT_IS_PROPORTIONAL + +//#elif defined DISPLAY_FONT_...another font + + // ... ... + +//#endif + +typedef struct { + #ifdef FONT_IS_PROPORTIONAL + uint8_t columns; + #endif + uint8_t data[FONT_COLUMNS]; +} symbol_t; + +extern const symbol_t PROGMEM font[]; + +#endif /* _FONT_H */ diff --git a/font_8x4.c b/font_8x4.c index 981efd0..8e41dbb 100644 --- a/font_8x4.c +++ b/font_8x4.c @@ -8,9 +8,12 @@ removed from font. */ -#include "font_8x4.h" +// So far we have no #define DISPLAY_FONT_... in Configtool. +#if defined TEACUP_C_INCLUDE /* && defined DISPLAY_FONT_8x4 */ -const symbol_t PROGMEM font_8x4[] = { +#include "font.h" + +const symbol_t PROGMEM font[] = { {2, {0x00, 0x00, 0x00, 0x00}}, /* space */ {3, {0x0C, 0x5E, 0x0C, 0x00}}, /* excl_mark */ {3, {0x03, 0x00, 0x03, 0x00}}, /* quot_mark */ @@ -113,3 +116,5 @@ const symbol_t PROGMEM font_8x4[] = { {4, {0x02, 0x01, 0x02, 0x01}}, /* tilde */ {4, {0x00, 0x00, 0x00, 0x00}} /* del */ }; + +#endif /* TEACUP_C_INCLUDE && DISPLAY_FONT_8x4 */ diff --git a/font_8x4.h b/font_8x4.h deleted file mode 100644 index a70cc2e..0000000 --- a/font_8x4.h +++ /dev/null @@ -1,19 +0,0 @@ - -#ifndef _FONT_8x4_H -#define _FONT_8x4_H - -#include -#include "arduino.h" // For PROGMEM. - -#define FONT_ROWS 8 -#define FONT_COLUMNS 4 -#define FONT_SYMBOL_SPACE 1 - -typedef struct { - uint8_t columns; - uint8_t data[FONT_COLUMNS]; -} symbol_t; - -extern const symbol_t PROGMEM font_8x4[]; - -#endif /* _FONT_8x4_H */ diff --git a/i2c_test.c b/i2c_test.c index 32dd6b2..764f195 100644 --- a/i2c_test.c +++ b/i2c_test.c @@ -16,7 +16,7 @@ #include #include "config_wrapper.h" #include "displaybus.h" -#include "font_8x4.h" +#include "font.h" #define DISPLAY_I2C_ADDRESS (0x3C << 1) @@ -96,8 +96,8 @@ static void i2c_test(void) { uint8_t index = (uint8_t)*message - 0x20; // Send the character bitmap. - for (i = 0; i < pgm_read_byte(&font_8x4[index].columns); i++) { - displaybus_write(pgm_read_byte(&font_8x4[index].data[i]), 0); + for (i = 0; i < pgm_read_byte(&font[index].columns); i++) { + displaybus_write(pgm_read_byte(&font[index].data[i]), 0); } // Send space between characters. for (i = 0; i < FONT_SYMBOL_SPACE; i++) {