Skip to content

Commit

Permalink
Merge pull request #47 from betrusted-io/hardware
Browse files Browse the repository at this point in the history
Reasonable stopping point for a demo
  • Loading branch information
bunnie authored Mar 10, 2021
2 parents aa7e6ab + 54cf95a commit 2b8b703
Show file tree
Hide file tree
Showing 30 changed files with 1,349 additions and 157 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Makefile text eol=lf
*.md eol=lf
README.* text eol=lf
LICENSE text eol=lf
*.txt text eol=lf

# Binary files
*.dfu binary
Expand Down
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion kernel/src/arch/hosted/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,15 @@ pub fn set_current_pid(pid: PID) {
}

pub fn register_connection_for_key(
conn: TcpStream,
mut conn: TcpStream,
key: ProcessKey,
) -> Result<PID, xous_kernel::Error> {
PROCESS_TABLE.with(|pt| {
let mut process_table = pt.borrow_mut();
for (pid_minus_1, process) in process_table.table.iter_mut().enumerate() {
if let Some(process) = process.as_mut() {
if process.key == key && process.conn.is_none() {
conn.write_all(&[pid_minus_1 as u8 + 1]).unwrap();
process.conn = Some(conn);
return Ok(PID::new(pid_minus_1 as u8 + 1).unwrap());
}
Expand Down
9 changes: 9 additions & 0 deletions services/gam/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ pub enum Opcode {
// the Gid argument is the rkyv return value.
RequestContentCanvas(ContentCanvasRequest),

// Requests setting the UI to the power down screen
PowerDownRequest,

/////// planned

// hides a canvas with a given GID
Expand All @@ -76,6 +79,7 @@ impl core::convert::TryFrom<&Message> for Opcode {
},
Message::BlockingScalar(m) => match m.id {
0 => Ok(Opcode::GetCanvasBounds(Gid::new([m.arg1 as _, m.arg2 as _, m.arg3 as _, m.arg4 as _]))),
1 => Ok(Opcode::PowerDownRequest),
_ => Err("GAM api: unknown BlockingScalar ID"),
}
_ => Err("GAM api: unhandled message type"),
Expand All @@ -86,15 +90,20 @@ impl core::convert::TryFrom<&Message> for Opcode {
impl Into<Message> for Opcode {
fn into(self) -> Message {
match self {
// scalars
Opcode::ClearCanvas(gid) => Message::Scalar(ScalarMessage {
id: 0, arg1: gid.gid()[0] as _, arg2: gid.gid()[1] as _, arg3: gid.gid()[2] as _, arg4: gid.gid()[3] as _
}),
Opcode::Redraw => Message::Scalar(ScalarMessage {
id: 1, arg1: 0, arg2: 0, arg3: 0, arg4: 0
}),
// blocking scalars
Opcode::GetCanvasBounds(gid) => Message::BlockingScalar(ScalarMessage {
id: 0, arg1: gid.gid()[0] as _, arg2: gid.gid()[1] as _, arg3: gid.gid()[2] as _, arg4: gid.gid()[3] as _
}),
Opcode::PowerDownRequest => Message::BlockingScalar(ScalarMessage {
id: 1, arg1: 0, arg2: 0, arg3: 0, arg4: 0
}),
_ => panic!("GAM api: Opcode type not handled by Into(), maybe you meant to use a helper method?"),
}
}
Expand Down
14 changes: 14 additions & 0 deletions services/gam/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
pub mod api;
use api::*;

use xous::send_message;
use rkyv::Write;
use rkyv::Unarchive;
use graphics_server::api::{TextOp, TextView};
Expand All @@ -14,6 +15,19 @@ pub fn redraw(gam_cid: xous::CID) -> Result<(), xous::Error> {
xous::send_message(gam_cid, api::Opcode::Redraw.into()).map(|_|())
}

pub fn powerdown_request(gam_cid: xous::CID) -> Result<bool, xous::Error> {
let response = send_message(gam_cid, api::Opcode::PowerDownRequest.into())?;
if let xous::Result::Scalar1(confirmed) = response {
if confirmed != 0 {
Ok(true)
} else {
Ok(false)
}
} else {
panic!("GAM_API: unexpected return value: {:#?}", response);
}
}

/// this "posts" a textview -- it's not a "draw" as the update is neither guaranteed nor instantaneous
/// the GAM first has to check that the textview is allowed to be updated, and then it will decide when
/// the actual screen update is allowed
Expand Down
22 changes: 16 additions & 6 deletions services/gam/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,6 @@ fn xmain() -> ! {
// this is broken into two steps because of https://github.com/rust-lang/rust/issues/71126
canvases = recompute_canvases(canvases, Rectangle::new(Point::new(0, 0), screensize));

// make a thread to manage the status bar
// the status bar is a trusted element managed by the OS, and we are chosing to domicile this in the GAM process for now
xous::create_thread_simple(status_thread, chatlayout.status.gid()).expect("GAM: couldn't create status thread");

// connect to the IME front end, and set its canvas
info!("GAM: acquiring connection to IMEF...");
let imef_conn = xous_names::request_connection_blocking(xous::names::SERVER_NAME_IME_FRONT).expect("GAM: can't connect to the IME front end");
Expand All @@ -221,6 +217,11 @@ fn xmain() -> ! {
// no content canvas initially, but keep a placeholder for one
let mut ccc: ContentCanvasConnection = ContentCanvasConnection{connection: None};

// make a thread to manage the status bar -- this needs to start after the IMEF is initialized
// the status bar is a trusted element managed by the OS, and we are chosing to domicile this in the GAM process for now
xous::create_thread_simple(status_thread, chatlayout.status.gid()).expect("GAM: couldn't create status thread");

let mut powerdown_requested = false;
let mut last_time: u64 = ticktimer_server::elapsed_ms(ticktimer_conn).unwrap();
info!("GAM: entering main loop");
loop {
Expand Down Expand Up @@ -252,10 +253,19 @@ fn xmain() -> ! {
rect.br.into(),
).expect("GAM: couldn't return canvas bounds");
},
None => info!("GAM: attempt to get bounds on bogus canvas, ignored."),
None => info!("GAM: attempt to get bounds on bogus canvas gid {:?}, {:?} ignored.", gid, envelope),
}
}
},
Opcode::PowerDownRequest => {
powerdown_requested = true;
graphics_server::draw_sleepscreen(gfx_conn).expect("GAM: couldn't draw sleep screen");
// a screen flush is part of the draw_sleepscreen abstraction
xous::return_scalar(envelope.sender, 1).expect("GAM: couldn't confirm power down UI request");
},
Opcode::Redraw => {
if powerdown_requested {
continue; // don't allow any redraws if a powerdown is requested
}
if let Ok(elapsed_time) = ticktimer_server::elapsed_ms(ticktimer_conn) {
if elapsed_time - last_time > 33 { // rate limit updates, no point in going faster than the eye can see
last_time = elapsed_time;
Expand Down
3 changes: 2 additions & 1 deletion services/gam/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use blitstr_ref as blitstr;
pub fn status_thread(canvas_gid: [u32; 4]) {
let debug1 = false;
let status_gid: Gid = Gid::new(canvas_gid);
if debug1{info!("GAM|status: my canvas {:?}", status_gid)};

if debug1{info!("GAM|status: registering GAM|status thread");}
let status_sid = xous_names::register_name(xous::names::SERVER_NAME_STATUS).expect("GAM|status: can't register server");
Expand All @@ -30,7 +31,7 @@ pub fn status_thread(canvas_gid: [u32; 4]) {
uptime_tv.untrusted = false;
uptime_tv.style = blitstr::GlyphStyle::Small;
uptime_tv.draw_border = false;
uptime_tv.margin = Point::new(0, 0);
uptime_tv.margin = Point::new(3, 0);
write!(uptime_tv, "Booting up...").expect("GAM|status: couldn't init uptime text");
if debug1{info!("GAM|status: screensize as reported: {:?}", screensize);}
if debug1{info!("GAM|status: uptime initialized to '{:?}'", uptime_tv);}
Expand Down
7 changes: 7 additions & 0 deletions services/graphics-server/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ pub enum Opcode {

/// draws an object that requires clipping
DrawClipObject(ClipObject),

/// draws the sleep screen; assumes requests are vetted by GAM/xous-names
DrawSleepScreen
}

impl core::convert::TryFrom<& Message> for Opcode {
Expand Down Expand Up @@ -146,6 +149,7 @@ impl core::convert::TryFrom<& Message> for Opcode {
DrawStyle::from(m.arg3)),
m.arg4 as _
))),
16 => Ok(Opcode::DrawSleepScreen),
_ => Err("unrecognized opcode"),
},
Message::BlockingScalar(m) => match m.id {
Expand Down Expand Up @@ -263,6 +267,9 @@ impl Into<Message> for Opcode {
arg3: rr.border.style.into(),
arg4: rr.radius as _,
}),
Opcode::DrawSleepScreen => Message::Scalar(ScalarMessage {
id: 16, arg1: 0, arg2: 0, arg3: 0, arg4: 0,
}),
_ => panic!("GFX api: Opcode type not handled by Into(), maybe you meant to use a helper method?"),
}
}
Expand Down
4 changes: 4 additions & 0 deletions services/graphics-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ pub fn flush(cid: CID) -> Result<(), xous::Error> {
send_message(cid, api::Opcode::Flush.into()).map(|_| ())
}

pub fn draw_sleepscreen(cid: CID) -> Result<(), xous::Error> {
send_message(cid, api::Opcode::DrawSleepScreen.into()).map(|_| ())
}

#[deprecated(
note = "Please use draw_textview for atomic text updates"
)]
Expand Down
13 changes: 7 additions & 6 deletions services/graphics-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ mod op;
use core::convert::TryFrom;

mod logo;
mod poweron;

use api::{DrawStyle, PixelColor, Rectangle, TextBounds, RoundedRectangle, Point};
use blitstr_ref as blitstr;

mod fontmap;

fn draw_boot_logo(display: &mut XousDisplay) {
display.blit_screen(logo::LOGO_MAP);
display.blit_screen(poweron::LOGO_MAP);
}

#[cfg(target_os = "none")]
Expand Down Expand Up @@ -433,11 +434,11 @@ fn xmain() -> ! {
)
.expect("GFX: could not return QueryGlyphProps request");
}
/*
Opcode::TextView(tv) => {
info!("GFX: got draw of '{:?}'", tv);
op::textview(display.native_buffer(), tv);
}*/
Opcode::DrawSleepScreen => {
display.blit_screen(logo::LOGO_MAP);
display.update();
display.redraw();
}
_ => panic!("GFX: received opcode scalar that is not handled")
}
} else {
Expand Down
Loading

0 comments on commit 2b8b703

Please sign in to comment.