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-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-11-27 18:05:55 +00:00
|
|
|
let mut current_glyph = blitstr::fonts::GlyphSet::Regular;
|
|
|
|
|
let mut current_string_clip = blitstr::Rect::full_screen();
|
|
|
|
|
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-10-30 02:22:03 +00:00
|
|
|
Opcode::Clear(_color) => {
|
2020-11-27 18:05:55 +00:00
|
|
|
blitstr::clear_region(display.native_buffer(), blitstr::Rect::full_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);
|
2020-11-22 19:49:09 +00:00
|
|
|
op::circle(display.native_buffer(), mid.x as _, mid.y as _, radius as _, 0, 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) => {
|
2020-11-27 18:05:55 +00:00
|
|
|
blitstr::clear_region(display.native_buffer(), blitstr::Rect::new(
|
|
|
|
|
rect.min.x as _,
|
|
|
|
|
rect.min.y as _,
|
|
|
|
|
rect.max.x as _,
|
|
|
|
|
rect.max.y as _,));
|
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
|
|
|
}
|
|
|
|
|
Opcode::SetGlyph(glyph) => {
|
|
|
|
|
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-11-23 07:42:58 +00:00
|
|
|
Opcode::QueryGlyph => {
|
|
|
|
|
xous::return_scalar2(
|
|
|
|
|
msg.sender,
|
2020-11-27 18:05:55 +00:00
|
|
|
blitstr::fonts::glyph_to_arg(current_glyph),
|
|
|
|
|
blitstr::fonts::glyph_to_height(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
|
|
|
}
|