Tiny framebuffer for SSD1306 and similar displays.
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.
ufb/framebuffer.h

84 lines
2.1 KiB

2 years ago
//
// 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
typedef uint16_t fbsize_t;
typedef uint8_t fbpos_t;
2 years ago
typedef uint8_t fbcolor_t;
#define FB_LEN ((FBH / 8) * FBW)
2 years ago
/// 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
2 years ago
extern uint8_t fb[ FB_LEN ];
2 years ago
/// 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);
2 years ago
/// Invert the entire screen
void fb_invert();
2 years ago
/// Clear the display (fill with 0x00)
static inline void fb_clear(void)
{
fb_fill(0);
}
2 years ago
/// 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);
2 years ago
/// Set a single pixel
2 years ago
void fb_px(fbpos_t x, fbpos_t y, fbcolor_t color);
2 years ago
/// Get pixel color
uint8_t fb_getpx(fbpos_t x, fbpos_t y);
/// Draw a horizontal line
2 years ago
void fb_hline(fbpos_t x, fbpos_t y, fbpos_t w, fbcolor_t color);
2 years ago
/// Draw a vertical line
2 years ago
void fb_vline(fbpos_t x, fbpos_t y, fbpos_t h, fbcolor_t color);
2 years ago
/// Draw a filled rect
2 years ago
void fb_rect(fbpos_t x, fbpos_t y, fbpos_t w, fbpos_t h, fbcolor_t color);
2 years ago
/// Draw a frame (unfilled rect)
2 years ago
void fb_frame(fbpos_t x, fbpos_t y, fbpos_t w, fbpos_t h, fbpos_t thickness, fbcolor_t color);
2 years ago
2 years ago
/// 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);
2 years ago
2 years ago
/// Draw a circle
void fb_circle(fbpos_t x, fbpos_t y, fbpos_t r, uint8_t thickness, fbcolor_t color);
2 years ago
/// Output the framebuffer array `fb` to the display device.
///
/// The user must implement this
extern void fb_blit(void);
#endif //FRAMEBUFFER_H