mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
Merge pull request #855 from betrusted-io/display-stability
improve display boot stability
This commit is contained in:
commit
31590c4c77
3 changed files with 41 additions and 9 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -414,6 +414,7 @@ dependencies = [
|
||||||
"xous 0.9.70 (registry+https://github.com/rust-lang/crates.io-index)",
|
"xous 0.9.70 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"xous-api-log",
|
"xous-api-log",
|
||||||
"xous-api-names",
|
"xous-api-names",
|
||||||
|
"xous-api-susres 0.9.68",
|
||||||
"xous-api-ticktimer",
|
"xous-api-ticktimer",
|
||||||
"xous-ipc 0.10.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
"xous-ipc 0.10.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ rkyv = { version = "0.8.8", default-features = false, features = [
|
||||||
"alloc",
|
"alloc",
|
||||||
] }
|
] }
|
||||||
modals = { path = "../modals", optional = true }
|
modals = { path = "../modals", optional = true }
|
||||||
|
susres = { package = "xous-api-susres", path = "../../api/xous-api-susres" }
|
||||||
|
|
||||||
# QR decoding
|
# QR decoding
|
||||||
libm = { version = "0.2.8" }
|
libm = { version = "0.2.8" }
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,8 @@ use xous_ipc::Buffer;
|
||||||
pub const IMAGE_WIDTH: usize = 256;
|
pub const IMAGE_WIDTH: usize = 256;
|
||||||
pub const IMAGE_HEIGHT: usize = 240;
|
pub const IMAGE_HEIGHT: usize = 240;
|
||||||
|
|
||||||
|
const MAX_RETRIES: u32 = 5;
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Clone, Copy)]
|
#[derive(PartialEq, Eq, Clone, Copy)]
|
||||||
enum DisplayOrientation {
|
enum DisplayOrientation {
|
||||||
Normal,
|
Normal,
|
||||||
|
|
@ -224,10 +226,9 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! {
|
||||||
let hal = Hal::new();
|
let hal = Hal::new();
|
||||||
|
|
||||||
let mut display = Oled128x128::new(main_thread_token, bao1x_api::PERCLK, &iox, &udma_global);
|
let mut display = Oled128x128::new(main_thread_token, bao1x_api::PERCLK, &iox, &udma_global);
|
||||||
// these unwrap because if we have a time-out at this stage, it's likely a hardware problem
|
retry_display_op(&udma_global, &mut display, |d| d.init()).unwrap();
|
||||||
display.init().unwrap();
|
|
||||||
display.clear();
|
display.clear();
|
||||||
display.draw().unwrap();
|
retry_display_op(&udma_global, &mut display, |d| d.draw()).unwrap();
|
||||||
|
|
||||||
// ---- panic handler - set up early so we can see panics quickly
|
// ---- panic handler - set up early so we can see panics quickly
|
||||||
// install the graphical panic handler. It won't catch really early panics, or panics in this crate,
|
// install the graphical panic handler. It won't catch really early panics, or panics in this crate,
|
||||||
|
|
@ -968,7 +969,9 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GfxOpcode::Quit => break,
|
GfxOpcode::Quit => {
|
||||||
|
log::info!("refusing to quit, this operation is not supported on this platform!");
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
// 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.
|
||||||
log::debug!("Invalid or unhandled opcode: {:?}", opcode);
|
log::debug!("Invalid or unhandled opcode: {:?}", opcode);
|
||||||
|
|
@ -979,11 +982,6 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! {
|
||||||
tt.sleep_ms(10_000).unwrap();
|
tt.sleep_ms(10_000).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log::trace!("main loop exit, destroying servers");
|
|
||||||
xns.unregister_server(sid).unwrap();
|
|
||||||
xous::destroy_server(sid).unwrap();
|
|
||||||
log::trace!("quitting");
|
|
||||||
xous::terminate_process(0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
|
|
@ -995,3 +993,35 @@ fn display_timeout_handler(udma_global: &UdmaGlobal, display: &mut Oled128x128)
|
||||||
display.reinit_spi();
|
display.reinit_spi();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This is actually "infalliable" in the sense that if we can't initialize the
|
||||||
|
/// display, we diverge and reboot.
|
||||||
|
fn retry_display_op<F, R, E>(udma: &UdmaGlobal, display: &mut Oled128x128, mut op: F) -> Result<R, E>
|
||||||
|
where
|
||||||
|
F: FnMut(&mut Oled128x128) -> Result<R, E>,
|
||||||
|
E: core::fmt::Debug,
|
||||||
|
{
|
||||||
|
let mut attempts = 0;
|
||||||
|
loop {
|
||||||
|
match op(display) {
|
||||||
|
Ok(val) => return Ok(val),
|
||||||
|
Err(e) => {
|
||||||
|
std::thread::sleep(std::time::Duration::from_millis(50));
|
||||||
|
attempts += 1;
|
||||||
|
if attempts >= MAX_RETRIES {
|
||||||
|
log::warn!("Display seems stuck, rebooting whole chip.");
|
||||||
|
let xns = xous_names::XousNames::new().unwrap();
|
||||||
|
let susres = susres::Susres::new_without_hook(&xns).unwrap();
|
||||||
|
susres.reboot(true).ok();
|
||||||
|
}
|
||||||
|
log::warn!(
|
||||||
|
"Display op failed (attempt {}/{}), resetting SPI block... {:?}",
|
||||||
|
attempts,
|
||||||
|
MAX_RETRIES,
|
||||||
|
e
|
||||||
|
);
|
||||||
|
display_timeout_handler(udma, display);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue