playground project testing RP2040 (Pico) with SSD1309 2.42" OLED from AliExpress
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
pico-ssd1309-test/ufb/framebuffer.h

108 lines
2.8 KiB

//
// Created by MightyPork on 2022/11/12.
//
#ifndef FRAMEBUFFER_H
#define FRAMEBUFFER_H
#include <stdbool.h>
#include <stdint.h>
#include "framebuffer_config.h"
#define FBSET 0xFF
#define FBCLEAR 0x00
/// Width/height type
typedef uint16_t fbsize_t;
/// Position type (X/Y)
typedef int16_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.
///
/// 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[ FB_LEN ];
/// Fill the entire screen with a byte pattern.
/// Use 0xFF or 0x00 for a solid fill. Other patterns may be used to create horizontal stripes.
void fb_fill(uint8_t pattern);
/// Invert the entire screen
void fb_invert();
/// Clear the display (fill with 0x00)
static inline void fb_clear(void)
{
fb_fill(0);
}
/// Fill screen with a repeating pattern
///
/// \param pattern - bytes to repeat, PROGMEM
/// \param pattern_len - len of the pattern
void fb_fill_pattern(const uint8_t* pattern, uint8_t pattern_len, fbcolor_t color);
/// Set a single pixel
void fb_px(fbpos_t x, fbpos_t y, fbcolor_t color);
/// Get pixel color
uint8_t fb_getpx(fbpos_t x, fbpos_t y);
/// Draw a horizontal line
void fb_hline(fbpos_t x, fbpos_t y, fbpos_t w, fbcolor_t color);
/// Draw a vertical line
void fb_vline(fbpos_t x, fbpos_t y, fbpos_t h, fbcolor_t color);
/// Draw a filled rect
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);
/// Draw a bitmap from progmem
#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, fbcolor_t color) {
fb_bitmap_ex_P(x, y, bitmap->width, bitmap->height, bitmap->data, color);
}
#else
static inline void fb_bitmap(fbpos_t x, fbpos_t y, const fb_bitmap_t *bitmap, fbcolor_t color) {
fb_bitmap_ex(x, y, bitmap->width, bitmap->height, bitmap->data, color);
}
#endif
/// Draw a circle
void fb_circle(fbpos_t x, fbpos_t y, fbpos_t r, uint8_t thickness, fbcolor_t color);
/// Output the framebuffer array `fb` to the display device.
///
/// The user must implement this
extern void fb_blit(void);
#endif //FRAMEBUFFER_H