From 61287e5b8e6fc35c39dcf673460822c69e03d867 Mon Sep 17 00:00:00 2001 From: pszsh Date: Mon, 9 Mar 2026 09:58:56 -0700 Subject: [PATCH] partial work --- cue/Cargo.lock | 378 ++++++++++---------------------------------- cue/Cargo.toml | 3 +- cue/src/app.rs | 2 +- cue/src/ble.rs | 105 ++++++------ cue/src/protocol.rs | 14 -- main/eis.c | 17 +- main/eis4.c | 6 +- 7 files changed, 148 insertions(+), 377 deletions(-) diff --git a/cue/Cargo.lock b/cue/Cargo.lock index 3c7cfb7..0afd6a4 100644 --- a/cue/Cargo.lock +++ b/cue/Cargo.lock @@ -54,6 +54,28 @@ version = "0.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" +[[package]] +name = "alsa" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed7572b7ba83a31e20d1b48970ee402d2e3e0537dcfe0a3ff4d6eb7508617d43" +dependencies = [ + "alsa-sys", + "bitflags 2.11.0", + "cfg-if", + "libc", +] + +[[package]] +name = "alsa-sys" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db8fee663d06c4e303404ef5f40488a53e062f89ba8bfed81f42325aafad1527" +dependencies = [ + "libc", + "pkg-config", +] + [[package]] name = "android-activity" version = "0.6.0" @@ -64,7 +86,7 @@ dependencies = [ "bitflags 2.11.0", "cc", "cesu8", - "jni 0.21.1", + "jni", "jni-sys", "libc", "log", @@ -350,63 +372,6 @@ dependencies = [ "piper", ] -[[package]] -name = "bluez-async" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84ae4213cc2a8dc663acecac67bbdad05142be4d8ef372b6903abf878b0c690a" -dependencies = [ - "bitflags 2.11.0", - "bluez-generated", - "dbus", - "dbus-tokio", - "futures", - "itertools", - "log", - "serde", - "serde-xml-rs", - "thiserror 2.0.18", - "tokio", - "uuid", -] - -[[package]] -name = "bluez-generated" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9676783265eadd6f11829982792c6f303f3854d014edfba384685dcf237dd062" -dependencies = [ - "dbus", -] - -[[package]] -name = "btleplug" -version = "0.11.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9a11621cb2c8c024e444734292482b1ad86fb50ded066cf46252e46643c8748" -dependencies = [ - "async-trait", - "bitflags 2.11.0", - "bluez-async", - "dashmap 6.1.0", - "dbus", - "futures", - "jni 0.19.0", - "jni-utils", - "log", - "objc2 0.5.2", - "objc2-core-bluetooth", - "objc2-foundation 0.2.2", - "once_cell", - "static_assertions", - "thiserror 2.0.18", - "tokio", - "tokio-stream", - "uuid", - "windows 0.61.3", - "windows-future", -] - [[package]] name = "bumpalo" version = "3.20.2" @@ -671,6 +636,27 @@ dependencies = [ "libc", ] +[[package]] +name = "coremidi" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "964eb3e10ea8b0d29c797086aab3ca730f75e06dced0cb980642fd274a5cca30" +dependencies = [ + "block", + "core-foundation", + "core-foundation-sys", + "coremidi-sys", +] + +[[package]] +name = "coremidi-sys" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc9504310988d938e49fff1b5f1e56e3dafe39bb1bae580c19660b58b83a191e" +dependencies = [ + "core-foundation-sys", +] + [[package]] name = "cosmic-text" version = "0.12.1" @@ -763,11 +749,10 @@ checksum = "e162d0c2e2068eb736b71e5597eff0b9944e6b973cd9f37b6a288ab9bf20e300" name = "cue" version = "0.1.0" dependencies = [ - "btleplug", "futures", "iced", + "midir", "tokio", - "uuid", ] [[package]] @@ -803,57 +788,6 @@ dependencies = [ "zbus", ] -[[package]] -name = "dashmap" -version = "5.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" -dependencies = [ - "cfg-if", - "hashbrown 0.14.5", - "lock_api", - "once_cell", - "parking_lot_core 0.9.12", -] - -[[package]] -name = "dashmap" -version = "6.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5041cc499144891f3790297212f32a74fb938e5136a14943f338ef9e0ae276cf" -dependencies = [ - "cfg-if", - "crossbeam-utils", - "hashbrown 0.14.5", - "lock_api", - "once_cell", - "parking_lot_core 0.9.12", -] - -[[package]] -name = "dbus" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21b3aa68d7e7abee336255bd7248ea965cc393f3e70411135a6f6a4b651345d4" -dependencies = [ - "futures-channel", - "futures-util", - "libc", - "libdbus-sys", - "windows-sys 0.59.0", -] - -[[package]] -name = "dbus-tokio" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "007688d459bc677131c063a3a77fb899526e17b7980f390b69644bdbc41fad13" -dependencies = [ - "dbus", - "libc", - "tokio", -] - [[package]] name = "dconf_rs" version = "0.3.0" @@ -1301,7 +1235,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1bd49230192a3797a9a4d6abe9b3eed6f7fa4c8a8a4947977c6f80025f92cbd8" dependencies = [ "rustix 1.1.4", - "windows-link 0.2.1", + "windows-link", ] [[package]] @@ -1732,35 +1666,12 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "itertools" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" -dependencies = [ - "either", -] - [[package]] name = "itoa" version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" -[[package]] -name = "jni" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6df18c2e3db7e453d3c6ac5b3e9d5182664d28788126d39b91f2d1e22b017ec" -dependencies = [ - "cesu8", - "combine", - "jni-sys", - "log", - "thiserror 1.0.69", - "walkdir", -] - [[package]] name = "jni" version = "0.21.1" @@ -1783,21 +1694,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" -[[package]] -name = "jni-utils" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "259e9f2c3ead61de911f147000660511f07ab00adeed1d84f5ac4d0386e7a6c4" -dependencies = [ - "dashmap 5.5.3", - "futures", - "jni 0.19.0", - "log", - "once_cell", - "static_assertions", - "uuid", -] - [[package]] name = "jobserver" version = "0.1.34" @@ -1857,15 +1753,6 @@ version = "0.2.183" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d" -[[package]] -name = "libdbus-sys" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "328c4789d42200f1eeec05bd86c9c13c7f091d2ba9a6ea35acdf51f31bc0f043" -dependencies = [ - "pkg-config", -] - [[package]] name = "libloading" version = "0.7.4" @@ -1883,7 +1770,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55" dependencies = [ "cfg-if", - "windows-link 0.2.1", + "windows-link", ] [[package]] @@ -2043,6 +1930,23 @@ dependencies = [ "paste", ] +[[package]] +name = "midir" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b73f8737248ad37b88291a2108d9df5f991dc8555103597d586b5a29d4d703c0" +dependencies = [ + "alsa", + "bitflags 1.3.2", + "coremidi", + "js-sys", + "libc", + "parking_lot 0.12.5", + "wasm-bindgen", + "web-sys", + "windows 0.56.0", +] + [[package]] name = "miniz_oxide" version = "0.8.9" @@ -2243,17 +2147,6 @@ dependencies = [ "objc2-foundation 0.2.2", ] -[[package]] -name = "objc2-core-bluetooth" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a644b62ffb826a5277f536cf0f701493de420b13d40e700c452c36567771111" -dependencies = [ - "bitflags 2.11.0", - "objc2 0.5.2", - "objc2-foundation 0.2.2", -] - [[package]] name = "objc2-core-data" version = "0.2.2" @@ -2588,7 +2481,7 @@ dependencies = [ "libc", "redox_syscall 0.5.18", "smallvec", - "windows-link 0.2.1", + "windows-link", ] [[package]] @@ -3070,18 +2963,6 @@ dependencies = [ "serde_derive", ] -[[package]] -name = "serde-xml-rs" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc2215ce3e6a77550b80a1c37251b7d294febaf42e36e21b7b411e0bf54d540d" -dependencies = [ - "log", - "serde", - "thiserror 2.0.18", - "xml", -] - [[package]] name = "serde_core" version = "1.0.228" @@ -3523,31 +3404,6 @@ dependencies = [ "syn 2.0.117", ] -[[package]] -name = "tokio-stream" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32da49809aab5c3bc678af03902d4ccddea2a87d028d86392a4b1560c6906c70" -dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", - "tokio-util", -] - -[[package]] -name = "tokio-util" -version = "0.7.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ae9cec805b01e8fc3fd2fe289f89149a9b66dd16786abd8b19cfa7b48cb0098" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "toml_datetime" version = "1.0.0+spec-1.1.0" @@ -3705,16 +3561,6 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" -[[package]] -name = "uuid" -version = "1.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a68d3c8f01c0cfa54a75291d83601161799e4a89a39e0929f4b0354d88757a37" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - [[package]] name = "version_check" version = "0.9.5" @@ -4188,24 +4034,12 @@ dependencies = [ [[package]] name = "windows" -version = "0.61.3" +version = "0.56.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9babd3a767a4c1aef6900409f85f5d53ce2544ccdfaa86dad48c91782c6d6893" +checksum = "1de69df01bdf1ead2f4ac895dc77c9351aefff65b2f3db429a343f9cbf05e132" dependencies = [ - "windows-collections", - "windows-core 0.61.2", - "windows-future", - "windows-link 0.1.3", - "windows-numerics", -] - -[[package]] -name = "windows-collections" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3beeceb5e5cfd9eb1d76b381630e82c4241ccd0d27f1a39ed41b2760b255c5e8" -dependencies = [ - "windows-core 0.61.2", + "windows-core 0.56.0", + "windows-targets 0.52.6", ] [[package]] @@ -4219,33 +4053,21 @@ dependencies = [ [[package]] name = "windows-core" -version = "0.61.2" +version = "0.56.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3" +checksum = "4698e52ed2d08f8658ab0c39512a7c00ee5fe2688c65f8c0a4f06750d729f2a6" dependencies = [ "windows-implement", "windows-interface", - "windows-link 0.1.3", "windows-result", - "windows-strings", -] - -[[package]] -name = "windows-future" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc6a41e98427b19fe4b73c550f060b59fa592d7d686537eebf9385621bfbad8e" -dependencies = [ - "windows-core 0.61.2", - "windows-link 0.1.3", - "windows-threading", + "windows-targets 0.52.6", ] [[package]] name = "windows-implement" -version = "0.60.2" +version = "0.56.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" +checksum = "f6fc35f58ecd95a9b71c4f2329b911016e6bec66b3f2e6a4aad86bd2e99e2f9b" dependencies = [ "proc-macro2", "quote", @@ -4254,53 +4076,28 @@ dependencies = [ [[package]] name = "windows-interface" -version = "0.59.3" +version = "0.56.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" +checksum = "08990546bf4edef8f431fa6326e032865f27138718c587dc21bc0265bbcb57cc" dependencies = [ "proc-macro2", "quote", "syn 2.0.117", ] -[[package]] -name = "windows-link" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" - [[package]] name = "windows-link" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" -[[package]] -name = "windows-numerics" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9150af68066c4c5c07ddc0ce30421554771e528bde427614c61038bc2c92c2b1" -dependencies = [ - "windows-core 0.61.2", - "windows-link 0.1.3", -] - [[package]] name = "windows-result" -version = "0.3.4" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6" +checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8" dependencies = [ - "windows-link 0.1.3", -] - -[[package]] -name = "windows-strings" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57" -dependencies = [ - "windows-link 0.1.3", + "windows-targets 0.52.6", ] [[package]] @@ -4336,7 +4133,7 @@ version = "0.61.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" dependencies = [ - "windows-link 0.2.1", + "windows-link", ] [[package]] @@ -4370,15 +4167,6 @@ dependencies = [ "windows_x86_64_msvc 0.52.6", ] -[[package]] -name = "windows-threading" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b66463ad2e0ea3bbf808b7f1d371311c80e115c0b71d60efc142cafbcfb057a6" -dependencies = [ - "windows-link 0.1.3", -] - [[package]] name = "windows_aarch64_gnullvm" version = "0.42.2" @@ -4694,12 +4482,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9cc00251562a284751c9973bace760d86c0276c471b4be569fe6b068ee97a56" -[[package]] -name = "xml" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8aa498d22c9bbaf482329839bc5620c46be275a19a812e9a22a2b07529a642a" - [[package]] name = "xml-rs" version = "0.8.28" diff --git a/cue/Cargo.toml b/cue/Cargo.toml index 867485c..bdef516 100644 --- a/cue/Cargo.toml +++ b/cue/Cargo.toml @@ -5,7 +5,6 @@ edition = "2024" [dependencies] iced = { version = "0.13", features = ["canvas", "tokio"] } -btleplug = "0.11" +midir = "0.10" tokio = { version = "1", features = ["full"] } futures = "0.3" -uuid = "1" diff --git a/cue/src/app.rs b/cue/src/app.rs index 29c59f7..d81e7ee 100644 --- a/cue/src/app.rs +++ b/cue/src/app.rs @@ -60,7 +60,7 @@ impl App { fn send_cmd(&self, sysex: &[u8]) { if let Some(tx) = &self.cmd_tx { - let _ = tx.send(protocol::wrap_ble_midi(sysex)); + let _ = tx.send(sysex.to_vec()); } } diff --git a/cue/src/ble.rs b/cue/src/ble.rs index 26188ef..f7fb7db 100644 --- a/cue/src/ble.rs +++ b/cue/src/ble.rs @@ -1,13 +1,9 @@ -use btleplug::api::{Central, Manager as _, Peripheral as _, ScanFilter, WriteType}; -use btleplug::platform::{Adapter, Manager, Peripheral}; -use futures::StreamExt; -use std::time::Duration; +use midir::{MidiInput, MidiOutput, MidiInputConnection, MidiOutputConnection}; +use std::sync::mpsc as std_mpsc; use tokio::sync::mpsc; -use uuid::Uuid; use crate::protocol::{self, EisMessage}; -const MIDI_CHR_UUID: Uuid = Uuid::from_u128(0x7772E5DB_3868_4112_A1A9_F2669D106BF3); const DEVICE_NAME: &str = "EIS4"; #[derive(Debug, Clone)] @@ -20,62 +16,77 @@ pub async fn connect_and_run( tx: mpsc::UnboundedSender, mut cmd_rx: mpsc::UnboundedReceiver>, ) -> Result<(), Box> { - let _ = tx.send(BleEvent::Status("Scanning...".into())); + let _ = tx.send(BleEvent::Status("Looking for MIDI device...".into())); - let manager = Manager::new().await?; - let adapter = manager.adapters().await?.into_iter().next() - .ok_or("no BLE adapter")?; + let (midi_in, in_port, midi_out, out_port) = loop { + if let Some(found) = find_midi_ports() { + break found; + } + tokio::time::sleep(std::time::Duration::from_secs(2)).await; + }; - adapter.start_scan(ScanFilter::default()).await?; - tokio::time::sleep(Duration::from_secs(3)).await; + let _ = tx.send(BleEvent::Status("Connecting MIDI...".into())); - let device = find_device(&adapter).await?; - let _ = tx.send(BleEvent::Status("Connecting...".into())); + let (sysex_tx, sysex_rx) = std_mpsc::channel::>(); - device.connect().await?; - device.discover_services().await?; + let _in_conn: MidiInputConnection<()> = midi_in.connect( + &in_port, "cue-in", + move |_ts, data, _| { + if let Some(sysex) = extract_sysex(data) { + let _ = sysex_tx.send(sysex); + } + }, + (), + ).map_err(|e| format!("MIDI input connect: {e}"))?; - let chars = device.characteristics(); - let midi_chr = chars.iter() - .find(|c| c.uuid == MIDI_CHR_UUID) - .ok_or("MIDI characteristic not found")? - .clone(); + let mut out_conn: MidiOutputConnection = midi_out.connect( + &out_port, "cue-out", + ).map_err(|e| format!("MIDI output connect: {e}"))?; - device.subscribe(&midi_chr).await?; let _ = tx.send(BleEvent::Status("Connected".into())); - let mut notifs = device.notifications().await?; - loop { - tokio::select! { - Some(notif) = notifs.next() => { - if notif.uuid == MIDI_CHR_UUID { - if let Some(sysex) = protocol::extract_sysex_from_ble_midi(¬if.value) { - if let Some(msg) = protocol::parse_sysex(&sysex) { - let _ = tx.send(BleEvent::Data(msg)); - } - } - } + while let Ok(sysex) = sysex_rx.try_recv() { + if let Some(msg) = protocol::parse_sysex(&sysex) { + let _ = tx.send(BleEvent::Data(msg)); } - Some(pkt) = cmd_rx.recv() => { - device.write(&midi_chr, &pkt, WriteType::WithoutResponse).await.ok(); - } - else => break, } + + match cmd_rx.try_recv() { + Ok(pkt) => { + out_conn.send(&pkt).ok(); + } + Err(mpsc::error::TryRecvError::Disconnected) => break, + Err(mpsc::error::TryRecvError::Empty) => {} + } + + tokio::time::sleep(std::time::Duration::from_millis(5)).await; } let _ = tx.send(BleEvent::Status("Disconnected".into())); Ok(()) } -async fn find_device(adapter: &Adapter) -> Result> { - let peripherals = adapter.peripherals().await?; - for p in peripherals { - if let Some(props) = p.properties().await? { - if props.local_name.as_deref() == Some(DEVICE_NAME) { - return Ok(p); - } - } - } - Err(format!("{} not found", DEVICE_NAME).into()) +fn find_midi_ports() -> Option<( + MidiInput, midir::MidiInputPort, + MidiOutput, midir::MidiOutputPort, +)> { + let midi_in = MidiInput::new("cue-in").ok()?; + let midi_out = MidiOutput::new("cue-out").ok()?; + + let in_port = midi_in.ports().into_iter().find(|p| { + midi_in.port_name(p).map_or(false, |n| n.contains(DEVICE_NAME)) + })?; + + let out_port = midi_out.ports().into_iter().find(|p| { + midi_out.port_name(p).map_or(false, |n| n.contains(DEVICE_NAME)) + })?; + + Some((midi_in, in_port, midi_out, out_port)) +} + +fn extract_sysex(data: &[u8]) -> Option> { + if data.first() != Some(&0xF0) { return None; } + let end = data.iter().position(|&b| b == 0xF7)?; + Some(data[1..end].to_vec()) } diff --git a/cue/src/protocol.rs b/cue/src/protocol.rs index 96a46e6..64c1c22 100644 --- a/cue/src/protocol.rs +++ b/cue/src/protocol.rs @@ -188,17 +188,3 @@ pub fn build_sysex_start_sweep() -> Vec { pub fn build_sysex_get_config() -> Vec { vec![0xF0, SYSEX_MFR, CMD_GET_CONFIG, 0xF7] } - -pub fn wrap_ble_midi(sysex: &[u8]) -> Vec { - let mut pkt = vec![0x80, 0x80]; - pkt.extend_from_slice(sysex); - pkt -} - -pub fn extract_sysex_from_ble_midi(packet: &[u8]) -> Option> { - if packet.len() < 4 { return None; } - let midi = &packet[2..]; - if midi.first() != Some(&0xF0) { return None; } - let end = midi.iter().position(|&b| b == 0xF7)?; - Some(midi[1..end].to_vec()) -} diff --git a/main/eis.c b/main/eis.c index ddbfe19..a9adc61 100644 --- a/main/eis.c +++ b/main/eis.c @@ -151,14 +151,7 @@ void eis_init(const EISConfig *cfg) gpio.OutputEnSet = AGPIO_Pin0; AD5940_AGPIOCfg(&gpio); - FIFOCfg_Type fifo; - AD5940_StructInit(&fifo, sizeof(fifo)); - fifo.FIFOEn = bFALSE; - fifo.FIFOMode = FIFOMODE_FIFO; - fifo.FIFOSize = FIFOSIZE_2KB; - fifo.FIFOSrc = FIFOSRC_DFT; - fifo.FIFOThresh = 4; - AD5940_FIFOCfg(&fifo); + AD5940_WriteReg(REG_AFE_FIFOCON, 0); SEQCfg_Type seq; seq.SeqMemSize = SEQMEMSIZE_4KB; @@ -184,7 +177,6 @@ void eis_reconfigure(const EISConfig *cfg) { memcpy(&ctx.cfg, cfg, sizeof(EISConfig)); resolve_config(); - apply_hsloop(); } /* ---------- internal helpers ---------- */ @@ -232,12 +224,17 @@ static int32_t sign_extend_18(uint32_t v) static void dft_measure(uint32_t mux_p, uint32_t mux_n, iImpCar_Type *out) { + AD5940_AFECtrlS(AFECTRL_ADCCNV | AFECTRL_DFT, bFALSE); + AD5940_WriteReg(REG_AFE_FIFOCON, 0); + AD5940_ReadAfeResult(AFERESULT_DFTREAL); + AD5940_ReadAfeResult(AFERESULT_DFTIMAGE); + AD5940_INTCClrFlag(AFEINTSRC_DFTRDY); + AD5940_ADCMuxCfgS(mux_p, mux_n); AD5940_AFECtrlS(AFECTRL_WG | AFECTRL_ADCPWR, bTRUE); AD5940_Delay10us(25); - AD5940_INTCClrFlag(AFEINTSRC_DFTRDY); AD5940_AFECtrlS(AFECTRL_ADCCNV | AFECTRL_DFT, bTRUE); uint32_t timeout = 10000000; diff --git a/main/eis4.c b/main/eis4.c index d302bf4..37f2c1e 100644 --- a/main/eis4.c +++ b/main/eis4.c @@ -11,14 +11,10 @@ static EISConfig cfg; static EISPoint results[EIS_MAX_POINTS]; -static bool afe_inited; static void do_sweep(void) { - if (!afe_inited) { - eis_init(&cfg); - afe_inited = true; - } + eis_init(&cfg); uint32_t n = eis_calc_num_points(&cfg); int got = eis_sweep(results, n);