Display: introduce font.h, paraphrase handling distinct fonts.

While this could also be done properly now, with a couple of
additional fonts, this would require quite some time. However,
it's more important to have at least one display working now,
rather than having a ton of sophisticated eye-candy, which isn't
even user-visible, because the upper layers are still missing.
This commit is contained in:
Markus Hitter 2016-04-18 21:36:34 +02:00
parent cb696701f8
commit 5f95784c0b
5 changed files with 61 additions and 24 deletions

16
font.c Normal file
View File

@ -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

35
font.h Normal file
View File

@ -0,0 +1,35 @@
#ifndef _FONT_H
#define _FONT_H
#include <stdint.h>
#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 */

View File

@ -8,9 +8,12 @@
removed from font. 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 */ {2, {0x00, 0x00, 0x00, 0x00}}, /* space */
{3, {0x0C, 0x5E, 0x0C, 0x00}}, /* excl_mark */ {3, {0x0C, 0x5E, 0x0C, 0x00}}, /* excl_mark */
{3, {0x03, 0x00, 0x03, 0x00}}, /* quot_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, {0x02, 0x01, 0x02, 0x01}}, /* tilde */
{4, {0x00, 0x00, 0x00, 0x00}} /* del */ {4, {0x00, 0x00, 0x00, 0x00}} /* del */
}; };
#endif /* TEACUP_C_INCLUDE && DISPLAY_FONT_8x4 */

View File

@ -1,19 +0,0 @@
#ifndef _FONT_8x4_H
#define _FONT_8x4_H
#include <stdint.h>
#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 */

View File

@ -16,7 +16,7 @@
#include <string.h> #include <string.h>
#include "config_wrapper.h" #include "config_wrapper.h"
#include "displaybus.h" #include "displaybus.h"
#include "font_8x4.h" #include "font.h"
#define DISPLAY_I2C_ADDRESS (0x3C << 1) #define DISPLAY_I2C_ADDRESS (0x3C << 1)
@ -96,8 +96,8 @@ static void i2c_test(void) {
uint8_t index = (uint8_t)*message - 0x20; uint8_t index = (uint8_t)*message - 0x20;
// Send the character bitmap. // Send the character bitmap.
for (i = 0; i < pgm_read_byte(&font_8x4[index].columns); i++) { for (i = 0; i < pgm_read_byte(&font[index].columns); i++) {
displaybus_write(pgm_read_byte(&font_8x4[index].data[i]), 0); displaybus_write(pgm_read_byte(&font[index].data[i]), 0);
} }
// Send space between characters. // Send space between characters.
for (i = 0; i < FONT_SYMBOL_SPACE; i++) { for (i = 0; i < FONT_SYMBOL_SPACE; i++) {