mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-20 09:03:28 +00:00
examples: graphics-server: use try_ calls for messaging
Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
d057cba0fb
commit
8d438e4796
3 changed files with 40 additions and 34 deletions
|
|
@ -106,31 +106,33 @@ impl DrawTarget<BinaryColor> for XousDisplay {
|
||||||
/// Draw a `Pixel` that has a color defined as `BinaryColor`.
|
/// Draw a `Pixel` that has a color defined as `BinaryColor`.
|
||||||
fn draw_pixel(&mut self, pixel: Pixel<BinaryColor>) -> Result<(), Self::Error> {
|
fn draw_pixel(&mut self, pixel: Pixel<BinaryColor>) -> Result<(), Self::Error> {
|
||||||
let Pixel(coord, color) = pixel;
|
let Pixel(coord, color) = pixel;
|
||||||
let framebuffer = self.fb.as_mut_ptr() as *mut u32;
|
if coord.x < FB_WIDTH_PIXELS as _ && coord.y < FB_LINES as _ {
|
||||||
let offset = (coord.x / 32 + coord.y * FB_WIDTH_WORDS as i32) as usize;
|
let framebuffer = self.fb.as_mut_ptr() as *mut u32;
|
||||||
match color {
|
let offset = (coord.x / 32 + coord.y * FB_WIDTH_WORDS as i32) as usize;
|
||||||
BinaryColor::Off => {
|
match color {
|
||||||
unsafe {
|
BinaryColor::Off => {
|
||||||
framebuffer.add(offset).write_volatile(
|
unsafe {
|
||||||
framebuffer.add(offset).read_volatile() | (1 << (coord.x % 32)),
|
framebuffer.add(offset).write_volatile(
|
||||||
)
|
framebuffer.add(offset).read_volatile() | (1 << (coord.x % 32)),
|
||||||
};
|
)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
BinaryColor::On => {
|
||||||
|
unsafe {
|
||||||
|
framebuffer.add(offset).write_volatile(
|
||||||
|
framebuffer.add(offset).read_volatile() & !(1 << (coord.x % 32)),
|
||||||
|
)
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
BinaryColor::On => {
|
|
||||||
unsafe {
|
|
||||||
framebuffer.add(offset).write_volatile(
|
|
||||||
framebuffer.add(offset).read_volatile() & !(1 << (coord.x % 32)),
|
|
||||||
)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// set the dirty bit on the line
|
// set the dirty bit on the line
|
||||||
unsafe {
|
unsafe {
|
||||||
framebuffer
|
framebuffer
|
||||||
.add(offset)
|
.add(offset)
|
||||||
.write_volatile(framebuffer.add(offset).read_volatile() | 0x1_0000)
|
.write_volatile(framebuffer.add(offset).read_volatile() | 0x1_0000)
|
||||||
};
|
};
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,11 +59,15 @@ impl DrawTarget<BinaryColor> for XousDisplay {
|
||||||
/// Draw a `Pixel` that has a color defined as `Gray8`.
|
/// Draw a `Pixel` that has a color defined as `Gray8`.
|
||||||
fn draw_pixel(&mut self, pixel: Pixel<BinaryColor>) -> Result<(), Self::Error> {
|
fn draw_pixel(&mut self, pixel: Pixel<BinaryColor>) -> Result<(), Self::Error> {
|
||||||
let Pixel(point, color) = pixel;
|
let Pixel(point, color) = pixel;
|
||||||
self.buffer[(point.y * (WIDTH as i32) + point.x) as usize] = if color == BinaryColor::On {
|
let w = WIDTH as _;
|
||||||
LIGHT_COLOUR
|
let h = HEIGHT as _;
|
||||||
} else {
|
if point.x < w && point.y < h && point.x >= 0 && point.y >= 0 {
|
||||||
DARK_COLOUR
|
self.buffer[(point.y * w + point.x) as usize] = if color == BinaryColor::On {
|
||||||
};
|
LIGHT_COLOUR
|
||||||
|
} else {
|
||||||
|
DARK_COLOUR
|
||||||
|
};
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,24 +3,24 @@
|
||||||
pub mod api;
|
pub mod api;
|
||||||
pub use api::{Point, Color};
|
pub use api::{Point, Color};
|
||||||
|
|
||||||
use xous::{send_message, CID};
|
use xous::{try_send_message, CID};
|
||||||
|
|
||||||
pub fn draw_line(cid: CID, start: Point, end: Point) -> Result<(), xous::Error> {
|
pub fn draw_line(cid: CID, start: Point, end: Point) -> Result<(), xous::Error> {
|
||||||
send_message(cid, api::Opcode::Line(start, end).into())
|
try_send_message(cid, api::Opcode::Line(start, end).into())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_circle(cid: CID, center: Point, radius: u32) -> Result<(), xous::Error> {
|
pub fn draw_circle(cid: CID, center: Point, radius: u32) -> Result<(), xous::Error> {
|
||||||
send_message(cid, api::Opcode::Circle(center, radius).into())
|
try_send_message(cid, api::Opcode::Circle(center, radius).into())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_rectangle(cid: CID, start: Point, end: Point) -> Result<(), xous::Error> {
|
pub fn draw_rectangle(cid: CID, start: Point, end: Point) -> Result<(), xous::Error> {
|
||||||
send_message(cid, api::Opcode::Rectangle(start, end).into())
|
try_send_message(cid, api::Opcode::Rectangle(start, end).into())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_style(cid: CID, width: u32, stroke: Color, fill: Color) -> Result<(), xous::Error> {
|
pub fn set_style(cid: CID, width: u32, stroke: Color, fill: Color) -> Result<(), xous::Error> {
|
||||||
send_message(cid, api::Opcode::Style(width, stroke, fill).into())
|
try_send_message(cid, api::Opcode::Style(width, stroke, fill).into())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn flush(cid: CID) -> Result<(), xous::Error> {
|
pub fn flush(cid: CID) -> Result<(), xous::Error> {
|
||||||
send_message(cid, api::Opcode::Flush.into())
|
try_send_message(cid, api::Opcode::Flush.into())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue