badge/jumpnrun/tiles.c \\r
badge/ui/display.c \\r
badge/ui/event.c \\r
+ badge/ui/font.c \\r
badge/ui/sprite.c\r
\r
SRCS += \\r
};
static badge_sprite const anim_snake[] = {
- { 10, 6, (uint8_t const *) "\x10\x86\x83\x30\x04\x83\xa2\x0f" },
- { 10, 6, (uint8_t const *) "\x10\x86\x83\x20\x0c\xc1\xa2\x0f" },
- { 10, 6, (uint8_t const *) "\x10\x86\x83\x20\x08\x82\xe0\x0f" },
- { 10, 6, (uint8_t const *) "\x10\x86\x83\x20\x08\x86\xe1\x0f" }
+ { 10, 6, (uint8_t const *) "\x10\x86\x83\x30\x04\x83\xa2\x07" },
+ { 10, 6, (uint8_t const *) "\x10\x86\x83\x20\x0c\xc1\xa2\x07" },
+ { 10, 6, (uint8_t const *) "\x10\x86\x83\x20\x08\x82\xe0\x07" },
+ { 10, 6, (uint8_t const *) "\x10\x86\x83\x20\x08\x86\xe1\x07" }
};
static badge_sprite const anim_spiral[] = {
#include "ui/display.h"
#include "ui/sprite.h"
#include "ui/event.h"
+#include "ui/font.h"
#include "util/util.h"
#include "jumpnrun/jumpnrun.h"
{ RB_PWR_CHRG, &RB_PWR_CHRG_IO, gpioPullupMode_PullUp }
#endif
};
-
+
for(int i = 0; i < ARRAY_SIZE(input_pins); ++i) {
gpioSetDir(input_pins[i].port, input_pins[i].pin, gpioDirection_Input);
gpioSetPullup(input_pins[i].reg, input_pins[i].mode);
}
*/
- {
- // f_mkfs(0, 1, 0);
- badge_framebuffer fb;
- int res = 0;
- FATFS fatvol;
-
- while(FR_OK != f_mount(0, &fatvol)) {
- f_mkfs(0, 1, 0);
- }
-
- FIL fil;
- if(FR_OK == (res = f_open(&fil, "sshot.dat", FA_OPEN_EXISTING | FA_READ))) {
- UINT readbytes;
+ FATFS fs;
+ f_mount(0, &fs);
- if(FR_OK != f_read(&fil, &fb, sizeof(fb), &readbytes)) {
- }
+ {
+ badge_framebuffer fb = { { { 0 } } };
- f_close(&fil);
- }
+ fb.data[0][0] = badge_framebuffer_render_text(&fb, 2, 10, "foobar");
badge_framebuffer_flush(&fb);
}
--- /dev/null
+#include "font.h"
+#include "sprite.h"
+
+#include <drivers/fatfs/ff.h>
+
+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_WIDTH];
+
+ if(c == 32) {
+ // intentionally left empty.
+ } else if(c >= 32 &&
+ FR_OK == f_lseek(fd, (c - 33) * BADGE_FONT_WIDTH) &&
+ FR_OK == f_read(fd, buffer, sizeof(buffer), &readbytes)) {
+ badge_sprite sp = { BADGE_FONT_WIDTH, BADGE_FONT_HEIGHT, buffer };
+ badge_framebuffer_blt(fb, pos_x, pos_y, &sp, 0);
+ } else {
+ return -1;
+ }
+
+ 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 == f_open(&fd, "font.dat", FA_OPEN_EXISTING | FA_READ)) {
+ 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 == f_open(&fd, "font.dat", FA_OPEN_EXISTING | FA_READ)) {
+ 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;
+ }
+
+ f_close(&fd);
+ }
+
+ return count;
+}
--- /dev/null
+#ifndef INCLUDED_BADGE_UI_FONT_H
+#define INCLUDED_BADGE_UI_FONT_H
+
+#include "display.h"
+
+enum {
+ BADGE_FONT_WIDTH = 6,
+ BADGE_FONT_HEIGHT = 8
+};
+
+uint8_t badge_framebuffer_render_char(badge_framebuffer *fb, int8_t pos_x, int8_t pos_y, char c);
+uint8_t badge_framebuffer_render_text(badge_framebuffer *fb, int8_t pos_x, int8_t pos_y, char const *text);
+
+#endif