|
|
|
//
|
|
|
|
// 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;
|
|
|
|
typedef uint8_t fbcolor_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
|
|
|
|
void fb_bitmap_P(fbpos_t x, fbpos_t y, fbpos_t w, fbpos_t h, const uint8_t *map, fbcolor_t color);
|
|
|
|
|
|
|
|
/// 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
|