2020-08-14 09:25:20 +00:00
|
|
|
#![cfg_attr(target_os = "none", no_std)]
|
|
|
|
|
#![cfg_attr(target_os = "none", no_main)]
|
|
|
|
|
|
|
|
|
|
mod backend;
|
2020-08-14 10:46:23 +00:00
|
|
|
use backend::XousDisplay;
|
|
|
|
|
|
|
|
|
|
use embedded_graphics::{
|
|
|
|
|
fonts::{Font6x8, Text},
|
|
|
|
|
pixelcolor::BinaryColor,
|
|
|
|
|
prelude::*,
|
|
|
|
|
primitives::{Circle, Rectangle, Triangle},
|
|
|
|
|
style::{PrimitiveStyle, TextStyle},
|
|
|
|
|
};
|
2020-08-14 09:25:20 +00:00
|
|
|
|
|
|
|
|
#[xous::xous_main]
|
|
|
|
|
fn xmain() -> ! {
|
2020-08-14 10:46:23 +00:00
|
|
|
// Create a new monochrome simulator display with 128x64 pixels.
|
|
|
|
|
let mut display = XousDisplay::new();
|
|
|
|
|
|
|
|
|
|
// Create styles used by the drawing operations.
|
|
|
|
|
let thin_stroke = PrimitiveStyle::with_stroke(BinaryColor::On, 1);
|
|
|
|
|
let thick_stroke = PrimitiveStyle::with_stroke(BinaryColor::On, 3);
|
|
|
|
|
let fill = PrimitiveStyle::with_fill(BinaryColor::On);
|
|
|
|
|
let text_style = TextStyle::new(Font6x8, BinaryColor::On);
|
|
|
|
|
|
|
|
|
|
let yoffset = 10;
|
|
|
|
|
|
|
|
|
|
// Draw a 3px wide outline around the display.
|
|
|
|
|
let bottom_right = Point::zero() + display.size() - Point::new(1, 1);
|
|
|
|
|
Rectangle::new(Point::zero(), bottom_right)
|
|
|
|
|
.into_styled(thick_stroke)
|
|
|
|
|
.draw(&mut display)
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
// Draw a triangle.
|
|
|
|
|
Triangle::new(
|
|
|
|
|
Point::new(16, 16 + yoffset),
|
|
|
|
|
Point::new(16 + 16, 16 + yoffset),
|
|
|
|
|
Point::new(16 + 8, yoffset),
|
|
|
|
|
)
|
|
|
|
|
.into_styled(thin_stroke)
|
|
|
|
|
.draw(&mut display)
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
// Draw a filled square
|
|
|
|
|
Rectangle::new(Point::new(52, yoffset), Point::new(52 + 16, 16 + yoffset))
|
|
|
|
|
.into_styled(fill)
|
|
|
|
|
.draw(&mut display)
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
// Draw a circle with a 3px wide stroke.
|
|
|
|
|
Circle::new(Point::new(96, yoffset + 8), 8)
|
|
|
|
|
.into_styled(thick_stroke)
|
|
|
|
|
.draw(&mut display)
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
// Draw centered text.
|
|
|
|
|
let text = "embedded-graphics";
|
|
|
|
|
let width = text.len() as i32 * 6;
|
|
|
|
|
Text::new(text, Point::new(64 - width / 2, 40))
|
|
|
|
|
.into_styled(text_style)
|
|
|
|
|
.draw(&mut display)
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
display.redraw();
|
|
|
|
|
|
|
|
|
|
loop {
|
|
|
|
|
display.update();
|
|
|
|
|
}
|
2020-08-14 09:25:20 +00:00
|
|
|
}
|