introduce bitmap struct
This commit is contained in:
@@ -17,6 +17,54 @@ const uint LED_PIN = 25;
|
||||
bi_decl(bi_program_description("OLED demo"))
|
||||
bi_decl(bi_1pin_with_name(LED_PIN, "Blink LED"))
|
||||
|
||||
static const uint8_t zir_data[] = {
|
||||
// levo
|
||||
0b10000000,
|
||||
0b01000000,
|
||||
0b00100000,
|
||||
0b00010000,
|
||||
0b00001000,
|
||||
0b00000100,
|
||||
0b00000010,
|
||||
0b00011001,
|
||||
0b00011111,
|
||||
0b11111000,
|
||||
0b00011111,
|
||||
0b00001000,
|
||||
//
|
||||
0b10000000,
|
||||
0b01000000,
|
||||
0b00100000,
|
||||
0b00010000,
|
||||
0b00001000,
|
||||
0b00000100,
|
||||
0b00000010,
|
||||
0b00000001,
|
||||
0b10000000,
|
||||
0b11111111,
|
||||
0b00100000,
|
||||
0b00010000,
|
||||
//
|
||||
0b00110000,
|
||||
0b10001000,
|
||||
0b11111000,
|
||||
0b00011000,
|
||||
0b11111000,
|
||||
0b10011000,
|
||||
0b00011000,
|
||||
0b10011000,
|
||||
0b11111000,
|
||||
0b00011111,
|
||||
0b11111000,
|
||||
0b10000000,
|
||||
};
|
||||
|
||||
static const fb_bitmap_t zir = {
|
||||
.width = 12,
|
||||
.height = 24,
|
||||
.data = zir_data
|
||||
};
|
||||
|
||||
int main() {
|
||||
stdio_init_all();
|
||||
|
||||
@@ -25,55 +73,16 @@ int main() {
|
||||
|
||||
oled_init();
|
||||
|
||||
#define ZIR_W 12
|
||||
#define ZIR_H 24
|
||||
const uint8_t zirafa[(ZIR_H/8) * ZIR_W] = {
|
||||
// levo
|
||||
0b10000000,
|
||||
0b01000000,
|
||||
0b00100000,
|
||||
0b00010000,
|
||||
0b00001000,
|
||||
0b00000100,
|
||||
0b00000010,
|
||||
0b00011001,
|
||||
0b00011111,
|
||||
0b11111000,
|
||||
0b00011111,
|
||||
0b00001000,
|
||||
//
|
||||
0b10000000,
|
||||
0b01000000,
|
||||
0b00100000,
|
||||
0b00010000,
|
||||
0b00001000,
|
||||
0b00000100,
|
||||
0b00000010,
|
||||
0b00000001,
|
||||
0b10000000,
|
||||
0b11111111,
|
||||
0b00100000,
|
||||
0b00010000,
|
||||
//
|
||||
0b00110000,
|
||||
0b10001000,
|
||||
0b11111000,
|
||||
0b00011000,
|
||||
0b11111000,
|
||||
0b10011000,
|
||||
0b00011000,
|
||||
0b10011000,
|
||||
0b11111000,
|
||||
0b00011111,
|
||||
0b11111000,
|
||||
0b10000000,
|
||||
};
|
||||
|
||||
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(50, 20, "meow", FONT_DOUBLE, 1);
|
||||
|
||||
fb_frame(0, 0, 128, 64, 2, 1);
|
||||
|
||||
fb_blit();
|
||||
|
||||
while (1) {
|
||||
|
||||
+4
-4
@@ -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
|
||||
|
||||
#if IS_AVR
|
||||
fb_bitmap_P(x, y, symw, symh, data, color);
|
||||
fb_bitmap_ex_P(x, y, symw, symh, data, color);
|
||||
#else
|
||||
fb_bitmap(x, y, symw, symh, data, color);
|
||||
fb_bitmap_ex(x, y, symw, symh, data, color);
|
||||
#endif
|
||||
|
||||
if (flags & FONT_BOLD) {
|
||||
x++;
|
||||
|
||||
#if IS_AVR
|
||||
fb_bitmap_P(x, y, symw, symh, data, color);
|
||||
fb_bitmap_ex_P(x, y, symw, symh, data, color);
|
||||
#else
|
||||
fb_bitmap(x, y, symw, symh, data, color);
|
||||
fb_bitmap_ex(x, y, symw, symh, data, color);
|
||||
#endif
|
||||
|
||||
x += symw+2;
|
||||
|
||||
+2
-2
@@ -230,9 +230,9 @@ void fb_circle(fbpos_t x0, fbpos_t y0, fbpos_t radius, uint8_t thickness, fbcolo
|
||||
}
|
||||
|
||||
#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
|
||||
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
|
||||
{
|
||||
if (x >= FBW || y >= FBH) { return; }
|
||||
|
||||
+24
-3
@@ -13,10 +13,20 @@
|
||||
#define FBSET 0xFF
|
||||
#define FBCLEAR 0x00
|
||||
|
||||
/// Width/height type
|
||||
typedef uint16_t fbsize_t;
|
||||
/// Position type (X/Y)
|
||||
typedef uint8_t fbpos_t;
|
||||
/// Color type
|
||||
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)
|
||||
|
||||
/// 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)
|
||||
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
|
||||
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(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
|
||||
|
||||
/// 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
|
||||
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
|
||||
|
||||
/// Draw a circle
|
||||
|
||||
Reference in New Issue
Block a user