diff --git a/firmware/src/editor_fmini.c b/firmware/src/editor_fmini.c index 433c6d9..595a0db 100644 --- a/firmware/src/editor_fmini.c +++ b/firmware/src/editor_fmini.c @@ -15,7 +15,8 @@ * kept besides the track's values (FMini-1: the tempo, the octave, the FX pop-ups' globals), as stored: BPM (40..240), * OCT (octave + 4: 1..7), the FX page's G_RSIZE G_DRREV G_CRATE G_DRLVL + 1 (1..128), then G_RTYPE G_RDAMP G_DTIME G_DFDBK * G_ENGGO G_CDEPTH G_INFO G_MIDI + 1; 0 = the preset has none (older). rc 2: not an FMINI preset. */ -enum { ED_FMINI_GET = 82, ED_FMINI_PUT, ED_FMINI_PRESET, ED_FMINI_REC, ED_FMINI_RPUT, ED_FMINI_RESTORE, ED_FMINI_RESET }; /* 85..88: the backup, the factory reset (protocol 4) */ +enum { ED_FMINI_GET = 82, ED_FMINI_PUT, ED_FMINI_PRESET, ED_FMINI_REC, ED_FMINI_RPUT, ED_FMINI_RESTORE, ED_FMINI_RESET, /* 85..88: the backup, the factory reset (protocol 4) */ + ED_FMINI_USBDIAG }; /* 89: the USB playback's counters (1.14.3) */ enum { ED_FMINI_TRACK = 0, ED_FMINI_FACTORY = 2, ED_FMINI_USER = 3 }; @@ -108,8 +109,36 @@ static void ed_fmini_reset(const uint8_t *a, uint32_t n) ed_b(n ? a[0] : 127u); ed_b(n > 1u ? a[1] : 127u); ed_b(rc); } +/* 89 USBDIAG: -> version 1, the playback alt setting, playing (0/1), then 9 counters of 5 bytes each (7 bits, + * LSB first): SET_INTERFACE to the playback interface, EP3 interrupts, packets, frames stored, packets dropped, + * dry blocks, frames dropped (ring above its band), frames repeated (ring below it), the ring's fill (frames). + * Without FELUCCA_UAC_OUT the alt, playing and the counters are 0. */ +static void ed_fmini_usbdiag(void) +{ + uint32_t v[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0}, k, j; + uint8_t alt = 0, play = 0; +#if FELUCCA_UAC_OUT + alt = uac_out_alt; + play = pb_play; + v[0] = pb_setif; + v[1] = pb_irq; + v[2] = pb_pkts; + v[3] = pb_frames; + v[4] = pb_drops; + v[5] = pb_under; + v[6] = pb_skip; + v[7] = pb_rep; + v[8] = (uint32_t)(pb_w - pb_r); +#endif + ed_b(1u); ed_b(alt); ed_b(play); + for (k = 0; k < 9u; k++) + for (j = 0; j < 5u; j++) + ed_b(v[k] >> (7u * j)); +} + static int ed_fmini_handle(uint32_t cmd, const uint8_t *a, uint32_t n) { + if (cmd == ED_FMINI_USBDIAG) { ed_fmini_usbdiag(); return 1; } if (cmd == ED_FMINI_REC) { ed_fmini_rec_get(a, n); return 1; } if (cmd == ED_FMINI_RPUT) { ed_fmini_rec_put(a, n); return 1; } if (cmd == ED_FMINI_RESTORE) { ed_fmini_restore(a, n); return 1; } diff --git a/firmware/src/usb.c b/firmware/src/usb.c index 10caa12..3cda33b 100644 --- a/firmware/src/usb.c +++ b/firmware/src/usb.c @@ -110,6 +110,7 @@ static volatile uint8_t pb_flush; /* writer -> reader: st static uint8_t pb_pend, pb_play; /* packet waiting; the reader is playing */ static int32_t pb_last_l, pb_last_r; /* the last frame played (repeated when the host is slow) */ static uint32_t pb_pkts, pb_frames, pb_drops, pb_under, pb_skip, pb_rep; /* counters */ +static uint32_t pb_setif, pb_irq; /* SET_INTERFACE of the playback interface; EP3 interrupts */ #define PB_PRIME 128u /* frames before the first sound (~3 ms) */ #define PB_TARGET (PB_N / 2u) /* the ring's fill the reader aims at */ #define PB_BAND 128u /* one frame dropped / repeated outside TARGET +- BAND */ @@ -829,6 +830,7 @@ static void ep0_service(void) #if FELUCCA_UAC #if FELUCCA_UAC_OUT if (s[4] == UAC_AS_OUT_IF && wvalue <= 1u && usb.config) { + pb_setif++; uac_out_stream(wvalue); goto ack; } @@ -1503,8 +1505,10 @@ static void usb_poll(void) /* TIMER5 ISR, 2 kHz */ if (usb.rx_pend) /* not every poll: 3 SIE round trips each */ ep1_rx(); #if FELUCCA_UAC_OUT - if (ir & 0x08u) + if (ir & 0x08u) { + pb_irq++; pb_pend = 1; + } if (pb_pend && uac_out_alt) uac_out_rx(); #endif diff --git a/tests/editor_test.c b/tests/editor_test.c index 84ef1af..f7efbbb 100644 --- a/tests/editor_test.c +++ b/tests/editor_test.c @@ -1526,6 +1526,15 @@ static int restore_protocol(void) request(ED_FMINI_RESET, kk, 2); bad += check(" .. a slot past 199 is refused (rc 1)", host_wire[7] == 1u); } + { /* USBDIAG (89): version 1, alt, playing, then 9 counters of 5 bytes; nothing played yet, so all 0 */ + uint32_t nw = request(ED_FMINI_USBDIAG, 0, 0), k, j, zero = 1; + bad += check("USBDIAG: the reply is command 89, version 1, 3 + 45 payload bytes", + nw == 5u + 3u + 45u + 1u && host_wire[4] == ED_FMINI_USBDIAG && host_wire[5] == 1u); + for (k = 0; k < 9u; k++) + for (j = 0; j < 5u; j++) + zero &= host_wire[8u + 5u * k + j] == 0u; + bad += check(" .. the counters are 0 before any playback (alt 0, not playing)", zero && host_wire[6] == 0u && host_wire[7] == 0u); + } return bad; } diff --git a/web/EDITOR_PROTOCOL.md b/web/EDITOR_PROTOCOL.md index e981d01..d84567f 100644 --- a/web/EDITOR_PROTOCOL.md +++ b/web/EDITOR_PROTOCOL.md @@ -1043,6 +1043,7 @@ tests `tests/editor_test.c` (fmini_patches) and `web/test_editor_fmini.py` (the | 86 FMINI_RPUT (protocol 4) | slot (two 7-bit bytes), length (two 7-bit bytes), the record as nibbles | slot, rc. Written only while the device has said YES (state 2 of 87). rc: 0 written, 1 arguments, 2 not accepted on the device, 3 not a preset record, 4 the flash refused | | 87 FMINI_RESTORE (protocol 4) | op: 0 ask, 1 status, 2 end | op, rc, state. The device shows its question (OVERWRITE ALL 200 PRESETS?, NO by default: ALGORITHM to YES, SAVE accepts; a page button or SAVE on NO refuses). State: 0 idle, 1 the question is up, 2 accepted (write now), 3 refused or no answer for 60 s. Ask when the state is 1 or 2 changes nothing; end (2) returns to idle | | 88 FMINI_RESET (protocol 4) | slot (two 7-bit bytes, 0..199) | slot, rc. The slot's saved preset is forgotten: it reads its factory preset again (every slot has one), a later firmware's factory bank included. No device question (the page asks first). rc: 0 done, 1 arguments, 4 the flash refused | +| 89 USBDIAG (1.14.3) | none | version 1, the playback alt setting, playing (0/1), then 9 counters of 5 bytes each (7 bits, LSB first): SET_INTERFACE to the playback interface, EP3 interrupts, packets, frames stored, packets dropped, dry blocks, frames dropped, frames repeated, the ring's fill (frames). Zeros without FELUCCA_UAC_OUT. Read by the editor's USB button (a pop-up); it changes nothing | Targets: 0 a track's own patch (index 0..3), 2 a factory patch (index 0..199, read only; `PUT` answers rc 1; from 1.14.1 an index past 127 is two 7-bit bytes, low first: a 3-byte `GET` replies target, lo, hi, rc, then the 32 bytes), 3 a user preset's patch (slot 0..31, read only; rc 2 when the slot is empty or holds another engine; a preset stored without its own patch gives diff --git a/web/editor_fmini.html b/web/editor_fmini.html index 331a271..f1f9567 100644 --- a/web/editor_fmini.html +++ b/web/editor_fmini.html @@ -118,6 +118,7 @@ +
@@ -162,7 +163,7 @@ const TX = { noedit: "Este firmware não parece ser o FMini-1. O editor é só para o FMini-1.", oldfw: "Este FMini-1 tem um firmware antigo. Atualize pelo instalador atual e conecte de novo.", getlink: "Abrir o instalador atual", - fwnew: "Há uma versão nova do firmware do FMini-1 (v%l). Seu aparelho tem %c. Atualize pelo instalador do site.", fwold: "uma versão anterior", fwok: "Abrir o instalador", fwclose: "Fechar", + fwnew: "Há uma versão nova do firmware do FMini-1 (v%l). Seu aparelho tem %c. Atualize pelo instalador do site.", fwold: "uma versão anterior", fwok: "Abrir o instalador", fwclose: "Fechar", usbTitle: "Áudio USB de saída: contadores", usbAlt: "Interface de saída ativa (alt)", usbPlay: "Tocando agora", usbSetIf: "Vezes que o Windows selecionou a saída", usbIrq: "Interrupções do endpoint 3", usbPkts: "Pacotes recebidos", usbFrames: "Quadros guardados", usbDrops: "Pacotes descartados (fila cheia)", usbDry: "Blocos sem quadro (fila vazia)", usbSkip: "Quadros descartados (fila acima da faixa)", usbRep: "Quadros repetidos (fila abaixo da faixa)", usbFill: "Fila agora (quadros, de 0 a 512)", usbYes: "sim", usbNo: "não", noext: "Atualização disponível: instale o FMini-1 v1.6.1 ou mais novo para editar a oitava e guardar tempo, oitava e efeitos na biblioteca.", noenv: "Atualização necessária: este firmware não tem o editor de osciladores e chaves. Instale a versão mais nova pelo site para editar tudo.", nonames: "Atualização disponível: este firmware envia só os nomes dos %n primeiros presets. Instale o FMini-1 v1.7.2 ou mais novo para ver todos.", @@ -186,7 +187,7 @@ const TX = { noedit: "This firmware does not look like the FMini-1. The editor is for the FMini-1 only.", oldfw: "This FMini-1 runs an old firmware. Update it with the current installer and connect again.", getlink: "Open the current installer", - fwnew: "A new FMini-1 firmware is out (v%l). Your device has %c. Update it with the installer on the site.", fwold: "an earlier version", fwok: "Open the installer", fwclose: "Close", + fwnew: "A new FMini-1 firmware is out (v%l). Your device has %c. Update it with the installer on the site.", fwold: "an earlier version", fwok: "Open the installer", fwclose: "Close", usbTitle: "USB audio out: counters", usbAlt: "Playback interface alt setting", usbPlay: "Playing now", usbSetIf: "Times Windows selected the output", usbIrq: "Endpoint 3 interrupts", usbPkts: "Packets received", usbFrames: "Frames stored", usbDrops: "Packets dropped (ring full)", usbDry: "Blocks without a frame (ring empty)", usbSkip: "Frames dropped (fill above the band)", usbRep: "Frames repeated (fill below the band)", usbFill: "Fill now (frames, 0 to 512)", usbYes: "yes", usbNo: "no", noext: "Update available: install FMini-1 v1.6.1 or newer to edit the octave and keep tempo, octave and effects in the library.", noenv: "Update needed: this firmware has no oscillator / switch editing. Install the newest version from the site to edit everything.", nonames: "Update available: this firmware sends only the names of the first %n presets. Install FMini-1 v1.7.2 or newer to see them all.", @@ -206,7 +207,7 @@ const T = (k, o) => { let t = TX[LANG][k] || k; for (const x in o || {}) t = t.r document.documentElement.lang = LANG === "pt" ? "pt-BR" : "en"; /* ---------------------------------------------------------------- protocol --- */ -const CMD = { INFO: 1, GET: 2, SET: 3, DUMP: 4, DESC: 5, PRESET: 8, NAMES: 10, TRACK: 27, FMINI_GET: 82, FMINI_PUT: 83, FMINI_PRESET: 84, FMINI_REC: 85, FMINI_RPUT: 86, FMINI_RESTORE: 87, FMINI_RESET: 88 }; +const CMD = { INFO: 1, GET: 2, SET: 3, DUMP: 4, DESC: 5, PRESET: 8, NAMES: 10, TRACK: 27, FMINI_GET: 82, FMINI_PUT: 83, FMINI_PRESET: 84, FMINI_REC: 85, FMINI_RPUT: 86, FMINI_RESTORE: 87, FMINI_RESET: 88, USBDIAG: 89 }; const FG = { R1: 0, R2: 1, R3: 2, W1: 3, W2: 4, W3: 5, F2: 6, F3: 7, L1: 8, L2: 9, L3: 10, LN: 11, SW1: 12, SW2: 13, TUNE: 14, MMIX: 15, KBD: 16, GLID: 17, SIZE: 32 }; const FS = { O1: 1, O2: 2, O3: 4, NZ: 8, PINK: 16, MOSC: 32, MFLT: 64 }, FT = { GLIDE: 1, SQR: 2 }; /* track parameters (core.h; all but E0..E7 are fixed ids) and globals */ @@ -506,6 +507,34 @@ async function connect() { setStatus(false, T("disc")); $("connect").textContent = T("connect"); $("connect").disabled = false; } } +/* USB diagnostics (command 89, firmware 1.14.3): the playback counters in a pop-up */ +function usbDiagShow(r) { + if (!r || r.length < 3 + 45 || r[0] !== 1) { msg(T("oldfw"), true); return; } + const cnt = (k) => { let v = 0; for (let j = 4; j >= 0; j--) v = v * 128 + (r[3 + 5 * k + j] & 127); return v; }; + const names = ["usbSetIf", "usbIrq", "usbPkts", "usbFrames", "usbDrops", "usbDry", "usbSkip", "usbRep", "usbFill"]; + const box = document.createElement("div"); + box.id = "usbpop"; + box.style.cssText = "position:fixed;inset:0;background:rgba(0,0,0,.55);display:flex;align-items:center;justify-content:center;z-index:50;padding:16px"; + const card = document.createElement("div"); + card.style.cssText = "background:var(--panel,#fff);color:var(--ink,#111);border:1px solid var(--line,#999);border-radius:8px;max-width:520px;padding:20px;font:14px/1.5 system-ui,sans-serif"; + const h = document.createElement("h3"); h.textContent = T("usbTitle"); h.style.margin = "0 0 8px"; + const pre = document.createElement("pre"); pre.style.cssText = "margin:0;white-space:pre-wrap;font:13px/1.5 ui-monospace,monospace"; + const lines = [[T("usbAlt"), String(r[1])], [T("usbPlay"), r[2] ? T("usbYes") : T("usbNo")]]; + names.forEach((n, k) => lines.push([T(n), String(cnt(k))])); + pre.textContent = lines.map(([a, b]) => a + ": " + b).join("\n"); + const row = document.createElement("div"); row.style.cssText = "display:flex;justify-content:flex-end;margin-top:14px"; + const x = document.createElement("button"); x.className = "btn"; x.textContent = T("fwclose"); + x.onclick = () => box.remove(); + row.append(x); card.append(h, pre, row); box.append(card); box.onclick = (e) => { if (e.target === box) box.remove(); }; + document.body.append(box); +} +$("usbdiag").addEventListener("click", async () => { + if (!dev.open) { msg(T("none")); return; } + let r; + try { r = await req(CMD.USBDIAG, [], 1500); } catch (e) { msg(T("timeout"), true); return; } + usbDiagShow(r); +}); + /* the device runs an older firmware than this page: a pop-up with the link to the installer */ function fwCheck() { const v = S.fwver;