diff --git a/src/framebuffer.c b/src/framebuffer.c index 4185ef1..74bf27c 100644 --- a/src/framebuffer.c +++ b/src/framebuffer.c @@ -2,18 +2,14 @@ // Created by MightyPork on 2022/11/12. // -#include "user_interface.h" #include "framebuffer.h" -#include "ssd1306.h" - -/* Tiny framebuffer */ -#define FBW DISPLAY_W -#define FBH DISPLAY_H #define MIN(a,b) ((a)>(b)?(b):(a)) #define MAX(a,b) ((a)>(b)?(a):(b)) -static uint8_t fb[(FBH/8)*FBW]; +#include + +uint8_t fb[(FBH / 8) * FBW]; /** Fill with a vertical pattern, 1 byte */ void fb_fill(uint8_t pattern) { @@ -245,7 +241,7 @@ void fb_bitmap(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *map, u // last for (uint8_t i = 0; i < w; i++) { - uint8_t mask = (map[i + mapc0] & (0xFF << (8 - rowrem))) >> rowrem; + uint8_t mask = (map[i + mapc0] & (0xFF << (8 - rowrem))) >> (8 - rowrem); if (color) { fb[cell + i] |= mask; } else { @@ -260,42 +256,6 @@ void fb_bitmap(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *map, u } mapc0 += w0; } - -#if 0 - // Middle - uint8_t whole_cells = h / 8; - h -= whole_cells * 8; - for(uint8_t j = 0; j < whole_cells; j++) { - cell += FBW; - mapc0 += w0; - for(uint8_t i = 0; i < w; i++) { - uint8_t mask = map[i + mapc0]; - if (color) { - fb[cell + i] |= mask; - } else { - fb[cell + i] &= ~mask; - } - } - } - - // last - mapc0 += w0; - cell += FBW; - - // last - for(uint8_t i = 0; i < w; i++) { - uint8_t mask = map[i + mapc0] & (0xFF >> (8-h)); - if (color) { - fb[cell + i] |= mask; - } else { - fb[cell + i] &= ~mask; - } - } -#endif } } - -void fb_blit() { - ssd1306_drawBuffer(0, 0, FBW, FBH, fb); -} diff --git a/src/framebuffer.h b/src/framebuffer.h index b9fdacf..b0dcb44 100644 --- a/src/framebuffer.h +++ b/src/framebuffer.h @@ -8,6 +8,24 @@ #include #include +#include "framebuffer_config.h" + +#define FBSET 0xFF +#define FBCLEAR 0x00 + +/// Framebuffer backing array. +/// +/// The format is the native format for SSD1306: array of bytes representing pixels in 8 rows at once, LSB is the topmost row. +/// +/// a0 b0 ... til the display width +/// a1 b1 +/// a2 b2 +/// ... ... +/// a7 b7 +/// +/// and more bytes continue rows 8-15 and so on +extern uint8_t fb[(FBH / 8) * FBW]; + void fb_fill(uint8_t pattern); void fb_clear(void); void fb_px(uint8_t x, uint8_t y, uint8_t color); @@ -15,6 +33,9 @@ void fb_hline(uint8_t x, uint8_t y, uint8_t w, uint8_t color); void fb_vline(uint8_t x, uint8_t y, uint8_t h, uint8_t color); void fb_rect(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t color); void fb_bitmap(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *map, uint8_t color); -void fb_blit(void); + +/// Output the framebuffer array `fb` to the display device. +extern void fb_blit(void); + #endif //FRAMEBUFFER_H diff --git a/src/framebuffer_config.h b/src/framebuffer_config.h new file mode 100644 index 0000000..56f495e --- /dev/null +++ b/src/framebuffer_config.h @@ -0,0 +1,7 @@ +#ifndef FRAMEBUFFER_CONFIG_H +#define FRAMEBUFFER_CONFIG_H + +#define FBW 128 +#define FBH 32 + +#endif /* FRAMEBUFFER_CONFIG_H */ diff --git a/src/user_interface.c b/src/user_interface.c index 483a520..e5be2a0 100644 --- a/src/user_interface.c +++ b/src/user_interface.c @@ -8,9 +8,14 @@ #include "sevenseg.h" #include "global_state.h" #include "radiation.h" +#include "framebuffer.h" static bool ended_loading = false; +void fb_blit() { + ssd1306_drawBuffer(0, 0, FBW, FBH, fb); +} + static struct SevenSeg sseg = { .x0 = 0, .y0 = 0,