2020-08-14 09:25:20 +00:00
|
|
|
#![cfg_attr(target_os = "none", no_std)]
|
|
|
|
|
#![cfg_attr(target_os = "none", no_main)]
|
|
|
|
|
|
2020-10-30 02:22:03 +00:00
|
|
|
#[cfg(target_os = "none")]
|
2020-10-13 17:28:10 +00:00
|
|
|
#[macro_use]
|
|
|
|
|
mod debug;
|
|
|
|
|
|
2020-10-30 13:27:06 +00:00
|
|
|
use log::info;
|
|
|
|
|
|
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;
|
|
|
|
|
mod fonts;
|
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-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-10-30 02:22:03 +00:00
|
|
|
let mut current_color = api::Color::from(0usize);
|
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-10-30 02:22:03 +00:00
|
|
|
Opcode::Clear(_color) => {
|
|
|
|
|
op::clear_region(display.native_buffer(), op::ClipRegion::screen());
|
2020-08-29 14:09:20 +00:00
|
|
|
}
|
|
|
|
|
Opcode::Line(start, end) => {
|
2020-10-30 13:27:06 +00:00
|
|
|
info!("GFX: Drawing line from {:?} to {:?}", start, end);
|
2020-10-30 02:22:03 +00:00
|
|
|
op::line(display.native_buffer(), start.x as _, start.y as _, end.x as _, end.y as _, if current_color.color == 0 { op::PixelColor::Off } else {op::PixelColor::On });
|
2020-08-29 14:09:20 +00:00
|
|
|
}
|
|
|
|
|
Opcode::Rectangle(start, end) => {
|
2020-10-30 02:22:03 +00:00
|
|
|
todo!();
|
|
|
|
|
// Line::new(start.into(), end.into())
|
|
|
|
|
// .into_styled(current_style)
|
|
|
|
|
// .draw(&mut display)
|
|
|
|
|
// .ok();
|
2020-08-29 14:09:20 +00:00
|
|
|
}
|
|
|
|
|
Opcode::Circle(mid, radius) => {
|
2020-11-22 16:40:40 +00:00
|
|
|
info!("GFX: Drawing cicrle at {:?} radius {:?}", mid, radius);
|
|
|
|
|
op::circle(display.native_buffer(), mid.x as _, mid.y as _, radius as _, 1, op::PixelColor::On);
|
2020-08-29 14:09:20 +00:00
|
|
|
}
|
|
|
|
|
Opcode::Style(stroke_width, stroke_color, fill_color) => {
|
2020-10-30 02:22:03 +00:00
|
|
|
current_color = stroke_color;
|
|
|
|
|
// todo!();
|
|
|
|
|
// current_style.stroke_width = stroke_width;
|
|
|
|
|
// current_style.stroke_color = Some(if stroke_color.color == 0 {
|
|
|
|
|
// BinaryColor::Off
|
|
|
|
|
// } else {
|
|
|
|
|
// BinaryColor::On
|
|
|
|
|
// });
|
|
|
|
|
// current_style.fill_color = Some(if fill_color.color == 0 {
|
|
|
|
|
// BinaryColor::Off
|
|
|
|
|
// } else {
|
|
|
|
|
// BinaryColor::On
|
|
|
|
|
// });
|
|
|
|
|
}
|
|
|
|
|
Opcode::ClearRegion(rect) => {
|
|
|
|
|
op::clear_region(display.native_buffer(), op::ClipRegion {
|
|
|
|
|
x0: rect.x0 as _,
|
|
|
|
|
y0: rect.y0 as _,
|
|
|
|
|
x1: rect.x1 as _,
|
|
|
|
|
y1: rect.y1 as _,
|
2020-08-29 14:09:20 +00:00
|
|
|
});
|
|
|
|
|
}
|
2020-10-30 02:22:03 +00:00
|
|
|
Opcode::String(s) => {
|
|
|
|
|
op::string_regular_left(display.native_buffer(), op::ClipRegion::screen(), s);
|
|
|
|
|
}
|
2020-08-29 14:09:20 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
2020-10-30 13:27:06 +00:00
|
|
|
// info!("Couldn't convert opcode");
|
2020-08-29 14:09:20 +00:00
|
|
|
}
|
2020-10-30 02:22:03 +00:00
|
|
|
// if let Some(mem) = msg.body.memory() {
|
|
|
|
|
// xous::return_memory(msg.sender, *mem).expect("couldn't return message");
|
|
|
|
|
// }
|
2020-08-14 10:46:23 +00:00
|
|
|
display.update();
|
|
|
|
|
}
|
2020-08-14 09:25:20 +00:00
|
|
|
}
|