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 @@ +