This commit is contained in:
2023-02-22 01:31:05 +01:00
commit 8260fb60f8
151 changed files with 124509 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
/**
* Draw 7-seg digits to the framebuffer
*/
#ifndef FB_7SEG_H
#define FB_7SEG_H
#include "framebuffer.h"
/// 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, fbcolor_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, fbcolor_t color);
#endif //FB_7SEG_H
+29
View File
@@ -0,0 +1,29 @@
/**
* Draw text
*/
#ifndef UFB_FB_TEXT_H
#define UFB_FB_TEXT_H
#include "framebuffer.h"
/// Use tiny font 5x4, supports only digits and select symbols
#define FONT_4X5 8
#define FONT_3X5 16
#define FONT_5X7 0 // default font
/// Use bold variant (each character is printed twice, 1px offset)
#define FONT_BOLD 1
/// Print characters 2x wider
#define FONT_DOUBLEW 2
/// Print characters 2x taller
#define FONT_DOUBLEH 4
/// Print characters 2x wider and taller
#define FONT_DOUBLE (FONT_DOUBLEW | FONT_DOUBLEH)
/// Print text stored in flash
void fb_text_P(fbpos_t x, fbpos_t y, const char *text, uint8_t flags, fbcolor_t color);
/// Print text stored in RAM
void fb_text(fbpos_t x, fbpos_t y, const char *text, uint8_t flags, fbcolor_t color);
#endif //UFB_FB_TEXT_H
+35
View File
@@ -0,0 +1,35 @@
/**
* UTF-8 capable bitmap font
*
* Created on 2020/01/04.
*/
#ifndef GFX_FONT_H
#define GFX_FONT_H
#include "font.h"
#include "utf8.h"
#include <stdint.h>
typedef struct {
uint8_t data[5];
} font5x_bitmap_t;
typedef struct {
uint8_t data[4];
} font4x_bitmap_t;
typedef struct {
uint8_t data[3];
} font3x_bitmap_t;
/// Get font graphic for a character.
///
/// The returned pointer is PROGMEM!
const font5x_bitmap_t *font57_getsym(const struct Utf8Char *ch);
const font4x_bitmap_t *font45_getsym(const struct Utf8Char *ch);
const font3x_bitmap_t *font35_getsym(const struct Utf8Char *ch);
#endif //GFX_FONT_H
+108
View File
@@ -0,0 +1,108 @@
//
// 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
+8
View File
@@ -0,0 +1,8 @@
#ifndef FRAMEBUFFER_CONFIG_H
#define FRAMEBUFFER_CONFIG_H
/* Tiny framebuffer - size of the big actual OLED */
#define FBW 128
#define FBH 64
#endif /* FRAMEBUFFER_CONFIG_H */
+18
View File
@@ -0,0 +1,18 @@
/**
* Progmem support
*/
#ifndef UFB_PROGMEM_H
#define UFB_PROGMEM_H
// if built for AVR, uncommend the include and comment the fake defines:
// #define IS_AVR 1
// #include <avr/pgmspace.h>
#define IS_AVR 0
#define PROGMEM
#define pgm_read_byte(adr) (*adr)
#define pgm_read_dword(adr) (*adr)
#endif //UFB_PROGMEM_H
+93
View File
@@ -0,0 +1,93 @@
/**
* UTF-8 string parsing and character iteration
*
* Created on 2020/01/04.
*/
#ifndef LIQUIDTYPE_UTF8_H
#define LIQUIDTYPE_UTF8_H
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include "progmem.h"
/**
* UTF-8 encoded character.
*/
struct Utf8Char {
union {
/** character bytes; padded by zero bytes if shorter than 4 */
uint8_t bytes[4];
/** u32 view of the bytes */
uint32_t uint;
};
};
/** UTF8 string parser internal state */
struct Utf8Parser {
/** UTF-8 bytes buffer */
struct Utf8Char buffer;
/** Currently collected UTF-8 character length */
uint8_t utf_len;
/** Position in the current character */
uint8_t utf_j;
};
static inline void Utf8Parser_Clear(struct Utf8Parser *self) {
self->buffer.uint = 0;
self->utf_j = 0;
self->utf_len = 0;
}
/**
* Utf8 character iterator.
*
* Usage:
* struct Utf8Iterator iter;
* Utf8Iterator_Init(&iter, myString);
*
* union Utf8Char uchar;
* while ((uchar = Utf8Iterator_Next(&iter)).uint) {
* // do something with the char
* }
*
* // Free myString if needed, it is not mutated.
*/
struct Utf8Iterator {
/* Characters to parse. The pointer is advanced as the iterator progresses. */
const char *source;
struct Utf8Parser parser;
bool is_progmem;
};
static inline void Utf8Iterator_Init(struct Utf8Iterator *self, const char *source) {
Utf8Parser_Clear(&self->parser);
self->source = source;
self->is_progmem = false;
}
static inline void Utf8Iterator_Init_P(struct Utf8Iterator *self, const char *source) {
Utf8Iterator_Init(self, source);
self->is_progmem = true;
}
size_t utf8_strlen(const char *text);
/**
* Get the next character from the iterator; Returns empty character if there are no more characters to parse.
*
* Invalid characters are skipped.
*/
struct Utf8Char Utf8Iterator_Next(struct Utf8Iterator *self);
/**
* Parse a character.
*
* The returned struct contains NIL (uint == 0) if no character is yet available.
*
* ASCII is passed through, utf-8 is collected and returned in one piece.
*/
struct Utf8Char Utf8Parser_Handle(struct Utf8Parser *self, char c);
#endif //LIQUIDTYPE_UTF8_H