mirror of
https://github.com/juanjiant-bit/JIANT.git
synced 2026-12-05 12:24:42 +01:00
(the owner: "dale implementalo"; a user's report, its details from an AI chat: a hypothesis: the units sold from late
2026, flash 0xB36014, carry another 1.3" 240 x 240 IPS panel, ST7789-compatible, its colours washed out)
- lcd.c: A as it was (LCD_SEQ and lcd_init's stream byte for byte: lcd_seq, the same loop out of line). B: after A's
set-up, the ST7789V datasheet's registers (written from its register descriptions, not from other firmwares):
B2 PORCTRL 0C 0C 00 33 33 | B7 GCTRL 35 | BB VCOMS 19 | C0 LCMCTRL 2C | C2 VDVVRHEN 01 FF | C3 VRHS 12 |
C4 VDVS 20 | C6 FRCTRL2 0F | D0 PWCTRL1 A4 A1 |
E0 PVGAMCTRL D0 04 0D 11 13 2B 3F 54 4C 18 0D 0B 1F 23 |
E1 NVGAMCTRL D0 04 0C 11 13 2C 3F 44 51 2F 1F 1F 20 23 |
20 INVOFF (A: 21 INVON); MADCTL (the colour order) as A's.
UNTESTED on the new panel. Back from B to A: A's reset and sequence again (lcd_panel_apply).
- MENU > DISPLAY > PANEL: AUTO (every older record) A B, engine 15's byte 15 bits 0-1 (INPUT's favourites 120..127,
never set), editor id 34; AUTO B only on flash 0xB36014 (project.c persist_boot keeps the JEDEC id); changed: the
panel at once, no reboot, "PANEL A" / "PANEL B". At power-on B's registers after A's (the splash), unless OCT- + SAVE
are held: A for that start (OCT- + OCT+ stays the calibration). The emulator: the setting, no visual change.
- tests: lcd_panel_test (A's bytes and stream as V10.8.62's, B once after A, back to A), in voice-user-check.yml;
ui_test (PANEL's row in DISPLAY, kept in the settings, applied with its banner, AUTO by a mocked JEDEC id); the
hosts' lcd stubs.
Layout recorded again (FELUCCA_REPIN=keep); the plain build passes. Image 580808 of 584336 (3528 B free), RAM code
40192 (the calls into the image shifted). audio.c as V23's.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KMHk6yH4XbP1xxHYKCo9Mh
170 lines
9.7 KiB
C
170 lines
9.7 KiB
C
/* SPDX-License-Identifier: GPL-3.0-only */
|
|
/* The palettes and the real canvas/text renderer (src/gfx.c): the family of seven in MENU's order, each token the
|
|
* stored one (JIANT's as it has been since 0.8.9), INK black, REC red, the knobs' colours and
|
|
* every palette's text contrast, the alpha blend, the ramp cache, the fonts' metrics and the ellipsis.
|
|
* Optional: a palette sheet (PPM). */
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <assert.h>
|
|
#include <math.h>
|
|
#include <string.h>
|
|
#define __attribute__(x)
|
|
static void lcd_sync(void) {}
|
|
static uint32_t fl_jedec_id; /* (V10.8.63: lcd.c, MENU > PANEL) */
|
|
static void lcd_panel_apply(uint32_t b, uint32_t boot) { (void)b; (void)boot; }
|
|
static void lcd_power(uint32_t s) { (void)s; } /* (MENU > SCREEN OFF: lcd.c) */
|
|
static void lcd_wake_now(void) {}
|
|
static void lcd_blit(uint32_t x, uint32_t y, uint32_t w, uint32_t h, const uint16_t *p)
|
|
{ (void)x; (void)y; (void)w; (void)h; (void)p; }
|
|
#include "../firmware/src/gfx.c"
|
|
|
|
#define SHEET_W 960u
|
|
#define SHEET_H (((NPALETTES + 3u) / 4u) * 124u)
|
|
static uint16_t sheet[SHEET_W * SHEET_H];
|
|
static unsigned channel(uint16_t c, unsigned n)
|
|
{ return n == 0 ? c >> 11 : n == 1 ? (c >> 5) & 63 : c & 31; }
|
|
static double luminance(uint16_t color)
|
|
{
|
|
const double weight[] = {0.2126, 0.7152, 0.0722};
|
|
double result = 0;
|
|
for (unsigned c = 0; c < 3; c++) {
|
|
double v = channel(color, c) / (c == 1 ? 63.0 : 31.0);
|
|
result += weight[c] * (v <= 0.04045 ? v / 12.92 : pow((v + 0.055) / 1.055, 2.4));
|
|
}
|
|
return result;
|
|
}
|
|
static double contrast(uint16_t fg, uint16_t bg)
|
|
{
|
|
double a = luminance(fg), b = luminance(bg);
|
|
return a > b ? (a + 0.05) / (b + 0.05) : (b + 0.05) / (a + 0.05);
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
/* one glyph 'A': 3 px, alpha 0, 8, 15, as a byte-packed record (gfx.c ag: off 0, adv 48, bx 0, by 0, bw 3, bh 1) */
|
|
static const uint8_t pg[5] = {0, 0, 0x23, 0x60, 0x04};
|
|
static const uint8_t pd[] = {0x08, 0xf0};
|
|
const aafont_t probe = {1, 1, 'A', 'A', 0, 0, pg, 0, pd, 0, 0, 0};
|
|
double worst = 100;
|
|
{ /* MENU > DISPLAY > COLOR: exactly these seven, in this order; JIANT the first, the default */
|
|
static const char *const FAMILY[] = {"JIANT", "SELVA", "CONTRAST", "BRASA", "ABISAL", "HUESO", "NEON"};
|
|
/* JIANT's tokens as they have been since 0.8.9 (five colours and their blends): unchanged */
|
|
static const uint16_t JIANT[12] = {0x0000, 0x0841, 0xf79d, 0xbb9f, 0xfbc0, 0xad54, 0x6b2c, 0x2965, 0x92d9, 0x1864, 0xfa49, 0x1082};
|
|
assert(NPALETTES == 7u && UI_JIANT_INDEX == 0u && sizeof UI_PALETTES / sizeof UI_PALETTES[0] == 7u);
|
|
for (unsigned p = 0; p < NPALETTES; p++) assert(!strcmp(UI_PALETTES[p].name, FAMILY[p]));
|
|
assert(!memcmp(UI_PALETTES[UI_JIANT_INDEX].c, JIANT, sizeof JIANT));
|
|
assert(&ux.raise - &ux.bg == 11 && &ux.grid - &ux.bg == 14); /* (palette_set copies the stored twelve) */
|
|
}
|
|
for (unsigned sk = 0; sk < 1; sk++) { /* the stored tokens as they are (V10.7.23: COLORS, the one skin) */
|
|
for (unsigned p = 0; p < NPALETTES; p++) {
|
|
const uint16_t *c = UI_PALETTES[p].c;
|
|
palette_set(p);
|
|
assert(T_BG == c[0] && T_SURF == c[1] && T_TEXT == c[2] && T_THEME == c[3] && T_ACCENT == c[4] &&
|
|
T_MID == c[5] && T_DIM == c[6] && T_LINE == c[7] && T_SEL == c[8] && T_TINT == c[9] && T_REC == c[10] &&
|
|
T_RAISE == c[11] && T_INK == 0u && T_K(0) == UI_KNOBS[p][0] && T_K(3) == UI_KNOBS[p][3]);
|
|
}
|
|
}
|
|
for (unsigned p = 0; p < NPALETTES; p++) {
|
|
uint16_t *tok = &ux.bg;
|
|
palette_set(p);
|
|
/* text and the things read on the screen; the generator checks the same (tools/gen_ui_palettes.py) */
|
|
struct { uint16_t fg, bg; double min; } c[] = {
|
|
{T_TEXT, T_BG, 12.0}, {T_TEXT, T_SURF, 9.0}, {T_MID, T_BG, 5.0}, {T_MID, T_SURF, 4.0},
|
|
{T_THEME, T_BG, 4.5}, {T_THEME, T_SURF, 4.5}, {T_ACCENT, T_BG, 4.5}, {T_ACCENT, T_SURF, 4.5},
|
|
{T_INK, T_SEL, 4.5}, {T_INK, T_THEME, 4.5}, {T_DIM, T_BG, 2.2}, {T_LINE, T_BG, 1.25}, {T_REC, T_BG, 3.0},
|
|
{T_INK, T_KEY, 4.5}, {T_KEY, T_BG, 3.0}, {T_KEY, T_SURF, 2.5}, {T_INK, T_DIM, 1.8}, {T_INK, T_ACCENT, 4.5},
|
|
{T_TEXT, T_RAISE, 7.0}, {T_INK, T_REC, 4.5}, {T_SEL, T_BG, 1.8},
|
|
/* the knobs' colours (each palette its own four) on what a card's value is drawn on */
|
|
{T_K(0), T_BG, 4.5}, {T_K(1), T_BG, 4.5}, {T_K(2), T_BG, 4.5}, {T_K(3), T_BG, 4.5},
|
|
{T_K(0), T_SURF, 4.5}, {T_K(1), T_SURF, 4.5}, {T_K(2), T_SURF, 4.5}, {T_K(3), T_SURF, 4.5},
|
|
{T_K(0), T_RAISE, 4.5}, {T_K(1), T_RAISE, 4.5}, {T_K(2), T_RAISE, 4.5}, {T_K(3), T_RAISE, 4.5}};
|
|
double min = 100;
|
|
for (unsigned i = 0; i < sizeof c / sizeof c[0]; i++) {
|
|
double r = contrast(c[i].fg, c[i].bg);
|
|
if (r < c[i].min) printf("%s: pairing %u contrast %.2f < %.2f\n", UI_PALETTES[p].name, i, r, c[i].min);
|
|
assert(r >= c[i].min);
|
|
if (r / c[i].min < min) min = r / c[i].min;
|
|
}
|
|
if (min < worst) worst = min;
|
|
printf("%-7s text %.1f:1, labels %.1f:1, values %.1f:1, selection %.1f:1\n", UI_PALETTES[p].name,
|
|
contrast(T_TEXT, T_BG), contrast(T_MID, T_BG), contrast(T_THEME, T_BG), contrast(T_INK, T_SEL));
|
|
assert(contrast(T_BG, 0) < 1.1); /* every palette is dark (one coverage curve) */
|
|
for (unsigned i = 0; i < 4; i++) { /* the four knobs apart from each other, and (but HUESO's
|
|
* fourth, its one orange) from the ACCENT, the active thing */
|
|
for (unsigned j = i + 1; j < 4; j++) assert(T_K(i) != T_K(j));
|
|
assert(T_K(i) != T_ACCENT || (p == 5u && i == 3u));
|
|
}
|
|
{ /* JIANT's as they were (the 0.6 colours); HUESO greys and the orange */
|
|
static const uint16_t J[4] = {0x8b7f, 0xfe87, 0x5bbf, 0xfa49};
|
|
if (p == UI_JIANT_INDEX) assert(!memcmp(UI_KNOBS[p], J, sizeof J));
|
|
}
|
|
/* the blend: transparent, solid and an edge between the two, on two backgrounds */
|
|
for (unsigned b = 0; b < 2; b++) {
|
|
uint16_t under = b ? T_SEL : T_BG, ink = b ? T_INK : T_THEME;
|
|
cv_begin(3, 1, under);
|
|
cv_text_on(0, 0, &probe, "A", ink, under);
|
|
assert(swap16(cv_px[0]) == under && swap16(cv_px[2]) == ink);
|
|
for (unsigned k = 0; k < 3; k++) {
|
|
unsigned a = channel(under, k), z = channel(ink, k), m = channel(swap16(cv_px[1]), k);
|
|
assert(m >= (a < z ? a : z) && m <= (a > z ? a : z)); /* no halo */
|
|
}
|
|
}
|
|
assert(text_w(&AF_S, UI_PALETTES[p].name) <= 60); /* the COLOR row's value */
|
|
cv_begin(240, 124, T_BG);
|
|
cv_text(4, 2, &AF_M, UI_PALETTES[p].name, T_TEXT);
|
|
for (unsigned k = 0; k < 5; k++) cv_rect(150 + k * 16, 4, 12, 12, tok[k]);
|
|
cv_text(4, 26, &AF_S, "LABEL", T_MID);
|
|
cv_text(70, 22, &AF_M, "VALUE 127", T_THEME);
|
|
cv_text(170, 22, &AF_M, "HOT", T_ACCENT);
|
|
cv_text(4, 46, &AF_S, "INACTIVE", T_DIM);
|
|
cv_rect(80, 44, 150, 17, T_SEL);
|
|
cv_text_on(86, 45, &AF_S, "SELECTED ROW", T_INK, T_SEL);
|
|
cv_rect(4, 66, 232, 1, T_LINE);
|
|
cv_rect(4, 72, 120, 3, T_LINE);
|
|
cv_rect(4, 72, 70, 3, T_SEL);
|
|
cv_rect(74, 70, 1, 7, T_THEME);
|
|
cv_text(136, 66, &AF_S, "REC", T_REC);
|
|
cv_text(4, 82, &AF_L, "124", T_THEME);
|
|
cv_text(80, 92, &AF_S, "Mixed case text", T_TEXT);
|
|
cv_key_hint(80, 108, KC_OCTUP, "LOAD", 1, T_BG); /* keycaps: available, unavailable */
|
|
cv_key_hint(150, 108, KC_OCTDN, "BACK", 0, T_BG);
|
|
for (unsigned y = 0; y < 124; y++)
|
|
for (unsigned x = 0; x < 240; x++) {
|
|
uint16_t v = swap16(cv_px[y * 240 + x]);
|
|
sheet[(p / 4 * 124 + y) * 960 + p % 4 * 240 + x] = v;
|
|
}
|
|
}
|
|
/* the ramp cache follows the palette (a stale ramp would blend toward the old background) */
|
|
palette_set(1);
|
|
cv_begin(3, 1, T_BG); cv_text(0, 0, &probe, "A", T_THEME);
|
|
uint16_t green = swap16(cv_px[1]);
|
|
palette_set(3);
|
|
cv_begin(3, 1, T_BG); cv_text(0, 0, &probe, "A", T_THEME);
|
|
assert(swap16(cv_px[1]) != green);
|
|
/* fonts: Chakra Petch (JIANT 0.5) S 12 px; (0.8.9) M Inter Tight SemiBold 15 px (the values, as the 0.6), L Michroma
|
|
* 18 px; tabular digits; the ellipsis; L has capitals only */
|
|
assert(AF_S.h == 16 && AF_S.asc == 12 && AF_M.h == 19 && AF_M.asc == 15 && AF_L.h == 26 && AF_L.asc == 21);
|
|
assert(text_w(&AF_M, "0000") == text_w(&AF_M, "1111") && text_w(&AF_S, "1.25") == text_w(&AF_S, "8.75"));
|
|
assert(glyph(&AF_S, (uint8_t)ELLIPSIS) != glyph(&AF_S, '?') && glyph(&AF_M, (uint8_t)ELLIPSIS) != glyph(&AF_M, '?'));
|
|
assert(text_w(&AF_L, "abc") == text_w(&AF_L, "ABC"));
|
|
{
|
|
char b[32];
|
|
assert(!text_fit(b, sizeof b, "KICK", &AF_S, 60) && !strcmp(b, "KICK"));
|
|
assert(text_fit(b, sizeof b, "A VERY LONG PRESET NAME", &AF_S, 60) && text_w(&AF_S, b) <= 60);
|
|
assert(b[strlen(b) - 1] == ELLIPSIS && b[strlen(b) - 2] != ' ');
|
|
assert(text_fit(b, sizeof b, "WWWWWWWW", &AF_M, 1) && b[0] == ELLIPSIS && !b[1]);
|
|
}
|
|
if (argc > 1) {
|
|
FILE *f = fopen(argv[1], "wb"); assert(f);
|
|
fprintf(f, "P6\n%u %u\n255\n", (unsigned)SHEET_W, (unsigned)SHEET_H);
|
|
for (unsigned i = 0; i < SHEET_W * SHEET_H; i++) {
|
|
fputc(channel(sheet[i], 0) * 255 / 31, f);
|
|
fputc(channel(sheet[i], 1) * 255 / 63, f);
|
|
fputc(channel(sheet[i], 2) * 255 / 31, f);
|
|
}
|
|
fclose(f);
|
|
}
|
|
printf("Palettes: the family of seven, stored tokens, contrast (worst margin x%.2f), blending, ramp cache, font metrics and ellipsis passed.\n", worst);
|
|
return 0;
|
|
}
|