mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
reformat early_settings interactions so that it only writes if data is actually changed
also abstract get/set off the early settings FLASH section, easier to maintain still todo: make hosted mode work again
This commit is contained in:
parent
b10a51a3bd
commit
42bc425ca9
2 changed files with 33 additions and 36 deletions
|
|
@ -31,11 +31,34 @@ impl Slot {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO(gsora): implement this so that it's a no-op on hosted mode
|
||||
struct State {
|
||||
settings_page: MemoryRange,
|
||||
spinor: Spinor,
|
||||
}
|
||||
|
||||
impl State {
|
||||
fn set(&self, data: &[u8], slot: &Slot) {
|
||||
let settings: &[u8] = self.settings_page.as_slice();
|
||||
|
||||
let new_data_u32 = u32::from_le_bytes(data.try_into().unwrap());
|
||||
|
||||
if new_data_u32 == self.get(slot) {
|
||||
return;
|
||||
}
|
||||
|
||||
self.spinor
|
||||
.patch(settings, xous::EARLY_SETTINGS, &data, slot.offset)
|
||||
.expect("couldn't patch slot data");
|
||||
}
|
||||
|
||||
fn get(&self, slot: &Slot) -> u32 {
|
||||
let settings: &[u8] = self.settings_page.as_slice();
|
||||
|
||||
u32::from_le_bytes(settings[slot.range()].try_into().unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> ! {
|
||||
log_server::init_wait().unwrap();
|
||||
log::set_max_level(log::LevelFilter::Info);
|
||||
|
|
@ -63,46 +86,20 @@ fn main() -> ! {
|
|||
log::trace!("Message: {:?}", msg);
|
||||
match FromPrimitive::from_usize(msg.body.id()) {
|
||||
Some(Opcode::GetKeymap) => {
|
||||
let settings: &[u8] = state.settings_page.as_slice();
|
||||
|
||||
let code = u32::from_le_bytes(settings[KEYMAP.range()].try_into().unwrap());
|
||||
|
||||
xous::return_scalar(msg.sender, code as usize).unwrap();
|
||||
xous::return_scalar(msg.sender, state.get(&KEYMAP) as usize).unwrap();
|
||||
}
|
||||
Some(Opcode::SetKeymap) => msg_blocking_scalar_unpack!(msg, map, _, _, _, {
|
||||
let code = (map as u32).to_le_bytes();
|
||||
let settings: &[u8] = state.settings_page.as_slice();
|
||||
|
||||
state
|
||||
.spinor
|
||||
.patch(settings, xous::EARLY_SETTINGS, &code, KEYMAP.offset)
|
||||
.expect("couldn't patch our keyboard code");
|
||||
|
||||
log::info!("writing early keymap: {}", map);
|
||||
|
||||
state.set(&code, &KEYMAP);
|
||||
xous::return_scalar(msg.sender, 0).unwrap();
|
||||
}),
|
||||
Some(Opcode::SetEarlySleep) => msg_blocking_scalar_unpack!(msg, value, _, _, _, {
|
||||
let code = (value as u32).to_le_bytes();
|
||||
let settings: &[u8] = state.settings_page.as_slice();
|
||||
|
||||
state
|
||||
.spinor
|
||||
.patch(settings, xous::EARLY_SETTINGS, &code, EARLY_SLEEP.offset)
|
||||
.expect("couldn't patch early reboot flag");
|
||||
|
||||
log::info!("writing must sleep on reboot: {}", value);
|
||||
|
||||
state.set(&code, &EARLY_SLEEP);
|
||||
xous::return_scalar(msg.sender, 0).unwrap();
|
||||
}),
|
||||
Some(Opcode::EarlySleep) => {
|
||||
let settings: &[u8] = state.settings_page.as_slice();
|
||||
|
||||
let value = u32::from_le_bytes(settings[EARLY_SLEEP.range()].try_into().unwrap());
|
||||
|
||||
log::info!("value read for early sleep: {}", value);
|
||||
|
||||
xous::return_scalar(msg.sender, value as usize).unwrap();
|
||||
xous::return_scalar(msg.sender, state.get(&EARLY_SLEEP) as usize).unwrap();
|
||||
}
|
||||
_ => log::warn!("unrecognized opcode"),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -629,11 +629,11 @@ fn wrapped_main() -> ! {
|
|||
|
||||
// get the last status
|
||||
let must_sleep = early_settings.early_sleep().unwrap();
|
||||
|
||||
// reset it for good measure
|
||||
early_settings.set_early_sleep(false).unwrap();
|
||||
|
||||
if must_sleep {
|
||||
// reset it for good measure
|
||||
early_settings.set_early_sleep(false).unwrap();
|
||||
|
||||
while ((llio.adc_vbus().unwrap() as u32) * 503) > 150_000 {
|
||||
modals.show_notification(t!("mainmenu.cant_sleep", xous::LANG), None).expect("couldn't notify that power is plugged in");
|
||||
}
|
||||
|
|
@ -647,7 +647,7 @@ fn wrapped_main() -> ! {
|
|||
Err(_e) => {
|
||||
panic!("Unhandled error on suspend request");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// spawn a thread to auto-mount the PDDB
|
||||
|
|
@ -1130,7 +1130,7 @@ fn wrapped_main() -> ! {
|
|||
early_settings.set_early_sleep(true).unwrap();
|
||||
|
||||
log::info!("forcing sleep on reboot");
|
||||
|
||||
|
||||
pddb.pddb_halt();
|
||||
susres.reboot(true).expect("couldn't issue reboot command");
|
||||
}
|
||||
|
|
@ -1605,4 +1605,4 @@ fn bars(g: &gam::Gam,
|
|||
|
||||
g.draw_list(dl).unwrap();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue