ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
board_overlay_draw.c
Go to the documentation of this file.
1
14
15#include <string.h>
16
18
19/* 5x7 column-major font, ASCII 0x20..0x7E. Five bytes per glyph; bit b of a
20 * column byte lights row b (0 = top). A public-domain 5x7 cell font. */
22 {0x00, 0x00, 0x00, 0x00, 0x00}, /* (space) */
23 {0x00, 0x00, 0x5F, 0x00, 0x00}, /* ! */
24 {0x00, 0x07, 0x00, 0x07, 0x00}, /* " */
25 {0x14, 0x7F, 0x14, 0x7F, 0x14}, /* # */
26 {0x24, 0x2A, 0x7F, 0x2A, 0x12}, /* $ */
27 {0x23, 0x13, 0x08, 0x64, 0x62}, /* % */
28 {0x36, 0x49, 0x55, 0x22, 0x50}, /* & */
29 {0x00, 0x05, 0x03, 0x00, 0x00}, /* ' */
30 {0x00, 0x1C, 0x22, 0x41, 0x00}, /* ( */
31 {0x00, 0x41, 0x22, 0x1C, 0x00}, /* ) */
32 {0x14, 0x08, 0x3E, 0x08, 0x14}, /* * */
33 {0x08, 0x08, 0x3E, 0x08, 0x08}, /* + */
34 {0x00, 0x50, 0x30, 0x00, 0x00}, /* , */
35 {0x08, 0x08, 0x08, 0x08, 0x08}, /* - */
36 {0x00, 0x60, 0x60, 0x00, 0x00}, /* . */
37 {0x20, 0x10, 0x08, 0x04, 0x02}, /* / */
38 {0x3E, 0x51, 0x49, 0x45, 0x3E}, /* 0 */
39 {0x00, 0x42, 0x7F, 0x40, 0x00}, /* 1 */
40 {0x42, 0x61, 0x51, 0x49, 0x46}, /* 2 */
41 {0x21, 0x41, 0x45, 0x4B, 0x31}, /* 3 */
42 {0x18, 0x14, 0x12, 0x7F, 0x10}, /* 4 */
43 {0x27, 0x45, 0x45, 0x45, 0x39}, /* 5 */
44 {0x3C, 0x4A, 0x49, 0x49, 0x30}, /* 6 */
45 {0x01, 0x71, 0x09, 0x05, 0x03}, /* 7 */
46 {0x36, 0x49, 0x49, 0x49, 0x36}, /* 8 */
47 {0x06, 0x49, 0x49, 0x29, 0x1E}, /* 9 */
48 {0x00, 0x36, 0x36, 0x00, 0x00}, /* : */
49 {0x00, 0x56, 0x36, 0x00, 0x00}, /* ; */
50 {0x08, 0x14, 0x22, 0x41, 0x00}, /* < */
51 {0x14, 0x14, 0x14, 0x14, 0x14}, /* = */
52 {0x00, 0x41, 0x22, 0x14, 0x08}, /* > */
53 {0x02, 0x01, 0x51, 0x09, 0x06}, /* ? */
54 {0x32, 0x49, 0x79, 0x41, 0x3E}, /* @ */
55 {0x7E, 0x11, 0x11, 0x11, 0x7E}, /* A */
56 {0x7F, 0x49, 0x49, 0x49, 0x36}, /* B */
57 {0x3E, 0x41, 0x41, 0x41, 0x22}, /* C */
58 {0x7F, 0x41, 0x41, 0x22, 0x1C}, /* D */
59 {0x7F, 0x49, 0x49, 0x49, 0x41}, /* E */
60 {0x7F, 0x09, 0x09, 0x09, 0x01}, /* F */
61 {0x3E, 0x41, 0x49, 0x49, 0x7A}, /* G */
62 {0x7F, 0x08, 0x08, 0x08, 0x7F}, /* H */
63 {0x00, 0x41, 0x7F, 0x41, 0x00}, /* I */
64 {0x20, 0x40, 0x41, 0x3F, 0x01}, /* J */
65 {0x7F, 0x08, 0x14, 0x22, 0x41}, /* K */
66 {0x7F, 0x40, 0x40, 0x40, 0x40}, /* L */
67 {0x7F, 0x02, 0x0C, 0x02, 0x7F}, /* M */
68 {0x7F, 0x04, 0x08, 0x10, 0x7F}, /* N */
69 {0x3E, 0x41, 0x41, 0x41, 0x3E}, /* O */
70 {0x7F, 0x09, 0x09, 0x09, 0x06}, /* P */
71 {0x3E, 0x41, 0x51, 0x21, 0x5E}, /* Q */
72 {0x7F, 0x09, 0x19, 0x29, 0x46}, /* R */
73 {0x46, 0x49, 0x49, 0x49, 0x31}, /* S */
74 {0x01, 0x01, 0x7F, 0x01, 0x01}, /* T */
75 {0x3F, 0x40, 0x40, 0x40, 0x3F}, /* U */
76 {0x1F, 0x20, 0x40, 0x20, 0x1F}, /* V */
77 {0x7F, 0x20, 0x18, 0x20, 0x7F}, /* W */
78 {0x63, 0x14, 0x08, 0x14, 0x63}, /* X */
79 {0x03, 0x04, 0x78, 0x04, 0x03}, /* Y */
80 {0x61, 0x51, 0x49, 0x45, 0x43}, /* Z */
81 {0x00, 0x7F, 0x41, 0x41, 0x00}, /* [ */
82 {0x02, 0x04, 0x08, 0x10, 0x20}, /* (backslash) */
83 {0x00, 0x41, 0x41, 0x7F, 0x00}, /* ] */
84 {0x04, 0x02, 0x01, 0x02, 0x04}, /* ^ */
85 {0x40, 0x40, 0x40, 0x40, 0x40}, /* _ */
86 {0x00, 0x01, 0x02, 0x04, 0x00}, /* ` */
87 {0x20, 0x54, 0x54, 0x54, 0x78}, /* a */
88 {0x7F, 0x48, 0x44, 0x44, 0x38}, /* b */
89 {0x38, 0x44, 0x44, 0x44, 0x20}, /* c */
90 {0x38, 0x44, 0x44, 0x48, 0x7F}, /* d */
91 {0x38, 0x54, 0x54, 0x54, 0x18}, /* e */
92 {0x08, 0x7E, 0x09, 0x01, 0x02}, /* f */
93 {0x0C, 0x52, 0x52, 0x52, 0x3E}, /* g */
94 {0x7F, 0x08, 0x04, 0x04, 0x78}, /* h */
95 {0x00, 0x44, 0x7D, 0x40, 0x00}, /* i */
96 {0x20, 0x40, 0x44, 0x3D, 0x00}, /* j */
97 {0x7F, 0x10, 0x28, 0x44, 0x00}, /* k */
98 {0x00, 0x41, 0x7F, 0x40, 0x00}, /* l */
99 {0x7C, 0x04, 0x18, 0x04, 0x78}, /* m */
100 {0x7C, 0x08, 0x04, 0x04, 0x78}, /* n */
101 {0x38, 0x44, 0x44, 0x44, 0x38}, /* o */
102 {0x7C, 0x14, 0x14, 0x14, 0x08}, /* p */
103 {0x08, 0x14, 0x14, 0x18, 0x7C}, /* q */
104 {0x7C, 0x08, 0x04, 0x04, 0x08}, /* r */
105 {0x48, 0x54, 0x54, 0x54, 0x20}, /* s */
106 {0x04, 0x3F, 0x44, 0x40, 0x20}, /* t */
107 {0x3C, 0x40, 0x40, 0x20, 0x7C}, /* u */
108 {0x1C, 0x20, 0x40, 0x20, 0x1C}, /* v */
109 {0x3C, 0x40, 0x30, 0x40, 0x3C}, /* w */
110 {0x44, 0x28, 0x10, 0x28, 0x44}, /* x */
111 {0x0C, 0x50, 0x50, 0x50, 0x3C}, /* y */
112 {0x44, 0x64, 0x54, 0x4C, 0x44}, /* z */
113 {0x00, 0x08, 0x36, 0x41, 0x00}, /* { */
114 {0x00, 0x00, 0x7F, 0x00, 0x00}, /* | */
115 {0x00, 0x41, 0x36, 0x08, 0x00}, /* } */
116 {0x08, 0x04, 0x08, 0x10, 0x08}, /* ~ */
117};
118
120{
121 return (uint16_t)k_ovl_sidebar_w;
122}
123
124uint16_t board_overlay_total_width(uint16_t panel_w)
125{
126 return (uint16_t)(panel_w + (uint16_t)k_ovl_sidebar_w);
127}
128
129uint16_t board_overlay_total_height(uint16_t panel_h)
130{
131 return (panel_h > (uint16_t)k_ovl_min_h) ? panel_h : (uint16_t)k_ovl_min_h;
132}
133
135void priv_px(board_overlay_surface_t* surface, int32_t x, int32_t y, uint16_t color)
136{
137 priv_fill_rect(surface, x, y, 1, 1, color);
138}
139
142 int32_t x,
143 int32_t y,
144 int32_t rw,
145 int32_t rh,
146 uint16_t color)
147{
148 if ((surface == nullptr) || !surface->ok || (surface->fill == nullptr) || (rw <= 0) ||
149 (rh <= 0)) {
150 return;
151 }
152 const int64_t right64 = (int64_t)x + (int64_t)rw;
153 const int64_t bottom64 = (int64_t)y + (int64_t)rh;
154 const int32_t left = (x > 0) ? x : 0;
155 const int32_t top = (y > 0) ? y : 0;
156 const int32_t right =
157 (right64 < (int64_t)surface->width) ? (int32_t)right64 : (int32_t)surface->width;
158 const int32_t bottom =
159 (bottom64 < (int64_t)surface->height) ? (int32_t)bottom64 : (int32_t)surface->height;
160 if ((left >= right) || (top >= bottom)) {
161 return;
162 }
163 surface->ok = surface->fill(surface->context,
164 (uint16_t)left,
165 (uint16_t)top,
166 (uint16_t)(right - left),
167 (uint16_t)(bottom - top),
168 color);
169}
170
186 int32_t x,
187 int32_t y,
188 char ch,
189 uint16_t color,
190 int32_t sc)
191{
192 uint8_t c = (uint8_t)ch;
193 if ((c < (uint8_t)k_ovl_glyph_first) || (c > (uint8_t)k_ovl_glyph_last)) {
194 c = (uint8_t)k_ovl_glyph_first;
195 }
196 const uint8_t* g = s_k_font5x7[c - (uint8_t)k_ovl_glyph_first];
197 for (uint32_t col = 0U; col < (uint32_t)k_ovl_glyph_w; col++) {
198 for (uint32_t row = 0U; row < (uint32_t)k_ovl_glyph_h; row++) {
199 if (((g[col] >> row) & 1U) != 0U) {
200 priv_fill_rect(surface, x + ((int32_t)col * sc), y + ((int32_t)row * sc), sc, sc, color);
201 }
202 }
203 }
204}
205
208 int32_t x,
209 int32_t y,
210 const char* s,
211 uint16_t color,
212 int32_t sc)
213{
214 const int32_t adv = ((int32_t)k_ovl_glyph_w + 1) * sc;
215 int32_t cx = x;
216 for (uint32_t i = 0U; (s != nullptr) && (s[i] != '\0'); i++) {
217 internal_draw_glyph(surface, cx, y, s[i], color, sc);
218 cx += adv;
219 }
220 return cx;
221}
222
224int32_t priv_section_head(board_overlay_surface_t* surface, int32_t x, int32_t y, const char* title)
225{
226 priv_draw_text(surface, x, y, title, (uint16_t)k_ovl_accent, 1);
227 priv_fill_rect(surface,
228 x,
229 y + (int32_t)k_rule_dy,
230 (int32_t)k_ovl_sidebar_w - (2 * (int32_t)k_pad_x),
231 1,
232 (uint16_t)k_ovl_rule);
233 return y + (int32_t)k_heading_gap;
234}
235
238 int32_t x,
239 int32_t y,
240 const char* label,
241 const char* value,
242 uint16_t val_color)
243{
244 const int32_t adv = ((int32_t)k_ovl_glyph_w + 1);
245 const int32_t value_dx = (int32_t)k_kv_label_cols * adv; /* fixed label column so values align */
246 priv_draw_text(surface, x, y, label, (uint16_t)k_ovl_dim, 1);
247 priv_draw_text(surface, x + value_dx, y, value, val_color, 1);
248 return y + (int32_t)k_row_step;
249}
250
252void priv_blit_panel(uint16_t* out,
253 uint16_t w,
254 uint16_t h,
255 const uint16_t* panel,
256 uint16_t panel_w,
257 uint16_t panel_h)
258{
259 for (uint16_t y = 0U; y < h; y++) {
260 for (uint16_t x = 0U; x < panel_w; x++) {
261 const bool in_panel = (panel != nullptr) && (y < panel_h);
262 const uint16_t c =
263 in_panel ? panel[((size_t)y * (size_t)panel_w) + (size_t)x] : (uint16_t)k_ovl_panel_bg;
264 out[((size_t)y * (size_t)w) + (size_t)x] = c;
265 }
266 }
267}
int32_t priv_draw_text(board_overlay_surface_t *surface, int32_t x, int32_t y, const char *s, uint16_t color, int32_t sc)
Draw a NUL-terminated string; returns the x just past the last cell.
uint16_t board_overlay_sidebar_width(void)
Width in pixels the status sidebar adds to the right of the panel.
uint16_t board_overlay_total_width(uint16_t panel_w)
Total composite width for a panel of width panel_w.
void priv_blit_panel(uint16_t *out, uint16_t w, uint16_t h, const uint16_t *panel, uint16_t panel_w, uint16_t panel_h)
Blit the panel framebuffer into the composite's top-left region.
static RA8_INTERNAL void internal_draw_glyph(board_overlay_surface_t *surface, int32_t x, int32_t y, char ch, uint16_t color, int32_t sc)
Draw one ASCII glyph at scale sc; non-printable maps to space.
int32_t priv_section_head(board_overlay_surface_t *surface, int32_t x, int32_t y, const char *title)
Draw a section heading (accent colour) with a thin rule beneath it.
static const uint8_t s_k_font5x7[(k_ovl_glyph_last - k_ovl_glyph_first)+1U][k_ovl_glyph_w]
void priv_fill_rect(board_overlay_surface_t *surface, int32_t x, int32_t y, int32_t rw, int32_t rh, uint16_t color)
Fill the axis-aligned rectangle [x,x+rw) x [y,y+rh) with color.
uint16_t board_overlay_total_height(uint16_t panel_h)
Total composite height for a panel of height panel_h.
int32_t priv_kv_row(board_overlay_surface_t *surface, int32_t x, int32_t y, const char *label, const char *value, uint16_t val_color)
Draw a "label value" row: dim label, bright value, returns next y.
void priv_px(board_overlay_surface_t *surface, int32_t x, int32_t y, uint16_t color)
Plot one pixel if it lies inside the supplied surface.
Module-private layout constants + draw primitives for the overlay.
@ k_rule_dy
Heading baseline to its underline rule.
@ k_kv_label_cols
Label column width (glyphs) so values align.
@ k_row_step
Vertical step between text rows.
@ k_heading_gap
Section heading to its first row.
@ k_pad_x
Left padding inside the sidebar.
@ k_ovl_rule
Thin horizontal section rule.
@ k_ovl_panel_bg
Fill behind a missing/short panel.
@ k_ovl_glyph_h
Font glyph height in pixels.
@ k_ovl_glyph_last
Last font glyph (tilde).
@ k_ovl_min_h
Minimum height.
@ k_ovl_accent
Cyan title accent.
@ k_ovl_glyph_w
Font glyph width in pixels.
@ k_ovl_sidebar_w
Sidebar width.
@ k_ovl_dim
Dim label text (field names).
@ k_ovl_glyph_first
First font glyph (space).
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Non-owning drawing surface used by memory and raw-fd compositors.
void * context
Caller-owned sink context.
board_overlay_fill_fn fill
Clipped solid-rectangle writer.
bool ok
Sticky false after a sink write fault.
uint16_t width
Complete composite width in pixels.
uint16_t height
Complete composite height in pixels.