diff --git a/firmware/litex-fw/Cargo.lock b/firmware/litex-fw/Cargo.lock index bf97b5a..ad74c15 100644 --- a/firmware/litex-fw/Cargo.lock +++ b/firmware/litex-fw/Cargo.lock @@ -11,6 +11,27 @@ dependencies = [ "memchr", ] +[[package]] +name = "atomic-polyfill" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3ff7eb3f316534d83a8a2c3d1674ace8a5a71198eba31e2e2b597833f699b28" +dependencies = [ + "critical-section", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "az" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b7e4c2464d97fe331d41de9d5db0def0a96f4d823b8b32a2efd503578988973" + [[package]] name = "bit_field" version = "0.10.2" @@ -23,6 +44,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + [[package]] name = "critical-section" version = "1.1.2" @@ -67,6 +94,29 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +[[package]] +name = "embedded-graphics" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0649998afacf6d575d126d83e68b78c0ab0e00ca2ac7e9b3db11b4cbe8274ef0" +dependencies = [ + "az", + "byteorder", + "embedded-graphics-core", + "float-cmp", + "micromath", +] + +[[package]] +name = "embedded-graphics-core" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba9ecd261f991856250d2207f6d8376946cd9f412a2165d3b75bc87a0bc7a044" +dependencies = [ + "az", + "byteorder", +] + [[package]] name = "embedded-hal" version = "0.2.7" @@ -87,6 +137,37 @@ dependencies = [ "nb 1.1.0", ] +[[package]] +name = "float-cmp" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4" +dependencies = [ + "num-traits", +] + +[[package]] +name = "hash32" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c35f58762feb77d74ebe43bdbc3210f09be9fe6742234d573bacc26ed92b67" +dependencies = [ + "byteorder", +] + +[[package]] +name = "heapless" +version = "0.7.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db04bc24a18b9ea980628ecf00e6c0264f3c1426dac36c00cb49b6fbad8b0743" +dependencies = [ + "atomic-polyfill", + "hash32", + "rustc_version", + "spin", + "stable_deref_trait", +] + [[package]] name = "itertools" version = "0.7.11" @@ -107,12 +188,13 @@ name = "litex-fw" version = "0.1.0" dependencies = [ "defmt", + "embedded-graphics", "embedded-midi", + "heapless", "litex-hal", "litex-pac", "micromath", "midi-types", - "panic-halt", "paste", "riscv", "riscv-rt", @@ -138,6 +220,16 @@ dependencies = [ "vcell", ] +[[package]] +name = "lock_api" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "memchr" version = "2.5.0" @@ -181,10 +273,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d5439c4ad607c3c23abf66de8c8bf57ba8adcd1f129e699851a6e43935d339d" [[package]] -name = "panic-halt" -version = "0.2.0" +name = "num-traits" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de96540e0ebde571dc55c73d60ef407c653844e6f9a1e2fdbd40c07b9252d812" +checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" +dependencies = [ + "autocfg", +] [[package]] name = "paste" @@ -313,21 +408,58 @@ dependencies = [ "regex", ] +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "semver" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" + [[package]] name = "seq-macro" version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3f0bf26fd526d2a95683cd0f87bf103b8539e2ca1ef48ce002d67aad59aa0b4" +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + [[package]] name = "ssd1322" version = "0.3.0" dependencies = [ + "embedded-graphics", "embedded-hal", "itertools", "nb 0.1.3", ] +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + [[package]] name = "syn" version = "1.0.109" diff --git a/firmware/litex-fw/Cargo.toml b/firmware/litex-fw/Cargo.toml index 01b8dc5..32f1e63 100644 --- a/firmware/litex-fw/Cargo.toml +++ b/firmware/litex-fw/Cargo.toml @@ -8,7 +8,6 @@ edition = "2021" [dependencies] riscv = "*" riscv-rt = "*" -panic-halt = "*" litex-hal = { path = "../deps/rust-litex-hal", features = ["gpio"] } litex-pac = { path = "../litex-pac", features = ["rt"] } ssd1322 = { path = "../ssd1322", features = [] } @@ -18,3 +17,5 @@ micromath = "2.0.0" midi-types = "0.1.7" seq-macro = "0.3.5" paste = "1.0.14" +embedded-graphics = "0.8.1" +heapless = "0.7.16" diff --git a/firmware/litex-fw/src/main.rs b/firmware/litex-fw/src/main.rs index 983e61a..f48a89d 100644 --- a/firmware/litex-fw/src/main.rs +++ b/firmware/litex-fw/src/main.rs @@ -10,7 +10,16 @@ use litex_pac as pac; use riscv; use riscv_rt::entry; use litex_hal::hal::digital::v2::OutputPin; -use core::iter; +use heapless::String; +use core::fmt::Write; + +use embedded_graphics::{ + pixelcolor::{Gray4, GrayColor}, + primitives::{Circle, PrimitiveStyle, PrimitiveStyleBuilder}, + mono_font::{ascii::FONT_6X10, MonoTextStyle}, + prelude::*, + text::Text, +}; use ssd1322 as oled; @@ -118,11 +127,30 @@ fn main() -> ! { timer.delay_ms(10_u16); rstn.set_high().unwrap(); + timer.delay_ms(1_u16); + + disp.init( + oled::Config::new( + oled::ComScanDirection::RowZeroLast, + oled::ComLayout::DualProgressive, + ).clock_fosc_divset(9, 1) + .display_enhancements(true, true) + .contrast_current(159) + .phase_lengths(5, 14) + .precharge_voltage(31) + .second_precharge_period(8) + .com_deselect_voltage(7), + ).unwrap(); defmt::info!("Starting main loop --"); loop { + /* + + defmt::info!("tick - elapsed {} sec", elapsed); + elapsed += 1.0f32; + defmt::info!("PMOD0"); defmt::info!("jack_detect {=u8:x}", peripherals.EURORACK_PMOD0.csr_jack.read().bits() as u8); defmt::info!("input0 {}", peripherals.EURORACK_PMOD0.csr_cal_in0.read().bits() as i16); @@ -139,38 +167,52 @@ fn main() -> ! { defmt::info!("input3 {}", peripherals.EURORACK_PMOD1.csr_cal_in3.read().bits() as i16); defmt::info!("serial {=u32:x}", peripherals.EURORACK_PMOD1.csr_eeprom_serial.read().bits() as u32); timer.delay_ms(1000u32); + */ - disp.init( - oled::Config::new( - oled::ComScanDirection::RowZeroLast, - oled::ComLayout::DualProgressive, - ).clock_fosc_divset(9, 1) - .display_enhancements(true, true) - .contrast_current(159) - .phase_lengths(5, 14) - .precharge_voltage(31) - .second_precharge_period(8) - .com_deselect_voltage(7), - ).unwrap(); + let rect_style = PrimitiveStyleBuilder::new() + .stroke_color(Gray4::new(0x5)) + .stroke_width(1) + .fill_color(Gray4::BLACK) + .build(); - timer.delay_ms(1000u32); + disp + .bounding_box() + .into_styled(rect_style) + .draw(&mut disp).ok(); - // Get a region covering the entire display area, and clear it by writing all zeros. - { - let mut region = disp - .region(oled::PixelCoord(0, 0), oled::PixelCoord(128, 128)) - .unwrap(); - region.draw_packed(iter::repeat(0x0f)).unwrap(); - } + let circle = Circle::new(Point::new(22, 22), 20) + .into_styled(PrimitiveStyle::with_stroke(Gray4::WHITE, 1)); - { - let mut region = disp - .region(oled::PixelCoord(128, 0), oled::PixelCoord(256, 128)) - .unwrap(); - region.draw_packed(iter::repeat(0x10)).unwrap(); - } + circle.draw(&mut disp).unwrap(); + + let style = MonoTextStyle::new(&FONT_6X10, Gray4::WHITE); + + Text::new("Hello,\nRust!", Point::new(0, 12), style).draw(&mut disp).ok(); + + let mut s: String<128> = String::new(); + write!(&mut s, "serial0 {:#06x}", peripherals.EURORACK_PMOD0.csr_eeprom_serial.read().bits() as u32).ok(); + + Text::new(&s, Point::new(128, 12), style).draw(&mut disp).ok(); + + s.clear(); + + write!(&mut s, "serial1 {:#06x}", peripherals.EURORACK_PMOD1.csr_eeprom_serial.read().bits() as u32).ok(); + + Text::new(&s, Point::new(128, 24), style).draw(&mut disp).ok(); + + s.clear(); + + write!(&mut s, "jack0 {:#06x}", peripherals.EURORACK_PMOD0.csr_jack.read().bits() as u32).ok(); + + Text::new(&s, Point::new(128, 36), style).draw(&mut disp).ok(); + + s.clear(); + + write!(&mut s, "jack1 {:#06x}", peripherals.EURORACK_PMOD1.csr_jack.read().bits() as u32).ok(); + + Text::new(&s, Point::new(128, 48), style).draw(&mut disp).ok(); + + disp.flush(); - defmt::info!("tick - elapsed {} sec", elapsed); - elapsed += 1.0f32; } } diff --git a/firmware/ssd1322 b/firmware/ssd1322 index 65ced3f..da053bf 160000 --- a/firmware/ssd1322 +++ b/firmware/ssd1322 @@ -1 +1 @@ -Subproject commit 65ced3f472f3e0fc5f812e94df7afdd4840de76d +Subproject commit da053bfbd1e0e16b727548215b2d51814425b8e9