now passing the linter

This commit is contained in:
Sam Chin 2025-06-09 16:27:34 +08:00
parent e5cdeaf2ca
commit c291b6a11f
4 changed files with 58 additions and 54 deletions

View file

@ -142,8 +142,8 @@ impl CmdEnv {
let mut echo_cmd = Echo {}; // this command has no persistent storage, so we can "create" it every time we call dispatch (but it's a zero-cost absraction so this doesn't actually create any instructions) let mut echo_cmd = Echo {}; // this command has no persistent storage, so we can "create" it every time we call dispatch (but it's a zero-cost absraction so this doesn't actually create any instructions)
let mut ver_cmd = Ver {}; let mut ver_cmd = Ver {};
let mut console_cmd = Test {}; let mut console_cmd = Test {};
let mut i2cdetect_cmd = I2cDetect{}; let mut i2cdetect_cmd = I2cDetect {};
let mut cute_cmd = Cute{}; let mut cute_cmd = Cute {};
let commands: &mut [&mut dyn ShellCmdApi] = &mut [ let commands: &mut [&mut dyn ShellCmdApi] = &mut [
///// 4. add your command to this array, so that it can be looked up and dispatched ///// 4. add your command to this array, so that it can be looked up and dispatched

View file

@ -9,19 +9,19 @@ impl<'a> ShellCmdApi<'a> for Cute {
cmd_api!(cute); cmd_api!(cute);
fn process(&mut self, args: String, _env: &mut CommonEnv) -> Result<Option<String>, xous::Error> { fn process(&mut self, args: String, _env: &mut CommonEnv) -> Result<Option<String>, xous::Error> {
use core::fmt::Write; use core::fmt::Write;
let mut ret = String::new(); let mut ret = String::new();
let helpstring = "Usage: let helpstring = "Usage:
cute cat - prints cat ascii art cute cat - prints cat ascii art
cute bread - prints bread ascii art cute bread - prints bread ascii art
cute breadcat - prints breadcat ascii art"; cute breadcat - prints breadcat ascii art";
let mut tokens = args.split_whitespace(); let mut tokens = args.split_whitespace();
if let Some(sub_cmd) = tokens.next() { if let Some(sub_cmd) = tokens.next() {
match sub_cmd { match sub_cmd {
"cat" => { "cat" => {
let cat_art = r#" let cat_art = r#"
⠀⠀⠀⠀⢀⠠⠤⠀⢀⣿⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⢀⠠⠤⠀⢀⣿⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠐⠀⠐⠀⠀⢀⣾⣿⡇⠀⠀⠀⠀⠀⢀⣼⡇⠀⠀⠀⠀ ⠀⠀⠐⠀⠐⠀⠀⢀⣾⣿⡇⠀⠀⠀⠀⠀⢀⣼⡇⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⣸⣿⣿⣿⠀⠀⠀⠀⣴⣿⣿⠇⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⣸⣿⣿⣿⠀⠀⠀⠀⣴⣿⣿⠇⠀⠀⠀⠀
@ -34,10 +34,10 @@ impl<'a> ShellCmdApi<'a> for Cute {
⠨⠠⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⠀⠀⠀⠀⠀⠀ ⠨⠠⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⠀⠀⠀⠀⠀⠀
⠁⠃⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠁⠃⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
"#; "#;
write!(ret, "{}", cat_art).unwrap(); write!(ret, "{}", cat_art).unwrap();
} }
"bread" => { "bread" => {
let bread_art = r#" let bread_art = r#"
⠀⠀⠀⠀⣀⣠⣤⣤⣤⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⣀⣠⣤⣤⣤⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⣴⣿⣿⠿⠛⣉⣁⣠⣤⣤⣤⣬⣀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⣴⣿⣿⠿⠛⣉⣁⣠⣤⣤⣤⣬⣀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⢸⣿⣿⣿⣿⣿⣿⡿⠛⣉⣁⣠⣤⣤⣤⣬⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⢸⣿⣿⣿⣿⣿⣿⡿⠛⣉⣁⣠⣤⣤⣤⣬⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
@ -54,10 +54,10 @@ impl<'a> ShellCmdApi<'a> for Cute {
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠛⠛⠛⠛⠻⠶⣶⣤⣈⣉⣉⣉⣁⣤⣴⠾⠛⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠛⠛⠛⠛⠻⠶⣶⣤⣈⣉⣉⣉⣁⣤⣴⠾⠛⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠙⠛⠉⠉⠉⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠙⠛⠉⠉⠉⠀⠀⠀⠀
"#; "#;
write!(ret, "{}", bread_art).unwrap(); write!(ret, "{}", bread_art).unwrap();
} }
"breadcat" => { "breadcat" => {
let breadcat_art = r#" let breadcat_art = r#"
⠀⠀⠀⠰⣦⣤⣤⣀⠀⠀⡀⠀⠀⠀⠀⣀⣀⠀⠠⢤⣶⣶⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠰⣦⣤⣤⣀⠀⠀⡀⠀⠀⠀⠀⣀⣀⠀⠠⢤⣶⣶⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⢿⣿⢋⣵⣾⣿⣿⡿⣥⣮⢻⣿⣿⣿⣿⣶⣌⢿⣿⢰⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣦⣤⡀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⢿⣿⢋⣵⣾⣿⣿⡿⣥⣮⢻⣿⣿⣿⣿⣶⣌⢿⣿⢰⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣦⣤⡀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠘⢡⣿⣿⣿⣿⣿⣷⡹⠟⣵⣿⣿⣿⣿⣿⣿⣦⢃⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠘⢡⣿⣿⣿⣿⣿⣷⡹⠟⣵⣿⣿⣿⣿⣿⣿⣦⢃⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀
@ -75,18 +75,16 @@ impl<'a> ShellCmdApi<'a> for Cute {
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢿⣿⣿⣿⣿⣿⠿⠟⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢿⣿⣿⣿⣿⣿⠿⠟⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠉⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠉⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
"#; "#;
write!(ret, "{}", breadcat_art).unwrap(); write!(ret, "{}", breadcat_art).unwrap();
} }
_ => { _ => {
write!(ret, "{}\n", helpstring).unwrap(); write!(ret, "{}\n", helpstring).unwrap();
}
} }
} else {
write!(ret, "{}\n", helpstring).unwrap();
} }
} else {
write!(ret, "{}\n", helpstring).unwrap(); Ok(Some(ret))
} }
Ok(Some(ret))
}
} }

View file

@ -1,7 +1,7 @@
use String; use String;
use cram_hal_service::I2c;
use cramium_api::I2cApi; use cramium_api::I2cApi;
use cramium_api::I2cResult; use cramium_api::I2cResult;
use cram_hal_service::I2c;
use crate::{CommonEnv, ShellCmdApi}; use crate::{CommonEnv, ShellCmdApi};
@ -23,37 +23,46 @@ fn probe_address(i2c: &mut I2c, addr: u8) -> ProbeStatus {
} }
} }
pub struct I2cDetect {} pub struct I2cDetect {}
impl<'a> ShellCmdApi<'a> for I2cDetect { impl<'a> ShellCmdApi<'a> for I2cDetect {
cmd_api!(i2cdetect); cmd_api!(i2cdetect);
fn process(&mut self, args: String, _env: &mut CommonEnv) -> Result<Option<String>, xous::Error> { fn process(&mut self, args: String, _env: &mut CommonEnv) -> Result<Option<String>, xous::Error> {
use core::fmt::Write; use core::fmt::Write;
let mut ret = String::new(); let mut ret = String::new();
let helpstring = "Usage: let helpstring = "Usage:
i2cdetect probe <hex> - probes a single I2C address (e.g. 34) i2cdetect probe <hex> - probes a single I2C address (e.g. 34)
i2cdetect scan - reads i2cdetect scan - reads
i2cdetect bmp180_temp - reads raw temperature from BMP180"; i2cdetect bmp180_temp - reads raw temperature from BMP180";
let mut tokens = args.split_whitespace(); let mut tokens = args.split_whitespace();
if let Some(sub_cmd) = tokens.next() { if let Some(sub_cmd) = tokens.next() {
match sub_cmd { match sub_cmd {
"probe" => { "probe" => {
if let Some(addr_str) = tokens.next() { if let Some(addr_str) = tokens.next() {
match u8::from_str_radix(addr_str, 16) { match u8::from_str_radix(addr_str, 16) {
Ok(addr) => { Ok(addr) => {
let mut i2c = I2c::new(); let mut i2c = I2c::new();
let status = probe_address(&mut i2c, addr); let status = probe_address(&mut i2c, addr);
match status { match status {
ProbeStatus::Ack => write!(ret, "Device found at address {:02X}\n", addr).unwrap(), ProbeStatus::Ack => {
ProbeStatus::Nack => write!(ret, "Device at address {:02X} responded with NACK\n", addr).unwrap(), write!(ret, "Device found at address {:02X}\n", addr).unwrap()
}
ProbeStatus::Nack => {
write!(ret, "Device at address {:02X} responded with NACK\n", addr)
.unwrap()
}
}; };
} }
Err(_) => { Err(_) => {
write!(ret, "Invalid hex address '{}'. Example: i2cdetect probe 3C\n", addr_str).unwrap(); write!(
ret,
"Invalid hex address '{}'. Example: i2cdetect probe 3C\n",
addr_str
)
.unwrap();
} }
} }
} else { } else {
@ -82,18 +91,14 @@ impl<'a> ShellCmdApi<'a> for I2cDetect {
} }
} }
_ => {
write!(ret, "{}\n", helpstring).unwrap();
_ => { }
write!(ret, "{}\n", helpstring).unwrap();
} }
} else {
write!(ret, "{}\n", helpstring).unwrap();
} }
} else {
write!(ret, "{}\n", helpstring).unwrap(); Ok(Some(ret))
} }
Ok(Some(ret))
}
} }

View file

@ -612,7 +612,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// - [planned] vault application // - [planned] vault application
let bao_rram_pkgs = let bao_rram_pkgs =
["xous-ticktimer", "xous-log", "xous-names", "keystore" /* "usb-cramium" */].to_vec(); /* "usb-cramium" */ ["xous-ticktimer", "xous-log", "xous-names", "keystore" /* "usb-cramium" */].to_vec(); /* "usb-cramium" */
let bao_swap_pkgs = ["cram-hal-service", "bao-console", /*"modals", "pddb", "bao-video"*/].to_vec(); /* "bao-video" */ let bao_swap_pkgs =
["cram-hal-service", "bao-console" /* "modals", "pddb", "bao-video" */].to_vec(); /* "bao-video" */
if !builder.is_swap_set() { if !builder.is_swap_set() {
builder.set_swap(0, 8 * 1024 * 1024); builder.set_swap(0, 8 * 1024 * 1024);
} }