Merge pull request #33 from betrusted-io/hardware

Hardware
This commit is contained in:
bunnie 2021-01-13 04:42:43 +08:00 committed by GitHub
commit 41ca6e421b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 200 additions and 76 deletions

46
Cargo.lock generated
View file

@ -68,7 +68,7 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]]
name = "blitstr"
version = "0.3.0"
source = "git+https://github.com/betrusted-io/blitstr.git?rev=69f7c04b9f44a20571c4792c8fc9166f5d6b548d#69f7c04b9f44a20571c4792c8fc9166f5d6b548d"
source = "git+https://github.com/betrusted-io/blitstr.git?rev=ea27e611d5ee165d8be894f9ca1c1130156c1931#ea27e611d5ee165d8be894f9ca1c1130156c1931"
[[package]]
name = "bstr"
@ -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"

View file

@ -57,6 +57,11 @@ set -- "${POSITIONAL[@]}"
DESTDIR=code/precursors
# 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
# only copy if changed, othrewise it seems to trigger extra build effort...

View file

@ -10,7 +10,7 @@ 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 = { git = "https://github.com/betrusted-io/blitstr.git", rev = "ea27e611d5ee165d8be894f9ca1c1130156c1931" }
# blitstr = { path = "../../../blitstr" }
[target.'cfg(not(any(windows,unix)))'.dependencies]

View file

@ -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<Message> 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,

View file

@ -7,26 +7,36 @@ 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,
hwfb: MemoryRange,
csr: utralib::CSR<u32>,
}
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(
@ -36,7 +46,12 @@ 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,
hwfb: hwfb,
csr: CSR::new(control.as_mut_ptr() as *mut u32),
};
display.set_clock(CONFIG_CLOCK_FREQUENCY);
display.sync_clear();
@ -45,10 +60,25 @@ impl XousDisplay {
}
pub fn redraw(&mut self) {
while self.busy() {}
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
pub fn update(&mut self) {}
pub fn native_buffer(&mut self) -> &mut [u32; FB_SIZE] {
@ -72,27 +102,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 +129,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
}
}

View file

@ -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) => {

View file

@ -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"}

View file

@ -1,6 +1,9 @@
// 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();
@ -13,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");
}

View file

@ -226,7 +226,13 @@ 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();
// 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();

View file

@ -13,12 +13,13 @@ 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"}
# blitstr = { path = "../../../blitstr" }
blitstr = { git = "https://github.com/betrusted-io/blitstr.git", rev = "69f7c04b9f44a20571c4792c8fc9166f5d6b548d" }
blitstr = { git = "https://github.com/betrusted-io/blitstr.git", rev = "ea27e611d5ee165d8be894f9ca1c1130156c1931" }
[target.'cfg(not(any(windows,unix)))'.dependencies]

View file

@ -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");
@ -134,7 +136,9 @@ 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);
}
}
},
@ -198,19 +202,21 @@ fn shell_main() -> ! {
let style_light = DrawStyle::new(PixelColor::Light, PixelColor::Light, 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");
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;
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 +225,10 @@ fn shell_main() -> ! {
graphics_server::draw_rectangle(graphics_conn, work_clipregion)
.expect("unable to clear region");
let mut firsttime = true;
let mut last_time: u64 = ticktimer_server::elapsed_ms(ticktimer_conn).unwrap();
let mut first_time = true;
loop {
// status bar
//////////////// status bar
graphics_server::set_glyph_style(graphics_conn, GlyphStyle::Small)
.expect("unable to set glyph");
@ -271,17 +277,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 +285,52 @@ 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
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);
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 +389,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");
}
}