Skip to content

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

const SYN_Font 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).

const uint8_t font_5x7_data[];


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:

  • c Canvas.
  • cx Center X.
  • cy Center Y.
  • r Radius.
  • start_angle_deg Start angle in degrees (0 = 3 o'clock, 90 = 6 o'clock).
  • end_angle_deg End angle in degrees.
  • color Line 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:

  • c Canvas.
  • x Destination X.
  • y Destination Y.
  • bitmap 1bpp bitmap data (row-major).
  • w Bitmap width in pixels.
  • h Bitmap height in pixels.
  • color Foreground color for set bits.

function syn_canvas_char

Draw a single character.

uint8_t syn_canvas_char (
    SYN_Canvas * c,
    int16_t x,
    int16_t y,
    char ch,
    uint16_t color
) 

Parameters:

  • c Canvas.
  • x X position.
  • y Y position.
  • ch Character to draw.
  • color Text color.

Returns:

Advance width in pixels.


function syn_canvas_circle

Draw a circle (Bresenham).

void syn_canvas_circle (
    SYN_Canvas * c,
    int16_t cx,
    int16_t cy,
    int16_t r,
    uint16_t color
) 

Parameters:

  • c Canvas.
  • cx Center X.
  • cy Center Y.
  • r Radius.
  • color Outline color.

function syn_canvas_circle_fill

Draw a filled circle.

void syn_canvas_circle_fill (
    SYN_Canvas * c,
    int16_t cx,
    int16_t cy,
    int16_t r,
    uint16_t color
) 

Parameters:

  • c Canvas.
  • cx Center X.
  • cy Center Y.
  • r Radius.
  • color Fill color.

function syn_canvas_clear

Clear the entire framebuffer (fill with zero).

void syn_canvas_clear (
    SYN_Canvas * c
) 

Parameters:

  • c Canvas.

function syn_canvas_fill

Fill the entire framebuffer with a color.

void syn_canvas_fill (
    SYN_Canvas * c,
    uint16_t color
) 

Parameters:

  • c Canvas.
  • color Fill color (0/1 for mono, RGB565 for color).

function syn_canvas_flush

Push framebuffer to display via the flush callback.

void syn_canvas_flush (
    SYN_Canvas * c
) 

Parameters:

  • c Canvas.

function syn_canvas_flush_partial

Push a slice of the framebuffer to the display.

void syn_canvas_flush_partial (
    SYN_Canvas * c,
    size_t offset,
    size_t len
) 

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:

  • c Canvas.
  • offset Byte offset into the framebuffer to start from.
  • len Number 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).

void syn_canvas_hline (
    SYN_Canvas * c,
    int16_t x,
    int16_t y,
    int16_t w,
    uint16_t color
) 

Parameters:

  • c Canvas.
  • x Start X.
  • y Y position.
  • w Width in pixels.
  • color Color.

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:

  • c Canvas instance.
  • buf Framebuffer (caller allocates: w*h/8 for 1bpp, w*h*2 for 16bpp).
  • w Width in pixels.
  • h Height in pixels.
  • bpp Bits per pixel (1 for mono, 16 for RGB565).
  • flush Callback to push framebuf to display hardware.
  • ctx Context 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:

  • c Canvas.
  • x0 Start X.
  • y0 Start Y.
  • x1 End X.
  • y1 End Y.
  • color Line 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:

  • c Canvas.
  • x0 Start X.
  • y0 Start Y.
  • x1 End X.
  • y1 End Y.
  • color Line 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:

  • c Canvas.
  • cx Origin X.
  • cy Origin Y.
  • angle_deg Angle in degrees (0 = 3 o'clock, 90 = 6 o'clock).
  • length Needle length in pixels.
  • color Line color.

function syn_canvas_pixel

Set a single pixel.

void syn_canvas_pixel (
    SYN_Canvas * c,
    int16_t x,
    int16_t y,
    uint16_t color
) 

Parameters:

  • c Canvas.
  • x X coordinate.
  • y Y coordinate.
  • color Pixel color (0/1 for mono, RGB565 for color).

function syn_canvas_rect

Draw a rectangle (outline only).

void syn_canvas_rect (
    SYN_Canvas * c,
    int16_t x,
    int16_t y,
    int16_t w,
    int16_t h,
    uint16_t color
) 

Parameters:

  • c Canvas.
  • x Left edge.
  • y Top edge.
  • w Width.
  • h Height.
  • color Outline 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:

  • c Canvas.
  • x Left edge.
  • y Top edge.
  • w Width.
  • h Height.
  • color Fill 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:

  • c Canvas.
  • x Left edge.
  • y Top edge.
  • w Width.
  • h Height.
  • r Corner radius.
  • color Outline 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:

  • c Canvas.
  • x Left edge.
  • y Top edge.
  • w Width.
  • h Height.
  • r Corner radius.
  • color Fill color.

function syn_canvas_reset_clip

Reset clip rectangle to the full display area.

void syn_canvas_reset_clip (
    SYN_Canvas * c
) 

Parameters:

  • c Canvas.

function syn_canvas_set_clip

Set the clip rectangle. Drawing is restricted to this region.

void syn_canvas_set_clip (
    SYN_Canvas * c,
    int16_t x,
    int16_t y,
    int16_t w,
    int16_t h
) 

Parameters:

  • c Canvas.
  • x Clip left edge.
  • y Clip top edge.
  • w Clip width.
  • h Clip height.

function syn_canvas_set_font

Set the active font.

void syn_canvas_set_font (
    SYN_Canvas * c,
    const SYN_Font * font
) 

Parameters:

  • c Canvas.
  • font Font descriptor, or NULL for built-in 5×7.

function syn_canvas_text

Draw a text string at (x,y) using the active font.

void syn_canvas_text (
    SYN_Canvas * c,
    int16_t x,
    int16_t y,
    const char * str,
    uint16_t color
) 

Parameters:

  • c Canvas.
  • x Start X.
  • y Start Y.
  • str Null-terminated string.
  • color Text color.

function syn_canvas_text_height

Return the height of the active font in pixels.

uint8_t syn_canvas_text_height (
    const SYN_Canvas * c
) 

Parameters:

  • c Canvas.

Returns:

Font height in pixels.


function syn_canvas_text_width

Measure text width in pixels (without drawing).

uint16_t syn_canvas_text_width (
    const SYN_Canvas * c,
    const char * str
) 

Parameters:

  • c Canvas (uses active font).
  • str Null-terminated string.

Returns:

Width in pixels.


function syn_canvas_vline

Draw a fast vertical line.

void syn_canvas_vline (
    SYN_Canvas * c,
    int16_t x,
    int16_t y,
    int16_t h,
    uint16_t color
) 

Parameters:

  • c Canvas.
  • x X position.
  • y Start Y.
  • h Height in pixels.
  • color Color.

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:

  • c Canvas.
  • x Rectangle X.
  • y Rectangle Y.
  • w Rectangle width.
  • h Rectangle height.
  • r Corner radius.
  • color Pixel color.


The documentation for this class was generated from the following file src/syntropic/display/syn_canvas.c