From 0a3c50f820515dae2fc114054098fbcb0b9969ae Mon Sep 17 00:00:00 2001 From: bunnie Date: Tue, 12 Jan 2021 23:30:52 +0800 Subject: [PATCH 1/8] add build timestamping/versioning to the Xous log output --- buildpush.sh | 2 ++ services/log-server/Cargo.toml | 3 +++ services/log-server/build.rs | 5 +++++ services/log-server/src/main.rs | 5 ++++- 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/buildpush.sh b/buildpush.sh index c0b6a0406..606791f90 100755 --- a/buildpush.sh +++ b/buildpush.sh @@ -57,6 +57,8 @@ set -- "${POSITIONAL[@]}" DESTDIR=code/precursors +touch services/log-server/src/main.rs # bump the build time in the log server + cargo xtask hw-image ../betrusted-soc/build/software/soc.svd # only copy if changed, othrewise it seems to trigger extra build effort... diff --git a/services/log-server/Cargo.toml b/services/log-server/Cargo.toml index ba434ac9c..e2c178cde 100644 --- a/services/log-server/Cargo.toml +++ b/services/log-server/Cargo.toml @@ -9,6 +9,9 @@ description = "Log output program" xous = { path = "../../xous-rs" } log = "0.4" +[build-dependencies] +vergen = "3" + [target.'cfg(not(any(windows,unix)))'.dependencies] utralib = { path = "../../utralib"} diff --git a/services/log-server/build.rs b/services/log-server/build.rs index 43c3deb4f..f9dd19b2f 100644 --- a/services/log-server/build.rs +++ b/services/log-server/build.rs @@ -1,9 +1,14 @@ // NOTE: Adapted from cortex-m/build.rs use std::env; +extern crate vergen; +use vergen::{ConstantsFlags, generate_cargo_keys}; + fn main() { let target = env::var("TARGET").unwrap(); + generate_cargo_keys(ConstantsFlags::SHA | ConstantsFlags::BUILD_TIMESTAMP).unwrap(); + let target_os = target.split('-').nth(2).unwrap_or("none"); // If we're not running on a desktop-class operating system, emit the "baremetal" diff --git a/services/log-server/src/main.rs b/services/log-server/src/main.rs index b863817b2..596bf9267 100644 --- a/services/log-server/src/main.rs +++ b/services/log-server/src/main.rs @@ -226,7 +226,10 @@ fn handle_scalar( fn reader_thread(mut output: implementation::OutputWriter) { writeln!(output, "LOG: Xous Logging Server starting up...").unwrap(); - writeln!(output, "LOG: Starting log server...").unwrap(); + writeln!(output, "LOG: ****************************************************************").unwrap(); + writeln!(output, "LOG: *** Welcome to Xous {:40} ***", env!("VERGEN_SHA")).unwrap(); + writeln!(output, "LOG: *** Built: {:49} ***", env!("VERGEN_BUILD_TIMESTAMP")).unwrap(); + writeln!(output, "LOG: ****************************************************************").unwrap(); let server_addr = xous::create_server_with_address(b"xous-log-server ").unwrap(); writeln!(output, "LOG: Server listening on address {:?}", server_addr).unwrap(); From f5f04a52bbf6138f335611b5f236f46a7d608937 Mon Sep 17 00:00:00 2001 From: bunnie Date: Tue, 12 Jan 2021 23:31:13 +0800 Subject: [PATCH 2/8] update lockfile for vergen inclusion --- Cargo.lock | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 92ea78ebf..bf373a92e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -115,6 +115,19 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +[[package]] +name = "chrono" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +dependencies = [ + "libc", + "num-integer", + "num-traits", + "time", + "winapi", +] + [[package]] name = "clap" version = "2.33.3" @@ -274,7 +287,7 @@ checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" dependencies = [ "cfg-if", "libc", - "wasi", + "wasi 0.9.0+wasi-snapshot-preview1", ] [[package]] @@ -401,6 +414,7 @@ version = "0.1.0" dependencies = [ "log", "utralib", + "vergen", "xous", ] @@ -860,6 +874,7 @@ dependencies = [ "blitstr", "com", "graphics-server", + "heapless", "keyboard", "log", "log-server", @@ -970,6 +985,17 @@ dependencies = [ "xous", ] +[[package]] +name = "time" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +dependencies = [ + "libc", + "wasi 0.10.0+wasi-snapshot-preview1", + "winapi", +] + [[package]] name = "tools" version = "0.1.0" @@ -1034,6 +1060,16 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" +[[package]] +name = "vergen" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ce50d8996df1f85af15f2cd8d33daae6e479575123ef4314a51a70a230739cb" +dependencies = [ + "bitflags", + "chrono", +] + [[package]] name = "version_check" version = "0.9.2" @@ -1052,6 +1088,12 @@ version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" +[[package]] +name = "wasi" +version = "0.10.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" + [[package]] name = "wayland-client" version = "0.25.0" From c848d374c6c1182b1396ecf840834df8b0bb549b Mon Sep 17 00:00:00 2001 From: bunnie Date: Wed, 13 Jan 2021 00:24:12 +0800 Subject: [PATCH 3/8] roll back the build time notice Turns out the build time only seems to capture the last time you managed to force a full rebuild (???). Even though cargo indicates that a rebuild had happened of the main.rs, the environment variable containing the time is not being updated, because the build.rs file isn't being run. But! if you force a trigger of that file, then cargo decides to rebuild *everything* which greatly increases the build time, which is a drag for development. So, just remove the build time notice. If it's not going to be correct, better to not emit it than to be outright misleading... --- buildpush.sh | 5 ++++- services/log-server/build.rs | 6 ++++-- services/log-server/src/main.rs | 5 ++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/buildpush.sh b/buildpush.sh index 606791f90..dbfa5651f 100755 --- a/buildpush.sh +++ b/buildpush.sh @@ -57,7 +57,10 @@ set -- "${POSITIONAL[@]}" DESTDIR=code/precursors -touch services/log-server/src/main.rs # bump the build time in the log server +# this didn't work. Timestamping is actually kinda broken, because +# you end up capturing just the time that you managed to trigger a +# full rebuild, and not just an incremental rebuild. :-/ +#touch services/log-server/src/main.rs # bump the build time in the log server cargo xtask hw-image ../betrusted-soc/build/software/soc.svd diff --git a/services/log-server/build.rs b/services/log-server/build.rs index f9dd19b2f..5fd27838d 100644 --- a/services/log-server/build.rs +++ b/services/log-server/build.rs @@ -7,8 +7,6 @@ use vergen::{ConstantsFlags, generate_cargo_keys}; fn main() { let target = env::var("TARGET").unwrap(); - generate_cargo_keys(ConstantsFlags::SHA | ConstantsFlags::BUILD_TIMESTAMP).unwrap(); - let target_os = target.split('-').nth(2).unwrap_or("none"); // If we're not running on a desktop-class operating system, emit the "baremetal" @@ -18,5 +16,9 @@ fn main() { println!("cargo:rustc-cfg=baremetal"); } + generate_cargo_keys(ConstantsFlags::SHA /*| ConstantsFlags::BUILD_TIMESTAMP*/).unwrap(); + // BUILD_TIMESTAMP doesn't work -- it doesn't update because of the below line + // removing the below line causes a lengthy full-rebuild just to capture a timestamp. + // so, we're removing the timestamp. println!("cargo:rerun-if-changed=build.rs"); } diff --git a/services/log-server/src/main.rs b/services/log-server/src/main.rs index 596bf9267..48217ca55 100644 --- a/services/log-server/src/main.rs +++ b/services/log-server/src/main.rs @@ -228,7 +228,10 @@ fn reader_thread(mut output: implementation::OutputWriter) { writeln!(output, "LOG: ****************************************************************").unwrap(); writeln!(output, "LOG: *** Welcome to Xous {:40} ***", env!("VERGEN_SHA")).unwrap(); - writeln!(output, "LOG: *** Built: {:49} ***", env!("VERGEN_BUILD_TIMESTAMP")).unwrap(); + // time stamp isn't actually the time stamp of the build, unfortunately. It's the time stamp of the + // last time you managed to force a rebuild that also causes log-server to be rebuilt, not necessarily + // capturing the build time of the very most recent change! + // writeln!(output, "LOG: *** Built: {:49} ***", env!("VERGEN_BUILD_TIMESTAMP")).unwrap(); writeln!(output, "LOG: ****************************************************************").unwrap(); let server_addr = xous::create_server_with_address(b"xous-log-server ").unwrap(); writeln!(output, "LOG: Server listening on address {:?}", server_addr).unwrap(); From a404e4ae614b379cc0cbc06c73779b9dbc345a6a Mon Sep 17 00:00:00 2001 From: bunnie Date: Wed, 13 Jan 2021 00:27:12 +0800 Subject: [PATCH 4/8] this panics with an alignment error (double string) issue #32 --- services/shell/Cargo.toml | 1 + services/shell/src/main.rs | 90 +++++++++++++++++++++++--------------- 2 files changed, 56 insertions(+), 35 deletions(-) diff --git a/services/shell/Cargo.toml b/services/shell/Cargo.toml index 56818f6e6..87e4f538e 100644 --- a/services/shell/Cargo.toml +++ b/services/shell/Cargo.toml @@ -13,6 +13,7 @@ ticktimer-server = { path = "../ticktimer-server" } xous-names = { path = "../xous-names" } log-server = { path = "../log-server" } keyboard = { path = "../keyboard" } +heapless = "0.5" log = "0.4" com = { path = "../com"} diff --git a/services/shell/src/main.rs b/services/shell/src/main.rs index a2fe40218..22b5c4478 100644 --- a/services/shell/src/main.rs +++ b/services/shell/src/main.rs @@ -96,7 +96,7 @@ impl Bounce { } } -use core::sync::atomic::{AtomicI16, AtomicU16, AtomicU8, Ordering}; +use core::sync::atomic::{AtomicI16, AtomicU16, AtomicU8, Ordering, AtomicU32, AtomicBool}; // need atomic global constants to pass data between threads // as we do not yet have a "Mutex" in Xous @@ -104,6 +104,8 @@ static BATT_STATS_VOLTAGE: AtomicU16 = AtomicU16::new(3700); static BATT_STATS_CURRENT: AtomicI16 = AtomicI16::new(-150); static BATT_STATS_SOC: AtomicU8 = AtomicU8::new(50); static BATT_STATS_REMAINING: AtomicU16 = AtomicU16::new(750); +static INCOMING_CHAR: AtomicU32 = AtomicU32::new(0); +static INCOMING_FRESH: AtomicBool = AtomicBool::new(false); fn event_thread(_arg: usize) { info!("SHELL|event_thread: registering shell SID"); @@ -135,6 +137,8 @@ fn event_thread(_arg: usize) { for &k in keys.iter() { if k != '\u{0000}' { info!("SHELL:event_thread: got key '{}'", k); + INCOMING_CHAR.store(k as u32, Ordering::Relaxed); + INCOMING_FRESH.store(true, Ordering::Relaxed); } } }, @@ -197,20 +201,23 @@ fn shell_main() -> ! { let style_dark = DrawStyle::new(PixelColor::Dark, PixelColor::Dark, 1); let style_light = DrawStyle::new(PixelColor::Light, PixelColor::Light, 1); + info!("SHELL: 1"); let mut string_buffer = String::new(4096); graphics_server::set_glyph_style(graphics_conn, GlyphStyle::Small) .expect("unable to set glyph"); let (_, font_h) = graphics_server::query_glyph(graphics_conn).expect("unable to query glyph"); let status_clipregion = - Rectangle::new_coords_with_style(4, 0, screensize.x, font_h as _, style_light); + Rectangle::new_coords_with_style(4, 0, screensize.x, font_h as i16 * 2, style_light); let mut status_cursor; + let small_font_h = font_h; + info!("SHELL: 2"); graphics_server::set_glyph_style(graphics_conn, GlyphStyle::Regular) .expect("unable to set glyph"); let (_, font_h) = graphics_server::query_glyph(graphics_conn).expect("unable to query glyph"); let mut work_clipregion = Rectangle::new_coords_with_style( 4, - font_h as i16 + 2, + small_font_h as i16 * 2, screensize.x, font_h as i16 * 8 + 18, style_light, @@ -219,10 +226,11 @@ fn shell_main() -> ! { graphics_server::draw_rectangle(graphics_conn, work_clipregion) .expect("unable to clear region"); - let mut firsttime = true; + info!("SHELL: 3"); let mut last_time: u64 = ticktimer_server::elapsed_ms(ticktimer_conn).unwrap(); + let mut input_buf = String::new(4096); loop { - // status bar + //////////////// status bar graphics_server::set_glyph_style(graphics_conn, GlyphStyle::Small) .expect("unable to set glyph"); @@ -271,17 +279,7 @@ fn shell_main() -> ! { graphics_server::set_cursor(graphics_conn, status_cursor).expect("can't set cursor"); graphics_server::draw_string(graphics_conn, &string_buffer).expect("unable to draw string"); - graphics_server::draw_line( - graphics_conn, - Line::new_with_style( - Point::new(0, font_h as i16), - Point::new(screensize.x as _, font_h as i16), - style_dark, - ), - ) - .expect("can't draw line"); - - // work area + //////////////// uptime string_buffer.clear(); write!( &mut string_buffer, @@ -289,30 +287,49 @@ fn shell_main() -> ! { last_time as f32 / 1000f32 ) .expect("Can't write"); - work_cursor = Cursor::from_top_left_of(work_clipregion.into()); - work_clipregion.br = Point::new(screensize.x, font_h as i16 * 3); - graphics_server::draw_rectangle(graphics_conn, work_clipregion) - .expect("unable to clear region"); - work_clipregion.br = Point::new(screensize.x, font_h as i16 * 8); - graphics_server::set_string_clipping(graphics_conn, work_clipregion.into()) - .expect("unable to set string clip region"); - graphics_server::set_cursor(graphics_conn, work_cursor).expect("can't set cursor"); - graphics_server::set_glyph_style(graphics_conn, GlyphStyle::Regular) - .expect("unable to set glyph"); + status_cursor.pt.x = 4; status_cursor.pt.y = small_font_h; graphics_server::draw_string(graphics_conn, &string_buffer).expect("unable to draw string"); - if firsttime { - string_buffer.clear(); - write!(&mut string_buffer, "Zwölf Boxkämpfer jagen Viktor quer über den großen Sylter Deich.\n 😸 🎩 🔑\n cat hat key\n").expect("Can't write"); - graphics_server::draw_string(graphics_conn, &string_buffer) - .expect("unable to draw string"); - firsttime = false; + // a line under the status area + graphics_server::draw_line( + graphics_conn, + Line::new_with_style( + Point::new(0, status_clipregion.br.y + 2), + Point::new(screensize.x as _, status_clipregion.br.y + 2), + style_dark, + ), + ) + .expect("can't draw line"); + + + + //////////////// work area + if INCOMING_FRESH.load(Ordering::Relaxed) { + INCOMING_FRESH.store(false, Ordering::Relaxed); + write!(&mut input_buf, "{}", core::char::from_u32(INCOMING_CHAR.load(Ordering::Relaxed)).unwrap()).expect("unable to copy to Xous string"); + + graphics_server::set_glyph_style(graphics_conn, GlyphStyle::Regular) + .expect("unable to set glyph"); + + // define the text area + work_clipregion.tl = Point::new(4, font_h as i16 * 2); + work_clipregion.br = Point::new(screensize.x, bouncyball.bounds.tl.y); + work_cursor = Cursor::from_top_left_of(work_clipregion.into()); + + // clear the text area, set string clipping and cursor + graphics_server::draw_rectangle(graphics_conn, work_clipregion) + .expect("unable to clear region"); + graphics_server::set_string_clipping(graphics_conn, work_clipregion.into()) + .expect("unable to set string clip region"); + graphics_server::set_cursor(graphics_conn, work_cursor).expect("can't set cursor"); + + info!("SHELL: attempting to render {}", input_buf); + graphics_server::draw_string(graphics_conn, &input_buf).expect("unable to draw string"); } - // rate limit graphics - //ticktimer_server::sleep_ms(ticktimer_conn, 500).expect("couldn't sleep"); - // draw the ball + + //////////////// draw the ball graphics_server::draw_rectangle( graphics_conn, Rectangle::new_with_style( @@ -371,5 +388,8 @@ fn shell_main() -> ! { } graphics_server::flush(graphics_conn).expect("unable to draw to screen"); + + // rate limit graphics + //ticktimer_server::sleep_ms(ticktimer_conn, 500).expect("couldn't sleep"); } } From 812fbf5d4f5648acdf9042fe8438fad99614e9f4 Mon Sep 17 00:00:00 2001 From: bunnie Date: Wed, 13 Jan 2021 00:32:07 +0800 Subject: [PATCH 5/8] this patch fixes the previous commit's panic --- services/shell/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/shell/src/main.rs b/services/shell/src/main.rs index 22b5c4478..a13f7823a 100644 --- a/services/shell/src/main.rs +++ b/services/shell/src/main.rs @@ -203,6 +203,7 @@ fn shell_main() -> ! { info!("SHELL: 1"); let mut string_buffer = String::new(4096); + let mut input_buf = String::new(4096); graphics_server::set_glyph_style(graphics_conn, GlyphStyle::Small) .expect("unable to set glyph"); let (_, font_h) = graphics_server::query_glyph(graphics_conn).expect("unable to query glyph"); @@ -228,7 +229,6 @@ fn shell_main() -> ! { info!("SHELL: 3"); let mut last_time: u64 = ticktimer_server::elapsed_ms(ticktimer_conn).unwrap(); - let mut input_buf = String::new(4096); loop { //////////////// status bar graphics_server::set_glyph_style(graphics_conn, GlyphStyle::Small) From 2958858a3a4475155eaeeb3fc14a48f2a66ddf80 Mon Sep 17 00:00:00 2001 From: bunnie Date: Wed, 13 Jan 2021 01:17:43 +0800 Subject: [PATCH 6/8] refactor to use UTRA for control registers --- .../graphics-server/src/backend/betrusted.rs | 40 ++++++------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/services/graphics-server/src/backend/betrusted.rs b/services/graphics-server/src/backend/betrusted.rs index d33fa9590..3aeb013e7 100644 --- a/services/graphics-server/src/backend/betrusted.rs +++ b/services/graphics-server/src/backend/betrusted.rs @@ -7,13 +7,9 @@ const FB_LINES: usize = 536; const FB_SIZE: usize = FB_WIDTH_WORDS * FB_LINES; // 44 bytes by 536 lines const CONFIG_CLOCK_FREQUENCY: u32 = 100_000_000; -const COMMAND_OFFSET: usize = 0; -const BUSY_OFFSET: usize = 1; -const PRESCALER_OFFSET: usize = 2; - pub struct XousDisplay { fb: MemoryRange, - control: MemoryRange, + csr: utralib::CSR, } impl XousDisplay { @@ -36,7 +32,11 @@ impl XousDisplay { xous::MemoryFlags::R | xous::MemoryFlags::W, ) .expect("couldn't map control port"); - let mut display = XousDisplay { fb, control }; + + let mut display = XousDisplay { + fb: fb, + csr: CSR::new(control.as_mut_ptr() as *mut u32), + }; display.set_clock(CONFIG_CLOCK_FREQUENCY); display.sync_clear(); @@ -45,10 +45,11 @@ impl XousDisplay { } pub fn redraw(&mut self) { - while self.busy() {} + while self.busy() {xous::yield_slice()} self.update_dirty(); } + // note: this API is used by emulation, don't remove calls to it pub fn update(&mut self) {} pub fn native_buffer(&mut self) -> &mut [u32; FB_SIZE] { @@ -72,27 +73,15 @@ impl XousDisplay { /// fn set_clock(&mut self, clk_mhz: u32) { - unsafe { - (self.control.as_ptr() as *mut u32) - .add(PRESCALER_OFFSET) - .write_volatile((clk_mhz / 2_000_000) - 1); - } + self.csr.wfo(utra::memlcd::PRESCALER_PRESCALER, (clk_mhz / 2_000_000) - 1); } fn update_all(&mut self) { - unsafe { - (self.control.as_ptr() as *mut u32) - .add(COMMAND_OFFSET) - .write_volatile(2) - }; + self.csr.wfo(utra::memlcd::COMMAND_UPDATEALL, 1); } fn update_dirty(&mut self) { - unsafe { - (self.control.as_ptr() as *mut u32) - .add(COMMAND_OFFSET) - .write_volatile(1) - }; + self.csr.wfo(utra::memlcd::COMMAND_UPDATEDIRTY, 1); } /// "synchronous clear" -- must be called on init, so that the state of the LCD @@ -111,11 +100,6 @@ impl XousDisplay { } fn busy(&self) -> bool { - unsafe { - (self.control.as_ptr() as *mut u32) - .add(BUSY_OFFSET) - .read_volatile() - == 1 - } + self.csr.rf(utra::memlcd::BUSY_BUSY) == 1 } } From 95cbf42cf20cb02dda8b4997a8d1b3e6eaee7343 Mon Sep 17 00:00:00 2001 From: bunnie Date: Wed, 13 Jan 2021 04:39:04 +0800 Subject: [PATCH 7/8] refactor frame buffer to use double buffering --- Cargo.lock | 1 - services/graphics-server/Cargo.toml | 4 +-- services/graphics-server/src/api.rs | 20 +++++++++-- .../graphics-server/src/backend/betrusted.rs | 35 +++++++++++++++++-- services/graphics-server/src/main.rs | 14 ++++++-- services/shell/Cargo.toml | 4 +-- services/shell/src/main.rs | 17 ++++----- 7 files changed, 75 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bf373a92e..f4dc654de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -68,7 +68,6 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" [[package]] name = "blitstr" version = "0.3.0" -source = "git+https://github.com/betrusted-io/blitstr.git?rev=69f7c04b9f44a20571c4792c8fc9166f5d6b548d#69f7c04b9f44a20571c4792c8fc9166f5d6b548d" [[package]] name = "bstr" diff --git a/services/graphics-server/Cargo.toml b/services/graphics-server/Cargo.toml index ae99c82e9..5c86cfa5d 100644 --- a/services/graphics-server/Cargo.toml +++ b/services/graphics-server/Cargo.toml @@ -10,8 +10,8 @@ xous = { path = "../../xous-rs" } log-server = { path = "../log-server" } xous-names = { path = "../xous-names" } log = "0.4" -blitstr = { git = "https://github.com/betrusted-io/blitstr.git", rev = "69f7c04b9f44a20571c4792c8fc9166f5d6b548d" } -# blitstr = { path = "../../../blitstr" } +# blitstr = { git = "https://github.com/betrusted-io/blitstr.git", rev = "69f7c04b9f44a20571c4792c8fc9166f5d6b548d" } +blitstr = { path = "../../../blitstr" } [target.'cfg(not(any(windows,unix)))'.dependencies] utralib = { path = "../../utralib"} diff --git a/services/graphics-server/src/api.rs b/services/graphics-server/src/api.rs index b3a16c205..1f55ddda1 100644 --- a/services/graphics-server/src/api.rs +++ b/services/graphics-server/src/api.rs @@ -411,9 +411,12 @@ pub enum Opcode<'a> { /// Set the clipping region for the string. SetStringClipping(ClipRect), - /// Render the string inside the clipping region. + /// Overwrite the string inside the clipping region. String(&'a str), + /// Xor the string inside the clipping region. + StringXor(&'a str), + /// Retrieve the X and Y dimensions of the screen ScreenSize, @@ -472,7 +475,16 @@ impl<'a> core::convert::TryFrom<&'a Message> for Opcode<'a> { ) }; Ok(Opcode::String(core::str::from_utf8(s).unwrap())) - } + }, + 2 => { + let s = unsafe { + core::slice::from_raw_parts( + m.buf.as_ptr(), + m.valid.map(|x| x.get()).unwrap_or_else(|| m.buf.len()), + ) + }; + Ok(Opcode::StringXor(core::str::from_utf8(s).unwrap())) + }, _ => Err("unrecognized opcode"), }, _ => Err("unhandled message type"), @@ -550,6 +562,10 @@ impl<'a> Into for Opcode<'a> { let region = xous::carton::Carton::from_bytes(string.as_bytes()); Message::Borrow(region.into_message(1)) } + Opcode::StringXor(string) => { + let region = xous::carton::Carton::from_bytes(string.as_bytes()); + Message::Borrow(region.into_message(2)) + } Opcode::SetCursor(c) => Message::Scalar(ScalarMessage { id: 12, arg1: c.pt.x, diff --git a/services/graphics-server/src/backend/betrusted.rs b/services/graphics-server/src/backend/betrusted.rs index 3aeb013e7..2cc379b8b 100644 --- a/services/graphics-server/src/backend/betrusted.rs +++ b/services/graphics-server/src/backend/betrusted.rs @@ -9,20 +9,34 @@ const CONFIG_CLOCK_FREQUENCY: u32 = 100_000_000; pub struct XousDisplay { fb: MemoryRange, + hwfb: MemoryRange, csr: utralib::CSR, } impl XousDisplay { pub fn new() -> XousDisplay { let fb = xous::syscall::map_memory( + None, + None, + ((FB_WIDTH_WORDS * FB_LINES * 4) + 4096) & !4095, + xous::MemoryFlags::R | xous::MemoryFlags::W, + ) + .expect("couldn't map backing frame buffer"); + let temp: *mut [u32; FB_SIZE] = fb.as_mut_ptr() as *mut [u32; FB_SIZE]; + for words in 0..FB_SIZE { + unsafe{(*temp)[words] = 0xFFFF_FFFF;} + } + + let hwfb = xous::syscall::map_memory( xous::MemoryAddress::new(HW_MEMLCD_MEM), None, ((FB_WIDTH_WORDS * FB_LINES * 4) + 4096) & !4095, xous::MemoryFlags::R | xous::MemoryFlags::W, ) - .expect("couldn't map frame buffer"); - for mem_offset in 0..(FB_SIZE / 4) { - unsafe { fb.as_mut_ptr().add(mem_offset).write_volatile(0) }; + .expect("couldn't map hardware frame buffer"); + let temp: *mut [u32; FB_SIZE] = hwfb.as_mut_ptr() as *mut [u32; FB_SIZE]; + for words in 0..FB_SIZE { + unsafe{(*temp)[words] = 0xFFFF_FFFF;} } let control = xous::syscall::map_memory( @@ -35,6 +49,7 @@ impl XousDisplay { let mut display = XousDisplay { fb: fb, + hwfb: hwfb, csr: CSR::new(control.as_mut_ptr() as *mut u32), }; @@ -46,7 +61,21 @@ impl XousDisplay { pub fn redraw(&mut self) { while self.busy() {xous::yield_slice()} + let fb: *mut [u32; FB_SIZE] = self.fb.as_mut_ptr() as *mut [u32; FB_SIZE]; + let hwfb: *mut [u32; FB_SIZE] = self.hwfb.as_mut_ptr() as *mut [u32; FB_SIZE]; + for words in 0..FB_SIZE { + unsafe { + (*hwfb)[words] = (*fb)[words]; + } + } self.update_dirty(); + // clear all the dirty bits, under the theory that it's time-wise cheaper on average + // to visit every line and clear the dirty bits than it is to do an update_all() + for lines in 0..FB_LINES { + unsafe { + (*fb)[lines * FB_WIDTH_WORDS + (FB_WIDTH_WORDS - 1)] &= 0x0000_FFFF; + } + } } // note: this API is used by emulation, don't remove calls to it diff --git a/services/graphics-server/src/main.rs b/services/graphics-server/src/main.rs index 6fe336e43..d4fde69fd 100644 --- a/services/graphics-server/src/main.rs +++ b/services/graphics-server/src/main.rs @@ -35,11 +35,10 @@ fn xmain() -> ! { let mut current_string_clip = blitstr::ClipRect::full_screen(); let mut current_cursor = blitstr::Cursor::from_top_left_of(current_string_clip); - display.redraw(); - let sid = xous_names::register_name(xous::names::SERVER_NAME_GFX).expect("GFX: can't register server"); info!("GFX: Server listening on address {:?}", sid); + display.redraw(); loop { let msg = xous::receive_message(sid).unwrap(); // info!("GFX: Message: {:?}", msg); @@ -71,6 +70,17 @@ fn xmain() -> ! { &mut current_cursor, current_glyph.into(), s, + false, + ); + } + Opcode::StringXor(s) => { + blitstr::paint_str( + display.native_buffer(), + current_string_clip.into(), + &mut current_cursor, + current_glyph.into(), + s, + true, ); } Opcode::SetGlyphStyle(glyph) => { diff --git a/services/shell/Cargo.toml b/services/shell/Cargo.toml index 87e4f538e..8ae15c9ea 100644 --- a/services/shell/Cargo.toml +++ b/services/shell/Cargo.toml @@ -18,8 +18,8 @@ log = "0.4" com = { path = "../com"} -# blitstr = { path = "../../../blitstr" } -blitstr = { git = "https://github.com/betrusted-io/blitstr.git", rev = "69f7c04b9f44a20571c4792c8fc9166f5d6b548d" } +blitstr = { path = "../../../blitstr" } +# blitstr = { git = "https://github.com/betrusted-io/blitstr.git", rev = "69f7c04b9f44a20571c4792c8fc9166f5d6b548d" } [target.'cfg(not(any(windows,unix)))'.dependencies] diff --git a/services/shell/src/main.rs b/services/shell/src/main.rs index a13f7823a..d563e7f6f 100644 --- a/services/shell/src/main.rs +++ b/services/shell/src/main.rs @@ -136,7 +136,7 @@ fn event_thread(_arg: usize) { keyboard::api::Opcode::KeyboardEvent(keys) => { for &k in keys.iter() { if k != '\u{0000}' { - info!("SHELL:event_thread: got key '{}'", k); + // info!("SHELL:event_thread: got key '{}'", k); INCOMING_CHAR.store(k as u32, Ordering::Relaxed); INCOMING_FRESH.store(true, Ordering::Relaxed); } @@ -201,7 +201,6 @@ fn shell_main() -> ! { let style_dark = DrawStyle::new(PixelColor::Dark, PixelColor::Dark, 1); let style_light = DrawStyle::new(PixelColor::Light, PixelColor::Light, 1); - info!("SHELL: 1"); let mut string_buffer = String::new(4096); let mut input_buf = String::new(4096); graphics_server::set_glyph_style(graphics_conn, GlyphStyle::Small) @@ -212,7 +211,6 @@ fn shell_main() -> ! { let mut status_cursor; let small_font_h = font_h; - info!("SHELL: 2"); graphics_server::set_glyph_style(graphics_conn, GlyphStyle::Regular) .expect("unable to set glyph"); let (_, font_h) = graphics_server::query_glyph(graphics_conn).expect("unable to query glyph"); @@ -227,8 +225,8 @@ fn shell_main() -> ! { graphics_server::draw_rectangle(graphics_conn, work_clipregion) .expect("unable to clear region"); - info!("SHELL: 3"); let mut last_time: u64 = ticktimer_server::elapsed_ms(ticktimer_conn).unwrap(); + let mut first_time = true; loop { //////////////// status bar graphics_server::set_glyph_style(graphics_conn, GlyphStyle::Small) @@ -317,18 +315,21 @@ fn shell_main() -> ! { work_cursor = Cursor::from_top_left_of(work_clipregion.into()); // clear the text area, set string clipping and cursor - graphics_server::draw_rectangle(graphics_conn, work_clipregion) - .expect("unable to clear region"); + if first_time { + info!("SHELL: first time clear of work area"); + graphics_server::draw_rectangle(graphics_conn, work_clipregion) + .expect("unable to clear region"); + first_time = false; + } graphics_server::set_string_clipping(graphics_conn, work_clipregion.into()) .expect("unable to set string clip region"); graphics_server::set_cursor(graphics_conn, work_cursor).expect("can't set cursor"); - info!("SHELL: attempting to render {}", input_buf); + // info!("SHELL: attempting to render {}", input_buf); graphics_server::draw_string(graphics_conn, &input_buf).expect("unable to draw string"); } - //////////////// draw the ball graphics_server::draw_rectangle( graphics_conn, From 18fbd046f6e9a8fecb62ea6b105f95eef8b0e93e Mon Sep 17 00:00:00 2001 From: bunnie Date: Wed, 13 Jan 2021 04:42:06 +0800 Subject: [PATCH 8/8] use git version of blitstr --- Cargo.lock | 1 + services/graphics-server/Cargo.toml | 4 ++-- services/shell/Cargo.toml | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f4dc654de..c59452bde 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -68,6 +68,7 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" [[package]] name = "blitstr" version = "0.3.0" +source = "git+https://github.com/betrusted-io/blitstr.git?rev=ea27e611d5ee165d8be894f9ca1c1130156c1931#ea27e611d5ee165d8be894f9ca1c1130156c1931" [[package]] name = "bstr" diff --git a/services/graphics-server/Cargo.toml b/services/graphics-server/Cargo.toml index 5c86cfa5d..e449aa4a6 100644 --- a/services/graphics-server/Cargo.toml +++ b/services/graphics-server/Cargo.toml @@ -10,8 +10,8 @@ xous = { path = "../../xous-rs" } log-server = { path = "../log-server" } xous-names = { path = "../xous-names" } log = "0.4" -# blitstr = { git = "https://github.com/betrusted-io/blitstr.git", rev = "69f7c04b9f44a20571c4792c8fc9166f5d6b548d" } -blitstr = { path = "../../../blitstr" } +blitstr = { git = "https://github.com/betrusted-io/blitstr.git", rev = "ea27e611d5ee165d8be894f9ca1c1130156c1931" } +# blitstr = { path = "../../../blitstr" } [target.'cfg(not(any(windows,unix)))'.dependencies] utralib = { path = "../../utralib"} diff --git a/services/shell/Cargo.toml b/services/shell/Cargo.toml index 8ae15c9ea..d9b9e9dfe 100644 --- a/services/shell/Cargo.toml +++ b/services/shell/Cargo.toml @@ -18,8 +18,8 @@ log = "0.4" com = { path = "../com"} -blitstr = { path = "../../../blitstr" } -# blitstr = { git = "https://github.com/betrusted-io/blitstr.git", rev = "69f7c04b9f44a20571c4792c8fc9166f5d6b548d" } +# blitstr = { path = "../../../blitstr" } +blitstr = { git = "https://github.com/betrusted-io/blitstr.git", rev = "ea27e611d5ee165d8be894f9ca1c1130156c1931" } [target.'cfg(not(any(windows,unix)))'.dependencies]