7 typedef uint8_t FRESULT
;
11 void f_close(FIL
*fd
) { fclose(*fd
); *fd
= NULL
; }
12 FRESULT
f_lseek(FIL
*fd
, unsigned pos
) { return fseek(*fd
, pos
, SEEK_SET
); }
13 FRESULT
f_read(FIL
*fd
, unsigned char *buffer
, size_t buflen
, UINT
*bytes
) {
14 *bytes
= fread(buffer
, 1, buflen
, *fd
);
19 #include <drivers/fatfs/ff.h>
22 static FRESULT
open_font_file(FIL
*fd
) {
24 *fd
= fopen("../sprites/font.dat", "r");
27 return f_open(fd
, "/font.dat", FA_OPEN_EXISTING
| FA_READ
);
31 static uint8_t badge_framebuffer_render_char_with_fd(badge_framebuffer
*fb
, int8_t pos_x
, int8_t pos_y
, char c
, FIL
*fd
) {
33 uint8_t buffer
[BADGE_FONT_GLYPH_WIDTH
];
36 // intentionally left empty.
38 FR_OK
== f_lseek(fd
, (c
- 33) * BADGE_FONT_GLYPH_WIDTH
) &&
39 FR_OK
== f_read(fd
, buffer
, sizeof(buffer
), &readbytes
)) {
40 badge_sprite sp
= { BADGE_FONT_GLYPH_WIDTH
, BADGE_FONT_HEIGHT
, buffer
};
41 badge_framebuffer_blt(fb
, pos_x
, pos_y
, &sp
, 0);
49 uint8_t badge_framebuffer_render_char(badge_framebuffer
*fb
, int8_t pos_x
, int8_t pos_y
, char c
) {
52 if(FR_OK
== open_font_file(&fd
)) {
53 badge_framebuffer_render_char_with_fd(fb
, pos_x
, pos_y
, c
, &fd
);
61 uint8_t badge_framebuffer_render_text(badge_framebuffer
*fb
, int8_t pos_x
, int8_t pos_y
, char const *text
) {
65 if(FR_OK
== open_font_file(&fd
)) {
67 if(0 != badge_framebuffer_render_char_with_fd(fb
, pos_x
, pos_y
, *text
, &fd
)) {
73 pos_x
+= BADGE_FONT_WIDTH
;
82 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
) {
84 badge_framebuffer_render_number_with_fd(fb
, pos_x
, pos_y
, number
/ 10, fd
);
87 uint8_t err
= badge_framebuffer_render_char_with_fd(fb
, *pos_x
, pos_y
, '0' + number
% 10, fd
);
89 if(err
!= 0) return err
;
91 *pos_x
+= BADGE_FONT_WIDTH
;
95 uint8_t badge_framebuffer_render_number(badge_framebuffer
*fb
, int8_t pos_x
, int8_t pos_y
, uint8_t number
) {
98 if(FR_OK
== open_font_file(&fd
)) {
99 uint8_t err
= badge_framebuffer_render_number_with_fd(fb
, &pos_x
, pos_y
, number
, &fd
);
This page took 0.043531 seconds and 5 git commands to generate.