2020-08-14 09:25:20 +00:00
|
|
|
#![cfg_attr(target_os = "none", no_std)]
|
|
|
|
|
#![cfg_attr(target_os = "none", no_main)]
|
|
|
|
|
|
2021-01-03 10:31:51 +00:00
|
|
|
use log::{error, info};
|
2020-10-30 13:27:06 +00:00
|
|
|
|
2020-08-29 14:09:20 +00:00
|
|
|
mod api;
|
|
|
|
|
use api::Opcode;
|
|
|
|
|
|
2021-02-14 20:42:30 +00:00
|
|
|
use xous::buffer;
|
|
|
|
|
use core::pin::Pin;
|
|
|
|
|
use rkyv::{archived_value, Unarchive};
|
|
|
|
|
use core::convert::TryInto;
|
|
|
|
|
|
|
|
|
|
mod backend;
|
|
|
|
|
use backend::XousDisplay;
|
|
|
|
|
|
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
|
|
|
|
2021-01-03 10:31:51 +00:00
|
|
|
use api::{DrawStyle, PixelColor, Rectangle};
|
2021-01-20 08:22:38 +00:00
|
|
|
use blitstr_ref as blitstr;
|
2020-11-27 18:05:55 +00:00
|
|
|
|
2021-02-26 18:12:19 +00:00
|
|
|
mod fontmap;
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2021-02-26 18:12:19 +00:00
|
|
|
#[cfg(target_os = "none")]
|
|
|
|
|
fn map_fonts() {
|
|
|
|
|
info!("GFX: mapping fonts");
|
|
|
|
|
// this maps an extra page if the total length happens to fall on a 4096-byte boundary, but this is ok
|
|
|
|
|
// because the reserved area is much larger
|
|
|
|
|
let fontlen: u32 = ((fontmap::FONT_TOTAL_LEN as u32) & 0xFFFF_F000) + 0x1000;
|
2021-02-27 06:35:53 +00:00
|
|
|
info!("GFX: requesting map of length 0x{:08x} at 0x{:08x}", fontlen, fontmap::FONT_BASE);
|
2021-02-26 18:12:19 +00:00
|
|
|
let fontregion = xous::syscall::map_memory(
|
|
|
|
|
xous::MemoryAddress::new(fontmap::FONT_BASE),
|
|
|
|
|
None,
|
|
|
|
|
fontlen as usize,
|
|
|
|
|
xous::MemoryFlags::R,
|
|
|
|
|
).expect("GFX: couldn't map fonts");
|
|
|
|
|
info!("GFX: font base at 0x{:08x}, len of 0x{:08x}", usize::from(fontregion.addr), usize::from(fontregion.size));
|
|
|
|
|
|
2021-02-27 06:35:53 +00:00
|
|
|
info!("GFX: mapping regular font to 0x{:08x}", usize::from(fontregion.addr) + fontmap::REGULAR_OFFSET as usize);
|
2021-02-26 18:12:19 +00:00
|
|
|
blitstr::map_font(blitstr::GlyphData::Emoji((usize::from(fontregion.addr) + fontmap::EMOJI_OFFSET) as usize));
|
|
|
|
|
blitstr::map_font(blitstr::GlyphData::Hanzi((usize::from(fontregion.addr) + fontmap::HANZI_OFFSET) as usize));
|
|
|
|
|
blitstr::map_font(blitstr::GlyphData::Regular((usize::from(fontregion.addr) + fontmap::REGULAR_OFFSET) as usize));
|
|
|
|
|
blitstr::map_font(blitstr::GlyphData::Small((usize::from(fontregion.addr) + fontmap::SMALL_OFFSET) as usize));
|
|
|
|
|
blitstr::map_font(blitstr::GlyphData::Bold((usize::from(fontregion.addr) + fontmap::BOLD_OFFSET) as usize));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(not(target_os = "none"))]
|
|
|
|
|
fn map_fonts() {
|
|
|
|
|
// does nothing
|
|
|
|
|
}
|
|
|
|
|
|
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();
|
2021-02-15 11:16:21 +00:00
|
|
|
info!("GFX: my PID is {}", xous::process::id());
|
2020-10-30 13:27:06 +00:00
|
|
|
|
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
|
|
|
|
2021-02-26 18:12:19 +00:00
|
|
|
map_fonts();
|
|
|
|
|
|
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
|
|
|
|
2021-01-08 18:12:01 +00:00
|
|
|
let sid = xous_names::register_name(xous::names::SERVER_NAME_GFX).expect("GFX: can't register server");
|
2021-01-04 20:45:23 +00:00
|
|
|
info!("GFX: Server listening on address {:?}", sid);
|
2021-01-08 18:12:01 +00:00
|
|
|
|
2021-01-12 20:39:04 +00:00
|
|
|
display.redraw();
|
2020-08-14 10:46:23 +00:00
|
|
|
loop {
|
2020-08-29 14:09:20 +00:00
|
|
|
let msg = xous::receive_message(sid).unwrap();
|
2021-02-27 06:35:53 +00:00
|
|
|
//info!("GFX: Message: {:?}", msg);
|
2021-02-14 20:42:30 +00:00
|
|
|
if let xous::Message::Borrow(m) = &msg.body {
|
2021-02-17 15:29:20 +00:00
|
|
|
let buf = unsafe { buffer::XousBuffer::from_memory_message(m) };
|
2021-02-14 20:42:30 +00:00
|
|
|
let bytes = Pin::new(buf.as_ref());
|
|
|
|
|
let value = unsafe {
|
|
|
|
|
archived_value::<api::Opcode>(&bytes, m.id.try_into().unwrap())
|
|
|
|
|
};
|
2021-02-17 15:29:20 +00:00
|
|
|
match &*value {
|
2021-02-14 20:42:30 +00:00
|
|
|
rkyv::Archived::<api::Opcode>::String(rkyv_s) => {
|
|
|
|
|
let s: xous::String<4096> = rkyv_s.unarchive();
|
2021-02-27 06:35:53 +00:00
|
|
|
//info!("GFX: unarchived string: {:?}", s);
|
2021-01-03 10:31:51 +00:00
|
|
|
blitstr::paint_str(
|
|
|
|
|
display.native_buffer(),
|
|
|
|
|
current_string_clip.into(),
|
|
|
|
|
&mut current_cursor,
|
|
|
|
|
current_glyph.into(),
|
2021-02-14 20:42:30 +00:00
|
|
|
s.as_str().unwrap(),
|
2021-01-12 20:39:04 +00:00
|
|
|
false,
|
2021-01-18 16:05:33 +00:00
|
|
|
blitstr::xor_char
|
2021-01-12 20:39:04 +00:00
|
|
|
);
|
2021-02-27 06:35:53 +00:00
|
|
|
//info!("GFX: string painted");
|
2021-02-14 20:42:30 +00:00
|
|
|
},
|
|
|
|
|
rkyv::Archived::<api::Opcode>::StringXor(rkyv_s) => {
|
|
|
|
|
let s: xous::String<4096> = rkyv_s.unarchive();
|
2021-01-12 20:39:04 +00:00
|
|
|
blitstr::paint_str(
|
|
|
|
|
display.native_buffer(),
|
|
|
|
|
current_string_clip.into(),
|
|
|
|
|
&mut current_cursor,
|
|
|
|
|
current_glyph.into(),
|
2021-02-14 20:42:30 +00:00
|
|
|
s.as_str().unwrap(),
|
2021-01-12 20:39:04 +00:00
|
|
|
true,
|
2021-01-18 16:05:33 +00:00
|
|
|
blitstr::xor_char
|
|
|
|
|
);
|
2021-02-14 20:42:30 +00:00
|
|
|
},
|
|
|
|
|
rkyv::Archived::<api::Opcode>::SimulateString(rkyv_s) => {
|
|
|
|
|
let s: xous::String<4096> = rkyv_s.unarchive();
|
2021-01-18 16:05:33 +00:00
|
|
|
blitstr::paint_str(
|
|
|
|
|
display.native_buffer(),
|
|
|
|
|
current_string_clip.into(),
|
|
|
|
|
&mut current_cursor,
|
|
|
|
|
current_glyph.into(),
|
2021-02-14 20:42:30 +00:00
|
|
|
s.as_str().unwrap(),
|
2021-01-18 16:05:33 +00:00
|
|
|
false,
|
|
|
|
|
blitstr::simulate_char
|
2021-01-03 10:31:51 +00:00
|
|
|
);
|
2021-02-14 20:42:30 +00:00
|
|
|
},
|
|
|
|
|
_ => panic!("GFX: invalid response from server -- corruption occurred in MemoryMessage")
|
|
|
|
|
};
|
|
|
|
|
} else if let Ok(opcode) = Opcode::try_from(&msg.body) {
|
|
|
|
|
// info!("GFX: Opcode: {:?}", opcode);
|
|
|
|
|
match opcode {
|
|
|
|
|
Opcode::Flush => {
|
|
|
|
|
display.update();
|
|
|
|
|
display.redraw();
|
|
|
|
|
}
|
|
|
|
|
Opcode::Clear => {
|
|
|
|
|
let mut r = Rectangle::full_screen();
|
|
|
|
|
r.style = DrawStyle::new(PixelColor::Light, PixelColor::Light, 0);
|
|
|
|
|
op::rectangle(display.native_buffer(), r)
|
|
|
|
|
}
|
|
|
|
|
Opcode::Line(l) => {
|
|
|
|
|
op::line(display.native_buffer(), l);
|
|
|
|
|
}
|
|
|
|
|
Opcode::Rectangle(r) => {
|
|
|
|
|
op::rectangle(display.native_buffer(), r);
|
|
|
|
|
}
|
|
|
|
|
Opcode::Circle(c) => {
|
|
|
|
|
op::circle(display.native_buffer(), c);
|
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 => {
|
2021-01-03 10:31:51 +00:00
|
|
|
let pt: api::Point =
|
|
|
|
|
api::Point::new(current_cursor.pt.x as i16, current_cursor.pt.y as i16);
|
2021-01-21 16:27:45 +00:00
|
|
|
xous::return_scalar2(msg.sender, pt.into(), current_cursor.line_height as usize)
|
2021-01-03 10:31:51 +00:00
|
|
|
.expect("GFX: could not return GetCursor request");
|
2020-11-27 18:05:55 +00:00
|
|
|
}
|
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 => {
|
2021-01-03 10:31:51 +00:00
|
|
|
xous::return_scalar2(msg.sender, 336 as usize, 536 as usize)
|
|
|
|
|
.expect("GFX: couldn't return ScreenSize request");
|
2020-11-23 06:55:56 +00:00
|
|
|
}
|
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");
|
|
|
|
|
}
|
2021-01-17 20:12:40 +00:00
|
|
|
Opcode::QueryGlyphProps(glyph) => {
|
|
|
|
|
xous::return_scalar2(
|
|
|
|
|
msg.sender,
|
|
|
|
|
glyph.into(),
|
|
|
|
|
blitstr::glyph_to_height_hint(glyph),
|
|
|
|
|
)
|
|
|
|
|
.expect("GFX: could not return QueryGlyphProps request");
|
|
|
|
|
}
|
2021-02-14 20:42:30 +00:00
|
|
|
/*
|
2021-01-18 20:54:54 +00:00
|
|
|
Opcode::TextView(tv) => {
|
2021-01-19 19:18:13 +00:00
|
|
|
info!("GFX: got draw of '{:?}'", tv);
|
2021-01-19 10:58:57 +00:00
|
|
|
op::textview(display.native_buffer(), tv);
|
2021-02-14 20:42:30 +00:00
|
|
|
}*/
|
|
|
|
|
_ => panic!("GFX: received opcode scalar that is not handled")
|
2020-08-29 14:09:20 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
2021-02-14 20:42:30 +00:00
|
|
|
error!("GFX: 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
|
|
|
}
|