diff --git a/deps/eurorack-pmod b/deps/eurorack-pmod index 80edda2..2190a91 160000 --- a/deps/eurorack-pmod +++ b/deps/eurorack-pmod @@ -1 +1 @@ -Subproject commit 80edda24c61a1f351a72f374ad69f095b559d845 +Subproject commit 2190a91cb2c8d9ab66f3c7d9561e29c24dc990d0 diff --git a/firmware/litex-fw/Cargo.lock b/firmware/litex-fw/Cargo.lock index 145cb76..ac42dc3 100644 --- a/firmware/litex-fw/Cargo.lock +++ b/firmware/litex-fw/Cargo.lock @@ -47,29 +47,6 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b7e4c2464d97fe331d41de9d5db0def0a96f4d823b8b32a2efd503578988973" -[[package]] -name = "bindgen" -version = "0.68.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "726e4313eb6ec35d2730258ad4e15b547ee75d6afaa1361a922e78e59b7d8078" -dependencies = [ - "bitflags 2.4.1", - "cexpr", - "clang-sys", - "lazy_static", - "lazycell", - "log", - "peeking_take_while", - "prettyplease", - "proc-macro2", - "quote", - "regex", - "rustc-hash", - "shlex", - "syn 2.0.39", - "which", -] - [[package]] name = "bit_field" version = "0.10.2" @@ -82,12 +59,6 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" -[[package]] -name = "bitflags" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" - [[package]] name = "bytemuck" version = "1.14.0" @@ -100,41 +71,12 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" -[[package]] -name = "cc" -version = "1.0.83" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" -dependencies = [ - "libc", -] - -[[package]] -name = "cexpr" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" -dependencies = [ - "nom", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "clang-sys" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c688fc74432808e3eb684cae8830a86be1d66a2bd58e1f248ed0960a590baf6f" -dependencies = [ - "glob", - "libc", - "libloading", -] - [[package]] name = "color_quant" version = "1.1.0" @@ -195,19 +137,13 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" -[[package]] -name = "cty" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" - [[package]] name = "defmt" version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8a2d011b2fee29fb7d659b83c43fce9a2cb4df453e16d441a51448e448f3f98" dependencies = [ - "bitflags 1.3.2", + "bitflags", "defmt-macros", ] @@ -282,16 +218,6 @@ dependencies = [ "nb 1.1.0", ] -[[package]] -name = "errno" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f258a7194e7f7c2a7837a8913aeab7fd8c383457034fa20ce4dd3dcb813e8eb8" -dependencies = [ - "libc", - "windows-sys", -] - [[package]] name = "exr" version = "1.71.0" @@ -365,12 +291,6 @@ dependencies = [ "weezl", ] -[[package]] -name = "glob" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" - [[package]] name = "half" version = "2.2.1" @@ -409,15 +329,6 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -[[package]] -name = "home" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb" -dependencies = [ - "windows-sys", -] - [[package]] name = "image" version = "0.24.7" @@ -470,40 +381,12 @@ dependencies = [ "spin 0.5.2", ] -[[package]] -name = "lazycell" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" - [[package]] name = "lebe" version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8" -[[package]] -name = "libc" -version = "0.2.150" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" - -[[package]] -name = "libloading" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" -dependencies = [ - "cfg-if", - "winapi", -] - -[[package]] -name = "linux-raw-sys" -version = "0.4.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829" - [[package]] name = "litex-fw" version = "0.1.0" @@ -527,7 +410,6 @@ dependencies = [ "ssd1322", "strum", "strum_macros", - "tinyusb-sys", "ufmt", "vexriscv", ] @@ -564,12 +446,6 @@ dependencies = [ "scopeguard", ] -[[package]] -name = "log" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" - [[package]] name = "memchr" version = "2.6.4" @@ -606,12 +482,6 @@ version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef0bbe5256e5c434947d790788426bb65773502784aed7b23408f7e7fb4d8eb5" -[[package]] -name = "minimal-lexical" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" - [[package]] name = "miniz_oxide" version = "0.7.1" @@ -637,16 +507,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d5439c4ad607c3c23abf66de8c8bf57ba8adcd1f129e699851a6e43935d339d" -[[package]] -name = "nom" -version = "7.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" -dependencies = [ - "memchr", - "minimal-lexical", -] - [[package]] name = "num-integer" version = "0.1.45" @@ -677,47 +537,25 @@ dependencies = [ "autocfg", ] -[[package]] -name = "once_cell" -version = "1.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" - [[package]] name = "paste" version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" -[[package]] -name = "peeking_take_while" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" - [[package]] name = "png" version = "0.17.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd75bf2d8dd3702b9707cdbc56a5b9ef42cec752eb8b3bafc01234558442aa64" dependencies = [ - "bitflags 1.3.2", + "bitflags", "crc32fast", "fdeflate", "flate2", "miniz_oxide", ] -[[package]] -name = "prettyplease" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae005bd773ab59b4725093fd7df83fd7892f7d8eafb48dbd7de6e024e4215f9d" -dependencies = [ - "proc-macro2", - "syn 2.0.39", -] - [[package]] name = "proc-macro-error" version = "1.0.4" @@ -886,12 +724,6 @@ dependencies = [ "regex", ] -[[package]] -name = "rustc-hash" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" - [[package]] name = "rustc_version" version = "0.4.0" @@ -901,19 +733,6 @@ dependencies = [ "semver", ] -[[package]] -name = "rustix" -version = "0.38.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc99bc2d4f1fed22595588a013687477aedf3cdcfb26558c559edb67b4d9b22e" -dependencies = [ - "bitflags 2.4.1", - "errno", - "libc", - "linux-raw-sys", - "windows-sys", -] - [[package]] name = "rustversion" version = "1.0.14" @@ -932,12 +751,6 @@ version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" -[[package]] -name = "shlex" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7cee0529a6d40f580e7a5e6c495c8fbfe21b7b52795ed4bb5e62cdf92bc6380" - [[package]] name = "simd-adler32" version = "0.3.7" @@ -1056,16 +869,6 @@ dependencies = [ "weezl", ] -[[package]] -name = "tinyusb-sys" -version = "0.1.1" -dependencies = [ - "bindgen", - "cc", - "cty", - "glob", -] - [[package]] name = "typenum" version = "1.17.0" @@ -1135,106 +938,6 @@ version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb" -[[package]] -name = "which" -version = "4.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" -dependencies = [ - "either", - "home", - "once_cell", - "rustix", -] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - [[package]] name = "zune-inflate" version = "0.2.54" diff --git a/firmware/litex-fw/Cargo.toml b/firmware/litex-fw/Cargo.toml index 6987289..02d0590 100644 --- a/firmware/litex-fw/Cargo.toml +++ b/firmware/litex-fw/Cargo.toml @@ -34,7 +34,6 @@ litex-interrupt = { path = "../deps/litex-interrupt" } critical-section = "1.1.2" strum_macros = "0.25.3" strum = {version = "0.25.0", features = ["derive"], default-features=false} -tinyusb-sys = { path = "../deps/tinyusb-sys-rs"} [dev-dependencies] critical-section = { version = "1.1.2", features = ["std"] } diff --git a/firmware/litex-fw/src/draw.rs b/firmware/litex-fw/src/draw.rs index 112fd3b..ff8a048 100644 --- a/firmware/litex-fw/src/draw.rs +++ b/firmware/litex-fw/src/draw.rs @@ -56,7 +56,7 @@ where // Channel title let mut s: String<16> = String::new(); ufmt::uwrite!(&mut s, "CH {}", ix).ok(); - draw_title_box(d, &s, Point::new(sx, sy as i32), Size::new(30, 30))?; + draw_title_box(d, &s, Point::new(sx, sy as i32), Size::new(31, 32))?; let mut stroke_gain = PrimitiveStyleBuilder::new() .stroke_color(Gray4::new(0x1)) @@ -123,15 +123,15 @@ where let opts_view = opts.view().options(); - let vx: i32 = 129; - let vy: usize = 18; + let vx: i32 = 128+64; + let vy: usize = 17; let screen_hl = match (opts.view().selected(), opts.modify) { (None, _) => true, _ => false, }; - draw_title_box(d, &String::new(), Point::new(vx, (vy-17) as i32), Size::new(62, 62))?; + draw_title_box(d, &String::new(), Point::new(vx, (vy-17) as i32), Size::new(64, 64))?; Text::with_alignment( opts.screen.value.into(), @@ -204,6 +204,7 @@ pub fn draw_main(d: &mut D, opts: opt::Options, voices: [Voice; N_VOICES], scope_samples: &[i16], + touch: &[u8], irq0_len_us: u32, trace_main_len_us: u32) -> Result<(), D::Error> where @@ -213,37 +214,25 @@ where let font_small_white = MonoTextStyle::new(&FONT_4X6, Gray4::WHITE); let thin_stroke = PrimitiveStyle::with_stroke(Gray4::WHITE, 1); - for (n_voice, voice) in voices.iter().enumerate() { - if n_voice % 2 == 0 { - draw_voice(d, 1, (1+32*n_voice/2) as u32, - n_voice as u32, voice)?; - } else { - draw_voice(d, 33, (1+32*(n_voice/2)) as u32, + if opts.screen.value == opt::Screen::Adsr { + + for (n_voice, voice) in voices.iter().enumerate() { + draw_voice(d, (32*n_voice) as i32, 0, n_voice as u32, voice)?; } - } - - draw_options(d, &opts)?; - - let mut s: String<16> = String::new(); - ufmt::uwrite!(&mut s, "STATS").ok(); - draw_title_box(d, &s, Point::new(128+64+1, 1), Size::new(62, 62))?; - draw_ms(d, "main", trace_main_len_us, - Point::new(128+64+5, 17), font_small_white)?; - draw_ms(d, "irq0", irq0_len_us, - Point::new(128+64+5, 24), font_small_white)?; + } - { + if opts.screen.value == opt::Screen::Scope { let mut s: String<16> = String::new(); ufmt::uwrite!(&mut s, "SCOPE").ok(); - draw_title_box(d, &s, Point::new(65, 1), Size::new(62, 62))?; + draw_title_box(d, &s, Point::new(0, 0), Size::new(126, 64))?; - let mut points: [Point; 60] = [Point::new(0, 0); 60]; + let mut points: [Point; 124] = [Point::new(0, 0); 124]; for (n, point) in points.iter_mut().enumerate() { if n < scope_samples.len() { - point.x = 66 + n as i32; - point.y = 32 + (scope_samples[n] >> 10) as i32; + point.x = 1 + n as i32; + point.y = 33 + (scope_samples[n] >> 10) as i32; } } Polyline::new(&points) @@ -251,6 +240,35 @@ where .draw(d)?; } + if opts.screen.value == opt::Screen::Touch { + for (n_touch, touch) in touch.iter().enumerate() { + let mut s: String<16> = String::new(); + ufmt::uwrite!(&mut s, "{}", n_touch).ok(); + draw_title_box(d, &s, Point::new((16*n_touch) as i32, 0), Size::new(15, 16))?; + + let stroke_gain = PrimitiveStyleBuilder::new() + .stroke_color(Gray4::new(((*touch as u32 * 15u32) / 256u32) as u8)) + .stroke_width(1) + .build(); + + Rectangle::new(Point::new((16*n_touch) as i32+1, 10), Size::new(13, 5)) + .into_styled(stroke_gain) + .draw(d)?; + } + } + + draw_options(d, &opts)?; + + let mut s: String<16> = String::new(); + ufmt::uwrite!(&mut s, "STATS").ok(); + draw_title_box(d, &s, Point::new(128, 0), Size::new(62, 64))?; + + draw_ms(d, "main", trace_main_len_us, + Point::new(128+5, 17), font_small_white)?; + draw_ms(d, "irq0", irq0_len_us, + Point::new(128+5, 24), font_small_white)?; + + Ok(()) } @@ -262,6 +280,8 @@ mod tests { use image::imageops::{rotate90, resize, FilterType}; use midi_types::MidiMessage; + use crate::opt::Screen; + struct FakeDisplay { img: RgbImage, } @@ -299,19 +319,33 @@ mod tests { let mut disp = FakeDisplay { img: ImageBuffer::new(256, 64) }; - let opts = opt::Options::new(); + let mut opts = opt::Options::new(); let mut voice_manager = VoiceManager::new(); - let scope_samples = [0i16; 64]; + let scope_samples = [0i16; 128]; + let mut touch = [0u8; 8]; + touch[1] = 128; + touch[4] = 255; voice_manager.event(MidiMessage::NoteOn(0.into(), 70.into(), 64.into()), 0u32); voice_manager.tick(10u32, &opts); voice_manager.tick(50u32, &opts); voice_manager.tick(200u32, &opts); - draw_main(&mut disp, opts, voice_manager.voices, &scope_samples, 1, 2).unwrap(); + opts.screen.value = Screen::Adsr; + draw_main(&mut disp, opts.clone(), voice_manager.voices.clone(), &scope_samples, &touch, 1, 2).unwrap(); + let rz = resize(&disp.img, 256*4, 64*4, FilterType::Nearest); + rz.save("screen_adsr.png").unwrap(); + opts.screen.value = Screen::Scope; + disp.img = ImageBuffer::new(256, 64); + draw_main(&mut disp, opts.clone(), voice_manager.voices.clone(), &scope_samples, &touch, 1, 2).unwrap(); let rz = resize(&disp.img, 256*4, 64*4, FilterType::Nearest); + rz.save("screen_scope.png").unwrap(); - rz.save("test.png").unwrap(); + opts.screen.value = Screen::Touch; + disp.img = ImageBuffer::new(256, 64); + draw_main(&mut disp, opts.clone(), voice_manager.voices.clone(), &scope_samples, &touch, 1, 2).unwrap(); + let rz = resize(&disp.img, 256*4, 64*4, FilterType::Nearest); + rz.save("screen_touch.png").unwrap(); } } diff --git a/firmware/litex-fw/src/gw.rs b/firmware/litex-fw/src/gw.rs index 4b89467..f685421 100644 --- a/firmware/litex-fw/src/gw.rs +++ b/firmware/litex-fw/src/gw.rs @@ -11,6 +11,7 @@ pub trait EurorackPmod { fn reset(&self, timer: &mut Timer); fn eeprom_serial(&self) -> u32; fn jack(&self) -> u8; + fn touch(&self) -> [u8; 8]; fn input(&self, index: usize) -> i16; } @@ -27,12 +28,6 @@ pub trait KarlsenLpf { fn set_resonance(&self, value: i16); } -pub trait PwmLed { - fn reset_line(&self, set_high: bool); - fn reset(&self, timer: &mut Timer); - fn led(&self, ix: usize, value: u8); -} - macro_rules! eurorack_pmod { ($($t:ty),+ $(,)?) => { $(impl EurorackPmod for $t { @@ -54,6 +49,19 @@ macro_rules! eurorack_pmod { self.csr_jack().read().bits() as u8 } + fn touch(&self) -> [u8; 8] { + [ + self.csr_touch0().read().bits() as u8, + self.csr_touch1().read().bits() as u8, + self.csr_touch2().read().bits() as u8, + self.csr_touch3().read().bits() as u8, + self.csr_touch4().read().bits() as u8, + self.csr_touch5().read().bits() as u8, + self.csr_touch6().read().bits() as u8, + self.csr_touch7().read().bits() as u8, + ] + } + fn input(&self, index: usize) -> i16 { (match index { 0 => self.csr_cal_in0().read().bits(), diff --git a/firmware/litex-fw/src/main.rs b/firmware/litex-fw/src/main.rs index 99d549f..ec9ac82 100644 --- a/firmware/litex-fw/src/main.rs +++ b/firmware/litex-fw/src/main.rs @@ -17,9 +17,6 @@ use critical_section::Mutex; use irq::{handler, scope, scoped_interrupts}; use litex_interrupt::return_as_is; -use tinyusb_sys::{tusb_init, dcd_int_handler, tud_task_ext, - tud_dfu_finish_flashing, dfu_state_t, dfu_status_t}; - use ssd1322 as oled; use polyvec_lib::voice::*; @@ -171,23 +168,6 @@ unsafe fn irq_handler() { let pending_irq = vexriscv::register::vmip::read(); - // TODO: grab these correctly from PAC! - // These are already in the SVD as constants, but not as - // sub-nodes of the peripheral parents, so they aren't - // rendered in the svd2rust bindings. - // - let irq_usb_device = 2usize; - let irq_usb_setup = 3usize; - let irq_usb_in_ep = 4usize; - let irq_usb_out_ep = 5usize; - - if (pending_irq & (1 << irq_usb_device)) != 0 || - (pending_irq & (1 << irq_usb_setup)) != 0 || - (pending_irq & (1 << irq_usb_in_ep)) != 0 || - (pending_irq & (1 << irq_usb_out_ep)) != 0 { - dcd_int_handler(0); - } - let peripherals = pac::Peripherals::steal(); if (pending_irq & (1 << pac::Interrupt::DMA_ROUTER0 as usize)) != 0 { let pending_subtype = peripherals.DMA_ROUTER0.ev_pending().read().bits(); @@ -318,31 +298,6 @@ fn oled_init(timer: &mut Timer, oled_spi: pac::OLED_SPI) disp } -#[no_mangle] -pub extern "C" fn tud_dfu_get_timeout_cb(_alt: u8, state: u8) -> u32 { - match state { - state if state == dfu_state_t::DFU_DNBUSY as u8 => TICK_MS, - state if state == dfu_state_t::DFU_MANIFEST as u8 => 0, - _ => 0 - } -} - -#[no_mangle] -pub extern "C" fn tud_dfu_download_cb(alt: u8, block_num: u16, data: *const u8, length: u16) { - log::info!("DOWNLOAD alt={} block_num={} len={}", alt, block_num, length); - unsafe { - tud_dfu_finish_flashing(dfu_status_t::DFU_STATUS_OK as u8); - } -} - -#[no_mangle] -pub extern "C" fn tud_dfu_manifest_cb(_alt: u8) { - // TODO - unsafe { - tud_dfu_finish_flashing(dfu_status_t::DFU_STATUS_OK as u8); - } -} - #[no_mangle] pub extern "C" fn _putchar(c: u8) { _logger_write(&[c]); @@ -371,7 +326,8 @@ fn main() -> ! { timer.delay_ms(100u32); } - peripherals.EURORACK_PMOD0.reset(&mut timer); + let pmod0 = peripherals.EURORACK_PMOD0; + pmod0.reset(&mut timer); let mut disp = oled_init(&mut timer, peripherals.OLED_SPI); let mut spi_dma = SpiDma::new(peripherals.SPI_DMA, pac::OLED_SPI::PTR); @@ -405,9 +361,6 @@ fn main() -> ! { vexriscv::register::vmim::write((1 << (pac::Interrupt::DMA_ROUTER0 as usize)) | (1 << (pac::Interrupt::TIMER0 as usize))); - // Also enables USB interrupts - tusb_init(); - // Enable machine external interrupts (basically everything added on by LiteX). riscv::register::mie::set_mext(); @@ -425,10 +378,6 @@ fn main() -> ! { trace_main.start(&timer); - unsafe { - tud_task_ext(u32::MAX, false); - } - let scope_samples = critical_section::with(|cs| { let scope = &mut oscope.borrow_ref_mut(cs); if scope.full() { @@ -445,7 +394,9 @@ fn main() -> ! { state.trace.len_us()) }); - draw::draw_main(&mut disp, opts, voices, &scope_samples, + let touch = pmod0.touch(); + + draw::draw_main(&mut disp, opts, voices, &scope_samples, &touch, irq0_len_us, trace_main.len_us()).ok(); let fb = disp.swap_clear(); diff --git a/firmware/litex-fw/src/opt.rs b/firmware/litex-fw/src/opt.rs index 9116c80..8a5bbe9 100644 --- a/firmware/litex-fw/src/opt.rs +++ b/firmware/litex-fw/src/opt.rs @@ -49,6 +49,7 @@ pub enum EnumTest { pub enum Screen { Adsr, Scope, + Touch, } #[derive(Clone)] @@ -67,6 +68,12 @@ pub struct ScopeOptions { pub enum_test: EnumOption, } +#[derive(Clone)] +pub struct TouchOptions { + pub selected: Option, + pub threshold: NumOption, +} + macro_rules! impl_option_view { ($struct_name:ident, $($field:ident),*) => { impl OptionView for $struct_name { @@ -97,6 +104,9 @@ impl_option_view!(AdsrOptions, impl_option_view!(ScopeOptions, delay_len, enum_test); +impl_option_view!(TouchOptions, + threshold); + #[derive(Clone)] pub struct Options { @@ -105,6 +115,7 @@ pub struct Options { pub adsr: AdsrOptions, pub scope: ScopeOptions, + pub touch: TouchOptions, } impl Options { @@ -159,6 +170,16 @@ impl Options { name: "enumt".into(), value: EnumTest::ValueA, }, + }, + touch: TouchOptions { + selected: None, + threshold: NumOption{ + name: "thresh".into(), + value: 128, + step: 1, + min: 0, + max: 255, + }, } } } @@ -200,6 +221,7 @@ impl Options { match self.screen.value { Screen::Adsr => &self.adsr, Screen::Scope => &self.scope, + Screen::Touch => &self.touch, } } @@ -208,6 +230,7 @@ impl Options { match self.screen.value { Screen::Adsr => &mut self.adsr, Screen::Scope => &mut self.scope, + Screen::Touch => &mut self.touch, } } }