File syn_canvas.c¶
FileList > display > syn_canvas.c
Go to the source code of this file
Display canvas implementation.
#include "../util/syn_assert.h"#include "../util/syn_qmath.h"#include "syn_canvas.h"#include <string.h>
Public Attributes¶
| Type | Name |
|---|---|
| const SYN_Font | syn_font_5x7 = /* multi line expression */ |
Public Static Attributes¶
| Type | Name |
|---|---|
| const uint8_t | font_5x7_data Built-in 5×7 font data (ASCII 32–126, column-major). |
Public Functions¶
| Type | Name |
|---|---|
| void | syn_canvas_arc (SYN_Canvas * c, int16_t cx, int16_t cy, int16_t r, int16_t start_angle_deg, int16_t end_angle_deg, uint16_t color) Draw a circular arc. |
| void | syn_canvas_bitmap (SYN_Canvas * c, int16_t x, int16_t y, const uint8_t * bitmap, int16_t w, int16_t h, uint16_t color) Draw a monochrome 1bpp bitmap. |
| uint8_t | syn_canvas_char (SYN_Canvas * c, int16_t x, int16_t y, char ch, uint16_t color) Draw a single character. |
| void | syn_canvas_circle (SYN_Canvas * c, int16_t cx, int16_t cy, int16_t r, uint16_t color) Draw a circle (Bresenham). |
| void | syn_canvas_circle_fill (SYN_Canvas * c, int16_t cx, int16_t cy, int16_t r, uint16_t color) Draw a filled circle. |
| void | syn_canvas_clear (SYN_Canvas * c) Clear the entire framebuffer (fill with zero). |
| void | syn_canvas_fill (SYN_Canvas * c, uint16_t color) Fill the entire framebuffer with a color. |
| void | syn_canvas_flush (SYN_Canvas * c) Push framebuffer to display via the flush callback. |
| void | syn_canvas_flush_partial (SYN_Canvas * c, size_t offset, size_t len) Push a slice of the framebuffer to the display. |
| void | syn_canvas_hline (SYN_Canvas * c, int16_t x, int16_t y, int16_t w, uint16_t color) Draw a fast horizontal line (optimised; no Bresenham overhead). |
| void | syn_canvas_init (SYN_Canvas * c, uint8_t * buf, uint16_t w, uint16_t h, uint8_t bpp, SYN_Canvas_FlushFn flush, void * ctx) Initialize the canvas. |
| void | syn_canvas_line (SYN_Canvas * c, int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color) Draw a line (Bresenham). |
| void | syn_canvas_line_aa (SYN_Canvas * c, int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color) Draw an anti-aliased line segment using Xiaolin Wu's algorithm. |
| void | syn_canvas_line_polar (SYN_Canvas * c, int16_t cx, int16_t cy, int16_t angle_deg, int16_t length, uint16_t color) Draw a line segment defined by origin, angle, and length (gauge needle helper). |
| void | syn_canvas_pixel (SYN_Canvas * c, int16_t x, int16_t y, uint16_t color) Set a single pixel. |
| void | syn_canvas_rect (SYN_Canvas * c, int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) Draw a rectangle (outline only). |
| void | syn_canvas_rect_fill (SYN_Canvas * c, int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) Draw a filled rectangle. |
| void | syn_canvas_rect_round (SYN_Canvas * c, int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, uint16_t color) Draw a rounded rectangle (outline only). |
| void | syn_canvas_rect_round_fill (SYN_Canvas * c, int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, uint16_t color) Draw a filled rounded rectangle. |
| void | syn_canvas_reset_clip (SYN_Canvas * c) Reset clip rectangle to the full display area. |
| void | syn_canvas_set_clip (SYN_Canvas * c, int16_t x, int16_t y, int16_t w, int16_t h) Set the clip rectangle. Drawing is restricted to this region. |
| void | syn_canvas_set_font (SYN_Canvas * c, const SYN_Font * font) Set the active font. |
| void | syn_canvas_text (SYN_Canvas * c, int16_t x, int16_t y, const char * str, uint16_t color) Draw a text string at (x,y) using the active font. |
| uint8_t | syn_canvas_text_height (const SYN_Canvas * c) Return the height of the active font in pixels. |
| uint16_t | syn_canvas_text_width (const SYN_Canvas * c, const char * str) Measure text width in pixels (without drawing). |
| void | syn_canvas_vline (SYN_Canvas * c, int16_t x, int16_t y, int16_t h, uint16_t color) Draw a fast vertical line. |
Public Static Functions¶
| Type | Name |
|---|---|
| void | draw_rounded_corners (SYN_Canvas * c, int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, uint16_t color) Draw the four rounded corners of a rectangle. |
Public Attributes Documentation¶
variable syn_font_5x7¶
Built-in 5×7 font (ASCII 32-126).
Public Static Attributes Documentation¶
variable font_5x7_data¶
Built-in 5×7 font data (ASCII 32–126, column-major).
Public Functions Documentation¶
function syn_canvas_arc¶
Draw a circular arc.
void syn_canvas_arc (
SYN_Canvas * c,
int16_t cx,
int16_t cy,
int16_t r,
int16_t start_angle_deg,
int16_t end_angle_deg,
uint16_t color
)
Parameters:
cCanvas.cxCenter X.cyCenter Y.rRadius.start_angle_degStart angle in degrees (0 = 3 o'clock, 90 = 6 o'clock).end_angle_degEnd angle in degrees.colorLine color.
function syn_canvas_bitmap¶
Draw a monochrome 1bpp bitmap.
void syn_canvas_bitmap (
SYN_Canvas * c,
int16_t x,
int16_t y,
const uint8_t * bitmap,
int16_t w,
int16_t h,
uint16_t color
)
Parameters:
cCanvas.xDestination X.yDestination Y.bitmap1bpp bitmap data (row-major).wBitmap width in pixels.hBitmap height in pixels.colorForeground color for set bits.
function syn_canvas_char¶
Draw a single character.
Parameters:
cCanvas.xX position.yY position.chCharacter to draw.colorText color.
Returns:
Advance width in pixels.
function syn_canvas_circle¶
Draw a circle (Bresenham).
Parameters:
cCanvas.cxCenter X.cyCenter Y.rRadius.colorOutline color.
function syn_canvas_circle_fill¶
Draw a filled circle.
Parameters:
cCanvas.cxCenter X.cyCenter Y.rRadius.colorFill color.
function syn_canvas_clear¶
Clear the entire framebuffer (fill with zero).
Parameters:
cCanvas.
function syn_canvas_fill¶
Fill the entire framebuffer with a color.
Parameters:
cCanvas.colorFill color (0/1 for mono, RGB565 for color).
function syn_canvas_flush¶
Push framebuffer to display via the flush callback.
Parameters:
cCanvas.
function syn_canvas_flush_partial¶
Push a slice of the framebuffer to the display.
Calls the flush callback with a pointer into the framebuffer at offset with length len. Intended for coroutine-friendly incremental flushing — yield between chunks to avoid blocking the scheduler during slow SPI/I2C transfers.
** **
static size_t flush_pos;
flush_pos = 0;
while (flush_pos < canvas.buf_size) {
size_t chunk = 128u;
if (chunk > canvas.buf_size - flush_pos)
chunk = canvas.buf_size - flush_pos;
syn_canvas_flush_partial(&canvas, flush_pos, chunk);
flush_pos += chunk;
PT_YIELD(pt); // other tasks run here
}
Parameters:
cCanvas.offsetByte offset into the framebuffer to start from.lenNumber of bytes to send.
Note:
The display driver's flush_fn receives ``(framebuf+offset, len, ctx) — the same three-argument signature as a full flush. It must be written to handle sequential partial writes correctly (i.e. not re-issue a start-of-frame command before each chunk).
function syn_canvas_hline¶
Draw a fast horizontal line (optimised; no Bresenham overhead).
Parameters:
cCanvas.xStart X.yY position.wWidth in pixels.colorColor.
function syn_canvas_init¶
Initialize the canvas.
void syn_canvas_init (
SYN_Canvas * c,
uint8_t * buf,
uint16_t w,
uint16_t h,
uint8_t bpp,
SYN_Canvas_FlushFn flush,
void * ctx
)
Parameters:
cCanvas instance.bufFramebuffer (caller allocates: w*h/8 for 1bpp, w*h*2 for 16bpp).wWidth in pixels.hHeight in pixels.bppBits per pixel (1 for mono, 16 for RGB565).flushCallback to push framebuf to display hardware.ctxContext for flush callback.
function syn_canvas_line¶
Draw a line (Bresenham).
void syn_canvas_line (
SYN_Canvas * c,
int16_t x0,
int16_t y0,
int16_t x1,
int16_t y1,
uint16_t color
)
Parameters:
cCanvas.x0Start X.y0Start Y.x1End X.y1End Y.colorLine color.
function syn_canvas_line_aa¶
Draw an anti-aliased line segment using Xiaolin Wu's algorithm.
void syn_canvas_line_aa (
SYN_Canvas * c,
int16_t x0,
int16_t y0,
int16_t x1,
int16_t y1,
uint16_t color
)
Parameters:
cCanvas.x0Start X.y0Start Y.x1End X.y1End Y.colorLine color.
function syn_canvas_line_polar¶
Draw a line segment defined by origin, angle, and length (gauge needle helper).
void syn_canvas_line_polar (
SYN_Canvas * c,
int16_t cx,
int16_t cy,
int16_t angle_deg,
int16_t length,
uint16_t color
)
Parameters:
cCanvas.cxOrigin X.cyOrigin Y.angle_degAngle in degrees (0 = 3 o'clock, 90 = 6 o'clock).lengthNeedle length in pixels.colorLine color.
function syn_canvas_pixel¶
Set a single pixel.
Parameters:
cCanvas.xX coordinate.yY coordinate.colorPixel color (0/1 for mono, RGB565 for color).
function syn_canvas_rect¶
Draw a rectangle (outline only).
Parameters:
cCanvas.xLeft edge.yTop edge.wWidth.hHeight.colorOutline color.
function syn_canvas_rect_fill¶
Draw a filled rectangle.
void syn_canvas_rect_fill (
SYN_Canvas * c,
int16_t x,
int16_t y,
int16_t w,
int16_t h,
uint16_t color
)
Parameters:
cCanvas.xLeft edge.yTop edge.wWidth.hHeight.colorFill color.
function syn_canvas_rect_round¶
Draw a rounded rectangle (outline only).
void syn_canvas_rect_round (
SYN_Canvas * c,
int16_t x,
int16_t y,
int16_t w,
int16_t h,
int16_t r,
uint16_t color
)
Parameters:
cCanvas.xLeft edge.yTop edge.wWidth.hHeight.rCorner radius.colorOutline color.
function syn_canvas_rect_round_fill¶
Draw a filled rounded rectangle.
void syn_canvas_rect_round_fill (
SYN_Canvas * c,
int16_t x,
int16_t y,
int16_t w,
int16_t h,
int16_t r,
uint16_t color
)
Parameters:
cCanvas.xLeft edge.yTop edge.wWidth.hHeight.rCorner radius.colorFill color.
function syn_canvas_reset_clip¶
Reset clip rectangle to the full display area.
Parameters:
cCanvas.
function syn_canvas_set_clip¶
Set the clip rectangle. Drawing is restricted to this region.
Parameters:
cCanvas.xClip left edge.yClip top edge.wClip width.hClip height.
function syn_canvas_set_font¶
Set the active font.
Parameters:
cCanvas.fontFont descriptor, or NULL for built-in 5×7.
function syn_canvas_text¶
Draw a text string at (x,y) using the active font.
Parameters:
cCanvas.xStart X.yStart Y.strNull-terminated string.colorText color.
function syn_canvas_text_height¶
Return the height of the active font in pixels.
Parameters:
cCanvas.
Returns:
Font height in pixels.
function syn_canvas_text_width¶
Measure text width in pixels (without drawing).
Parameters:
cCanvas (uses active font).strNull-terminated string.
Returns:
Width in pixels.
function syn_canvas_vline¶
Draw a fast vertical line.
Parameters:
cCanvas.xX position.yStart Y.hHeight in pixels.colorColor.
Public Static Functions Documentation¶
function draw_rounded_corners¶
Draw the four rounded corners of a rectangle.
static void draw_rounded_corners (
SYN_Canvas * c,
int16_t x,
int16_t y,
int16_t w,
int16_t h,
int16_t r,
uint16_t color
)
Parameters:
cCanvas.xRectangle X.yRectangle Y.wRectangle width.hRectangle height.rCorner radius.colorPixel color.
The documentation for this class was generated from the following file src/syntropic/display/syn_canvas.c