2020-08-14 09:25:20 +00:00
|
|
|
#![cfg_attr(target_os = "none", no_std)]
|
|
|
|
|
#![cfg_attr(target_os = "none", no_main)]
|
|
|
|
|
|
2020-11-27 18:05:55 +00:00
|
|
|
use log::{info, error};
|
2020-10-30 13:27:06 +00:00
|
|
|
|
2020-08-14 09:25:20 +00:00
|
|
|
mod backend;
|
2020-08-14 10:46:23 +00:00
|
|
|
use backend::XousDisplay;
|
|
|
|
|
|
2020-08-29 14:09:20 +00:00
|
|
|
mod api;
|
|
|
|
|
use api::Opcode;
|
|
|
|
|
|
2020-10-30 02:22:03 +00:00
|
|
|
mod op;
|
2020-08-14 09:25:20 +00:00
|
|
|
|
2020-08-29 14:09:20 +00:00
|
|
|
use core::convert::TryFrom;
|
2020-08-14 10:46:23 +00:00
|
|
|
|
2020-10-11 19:23:15 +00:00
|
|
|
mod logo;
|
2020-08-14 10:46:23 +00:00
|
|
|
|
2020-11-27 18:05:55 +00:00
|
|
|
use blitstr;
|
2020-12-02 17:48:10 +00:00
|
|
|
use api::{PixelColor, Rectangle, DrawStyle};
|
2020-11-27 18:05:55 +00:00
|
|
|
|
2020-10-11 19:23:15 +00:00
|
|
|
fn draw_boot_logo(display: &mut XousDisplay) {
|
2020-10-30 02:22:03 +00:00
|
|
|
display.blit_screen(logo::LOGO_MAP);
|
2020-08-29 14:09:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[xous::xous_main]
|
|
|
|
|
fn xmain() -> ! {
|
2020-10-30 13:27:06 +00:00
|
|
|
log_server::init_wait().unwrap();
|
|
|
|
|
|
2020-08-29 14:09:20 +00:00
|
|
|
// Create a new monochrome simulator display.
|
|
|
|
|
let mut display = XousDisplay::new();
|
|
|
|
|
|
|
|
|
|
draw_boot_logo(&mut display);
|
2020-08-14 10:46:23 +00:00
|
|
|
|
2020-12-02 17:48:10 +00:00
|
|
|
let mut current_glyph = blitstr::GlyphStyle::Regular;
|
|
|
|
|
let mut current_string_clip = blitstr::ClipRect::full_screen();
|
2020-11-27 18:05:55 +00:00
|
|
|
let mut current_cursor = blitstr::Cursor::from_top_left_of(current_string_clip);
|
2020-08-14 10:46:23 +00:00
|
|
|
|
2020-10-30 02:22:03 +00:00
|
|
|
display.redraw();
|
2020-08-29 14:09:20 +00:00
|
|
|
|
|
|
|
|
let sid = xous::create_server(b"graphics-server ").unwrap();
|
2020-10-30 13:27:06 +00:00
|
|
|
// info!("GFX: Server listening on address {:?}", sid);
|
2020-10-30 02:22:03 +00:00
|
|
|
// ::debug_here::debug_here!();
|
2020-08-14 10:46:23 +00:00
|
|
|
loop {
|
2020-08-29 14:09:20 +00:00
|
|
|
let msg = xous::receive_message(sid).unwrap();
|
2020-10-30 13:27:06 +00:00
|
|
|
// info!("GFX: Message: {:?}", msg);
|
2020-08-29 14:09:20 +00:00
|
|
|
if let Ok(opcode) = Opcode::try_from(&msg.body) {
|
2020-10-30 13:27:06 +00:00
|
|
|
// info!("GFX: Opcode: {:?}", opcode);
|
2020-08-29 14:09:20 +00:00
|
|
|
match opcode {
|
|
|
|
|
Opcode::Flush => {
|
|
|
|
|
display.update();
|
|
|
|
|
display.redraw();
|
|
|
|
|
},
|
2020-12-02 17:48:10 +00:00
|
|
|
Opcode::Clear => {
|
|
|
|
|
let mut r = Rectangle::full_screen();
|
|
|
|
|
r.style = DrawStyle::new(PixelColor::Light, PixelColor::Light, 0);
|
|
|
|
|
op::rectangle(display.native_buffer(), r)
|
2020-08-29 14:09:20 +00:00
|
|
|
}
|
2020-12-02 17:48:10 +00:00
|
|
|
Opcode::Line(l) => {
|
|
|
|
|
op::line(display.native_buffer(), l);
|
2020-08-29 14:09:20 +00:00
|
|
|
}
|
2020-12-02 17:48:10 +00:00
|
|
|
Opcode::Rectangle(r) => {
|
|
|
|
|
op::rectangle(display.native_buffer(), r);
|
2020-08-29 14:09:20 +00:00
|
|
|
}
|
2020-12-02 17:48:10 +00:00
|
|
|
Opcode::Circle(c) => {
|
|
|
|
|
op::circle(display.native_buffer(), c);
|
2020-08-29 14:09:20 +00:00
|
|
|
}
|
2020-10-30 02:22:03 +00:00
|
|
|
Opcode::String(s) => {
|
2020-11-27 18:05:55 +00:00
|
|
|
blitstr::paint_str(display.native_buffer(), current_string_clip.into(), &mut current_cursor, current_glyph.into(), s);
|
2020-11-23 07:42:58 +00:00
|
|
|
}
|
2020-12-02 17:48:10 +00:00
|
|
|
Opcode::SetGlyphStyle(glyph) => {
|
2020-11-23 07:42:58 +00:00
|
|
|
current_glyph = glyph;
|
2020-10-30 02:22:03 +00:00
|
|
|
}
|
2020-11-27 18:05:55 +00:00
|
|
|
Opcode::SetCursor(c) => {
|
|
|
|
|
current_cursor = c;
|
|
|
|
|
}
|
|
|
|
|
Opcode::GetCursor => {
|
|
|
|
|
let pt: api::Point = api::Point::new(current_cursor.pt.x as i16, current_cursor.pt.y as i16);
|
|
|
|
|
xous::return_scalar2(
|
|
|
|
|
msg.sender,
|
|
|
|
|
pt.into(),
|
|
|
|
|
current_cursor.line_height,
|
|
|
|
|
)
|
|
|
|
|
.expect("GFX: could not return GetCursor request");
|
|
|
|
|
}
|
2020-11-26 19:33:44 +00:00
|
|
|
Opcode::SetStringClipping(r) => {
|
2020-11-27 18:05:55 +00:00
|
|
|
current_string_clip = r;
|
2020-11-26 19:33:44 +00:00
|
|
|
}
|
2020-11-23 06:55:56 +00:00
|
|
|
Opcode::ScreenSize => {
|
|
|
|
|
xous::return_scalar2(
|
|
|
|
|
msg.sender,
|
|
|
|
|
336 as usize,
|
|
|
|
|
536 as usize,
|
|
|
|
|
)
|
|
|
|
|
.expect("GFX: couldn't return ScreenSize request");
|
|
|
|
|
}
|
2020-12-02 17:48:10 +00:00
|
|
|
Opcode::QueryGlyphStyle => {
|
2020-11-23 07:42:58 +00:00
|
|
|
xous::return_scalar2(
|
|
|
|
|
msg.sender,
|
2020-12-02 17:48:10 +00:00
|
|
|
current_glyph.into(),
|
|
|
|
|
blitstr::glyph_to_height_hint(current_glyph),
|
2020-11-23 07:42:58 +00:00
|
|
|
)
|
|
|
|
|
.expect("GFX: could not return QueryGlyph request");
|
|
|
|
|
}
|
2020-08-29 14:09:20 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
2020-11-27 18:05:55 +00:00
|
|
|
error!("Couldn't convert opcode");
|
2020-08-29 14:09:20 +00:00
|
|
|
}
|
2020-08-14 10:46:23 +00:00
|
|
|
display.update();
|
|
|
|
|
}
|
2020-08-14 09:25:20 +00:00
|
|
|
}
|