feat(display-server): add DisplayServer<F: Framebuffer> with protocol, mock adapter, and tests

This commit is contained in:
2026-10-18 03:03:58 +02:00
parent c14fe50c23
commit b6cfea814a
10 changed files with 336 additions and 12 deletions

View File

@@ -0,0 +1,76 @@
use server_framework::{Decode, Encode};
#[derive(Debug, PartialEq)]
pub enum DisplayRequest {
DrawRect { x: u16, y: u16, w: u16, h: u16, color: u32 },
Clear { color: u32 },
Flush,
GetDimensions,
}
#[derive(Debug, PartialEq)]
pub enum DisplayResponse {
Ok,
Dimensions { width: u16, height: u16 },
Error,
}
impl Encode for DisplayRequest {
fn encode(&self) -> [usize; 4] {
match self {
DisplayRequest::DrawRect { x, y, w, h, color } => {
let xy = (*x as usize) | ((*y as usize) << 16);
let wh = (*w as usize) | ((*h as usize) << 16);
[0, xy, wh, *color as usize]
}
DisplayRequest::Clear { color } => [1, *color as usize, 0, 0],
DisplayRequest::Flush => [2, 0, 0, 0],
DisplayRequest::GetDimensions => [3, 0, 0, 0],
}
}
}
impl Decode for DisplayRequest {
fn decode(words: [usize; 4]) -> Option<Self> {
match words[0] {
0 => {
let x = (words[1] & 0xFFFF) as u16;
let y = ((words[1] >> 16) & 0xFFFF) as u16;
let w = (words[2] & 0xFFFF) as u16;
let h = ((words[2] >> 16) & 0xFFFF) as u16;
let color = words[3] as u32;
Some(DisplayRequest::DrawRect { x, y, w, h, color })
}
1 => Some(DisplayRequest::Clear { color: words[1] as u32 }),
2 => Some(DisplayRequest::Flush),
3 => Some(DisplayRequest::GetDimensions),
_ => None,
}
}
}
impl Encode for DisplayResponse {
fn encode(&self) -> [usize; 4] {
match self {
DisplayResponse::Ok => [0, 0, 0, 0],
DisplayResponse::Dimensions { width, height } => {
[1, *width as usize, *height as usize, 0]
}
DisplayResponse::Error => [2, 0, 0, 0],
}
}
}
impl Decode for DisplayResponse {
fn decode(words: [usize; 4]) -> Option<Self> {
match words[0] {
0 => Some(DisplayResponse::Ok),
1 => Some(DisplayResponse::Dimensions {
width: words[1] as u16,
height: words[2] as u16,
}),
2 => Some(DisplayResponse::Error),
_ => None,
}
}
}