feat(useq-cv): flash scripts per board + handshake status in Outputs panel
- scripts/flash-useq-main.sh + scripts/flash-useq-expander.sh: build + flash each uSEQ board via PlatformIO (nix-shell fallback for pio; extra args pass through; BOOTSEL hint). - CV backend: green status now means a CONFIRMED handshake, not just an open port. Any valid device->host frame (the firmware streams INPUT at 20 Hz, or an identify ack) flips it ready/green; a 2.5s watchdog after open surfaces a red 'no response from module' if nothing replies. idle/grey when nothing connected. - Outputs panel CV config: explicit handshake indicator (coloured dot + label — green 'Module handshake OK' / amber waiting / red error / grey not connected). - Docs: firmware README + MAP.md note the scripts.
This commit is contained in:
parent
68f7d681fe
commit
b853113ac1
6 changed files with 198 additions and 21 deletions
1
MAP.md
1
MAP.md
|
|
@ -112,6 +112,7 @@ the "BUILD DELTAS" block at the top of `vcv/SPEC.md`). `src/MEMLNaut.cpp` (modul
|
|||
|
||||
### `scripts/` — build + verify entry points
|
||||
- `build-firmware.sh`, `flash-firmware.sh`, `build-and-flash-firmware.sh`, `firmware-common.sh` — Arduino-CLI wrapper for RP2350 target with C++20 flag.
|
||||
- `flash-useq-main.sh`, `flash-useq-expander.sh` — build + flash the uSEQ-CV firmware (`firmware/useq-celium/{main,expander}`) via PlatformIO (nix-shell fallback for `pio`).
|
||||
- `build-wasm.sh` — Emscripten compile producing `playground/public/nisps.{wasm,js}`.
|
||||
- `build-cpp-tests.sh` — CMake configure + build + ctest (Ninja).
|
||||
- `parity-check.sh` — runs native + WASM and diffs binary outputs.
|
||||
|
|
|
|||
|
|
@ -27,12 +27,22 @@ expander/ uSEQ expander: I2C slave → CV4..11 (8× PWM)
|
|||
The main board forwards CV4–CV11 to the expander over I2C (addr `0x10`, 400 kHz)
|
||||
and rescans every 2 s until the expander is found (hot-attach friendly).
|
||||
|
||||
## Build / flash (PlatformIO)
|
||||
## Build / flash
|
||||
|
||||
Convenience scripts (resolve PlatformIO via `nix-shell` if `pio` isn't on PATH;
|
||||
extra args pass through to `pio`, e.g. `--upload-port /dev/ttyACM0`):
|
||||
|
||||
```bash
|
||||
scripts/flash-useq-main.sh # build + flash the main module
|
||||
scripts/flash-useq-expander.sh # build + flash the expander
|
||||
```
|
||||
|
||||
If an upload can't auto-reset the board, hold **BOOTSEL** while plugging in USB.
|
||||
|
||||
Raw PlatformIO, equivalently:
|
||||
|
||||
```bash
|
||||
# main board
|
||||
cd firmware/useq-celium/main && pio run -e main -t upload
|
||||
# expander board
|
||||
cd firmware/useq-celium/expander && pio run -e expander -t upload
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -35,6 +35,9 @@ import {
|
|||
const SEND_INTERVAL_MS = 1000 / STREAM_HZ; // ~10 ms
|
||||
const CV_DEAD_ZONE = 8; // on the 12-bit value (~0.2%)
|
||||
const IDENTIFY_TIMEOUT_MS = 5000;
|
||||
// The firmware streams INPUT frames at 20 Hz, so a live module proves itself
|
||||
// within ~50 ms. Allow for a USB-CDC (DTR) reset on open before giving up.
|
||||
const HANDSHAKE_TIMEOUT_MS = 2500;
|
||||
|
||||
/** Resolve a channel id into a fast {kind, index} target (or null for 'none'). */
|
||||
type Target = { kind: 'cv'; idx: number } | { kind: 'gate'; idx: number } | null;
|
||||
|
|
@ -57,10 +60,14 @@ export class UseqCvBackend implements OutputBackend {
|
|||
private writer: WritableStreamDefaultWriter<Uint8Array> | null = null;
|
||||
private reader: ReadableStreamDefaultReader<Uint8Array> | null = null;
|
||||
private parser = new UseqRxParser(
|
||||
() => {},
|
||||
() => this.onDeviceFrame(), // any INPUT frame proves the module is alive
|
||||
(ok) => this.onAck(ok),
|
||||
);
|
||||
|
||||
/** True once a valid device→host frame has been received (handshake OK). */
|
||||
private handshook = false;
|
||||
private handshakeTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
private cvVals = new Uint16Array(NUM_CV); // last computed 12-bit CV per channel
|
||||
private gateBits = 0;
|
||||
private lastCv = new Int32Array(NUM_CV).fill(-1);
|
||||
|
|
@ -84,7 +91,11 @@ export class UseqCvBackend implements OutputBackend {
|
|||
return;
|
||||
}
|
||||
if (this.port) {
|
||||
this.setStatus({ state: 'ready', message: 'uSEQ connected' });
|
||||
this.setStatus(
|
||||
this.handshook
|
||||
? { state: 'ready', message: 'uSEQ handshake OK' }
|
||||
: { state: 'connecting', message: 'uSEQ port open — waiting for module…' },
|
||||
);
|
||||
return;
|
||||
}
|
||||
// Try to silently re-open a previously-granted port (no user gesture needed).
|
||||
|
|
@ -97,7 +108,7 @@ export class UseqCvBackend implements OutputBackend {
|
|||
} catch {
|
||||
/* ignore — fall through to the idle "connect" prompt */
|
||||
}
|
||||
this.setStatus({ state: 'ready', message: 'uSEQ ready — click Connect device' });
|
||||
this.setStatus({ state: 'idle', message: 'No uSEQ — click Connect device' });
|
||||
}
|
||||
|
||||
setContext(ctx: BackendContext): void {
|
||||
|
|
@ -123,7 +134,7 @@ export class UseqCvBackend implements OutputBackend {
|
|||
try {
|
||||
port = await navigator.serial.requestPort();
|
||||
} catch {
|
||||
this.setStatus({ state: 'ready', message: 'uSEQ ready — click Connect device' });
|
||||
this.setStatus({ state: 'idle', message: 'No uSEQ — click Connect device' });
|
||||
return; // user dismissed the picker
|
||||
}
|
||||
await this.open(port);
|
||||
|
|
@ -140,11 +151,43 @@ export class UseqCvBackend implements OutputBackend {
|
|||
this.writer = port.writable?.getWriter() ?? null;
|
||||
this.lastCv.fill(-1);
|
||||
this.lastGateBits = -1;
|
||||
this.handshook = false;
|
||||
if (typeof port.addEventListener === 'function') {
|
||||
port.addEventListener('disconnect', () => this.handleDisconnect());
|
||||
}
|
||||
this.startReadLoop();
|
||||
this.setStatus({ state: 'ready', message: 'uSEQ connected' });
|
||||
// Port is open, but a handshake isn't confirmed until the module talks back.
|
||||
this.setStatus({ state: 'connecting', message: 'uSEQ port open — waiting for module…' });
|
||||
this.armHandshakeWatchdog();
|
||||
}
|
||||
|
||||
/** If no device frame arrives within the timeout, surface a clear error. */
|
||||
private armHandshakeWatchdog(): void {
|
||||
this.clearHandshakeWatchdog();
|
||||
this.handshakeTimer = setTimeout(() => {
|
||||
this.handshakeTimer = null;
|
||||
if (this.port && !this.handshook) {
|
||||
this.setStatus({
|
||||
state: 'error',
|
||||
message: 'No response from module — check firmware / cable, then Identify',
|
||||
});
|
||||
}
|
||||
}, HANDSHAKE_TIMEOUT_MS);
|
||||
}
|
||||
|
||||
private clearHandshakeWatchdog(): void {
|
||||
if (this.handshakeTimer !== null) {
|
||||
clearTimeout(this.handshakeTimer);
|
||||
this.handshakeTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
/** A valid device→host frame arrived → the module is alive (handshake OK). */
|
||||
private onDeviceFrame(): void {
|
||||
this.clearHandshakeWatchdog();
|
||||
if (this.handshook) return;
|
||||
this.handshook = true;
|
||||
if (this.port) this.setStatus({ state: 'ready', message: 'uSEQ handshake OK' });
|
||||
}
|
||||
|
||||
private async startReadLoop(): Promise<void> {
|
||||
|
|
@ -175,22 +218,30 @@ export class UseqCvBackend implements OutputBackend {
|
|||
if (!w) return;
|
||||
const frame = new Uint8Array(FRAME_IDENTIFY_LEN);
|
||||
encodeIdentify(frame);
|
||||
this.setStatus({ state: 'connecting', message: 'Identify… (watch the LEDs)' });
|
||||
this.setStatus({ state: 'connecting', message: 'Identify sent — watch the LEDs…' });
|
||||
let settled = false;
|
||||
const done = (msg: string) => {
|
||||
const done = (s: BackendStatus) => {
|
||||
if (settled) return;
|
||||
settled = true;
|
||||
this.pendingIdentify = null;
|
||||
if (this.port) this.setStatus({ state: 'ready', message: msg });
|
||||
if (this.port) this.setStatus(s);
|
||||
};
|
||||
this.pendingIdentify = () => done('uSEQ connected — identify ack');
|
||||
w.write(frame).catch(() => done('uSEQ connected'));
|
||||
setTimeout(() => done('uSEQ connected'), IDENTIFY_TIMEOUT_MS);
|
||||
this.pendingIdentify = () => done({ state: 'ready', message: 'uSEQ handshake OK — LEDs flashed' });
|
||||
w.write(frame).catch(() => done({ state: 'error', message: 'Identify failed — module not responding' }));
|
||||
setTimeout(
|
||||
() =>
|
||||
done(
|
||||
this.handshook
|
||||
? { state: 'ready', message: 'uSEQ handshake OK' }
|
||||
: { state: 'error', message: 'No identify ack — check firmware / cable' },
|
||||
),
|
||||
IDENTIFY_TIMEOUT_MS,
|
||||
);
|
||||
}
|
||||
|
||||
private onAck(ok: boolean): void {
|
||||
private onAck(_ok: boolean): void {
|
||||
this.onDeviceFrame(); // an ack is also proof the module is alive
|
||||
if (this.pendingIdentify) this.pendingIdentify();
|
||||
else if (ok && this.port) this.setStatus({ state: 'ready', message: 'uSEQ connected' });
|
||||
}
|
||||
|
||||
send(routed: Float32Array): void {
|
||||
|
|
@ -245,6 +296,8 @@ export class UseqCvBackend implements OutputBackend {
|
|||
|
||||
private handleDisconnect(): void {
|
||||
if (!this.port) return;
|
||||
this.clearHandshakeWatchdog();
|
||||
this.handshook = false;
|
||||
this.port = null;
|
||||
this.writer = null;
|
||||
this.setStatus({ state: 'error', message: 'uSEQ disconnected — click Connect device' });
|
||||
|
|
@ -252,10 +305,12 @@ export class UseqCvBackend implements OutputBackend {
|
|||
|
||||
async disconnect(): Promise<void> {
|
||||
await this.closePort();
|
||||
this.setStatus({ state: 'ready', message: 'uSEQ ready — click Connect device' });
|
||||
this.setStatus({ state: 'idle', message: 'No uSEQ — click Connect device' });
|
||||
}
|
||||
|
||||
private async closePort(): Promise<void> {
|
||||
this.clearHandshakeWatchdog();
|
||||
this.handshook = false;
|
||||
try {
|
||||
this.reader?.cancel().catch(() => {});
|
||||
this.writer?.releaseLock();
|
||||
|
|
|
|||
|
|
@ -587,8 +587,22 @@ function VcvConfig({ ctx }: { ctx: ConsoleCtx }) {
|
|||
|
||||
function CvConfig({ ctx }: { ctx: ConsoleCtx }) {
|
||||
const s = ctx.backendStatus;
|
||||
const statusColor =
|
||||
s.state === 'ready' ? 'var(--good)' : s.state === 'connecting' ? 'var(--warn)' : 'var(--danger)';
|
||||
// Green ONLY when the module has actually talked back (handshake confirmed);
|
||||
// amber while waiting, red on error, grey when nothing is connected.
|
||||
const dotColor =
|
||||
s.state === 'ready'
|
||||
? 'var(--good)'
|
||||
: s.state === 'connecting'
|
||||
? 'var(--warn)'
|
||||
: s.state === 'idle'
|
||||
? 'var(--fg-mute)'
|
||||
: 'var(--danger)';
|
||||
const handshakeLabel =
|
||||
s.state === 'ready'
|
||||
? 'Module handshake OK'
|
||||
: s.state === 'idle'
|
||||
? 'Not connected'
|
||||
: s.message;
|
||||
return (
|
||||
<>
|
||||
<SectionLabel>uSEQ device (USB serial)</SectionLabel>
|
||||
|
|
@ -602,7 +616,32 @@ function CvConfig({ ctx }: { ctx: ConsoleCtx }) {
|
|||
<button type="button" style={btn('var(--danger)')} onClick={ctx.cvDisconnect}>
|
||||
Disconnect
|
||||
</button>
|
||||
<span style={{ fontSize: 9, color: statusColor }}>{s.message}</span>
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
gap: 7,
|
||||
padding: '4px 8px',
|
||||
background: 'var(--bg-2)',
|
||||
border: '1px solid var(--line)',
|
||||
borderRadius: 'var(--r-1)',
|
||||
}}
|
||||
title={s.message}
|
||||
>
|
||||
<span
|
||||
style={{
|
||||
width: 10,
|
||||
height: 10,
|
||||
borderRadius: '50%',
|
||||
flex: '0 0 auto',
|
||||
background: dotColor,
|
||||
boxShadow: s.state === 'ready' ? `0 0 6px ${dotColor}` : 'none',
|
||||
}}
|
||||
/>
|
||||
<span style={{ fontSize: 'var(--fs-xs)', fontFamily: 'var(--font-mono)', color: dotColor }}>
|
||||
{handshakeLabel}
|
||||
</span>
|
||||
</div>
|
||||
<p style={{ fontSize: 9, color: 'var(--fg-dim)', margin: 0, lineHeight: 1.6 }}>
|
||||
Flash the uSEQ main + expander with <code>firmware/useq-celium</code>, connect over USB, then assign each
|
||||
|
|
|
|||
36
scripts/flash-useq-expander.sh
Executable file
36
scripts/flash-useq-expander.sh
Executable file
|
|
@ -0,0 +1,36 @@
|
|||
#!/usr/bin/env bash
|
||||
# Build + flash the uSEQ-CV **expander** firmware (firmware/useq-celium/expander).
|
||||
# Target: uSEQ USEQHARDWARE_EXPANDER_OUT_0_1 (RP2040). Any extra args are passed
|
||||
# to pio (e.g. --upload-port /dev/ttyACM1).
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
BOARD_DIR="$SCRIPT_DIR/../firmware/useq-celium/expander"
|
||||
ENV="expander"
|
||||
|
||||
if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
|
||||
echo "Usage: scripts/flash-useq-expander.sh [extra pio args]"
|
||||
echo " Builds firmware/useq-celium/expander and uploads it to the uSEQ EXPANDER board."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Resolve PlatformIO (nix-friendly: fall back to an ephemeral nix-shell).
|
||||
run_pio() {
|
||||
if command -v pio >/dev/null 2>&1; then
|
||||
pio "$@"
|
||||
elif command -v platformio >/dev/null 2>&1; then
|
||||
platformio "$@"
|
||||
elif command -v nix-shell >/dev/null 2>&1; then
|
||||
nix-shell -p platformio --run "pio $*"
|
||||
else
|
||||
echo "error: PlatformIO not found. Install it, e.g.:" >&2
|
||||
echo " nix-shell -p platformio # or: pipx install platformio" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
echo "==> Build + flash uSEQ EXPANDER (env: $ENV)"
|
||||
echo " If the upload can't auto-reset the board, hold BOOTSEL while plugging in USB."
|
||||
cd "$BOARD_DIR"
|
||||
run_pio run -e "$ENV" -t upload "$@"
|
||||
echo "==> Done. The expander LEDs sweep when the main board forwards an Identify."
|
||||
36
scripts/flash-useq-main.sh
Executable file
36
scripts/flash-useq-main.sh
Executable file
|
|
@ -0,0 +1,36 @@
|
|||
#!/usr/bin/env bash
|
||||
# Build + flash the uSEQ-CV **main** module firmware (firmware/useq-celium/main).
|
||||
# Target: uSEQ USEQHARDWARE_1_0 (RP2040). Any extra args are passed to pio
|
||||
# (e.g. --upload-port /dev/ttyACM0).
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
BOARD_DIR="$SCRIPT_DIR/../firmware/useq-celium/main"
|
||||
ENV="main"
|
||||
|
||||
if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
|
||||
echo "Usage: scripts/flash-useq-main.sh [extra pio args]"
|
||||
echo " Builds firmware/useq-celium/main and uploads it to the uSEQ MAIN board."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Resolve PlatformIO (nix-friendly: fall back to an ephemeral nix-shell).
|
||||
run_pio() {
|
||||
if command -v pio >/dev/null 2>&1; then
|
||||
pio "$@"
|
||||
elif command -v platformio >/dev/null 2>&1; then
|
||||
platformio "$@"
|
||||
elif command -v nix-shell >/dev/null 2>&1; then
|
||||
nix-shell -p platformio --run "pio $*"
|
||||
else
|
||||
echo "error: PlatformIO not found. Install it, e.g.:" >&2
|
||||
echo " nix-shell -p platformio # or: pipx install platformio" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
echo "==> Build + flash uSEQ MAIN module (env: $ENV)"
|
||||
echo " If the upload can't auto-reset the board, hold BOOTSEL while plugging in USB."
|
||||
cd "$BOARD_DIR"
|
||||
run_pio run -e "$ENV" -t upload "$@"
|
||||
echo "==> Done. The main board's LEDs sweep on Identify from the Manifold CV panel."
|
||||
Loading…
Reference in a new issue