mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
add a usb test routine to the console api
this one just sends a string as if typed on a keyboard.
This commit is contained in:
parent
f2886d38f4
commit
99ab382d99
3 changed files with 63 additions and 0 deletions
|
|
@ -14,6 +14,7 @@ num-derive = { version = "0.4.2", default-features = false }
|
|||
num-traits = { version = "0.2.14", default-features = false }
|
||||
cramium-hal = { path = "../../libs/cramium-hal", features = ["std"] }
|
||||
cram-hal-service = { path = "../cram-hal-service" }
|
||||
usb-cramium = { path = "../usb-cramium" }
|
||||
|
||||
[features]
|
||||
cramium-soc = ["utralib/cramium-soc"]
|
||||
|
|
|
|||
|
|
@ -80,12 +80,15 @@ mod test;
|
|||
use test::*;
|
||||
mod trng_cmd;
|
||||
use trng_cmd::*;
|
||||
mod usb;
|
||||
use usb::*;
|
||||
|
||||
pub struct CmdEnv {
|
||||
common_env: CommonEnv,
|
||||
lastverb: String,
|
||||
///// 2. declare storage for your command here.
|
||||
trng_cmd: TrngCmd,
|
||||
usb: Usb,
|
||||
}
|
||||
impl CmdEnv {
|
||||
pub fn new(xns: &xous_names::XousNames) -> CmdEnv {
|
||||
|
|
@ -106,6 +109,7 @@ impl CmdEnv {
|
|||
log::debug!("trng");
|
||||
TrngCmd::new()
|
||||
},
|
||||
usb: Usb::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -125,6 +129,7 @@ impl CmdEnv {
|
|||
&mut ver_cmd,
|
||||
&mut self.trng_cmd,
|
||||
&mut console_cmd,
|
||||
&mut self.usb,
|
||||
];
|
||||
|
||||
if let Some(cmdline) = maybe_cmdline {
|
||||
|
|
|
|||
57
services/bao-console/src/cmds/usb.rs
Normal file
57
services/bao-console/src/cmds/usb.rs
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
use std::fmt::Write;
|
||||
|
||||
use String;
|
||||
use usb_cramium::UsbHid;
|
||||
|
||||
use crate::{CommonEnv, ShellCmdApi};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Usb {
|
||||
usb_dev: UsbHid,
|
||||
}
|
||||
impl Usb {
|
||||
pub fn new() -> Usb { Usb { usb_dev: UsbHid::new() } }
|
||||
}
|
||||
|
||||
impl<'a> ShellCmdApi<'a> for Usb {
|
||||
cmd_api!(usb);
|
||||
|
||||
// inserts boilerplate for command API
|
||||
|
||||
fn process(&mut self, args: String, _env: &mut CommonEnv) -> Result<Option<String>, xous::Error> {
|
||||
use core::fmt::Write;
|
||||
let mut ret = String::new();
|
||||
let helpstring = "usb [send <string>]";
|
||||
|
||||
let mut tokens = args.split(' ');
|
||||
|
||||
if let Some(sub_cmd) = tokens.next() {
|
||||
match sub_cmd {
|
||||
"send" => {
|
||||
let mut val = String::new();
|
||||
join_tokens(&mut val, &mut tokens);
|
||||
match self.usb_dev.send_str(&val) {
|
||||
Ok(n) => write!(ret, "Sent {} chars", n).unwrap(),
|
||||
Err(_e) => write!(ret, "Can't send: are we connected to a host?").unwrap(),
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
write!(ret, "{}", helpstring).unwrap();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
write!(ret, "{}", helpstring).unwrap();
|
||||
}
|
||||
Ok(Some(ret))
|
||||
}
|
||||
}
|
||||
|
||||
fn join_tokens<'a>(buf: &mut String, tokens: impl Iterator<Item = &'a str>) {
|
||||
for (i, tok) in tokens.enumerate() {
|
||||
if i == 0 {
|
||||
write!(buf, "{}", tok).unwrap();
|
||||
} else {
|
||||
write!(buf, " {}", tok).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue