From: Wintermate Date: Sat, 26 Oct 2013 11:37:30 +0000 (+0200) Subject: Schrift fest in Firmware eingebacken, damit die auch funktioniert, wenn auf dem X-Git-Url: https://git.rohieb.name/hackover2013-badge-firmware.git/commitdiff_plain/08bad2415b930c2b6aa9198789b83db590fa1190 Schrift fest in Firmware eingebacken, damit die auch funktioniert, wenn auf dem Dataflash nichts ist. --- diff --git a/badge/ui/font.c b/badge/ui/font.c index 5914cd1..3ca485f 100644 --- a/badge/ui/font.c +++ b/badge/ui/font.c @@ -1,43 +1,237 @@ #include "font.h" #include "sprite.h" -#ifdef __linux__ -#include -typedef FILE *FIL; -typedef uint8_t FRESULT; -typedef unsigned UINT; -enum { FR_OK = 0 }; - -void f_close(FIL *fd) { fclose(*fd); *fd = NULL; } -FRESULT f_lseek(FIL *fd, unsigned pos) { return fseek(*fd, pos, SEEK_SET); } -FRESULT f_read(FIL *fd, unsigned char *buffer, size_t buflen, UINT *bytes) { - *bytes = fread(buffer, 1, buflen, *fd); - return *bytes == 0; -} - -#else -#include -#endif - -static FRESULT open_font_file(FIL *fd) { -#ifdef __linux__ - *fd = fopen("../sprites/font.dat", "r"); - return fd ? 0 : -1; -#else - return f_open(fd, "/font.dat", FA_OPEN_EXISTING | FA_READ); -#endif -} - -static uint8_t badge_framebuffer_render_char_with_fd(badge_framebuffer *fb, int8_t pos_x, int8_t pos_y, char c, FIL *fd) { - UINT readbytes; - uint8_t buffer[BADGE_FONT_GLYPH_WIDTH]; +static unsigned char const fontdata[][BADGE_FONT_GLYPH_WIDTH] = { + { 0x00, 0x00, 0x4f, 0x00, 0x00 }, + { 0x00, 0x07, 0x00, 0x07, 0x00 }, + { 0x14, 0x7f, 0x14, 0x7f, 0x14 }, + { 0x24, 0x2a, 0x7f, 0x2a, 0x12 }, + { 0x23, 0x13, 0x08, 0x64, 0x62 }, + { 0x36, 0x49, 0x55, 0x22, 0x50 }, + { 0x00, 0x05, 0x03, 0x00, 0x00 }, + { 0x00, 0x1c, 0x22, 0x41, 0x00 }, + { 0x00, 0x41, 0x22, 0x1c, 0x00 }, + { 0x08, 0x2a, 0x1c, 0x2a, 0x08 }, + { 0x08, 0x08, 0x3e, 0x08, 0x08 }, + { 0x00, 0x50, 0x30, 0x00, 0x00 }, + { 0x08, 0x08, 0x08, 0x08, 0x08 }, + { 0x00, 0x30, 0x30, 0x00, 0x00 }, + { 0x20, 0x10, 0x08, 0x04, 0x02 }, + { 0x3e, 0x51, 0x49, 0x45, 0x3e }, + { 0x00, 0x42, 0x7f, 0x40, 0x00 }, + { 0x42, 0x61, 0x51, 0x49, 0x46 }, + { 0x21, 0x41, 0x45, 0x4b, 0x31 }, + { 0x18, 0x14, 0x12, 0x7f, 0x10 }, + { 0x27, 0x45, 0x45, 0x45, 0x39 }, + { 0x3c, 0x4a, 0x49, 0x49, 0x30 }, + { 0x01, 0x71, 0x09, 0x05, 0x03 }, + { 0x36, 0x49, 0x49, 0x49, 0x36 }, + { 0x06, 0x49, 0x49, 0x29, 0x1e }, + { 0x00, 0x36, 0x36, 0x00, 0x00 }, + { 0x00, 0x56, 0x36, 0x00, 0x00 }, + { 0x00, 0x08, 0x14, 0x22, 0x41 }, + { 0x14, 0x14, 0x14, 0x14, 0x14 }, + { 0x41, 0x22, 0x14, 0x08, 0x00 }, + { 0x02, 0x01, 0x51, 0x09, 0x06 }, + { 0x32, 0x49, 0x79, 0x41, 0x3e }, + { 0x7e, 0x11, 0x11, 0x11, 0x7e }, + { 0x7f, 0x49, 0x49, 0x49, 0x36 }, + { 0x3e, 0x41, 0x41, 0x41, 0x22 }, + { 0x7f, 0x41, 0x41, 0x22, 0x1c }, + { 0x7f, 0x49, 0x49, 0x49, 0x41 }, + { 0x7f, 0x09, 0x09, 0x01, 0x01 }, + { 0x3e, 0x41, 0x41, 0x51, 0x32 }, + { 0x7f, 0x08, 0x08, 0x08, 0x7f }, + { 0x00, 0x41, 0x7f, 0x41, 0x00 }, + { 0x20, 0x40, 0x41, 0x3f, 0x01 }, + { 0x7f, 0x08, 0x14, 0x22, 0x41 }, + { 0x7f, 0x40, 0x40, 0x40, 0x40 }, + { 0x7f, 0x02, 0x04, 0x02, 0x7f }, + { 0x7f, 0x04, 0x08, 0x10, 0x7f }, + { 0x3e, 0x41, 0x41, 0x41, 0x3e }, + { 0x7f, 0x09, 0x09, 0x09, 0x06 }, + { 0x3e, 0x41, 0x51, 0x21, 0x5e }, + { 0x7f, 0x09, 0x19, 0x29, 0x46 }, + { 0x46, 0x49, 0x49, 0x49, 0x31 }, + { 0x01, 0x01, 0x7f, 0x01, 0x01 }, + { 0x3f, 0x40, 0x40, 0x40, 0x3f }, + { 0x1f, 0x20, 0x40, 0x20, 0x1f }, + { 0x7f, 0x20, 0x18, 0x20, 0x7f }, + { 0x63, 0x14, 0x08, 0x14, 0x63 }, + { 0x03, 0x04, 0x78, 0x04, 0x03 }, + { 0x61, 0x51, 0x49, 0x45, 0x43 }, + { 0x00, 0x00, 0x7f, 0x41, 0x41 }, + { 0x02, 0x04, 0x08, 0x10, 0x20 }, + { 0x41, 0x41, 0x7f, 0x00, 0x00 }, + { 0x04, 0x02, 0x01, 0x02, 0x04 }, + { 0x40, 0x40, 0x40, 0x40, 0x40 }, + { 0x00, 0x01, 0x02, 0x04, 0x00 }, + { 0x20, 0x54, 0x54, 0x54, 0x78 }, + { 0x7f, 0x48, 0x44, 0x44, 0x38 }, + { 0x38, 0x44, 0x44, 0x44, 0x20 }, + { 0x38, 0x44, 0x44, 0x48, 0x7f }, + { 0x38, 0x54, 0x54, 0x54, 0x18 }, + { 0x08, 0x7e, 0x09, 0x01, 0x02 }, + { 0x08, 0x14, 0x54, 0x54, 0x3c }, + { 0x7f, 0x08, 0x04, 0x04, 0x78 }, + { 0x00, 0x44, 0x7d, 0x40, 0x00 }, + { 0x20, 0x40, 0x44, 0x3d, 0x00 }, + { 0x00, 0x7f, 0x10, 0x28, 0x44 }, + { 0x00, 0x41, 0x7f, 0x40, 0x00 }, + { 0x7c, 0x04, 0x18, 0x04, 0x78 }, + { 0x7c, 0x08, 0x04, 0x04, 0x78 }, + { 0x38, 0x44, 0x44, 0x44, 0x38 }, + { 0x7c, 0x14, 0x14, 0x14, 0x08 }, + { 0x08, 0x14, 0x14, 0x18, 0x7c }, + { 0x7c, 0x08, 0x04, 0x04, 0x08 }, + { 0x48, 0x54, 0x54, 0x54, 0x20 }, + { 0x04, 0x3f, 0x44, 0x40, 0x20 }, + { 0x3c, 0x40, 0x40, 0x20, 0x7c }, + { 0x1c, 0x20, 0x40, 0x20, 0x1c }, + { 0x3c, 0x40, 0x30, 0x40, 0x3c }, + { 0x44, 0x28, 0x10, 0x28, 0x44 }, + { 0x0c, 0x50, 0x50, 0x50, 0x3c }, + { 0x44, 0x64, 0x54, 0x4c, 0x44 }, + { 0x00, 0x08, 0x36, 0x41, 0x00 }, + { 0x00, 0x00, 0x7f, 0x00, 0x00 }, + { 0x00, 0x41, 0x36, 0x08, 0x00 }, + { 0x10, 0x08, 0x08, 0x10, 0x08 }, + { 0x78, 0x44, 0x42, 0x44, 0x78 }, + { 0x14, 0x3e, 0x55, 0x41, 0x22 }, + { 0x78, 0x14, 0x13, 0x10, 0x7f }, + { 0x00, 0x50, 0x30, 0x00, 0x00 }, + { 0x20, 0x48, 0x3e, 0x09, 0x02 }, + { 0x60, 0x50, 0x00, 0x60, 0x50 }, + { 0x40, 0x00, 0x40, 0x00, 0x40 }, + { 0x00, 0x02, 0x7f, 0x02, 0x00 }, + { 0x00, 0x22, 0x7f, 0x22, 0x00 }, + { 0x00, 0x02, 0x01, 0x02, 0x00 }, + { 0x61, 0x69, 0x04, 0x62, 0x61 }, + { 0x26, 0x49, 0x49, 0x49, 0x32 }, + { 0x00, 0x08, 0x14, 0x00, 0x00 }, + { 0x3e, 0x41, 0x41, 0x3e, 0x49 }, + { 0x01, 0x7f, 0x48, 0x48, 0x30 }, + { 0x61, 0x51, 0x49, 0x45, 0x43 }, + { 0x22, 0x49, 0x45, 0x49, 0x3e }, + { 0x38, 0x44, 0x48, 0x30, 0x4c }, + { 0x00, 0x01, 0x02, 0x04, 0x00 }, + { 0x00, 0x04, 0x02, 0x01, 0x00 }, + { 0x01, 0x02, 0x05, 0x02, 0x04 }, + { 0x04, 0x02, 0x05, 0x02, 0x01 }, + { 0x00, 0x1c, 0x1c, 0x1c, 0x00 }, + { 0x00, 0x08, 0x08, 0x08, 0x08 }, + { 0x08, 0x08, 0x08, 0x08, 0x08 }, + { 0x01, 0x00, 0x01, 0x02, 0x01 }, + { 0x78, 0x2d, 0x2a, 0x28, 0x28 }, + { 0x48, 0x54, 0x55, 0x54, 0x20 }, + { 0x00, 0x44, 0x28, 0x10, 0x00 }, + { 0x38, 0x44, 0x38, 0x54, 0x58 }, + { 0x1c, 0x3e, 0x7c, 0x3e, 0x1c }, + { 0x44, 0x64, 0x55, 0x4c, 0x44 }, + { 0x0e, 0x10, 0x60, 0x10, 0x0e }, + { 0x00, 0x00, 0x00, 0x00, 0x00 }, + { 0x00, 0x00, 0x79, 0x00, 0x00 }, + { 0x1c, 0x22, 0x7f, 0x22, 0x10 }, + { 0x48, 0x3e, 0x49, 0x41, 0x20 }, + { 0x22, 0x1c, 0x14, 0x1c, 0x22 }, + { 0x15, 0x16, 0x7c, 0x16, 0x15 }, + { 0x00, 0x00, 0x77, 0x00, 0x00 }, + { 0x20, 0x4a, 0x55, 0x29, 0x02 }, + { 0x00, 0x01, 0x00, 0x01, 0x00 }, + { 0x7f, 0x41, 0x5d, 0x49, 0x7f }, + { 0x48, 0x55, 0x55, 0x55, 0x5e }, + { 0x10, 0x28, 0x54, 0x28, 0x44 }, + { 0x10, 0x10, 0x10, 0x10, 0x70 }, + { 0x10, 0x10, 0x10, 0x10, 0x10 }, + { 0x7f, 0x41, 0x65, 0x51, 0x7f }, + { 0x01, 0x01, 0x01, 0x01, 0x01 }, + { 0x07, 0x08, 0x08, 0x07, 0x00 }, + { 0x44, 0x44, 0x5f, 0x44, 0x44 }, + { 0x09, 0x0c, 0x0a, 0x09, 0x00 }, + { 0x08, 0x0a, 0x0a, 0x05, 0x00 }, + { 0x00, 0x04, 0x02, 0x01, 0x00 }, + { 0x7f, 0x10, 0x10, 0x08, 0x1f }, + { 0x06, 0x09, 0x09, 0x7f, 0x7f }, + { 0x00, 0x18, 0x18, 0x00, 0x00 }, + { 0x00, 0x40, 0x58, 0x20, 0x00 }, + { 0x00, 0x01, 0x07, 0x00, 0x00 }, + { 0x00, 0x01, 0x02, 0x01, 0x00 }, + { 0x22, 0x14, 0x2a, 0x14, 0x08 }, + { 0x11, 0x0f, 0x34, 0x2a, 0x7d }, + { 0x01, 0x0f, 0x48, 0x64, 0x58 }, + { 0x0a, 0x0f, 0x30, 0x28, 0x7c }, + { 0x30, 0x48, 0x45, 0x40, 0x20 }, + { 0x78, 0x14, 0x13, 0x14, 0x78 }, + { 0x78, 0x14, 0x13, 0x14, 0x78 }, + { 0x78, 0x15, 0x14, 0x15, 0x78 }, + { 0x79, 0x14, 0x14, 0x15, 0x78 }, + { 0x78, 0x14, 0x12, 0x14, 0x78 }, + { 0x78, 0x15, 0x16, 0x15, 0x78 }, + { 0x7c, 0x12, 0x7f, 0x49, 0x49 }, + { 0x0f, 0x10, 0x50, 0x70, 0x09 }, + { 0x7c, 0x54, 0x55, 0x54, 0x44 }, + { 0x7c, 0x54, 0x55, 0x54, 0x44 }, + { 0x7c, 0x55, 0x54, 0x55, 0x44 }, + { 0x7c, 0x55, 0x54, 0x55, 0x44 }, + { 0x00, 0x44, 0x7d, 0x44, 0x00 }, + { 0x00, 0x44, 0x7d, 0x44, 0x00 }, + { 0x00, 0x45, 0x7c, 0x45, 0x00 }, + { 0x00, 0x45, 0x7c, 0x45, 0x00 }, + { 0x08, 0x7f, 0x49, 0x41, 0x3e }, + { 0x7d, 0x08, 0x10, 0x21, 0x7c }, + { 0x3c, 0x42, 0x43, 0x42, 0x3c }, + { 0x3c, 0x42, 0x43, 0x42, 0x3c }, + { 0x38, 0x45, 0x44, 0x45, 0x38 }, + { 0x39, 0x44, 0x44, 0x45, 0x38 }, + { 0x3c, 0x42, 0x42, 0x42, 0x3c }, + { 0x22, 0x14, 0x08, 0x14, 0x22 }, + { 0x08, 0x55, 0x7f, 0x55, 0x08 }, + { 0x3e, 0x40, 0x41, 0x40, 0x3e }, + { 0x3e, 0x40, 0x41, 0x40, 0x3e }, + { 0x3c, 0x41, 0x40, 0x41, 0x3c }, + { 0x3e, 0x40, 0x40, 0x40, 0x3e }, + { 0x02, 0x04, 0x79, 0x04, 0x02 }, + { 0x40, 0x7f, 0x12, 0x12, 0x0c }, + { 0x40, 0x3e, 0x49, 0x49, 0x36 }, + { 0x20, 0x54, 0x55, 0x54, 0x78 }, + { 0x20, 0x54, 0x55, 0x54, 0x78 }, + { 0x20, 0x55, 0x54, 0x55, 0x78 }, + { 0x21, 0x54, 0x54, 0x55, 0x78 }, + { 0x20, 0x55, 0x54, 0x55, 0x78 }, + { 0x20, 0x55, 0x56, 0x55, 0x78 }, + { 0x32, 0x4a, 0x3c, 0x4a, 0x2c }, + { 0x0c, 0x12, 0x52, 0x72, 0x08 }, + { 0x38, 0x54, 0x55, 0x54, 0x18 }, + { 0x38, 0x54, 0x55, 0x54, 0x18 }, + { 0x38, 0x55, 0x54, 0x55, 0x18 }, + { 0x38, 0x55, 0x54, 0x55, 0x18 }, + { 0x00, 0x48, 0x7d, 0x40, 0x00 }, + { 0x00, 0x48, 0x7d, 0x40, 0x00 }, + { 0x00, 0x49, 0x7c, 0x41, 0x00 }, + { 0x00, 0x49, 0x7c, 0x41, 0x00 }, + { 0x25, 0x52, 0x55, 0x58, 0x30 }, + { 0x7d, 0x08, 0x04, 0x05, 0x78 }, + { 0x38, 0x44, 0x45, 0x44, 0x38 }, + { 0x38, 0x44, 0x45, 0x44, 0x38 }, + { 0x30, 0x4a, 0x49, 0x4a, 0x30 }, + { 0x32, 0x49, 0x49, 0x4a, 0x31 }, + { 0x38, 0x45, 0x44, 0x45, 0x38 }, + { 0x08, 0x08, 0x2a, 0x08, 0x08 }, + { 0x08, 0x54, 0x3e, 0x15, 0x08 }, + { 0x3c, 0x40, 0x41, 0x20, 0x7c }, + { 0x3c, 0x40, 0x41, 0x20, 0x7c }, + { 0x3c, 0x41, 0x40, 0x21, 0x7c }, + { 0x3c, 0x41, 0x40, 0x21, 0x7c }, + { 0x0c, 0x50, 0x52, 0x51, 0x3c }, + { 0x00, 0x41, 0x7f, 0x54, 0x08 }, + { 0x0c, 0x51, 0x50, 0x51, 0x3c }, +}; +uint8_t badge_framebuffer_render_char(badge_framebuffer *fb, int8_t pos_x, int8_t pos_y, char c) { if(c == 32) { // intentionally left empty. - } else if(c >= 32 && - FR_OK == f_lseek(fd, (c - 33) * BADGE_FONT_GLYPH_WIDTH) && - FR_OK == f_read(fd, buffer, sizeof(buffer), &readbytes)) { - badge_sprite sp = { BADGE_FONT_GLYPH_WIDTH, BADGE_FONT_HEIGHT, buffer }; + } else if(c > 32) { + badge_sprite sp = { BADGE_FONT_GLYPH_WIDTH, BADGE_FONT_HEIGHT, fontdata[c - 33] }; badge_framebuffer_blt(fb, pos_x, pos_y, &sp, 0); } else { return -1; @@ -46,45 +240,28 @@ static uint8_t badge_framebuffer_render_char_with_fd(badge_framebuffer *fb, int8 return 0; } -uint8_t badge_framebuffer_render_char(badge_framebuffer *fb, int8_t pos_x, int8_t pos_y, char c) { - FIL fd; - - if(FR_OK == open_font_file(&fd)) { - badge_framebuffer_render_char_with_fd(fb, pos_x, pos_y, c, &fd); - f_close(&fd); - return 0; - } - - return -1; -} - uint8_t badge_framebuffer_render_text(badge_framebuffer *fb, int8_t pos_x, int8_t pos_y, char const *text) { uint8_t count = 0; - FIL fd; - if(FR_OK == open_font_file(&fd)) { - while(*text) { - if(0 != badge_framebuffer_render_char_with_fd(fb, pos_x, pos_y, *text, &fd)) { - break; - } - - ++count; - ++text; - pos_x += BADGE_FONT_WIDTH; + while(*text) { + if(0 != badge_framebuffer_render_char(fb, pos_x, pos_y, *text)) { + break; } - f_close(&fd); + ++count; + ++text; + pos_x += BADGE_FONT_WIDTH; } return count; } -static uint8_t badge_framebuffer_render_number_with_fd(badge_framebuffer *fb, int8_t *pos_x, int8_t pos_y, uint8_t number, FIL *fd) { +static uint8_t badge_framebuffer_render_number_aux(badge_framebuffer *fb, int8_t *pos_x, int8_t pos_y, uint8_t number) { if(number >= 10) { - badge_framebuffer_render_number_with_fd(fb, pos_x, pos_y, number / 10, fd); + badge_framebuffer_render_number_aux(fb, pos_x, pos_y, number / 10); } - uint8_t err = badge_framebuffer_render_char_with_fd(fb, *pos_x, pos_y, '0' + number % 10, fd); + uint8_t err = badge_framebuffer_render_char(fb, *pos_x, pos_y, '0' + number % 10); if(err != 0) return err; @@ -93,15 +270,5 @@ static uint8_t badge_framebuffer_render_number_with_fd(badge_framebuffer *fb, in } uint8_t badge_framebuffer_render_number(badge_framebuffer *fb, int8_t pos_x, int8_t pos_y, uint8_t number) { - FIL fd; - - if(FR_OK == open_font_file(&fd)) { - uint8_t err = badge_framebuffer_render_number_with_fd(fb, &pos_x, pos_y, number, &fd); - - if(err != 0) { - return err; - } - } - - return 0; + return badge_framebuffer_render_number_aux(fb, &pos_x, pos_y, number); } diff --git a/sprites/fontdata.c b/sprites/fontdata.c index 3d9f044..365beb4 100644 --- a/sprites/fontdata.c +++ b/sprites/fontdata.c @@ -229,12 +229,13 @@ unsigned char const font5x8[] = { }; int main(void) { - FILE *fd = fopen("font.dat", "wb"); - size_t i; + size_t i, j; - for(i = 0; i < sizeof(font5x8); ++i) { - fputc(font5x8[i] >> 1, fd); + for(i = 0; i < sizeof(font5x8) / 5; ++i) { + printf(" { "); + for(j = 0; j < 4; ++j) { + printf("0x%02x, ", font5x8[i * 5 + j] >> 1); + } + printf("0x%02x },\n", font5x8[i * 5 + 4] >> 1); } - - fclose(fd); }