Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions apis/display/screen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ impl<S: Syscalls, C: Config> Screen<S, C> {
let called: Cell<Option<(u32,)>> = Cell::new(None);
share::scope(|subscribe| {
S::subscribe::<_, _, C, DRIVER_NUM, { subscribe::WRITE }>(subscribe, &called)?;
let val = S::command(DRIVER_NUM, command::SET_BRIGHTNESS, value as u32, 0).to_result();
S::command(DRIVER_NUM, command::SET_BRIGHTNESS, value as u32, 0)
.to_result::<(), _>()?;
loop {
S::yield_wait();
if let Some((_,)) = called.get() {
return val;
return Ok(());
}
}
})
Expand All @@ -53,11 +54,11 @@ impl<S: Syscalls, C: Config> Screen<S, C> {
let called: Cell<Option<(u32,)>> = Cell::new(None);
share::scope(|subscribe| {
S::subscribe::<_, _, C, DRIVER_NUM, { subscribe::WRITE }>(subscribe, &called)?;
let val = S::command(DRIVER_NUM, command::SET_INVERT_ON, 0, 0).to_result();
S::command(DRIVER_NUM, command::SET_INVERT_ON, 0, 0).to_result::<(), _>()?;
loop {
S::yield_wait();
if let Some((_,)) = called.get() {
return val;
return Ok(());
}
}
})
Expand All @@ -68,11 +69,11 @@ impl<S: Syscalls, C: Config> Screen<S, C> {
let called: Cell<Option<(u32,)>> = Cell::new(None);
share::scope(|subscribe| {
S::subscribe::<_, _, C, DRIVER_NUM, { subscribe::WRITE }>(subscribe, &called)?;
let val = S::command(DRIVER_NUM, command::SET_INVERT_OFF, 0, 0).to_result();
S::command(DRIVER_NUM, command::SET_INVERT_OFF, 0, 0).to_result::<(), _>()?;
loop {
S::yield_wait();
if let Some((_,)) = called.get() {
return val;
return Ok(());
}
}
})
Expand Down Expand Up @@ -119,6 +120,7 @@ impl<S: Syscalls, C: Config> Screen<S, C> {
share::scope(|subscribe| {
S::subscribe::<_, _, C, DRIVER_NUM, { subscribe::WRITE }>(subscribe, &called)?;
let val = S::command(DRIVER_NUM, command::GET_ROTATION, 0, 0).to_result();
val?;
loop {
S::yield_wait();
if let Some((_,)) = called.get() {
Expand All @@ -133,11 +135,12 @@ impl<S: Syscalls, C: Config> Screen<S, C> {
let called: Cell<Option<(u32,)>> = Cell::new(None);
share::scope(|subscribe| {
S::subscribe::<_, _, C, DRIVER_NUM, { subscribe::WRITE }>(subscribe, &called)?;
let val = S::command(DRIVER_NUM, command::SET_ROTATION, rotation as u32, 0).to_result();
S::command(DRIVER_NUM, command::SET_ROTATION, rotation as u32, 0)
.to_result::<(), _>()?;
loop {
S::yield_wait();
if let Some((_,)) = called.get() {
return val;
return Ok(());
}
}
})
Expand All @@ -153,17 +156,17 @@ impl<S: Syscalls, C: Config> Screen<S, C> {
let called: Cell<Option<(u32,)>> = Cell::new(None);
share::scope(|subscribe| {
S::subscribe::<_, _, C, DRIVER_NUM, { subscribe::WRITE }>(subscribe, &called)?;
let val = S::command(
S::command(
DRIVER_NUM,
command::SET_RESOLUTION,
width as u32,
height as u32,
)
.to_result();
.to_result::<(), _>()?;
loop {
S::yield_wait();
if let Some((_,)) = called.get() {
return val;
return Ok(());
}
}
})
Expand All @@ -179,12 +182,12 @@ impl<S: Syscalls, C: Config> Screen<S, C> {
let called: Cell<Option<(u32,)>> = Cell::new(None);
share::scope(|subscribe| {
S::subscribe::<_, _, C, DRIVER_NUM, { subscribe::WRITE }>(subscribe, &called)?;
let val =
S::command(DRIVER_NUM, command::SET_PIXEL_FORMAT, format as u32, 0).to_result();
S::command(DRIVER_NUM, command::SET_PIXEL_FORMAT, format as u32, 0)
.to_result::<(), _>()?;
loop {
S::yield_wait();
if let Some((_,)) = called.get() {
return val;
return Ok(());
}
}
})
Expand All @@ -197,11 +200,11 @@ impl<S: Syscalls, C: Config> Screen<S, C> {
let called: Cell<Option<(u32,)>> = Cell::new(None);
share::scope(|subscribe| {
S::subscribe::<_, _, C, DRIVER_NUM, { subscribe::WRITE }>(subscribe, &called)?;
let val = S::command(DRIVER_NUM, command::SET_WRITE_FRAME, data1, data2).to_result();
S::command(DRIVER_NUM, command::SET_WRITE_FRAME, data1, data2).to_result::<(), _>()?;
loop {
S::yield_wait();
if let Some((_,)) = called.get() {
return val;
return Ok(());
}
}
})
Expand All @@ -221,11 +224,11 @@ impl<S: Syscalls, C: Config> Screen<S, C> {
let (allow_ro, subscribe) = handle.split();
S::allow_ro::<C, DRIVER_NUM, { allow_ro::WRITE_BUFFER_ID }>(allow_ro, s)?;
S::subscribe::<_, _, C, DRIVER_NUM, { subscribe::WRITE }>(subscribe, &called)?;
let val = S::command(DRIVER_NUM, command::WRITE, s.len() as u32, 0).to_result();
S::command(DRIVER_NUM, command::WRITE, s.len() as u32, 0).to_result::<(), _>()?;
loop {
S::yield_wait();
if let Some((_,)) = called.get() {
return val;
return Ok(());
}
}
})
Expand All @@ -249,11 +252,11 @@ impl<S: Syscalls, C: Config> Screen<S, C> {
let (allow_ro, subscribe) = handle.split();
S::allow_ro::<C, DRIVER_NUM, { allow_ro::WRITE_BUFFER_ID }>(allow_ro, s)?;
S::subscribe::<_, _, C, DRIVER_NUM, { subscribe::WRITE }>(subscribe, &called)?;
let val = S::command(DRIVER_NUM, command::FILL, 0, 0).to_result();
S::command(DRIVER_NUM, command::FILL, 0, 0).to_result::<(), _>()?;
loop {
S::yield_wait();
if let Some((_,)) = called.get() {
return val;
return Ok(());
}
}
})
Expand Down
24 changes: 12 additions & 12 deletions unittest/src/fake/screen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ impl crate::fake::SyscallDriver for Screen {
}

GET_RESOLUTION_WIDTH_HEIGHT => {
self.share_ref
.schedule_upcall(0, (0, 0, 0))
.expect("Unable to schedule upcall {}");
if argument0 < self.screen_resolution_width_height.len() as u32 {
if Option::is_some(&self.screen_setup) {
self.share_ref
.schedule_upcall(0, (0, 0, 0))
.expect("Unable to schedule upcall {}");
crate::command_return::success_2_u32(
self.screen_resolution_width_height[argument0 as usize]
.unwrap()
Expand All @@ -193,11 +193,11 @@ impl crate::fake::SyscallDriver for Screen {
}

PIXEL_FORMAT => {
self.share_ref
.schedule_upcall(0, (0, 0, 0))
.expect("Unable to schedule upcall {}");
if argument0 < self.screen_pixel_format.len() as u32 {
if Option::is_some(&self.screen_setup) {
self.share_ref
.schedule_upcall(0, (0, 0, 0))
.expect("Unable to schedule upcall {}");
crate::command_return::success_u32(
self.screen_pixel_format[argument0 as usize] as u32,
)
Expand All @@ -217,13 +217,13 @@ impl crate::fake::SyscallDriver for Screen {
}

SET_ROTATION => {
self.share_ref
.schedule_upcall(0, (0, 0, 0))
.expect("Unable to schedule upcall {}");
if argument0 > 359 {
command_return::failure(ErrorCode::Invalid)
} else {
self.rotation.set(argument0 as u16);
self.share_ref
.schedule_upcall(0, (0, 0, 0))
.expect("Unable to schedule upcall {}");
command_return::success()
}
}
Expand All @@ -245,11 +245,11 @@ impl crate::fake::SyscallDriver for Screen {
GET_PIXEL_FORMAT => command_return::success_u32(self.pixel_format.get()),

SET_PIXEL_FORMAT => {
self.share_ref
.schedule_upcall(0, (0, 0, 0))
.expect("Unable to schedule upcall {}");
if argument0 < self.pixel_modes.unwrap() as u32 {
self.pixel_format.set(argument0);
self.share_ref
.schedule_upcall(0, (0, 0, 0))
.expect("Unable to schedule upcall {}");
command_return::success()
} else {
command_return::failure(ErrorCode::Invalid)
Expand Down
3 changes: 3 additions & 0 deletions unittest/src/fake/screen/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ fn command() {
// Set and validate pixel format
assert!(screen.command(SET_PIXEL_FORMAT, 1, 0).is_success());

// Ensure that an invalid pixel format returns an error.
assert!(screen.command(SET_PIXEL_FORMAT, 99999, 0).is_failure());

// Kernel setup for screen and buffer simulation
let kernel = fake::Kernel::new();
kernel.add_driver(&screen);
Expand Down