Files
JIANT/firmware/src/panel.c
T
Claude 65d0d64cdf COLOR: the family of seven palettes (JIANT SELVA CONTRAST BRASA ABISAL HUESO NEON)
MENU > DISPLAY > COLOR offers exactly seven, all the owner's: JIANT (unchanged, the
default) and six of its own. The ten inherited from Felucca (GREY GREEN AMBER ICE
VIOLET ROSE PAPER HI-CON NIGHT MONO) are gone.

- tools/gen_ui_palettes.py: a palette is twelve stored tokens (bg surf text theme
  accent mid dim line sel tint rec raise); JIANT's are its five colours and the
  blends it has had since 0.8.9 (bit for bit), the six new ones the owner's hex
  values at the nearest RGB565. INK is black in all. NEON's SEL a step lighter than
  set (#D43589) so black INK on it passes 4.5.
- gfx.c palette_set copies the twelve; KEY, LANE, GRID stay derived. The GREY
  (gray axis), MONO (black and white) and PAPER (light) paths are removed: ux.mono,
  ux.light, the light coverage curve, ux_gray / ux_luma, the knob table per palette.
- The thermal ramp (beings, notes, bars, card values) in every palette.
- Saved ids: UI_PAL_TAG + the place the nearest palette had up to V10.7.18, so old
  settings land on the nearest of the family (GREY MONO NIGHT -> HUESO, GREEN ->
  SELVA, AMBER ROSE -> BRASA, ICE -> ABISAL, VIOLET -> JIANT, PAPER HI-CON ->
  CONTRAST) and older firmware reads new settings as its nearest palette (NEON: a
  new id, its fallback). The record's format and version are unchanged.
- A card value too long for S (COLOR's CONTRAST) is set whole in the small face;
  COLOR's chips fit it. An arrange row of an empty section is a well (DIM on the
  section's colour could not be read).
- Tests: theme_test (the family, the stored tokens, the knobs' contrast; its probe
  glyph in the byte-packed format, which is what failed before), settings_test and
  backup_test (the migration), ui_test, ui_render (gray / neutral lints replaced by
  a contrast lint of every ink drawn), editor_test, the web mock.
- Manuals (EN, ES), README, cheat sheet text, EDITOR_PROTOCOL.

Image: 1992 B free (was 256).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KMHk6yH4XbP1xxHYKCo9Mh
2026-11-11 22:42:46 +00:00

132 lines
6.4 KiB
C

/* SPDX-License-Identifier: GPL-3.0-only
* Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments
* Portions Copyright (C) 2026 Juan Ignacio Antonucci (Juan Jiant) */
/* Physical panel: which matrix button / encoder carries which printed label.
* The matrix ids are known, the printed labels are not, so
* the mapping is a table with a best guess, overridable by HARDWARE CALIBRATION
* (hold OCT- and OCT+ while powering on): FELUCCA asks for each label in turn.
* The learned table lives in .noinit and, with FELUCCA_FLASH, in flash with
* the settings (project.c); read it back with `fm1t memr` to bake it in. */
enum { B_FX, B_SCL, B_ENV, B_LFO, B_EDIT, B_GLO, B_HOME, B_SAVE, B_ARP, B_SEQ, B_PLAY, B_REC,
B_OCTDN, B_OCTUP, NB };
enum { EN_SELECT, EN_ALGO, EN_PRESET, EN_K1, EN_K2, EN_K3, EN_K4, NE };
static const char *const B_NAME[NB] = {"FX", "SCL", "ENV", "LFO", "EDIT", "GLO", "HOME", "SAVE",
"ARP", "SEQ", "PLAY", "REC", "OCT-", "OCT+"};
static const char *const E_NAME[NE] = {"SELECT", "ALGORITHM", "PRESETS", "KNOB 1", "KNOB 2",
"KNOB 3", "KNOB 4"};
#define PANEL_MAGIC 0x50414E35u /* "PAN5": bump when PANEL_DEFAULT changes */
typedef struct {
uint32_t magic;
uint8_t btn[NB]; /* matrix button id (0..13) per label */
uint8_t enc[NE]; /* matrix encoder (0..6) per role */
int8_t dir[NE]; /* +1 / -1 so that clockwise is + */
} panel_t;
panel_t panel __attribute__((section(".noinit")));
static const panel_t PANEL_DEFAULT = {
PANEL_MAGIC,
{2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 0, 1}, /* PLAY = 12, REC = 13 (measured on hardware) */
{0, 1, 6, 2, 3, 4, 5}, /* SELECT = enc 0, ALGORITHM = enc 1, PRESETS = enc 6 (printed labels) */
{1, 1, 1, 1, 1, 1, 1},
};
static void panel_init(void) /* also after a flash load: ids are used as array indexes and shifts */
{
uint32_t i, buttons = 0, encoders = 0, ok = panel.magic == PANEL_MAGIC;
for (i = 0; ok && i < NB; i++) {
ok = panel.btn[i] < NB && !(buttons & (1u << panel.btn[i]));
if (ok) buttons |= 1u << panel.btn[i];
}
for (i = 0; ok && i < NE; i++) {
ok = panel.enc[i] < NE && !(encoders & (1u << panel.enc[i])) &&
(panel.dir[i] == 1 || panel.dir[i] == -1);
if (ok) encoders |= 1u << panel.enc[i];
}
if (!ok)
panel = PANEL_DEFAULT;
}
static uint32_t panel_btn_of(uint32_t matrix_id) /* label of a matrix button, NB if none */
{
uint32_t b;
for (b = 0; b < NB; b++)
if (panel.btn[b] == matrix_id)
return b;
return NB;
}
/* steps of a role, + = clockwise */
static uint8_t panel_moved; /* a knob turned since ui.c scr_input last looked (SCREEN OFF) */
static int32_t panel_enc(uint32_t role)
{
int32_t s = fm1_enc_take(panel.enc[role]) * panel.dir[role];
if (s)
panel_moved = 1;
return s;
}
/* Keep the retained settings layout fixed. palette: the index into UI_PALETTES (SET3 held an index
* into the 20 palettes of earlier firmware) */
#define SETTINGS_MAGIC 0x53455434u /* "SET4" */
#define SETTINGS_MAGIC_OLD 0x53455433u /* "SET3" */
struct { uint32_t magic, palette, lowcut, zoom; } settings __attribute__((section(".noinit")));
static void settings_save(void); /* project.c: flash copy (FELUCCA_FLASH) */
/* HOLD (menu): how long a button is held before its layer opens (ui_input.c). Saved in the settings record's
* retired bold field as HOLD_TAG | index; any other value there (0 or 1 from older firmware) is the default */
#define HOLD_TAG 0x484C4400u
#define HOLD_DEF 1u
static const uint16_t HOLD_MS[4] = {300, 400, 500, 600};
static uint8_t settings_hold = HOLD_DEF;
static uint32_t hold_from_stored(uint32_t v) { return (v & ~3u) == HOLD_TAG ? v & 3u : HOLD_DEF; }
static uint32_t hold_to_stored(uint32_t old, uint32_t i)
{
return i % 4u != HOLD_DEF ? HOLD_TAG | (i & 3u) : old > 1u ? 0u : old;
}
static int hold_stored_ok(uint32_t v) { return v <= 1u || (v & ~3u) == HOLD_TAG; }
/* LEDS (menu): OFF, DIM LO, DIM HI, INV. DIM HI (the default), the idle buttons and keys glow dim (~1/30) and the
* active ones are lit (#35); DIM LO the same, darker (~1/60, hal/fm1_input.h FM1_LED_DIM_LO_NS); OFF no glow,
* the active ones lit (as 1.0); INV the idle ones lit and the active ones dark, as the stock firmware (ui_input.c
* ui_leds). Saved in the settings record's retired zoom field as LEDS_TAG | mode, the modes append-only: DIM 0
* (now DIM HI) and INV 1 keep their values, OFF 2 and DIM LO 3 are new; any other value there (0 or 1 from older
* firmware) is DIM HI. LEDS_MENU: the menu's order, darkest first */
#define LEDS_TAG 0x4C454400u /* "LED" */
enum { LEDS_DIM, LEDS_INV, LEDS_OFF, LEDS_DIM_LO, LEDS_COUNT };
static const uint8_t LEDS_MENU[LEDS_COUNT] = {LEDS_OFF, LEDS_DIM_LO, LEDS_DIM, LEDS_INV};
static const char *const LEDS_NAME[LEDS_COUNT] = {"DIM HI", "INV", "OFF", "DIM LO"};
static uint8_t settings_leds = LEDS_DIM;
static uint32_t leds_from_stored(uint32_t v) { return (v & ~3u) == LEDS_TAG && (v & 3u) < LEDS_COUNT ? v & 3u : LEDS_DIM; }
static uint32_t leds_to_stored(uint32_t old, uint32_t m)
{
return m != LEDS_DIM && m < LEDS_COUNT ? LEDS_TAG | m : old > 1u ? 0u : old;
}
static int leds_stored_ok(uint32_t v) { return v <= 1u || ((v & ~3u) == LEDS_TAG && (v & 3u) < LEDS_COUNT); }
/* the menu's next / previous mode (KNOB 1 stops at the ends, OCT+ (s 0) cycles) */
static uint32_t leds_step(uint32_t m, int32_t s)
{
uint32_t i = 0;
while (i + 1u < LEDS_COUNT && LEDS_MENU[i] != m)
i++;
i = s > 0 ? (i + 1u < LEDS_COUNT ? i + 1u : i) : s < 0 ? (i ? i - 1u : 0u) : (i + 1u) % LEDS_COUNT;
return LEDS_MENU[i];
}
static void settings_init(void)
{
if (settings.magic == SETTINGS_MAGIC_OLD && settings.palette < 20u) {
settings.magic = SETTINGS_MAGIC;
settings.palette = palette_from_stored(settings.palette);
}
if (settings.magic != SETTINGS_MAGIC || settings.palette >= NPALETTES) {
settings.magic = SETTINGS_MAGIC;
settings.palette = UI_JIANT_INDEX; /* JIANT FM (the default since JIANT 0.1) */
settings.lowcut = 0;
settings.zoom = 0; /* (retired: the LEDS setting, settings_persist.c) */
}
palette_set(settings.palette);
fx_lowcut = (uint8_t)(settings.lowcut % 3u);
}