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

90 lines
2.5 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
typedef uint16_t fbsize_t;
typedef uint8_t fbpos_t;
/// 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[(FBH / 8) * FBW];
/// 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);
/// Clear the display (fill with 0x00)
static inline void fb_clear(void)
{
fb_fill(0);
}
/// Set a single pixel
void fb_px(fbpos_t x, fbpos_t y, uint8_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, uint8_t color);
/// Draw a vertical line
void fb_vline(fbpos_t x, fbpos_t y, fbpos_t h, uint8_t color);
/// Draw a filled rect
void fb_rect(fbpos_t x, fbpos_t y, fbpos_t w, fbpos_t h, uint8_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, uint8_t color);
/// Draw a bitmap
void fb_bitmap(fbpos_t x, fbpos_t y, fbpos_t w, fbpos_t h, const uint8_t *map, uint8_t color);
/// Draw a 7-segment digit. Returns its width (without spacing)
///
/// \param x - pos X (left top)
/// \param y - pos Y (left top)
/// \param w - full digit width
/// \param h - full digit height; will be adjusted down if needed
/// \param th - thickness
/// \param digit - digit 0-9
/// \return width taken
fbpos_t fb_7seg_dig(fbpos_t x, fbpos_t y, fbpos_t w, fbpos_t h, fbpos_t th, uint8_t digit, uint8_t color);
/// Draw a 7-segment period. Returns its width (without spacing).
/// Digit height is (w * 2 - th)
///
/// \param x - pos X (digit left top)
/// \param y - pos Y (digit left top)
/// \param w - full digit width
/// \param h - full digit height; will be adjusted down if needed
/// \param th - thickness
/// \return width taken
fbpos_t fb_7seg_period(fbpos_t x, fbpos_t y, fbpos_t w, fbpos_t h, fbpos_t th, uint8_t color);
/// Output the framebuffer array `fb` to the display device.
///
/// The user must implement this
extern void fb_blit(void);
#endif //FRAMEBUFFER_H