format services/early_settings

This commit is contained in:
bunnie 2024-01-14 22:08:57 +08:00
parent e096384f66
commit 6607854320
2 changed files with 12 additions and 30 deletions

View file

@ -1,4 +1,5 @@
use core::sync::atomic::{AtomicU32, Ordering};
use num_traits::*;
use xous::{send_message, Message};
@ -28,9 +29,7 @@ pub struct EarlySettings {
impl EarlySettings {
pub fn new(xns: &xous_names::XousNames) -> Result<Self, xous::Error> {
REFCOUNT.fetch_add(1, Ordering::Relaxed);
let conn = xns
.request_connection_blocking(SERVER_NAME_ES)
.expect("Can't connect to EarlySettings");
let conn = xns.request_connection_blocking(SERVER_NAME_ES).expect("Can't connect to EarlySettings");
Ok(EarlySettings { conn })
}
@ -39,13 +38,7 @@ impl EarlySettings {
pub fn set_keymap(&self, map: usize) -> Result<(), xous::Error> {
send_message(
self.conn,
Message::new_blocking_scalar(
Opcode::SetKeymap.to_usize().unwrap(),
map.into(),
0,
0,
0,
),
Message::new_blocking_scalar(Opcode::SetKeymap.to_usize().unwrap(), map.into(), 0, 0, 0),
)
.map(|_| ())
}
@ -66,13 +59,7 @@ impl EarlySettings {
pub fn set_early_sleep(&self, value: bool) -> Result<(), xous::Error> {
send_message(
self.conn,
Message::new_blocking_scalar(
Opcode::SetEarlySleep.to_usize().unwrap(),
value as usize,
0,
0,
0,
),
Message::new_blocking_scalar(Opcode::SetEarlySleep.to_usize().unwrap(), value as usize, 0, 0, 0),
)
.map(|_| ())
}
@ -86,8 +73,9 @@ impl EarlySettings {
Ok(xous::Result::Scalar1(value)) => match value {
0 => Ok(false),
1 => Ok(true),
_ => Ok(false), // instead of doing `value != 0` we're explicitly matching against specific values, because
// reading off FLASH can yield a true value otherwise, even if it wasn't set before
_ => Ok(false), /* instead of doing `value != 0` we're explicitly matching against specific
* values, because reading off FLASH can
* yield a true value otherwise, even if it wasn't set before */
},
_ => Err(xous::Error::InternalError),
}
@ -97,7 +85,8 @@ impl EarlySettings {
static REFCOUNT: AtomicU32 = AtomicU32::new(0);
impl Drop for EarlySettings {
fn drop(&mut self) {
// now de-allocate myself. It's unsafe because we are responsible to make sure nobody else is using the connection.
// now de-allocate myself. It's unsafe because we are responsible to make sure nobody else is using
// the connection.
if REFCOUNT.fetch_sub(1, Ordering::Relaxed) == 1 {
unsafe {
xous::disconnect(self.conn).unwrap();

View file

@ -26,9 +26,7 @@ struct Slot {
}
impl Slot {
fn range(&self) -> Range<usize> {
(self.offset as usize)..((self.offset + self.size) as usize)
}
fn range(&self) -> Range<usize> { (self.offset as usize)..((self.offset + self.size) as usize) }
}
struct State {
@ -77,14 +75,9 @@ fn main() -> ! {
let xns = xous_names::XousNames::new().unwrap();
let state = State {
settings_page: page_provider(),
spinor: spinor::Spinor::new(&xns).unwrap(),
};
let state = State { settings_page: page_provider(), spinor: spinor::Spinor::new(&xns).unwrap() };
let sid = xns
.register_name(SERVER_NAME_ES, None)
.expect("can't register server");
let sid = xns.register_name(SERVER_NAME_ES, None).expect("can't register server");
loop {
let msg = xous::receive_message(sid).unwrap();