fb image drawing fixes

gui-dev
Ondřej Hruška 2 years ago
parent 8dad247e5e
commit 317aed825e
  1. 48
      src/framebuffer.c
  2. 23
      src/framebuffer.h
  3. 7
      src/framebuffer_config.h
  4. 5
      src/user_interface.c

@ -2,18 +2,14 @@
// Created by MightyPork on 2022/11/12. // Created by MightyPork on 2022/11/12.
// //
#include "user_interface.h"
#include "framebuffer.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 MIN(a,b) ((a)>(b)?(b):(a))
#define MAX(a,b) ((a)>(b)?(a):(b)) #define MAX(a,b) ((a)>(b)?(a):(b))
static uint8_t fb[(FBH/8)*FBW]; #include <string.h>
uint8_t fb[(FBH / 8) * FBW];
/** Fill with a vertical pattern, 1 byte */ /** Fill with a vertical pattern, 1 byte */
void fb_fill(uint8_t pattern) { 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 // last
for (uint8_t i = 0; i < w; i++) { 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) { if (color) {
fb[cell + i] |= mask; fb[cell + i] |= mask;
} else { } 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; 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);
}

@ -8,6 +8,24 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#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_fill(uint8_t pattern);
void fb_clear(void); void fb_clear(void);
void fb_px(uint8_t x, uint8_t y, uint8_t color); 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_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_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_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 #endif //FRAMEBUFFER_H

@ -0,0 +1,7 @@
#ifndef FRAMEBUFFER_CONFIG_H
#define FRAMEBUFFER_CONFIG_H
#define FBW 128
#define FBH 32
#endif /* FRAMEBUFFER_CONFIG_H */

@ -8,9 +8,14 @@
#include "sevenseg.h" #include "sevenseg.h"
#include "global_state.h" #include "global_state.h"
#include "radiation.h" #include "radiation.h"
#include "framebuffer.h"
static bool ended_loading = false; static bool ended_loading = false;
void fb_blit() {
ssd1306_drawBuffer(0, 0, FBW, FBH, fb);
}
static struct SevenSeg sseg = { static struct SevenSeg sseg = {
.x0 = 0, .x0 = 0,
.y0 = 0, .y0 = 0,

Loading…
Cancel
Save