mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
add bitmap rendering API for baosec targets
This commit is contained in:
parent
54ed7a1e8d
commit
4f37317427
4 changed files with 93 additions and 0 deletions
|
|
@ -512,6 +512,56 @@ impl<'a> Oled128x128<'a> {
|
||||||
crate::board::assert_periph_reset(self.iox, false);
|
crate::board::assert_periph_reset(self.iox, false);
|
||||||
self.powerdown = false;
|
self.powerdown = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
pub fn render_bitmap(&mut self, bitmap: ux_api::service::api::BaosecBitmap) {
|
||||||
|
const W: isize = WIDTH as _;
|
||||||
|
const H: isize = LINES as _;
|
||||||
|
|
||||||
|
// Clamp bounding box to valid bitmap dimensions.
|
||||||
|
// If br > 128, truncate. If tl < 0, clamp to 0.
|
||||||
|
let src_x0 = bitmap.bounding_box.tl.x.max(0);
|
||||||
|
let src_y0 = bitmap.bounding_box.tl.y.max(0);
|
||||||
|
let src_x1 = bitmap.bounding_box.br.x.min(W);
|
||||||
|
let src_y1 = bitmap.bounding_box.br.y.min(H);
|
||||||
|
|
||||||
|
for src_y in src_y0..src_y1 {
|
||||||
|
// Map this bitmap row to its destination row in the framebuffer.
|
||||||
|
let dst_y = src_y + bitmap.top_left.y;
|
||||||
|
|
||||||
|
// Skip rows that land outside the framebuffer.
|
||||||
|
if dst_y < 0 || dst_y >= H {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for src_x in src_x0..src_x1 {
|
||||||
|
// Map this bitmap column to its destination column.
|
||||||
|
let dst_x = src_x + bitmap.top_left.x;
|
||||||
|
|
||||||
|
// Skip columns that land outside the framebuffer.
|
||||||
|
if dst_x < 0 || dst_x >= W {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- read source bit ---
|
||||||
|
let src_linear = (src_x + src_y * W) as usize;
|
||||||
|
let src_word = src_linear >> 5; // / 32
|
||||||
|
let src_shift = src_linear & 0x1F; // % 32
|
||||||
|
let on = (bitmap.bits[src_word] >> src_shift) & 1;
|
||||||
|
|
||||||
|
// --- write destination bit ---
|
||||||
|
let dst_linear = (dst_x + dst_y * W) as usize;
|
||||||
|
let dst_word = dst_linear >> 5;
|
||||||
|
let dst_shift = dst_linear & 0x1F;
|
||||||
|
|
||||||
|
if on != 0 {
|
||||||
|
self.buffer[dst_word] |= 1 << dst_shift;
|
||||||
|
} else {
|
||||||
|
self.buffer[dst_word] &= !(1 << dst_shift);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> FrameBuffer for Oled128x128<'a> {
|
impl<'a> FrameBuffer for Oled128x128<'a> {
|
||||||
|
|
|
||||||
|
|
@ -107,6 +107,9 @@ pub enum GfxOpcode {
|
||||||
PowerDown,
|
PowerDown,
|
||||||
#[cfg(feature = "board-baosec")]
|
#[cfg(feature = "board-baosec")]
|
||||||
PowerUp,
|
PowerUp,
|
||||||
|
#[cfg(feature = "board-baosec")]
|
||||||
|
/// This call is specific and highly optimized to the display on Baosec
|
||||||
|
BaosecBitmap,
|
||||||
|
|
||||||
/// Gutter for invalid calls
|
/// Gutter for invalid calls
|
||||||
InvalidCall,
|
InvalidCall,
|
||||||
|
|
@ -154,3 +157,14 @@ pub struct KeyboardRegistration {
|
||||||
pub server_name: String,
|
pub server_name: String,
|
||||||
pub listener_op_id: usize,
|
pub listener_op_id: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "board-baosec")]
|
||||||
|
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Clone)]
|
||||||
|
pub struct BaosecBitmap {
|
||||||
|
// exactly enough for a 128x128 black and white display = 2048 bytes
|
||||||
|
pub bits: [u32; 512],
|
||||||
|
// top left corner of the bitmap
|
||||||
|
pub top_left: crate::minigfx::Point,
|
||||||
|
// bounding box of the bitmap - if we want only a portion of the bitmap to be drawn
|
||||||
|
pub bounding_box: crate::minigfx::Rectangle,
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -769,6 +769,29 @@ impl Gfx {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "board-baosec")]
|
||||||
|
pub fn bitmap(
|
||||||
|
&self,
|
||||||
|
bitmap: &[u32],
|
||||||
|
top_left: Option<Point>,
|
||||||
|
bounding_box: Option<Rectangle>,
|
||||||
|
) -> Result<(), xous::Error> {
|
||||||
|
let mut bmp = BaosecBitmap {
|
||||||
|
bits: [0u32; 512],
|
||||||
|
top_left: top_left.unwrap_or(Point::new(0, 0)),
|
||||||
|
bounding_box: bounding_box.unwrap_or(Rectangle {
|
||||||
|
tl: Point::new(0, 0),
|
||||||
|
// br is *exclusive*
|
||||||
|
br: Point::new(128, 128),
|
||||||
|
style: DrawStyle { fill_color: None, stroke_color: None, stroke_width: 0 },
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
bmp.bits[..bitmap.len().min(512)].copy_from_slice(&bitmap[..bitmap.len().min(512)]);
|
||||||
|
let mut buf = Buffer::into_buf(bmp).unwrap();
|
||||||
|
buf.lend_mut(self.conn, GfxOpcode::BaosecBitmap.to_u32().unwrap())?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "hosted-baosec")]
|
#[cfg(feature = "hosted-baosec")]
|
||||||
pub fn acquire_qr(&self) -> Result<QrAcquisition, xous::Error> {
|
pub fn acquire_qr(&self) -> Result<QrAcquisition, xous::Error> {
|
||||||
let dummy = "otpauth://totp/ACME%20Co:john.doe@email.com?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ&issuer=ACME%20Co&algorithm=SHA1&digits=6&period=30".to_string();
|
let dummy = "otpauth://totp/ACME%20Co:john.doe@email.com?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ&issuer=ACME%20Co&algorithm=SHA1&digits=6&period=30".to_string();
|
||||||
|
|
|
||||||
|
|
@ -861,6 +861,12 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! {
|
||||||
scalar.arg1 = 1;
|
scalar.arg1 = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "board-baosec")]
|
||||||
|
GfxOpcode::BaosecBitmap => {
|
||||||
|
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||||
|
let bitmap = buffer.to_original::<BaosecBitmap, _>().unwrap();
|
||||||
|
display.render_bitmap(bitmap);
|
||||||
|
}
|
||||||
GfxOpcode::Quit => break,
|
GfxOpcode::Quit => break,
|
||||||
_ => {
|
_ => {
|
||||||
// This is perfectly normal because not all opcodes are handled by all platforms.
|
// This is perfectly normal because not all opcodes are handled by all platforms.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue