introduce bitmap struct

master
Ondřej Hruška 2 years ago
parent 9af5a84669
commit ab4119a1a9
  1. 35
      main.c
  2. 8
      ufb/fb_text.c
  3. 4
      ufb/framebuffer.c
  4. 27
      ufb/framebuffer.h

@ -17,17 +17,7 @@ const uint LED_PIN = 25;
bi_decl(bi_program_description("OLED demo")) bi_decl(bi_program_description("OLED demo"))
bi_decl(bi_1pin_with_name(LED_PIN, "Blink LED")) bi_decl(bi_1pin_with_name(LED_PIN, "Blink LED"))
int main() { static const uint8_t zir_data[] = {
stdio_init_all();
gpio_init(LED_PIN);
gpio_set_dir(LED_PIN, GPIO_OUT);
oled_init();
#define ZIR_W 12
#define ZIR_H 24
const uint8_t zirafa[(ZIR_H/8) * ZIR_W] = {
// levo // levo
0b10000000, 0b10000000,
0b01000000, 0b01000000,
@ -67,13 +57,32 @@ int main() {
0b00011111, 0b00011111,
0b11111000, 0b11111000,
0b10000000, 0b10000000,
}; };
static const fb_bitmap_t zir = {
.width = 12,
.height = 24,
.data = zir_data
};
int main() {
stdio_init_all();
gpio_init(LED_PIN);
gpio_set_dir(LED_PIN, GPIO_OUT);
oled_init();
fb_clear(); fb_clear();
fb_bitmap(5, 5, ZIR_W, ZIR_H, zirafa, 1);
fb_bitmap(5, 5, &zir);
fb_bitmap(20, 5, &zir);
fb_text(40, 35, "MEOW", FONT_DOUBLE, 1); fb_text(40, 35, "MEOW", FONT_DOUBLE, 1);
fb_text(50, 20, "meow", FONT_DOUBLE, 1); fb_text(50, 20, "meow", FONT_DOUBLE, 1);
fb_frame(0, 0, 128, 64, 2, 1); fb_frame(0, 0, 128, 64, 2, 1);
fb_blit(); fb_blit();
while (1) { while (1) {

@ -44,18 +44,18 @@ void fb_text_P_or_RAM(fbpos_t x, fbpos_t y, const char *text, uint8_t flags, fbc
// no double, using normal format // no double, using normal format
#if IS_AVR #if IS_AVR
fb_bitmap_P(x, y, symw, symh, data, color); fb_bitmap_ex_P(x, y, symw, symh, data, color);
#else #else
fb_bitmap(x, y, symw, symh, data, color); fb_bitmap_ex(x, y, symw, symh, data, color);
#endif #endif
if (flags & FONT_BOLD) { if (flags & FONT_BOLD) {
x++; x++;
#if IS_AVR #if IS_AVR
fb_bitmap_P(x, y, symw, symh, data, color); fb_bitmap_ex_P(x, y, symw, symh, data, color);
#else #else
fb_bitmap(x, y, symw, symh, data, color); fb_bitmap_ex(x, y, symw, symh, data, color);
#endif #endif
x += symw+2; x += symw+2;

@ -230,9 +230,9 @@ void fb_circle(fbpos_t x0, fbpos_t y0, fbpos_t radius, uint8_t thickness, fbcolo
} }
#if IS_AVR #if IS_AVR
void fb_bitmap_P(fbpos_t x, fbpos_t y, fbpos_t w, fbpos_t h, const uint8_t *map, fbcolor_t color) void fb_bitmap_ex_P(fbpos_t x, fbpos_t y, fbpos_t w, fbpos_t h, const uint8_t *map, fbcolor_t color)
#else #else
void fb_bitmap(fbpos_t x, fbpos_t y, fbpos_t w, fbpos_t h, const uint8_t *map, fbcolor_t color) void fb_bitmap_ex(fbpos_t x, fbpos_t y, fbpos_t w, fbpos_t h, const uint8_t *map, fbcolor_t color)
#endif #endif
{ {
if (x >= FBW || y >= FBH) { return; } if (x >= FBW || y >= FBH) { return; }

@ -13,10 +13,20 @@
#define FBSET 0xFF #define FBSET 0xFF
#define FBCLEAR 0x00 #define FBCLEAR 0x00
/// Width/height type
typedef uint16_t fbsize_t; typedef uint16_t fbsize_t;
/// Position type (X/Y)
typedef uint8_t fbpos_t; typedef uint8_t fbpos_t;
/// Color type
typedef uint8_t fbcolor_t; typedef uint8_t fbcolor_t;
/// Bitmap struct
typedef struct {
const uint8_t *data;
fbsize_t width;
fbsize_t height;
} fb_bitmap_t;
#define FB_LEN ((FBH / 8) * FBW) #define FB_LEN ((FBH / 8) * FBW)
/// Framebuffer backing array. /// Framebuffer backing array.
@ -69,11 +79,22 @@ void fb_rect(fbpos_t x, fbpos_t y, fbpos_t w, fbpos_t h, fbcolor_t color);
/// Draw a frame (unfilled rect) /// Draw a frame (unfilled rect)
void fb_frame(fbpos_t x, fbpos_t y, fbpos_t w, fbpos_t h, fbpos_t thickness, fbcolor_t color); void fb_frame(fbpos_t x, fbpos_t y, fbpos_t w, fbpos_t h, fbpos_t thickness, fbcolor_t color);
#if IS_AVR
/// Draw a bitmap from progmem /// Draw a bitmap from progmem
void fb_bitmap_P(fbpos_t x, fbpos_t y, fbpos_t w, fbpos_t h, const uint8_t *map, fbcolor_t color); #if IS_AVR
void fb_bitmap_ex_P(fbpos_t x, fbpos_t y, fbpos_t w, fbpos_t h, const uint8_t *map, fbcolor_t color);
#else
void fb_bitmap_ex(fbpos_t x, fbpos_t y, fbpos_t w, fbpos_t h, const uint8_t *map, fbcolor_t color);
#endif
/// Draw a bitmap using the bitmap struct
#if IS_AVR
static inline void fb_bitmap_P(fbpos_t x, fbpos_t y, const fb_bitmap_t *bitmap) {
fb_bitmap_ex_P(x, y, bitmap->width, bitmap->height, bitmap->data, 1);
}
#else #else
void fb_bitmap(fbpos_t x, fbpos_t y, fbpos_t w, fbpos_t h, const uint8_t *map, fbcolor_t color); static inline void fb_bitmap(fbpos_t x, fbpos_t y, const fb_bitmap_t *bitmap) {
fb_bitmap_ex(x, y, bitmap->width, bitmap->height, bitmap->data, 1);
}
#endif #endif
/// Draw a circle /// Draw a circle

Loading…
Cancel
Save