mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
Merge branch 'main' into u2f
This commit is contained in:
commit
6e34659a33
5 changed files with 70 additions and 11 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -1157,6 +1157,7 @@ name = "ffi-test"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"ffi-sys",
|
||||
"keyboard",
|
||||
"log",
|
||||
"log-server",
|
||||
"num-derive",
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ num-derive = {version = "0.3.3", default-features = false}
|
|||
num-traits = {version = "0.2.14", default-features = false}
|
||||
susres = {path = "../susres"}
|
||||
ffi-sys = {path = "sys"}
|
||||
keyboard = {path = "../keyboard"}
|
||||
|
||||
[target.'cfg(not(any(windows,unix)))'.dependencies]
|
||||
utralib = { path = "../../utralib"}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,60 @@ pub type c_float = f32;
|
|||
pub type c_double = f64;
|
||||
pub type c_void = core::ffi::c_void;
|
||||
|
||||
use xous::{send_message, Message};
|
||||
static mut KBD: Option<keyboard::Keyboard> = None;
|
||||
fn get_keys_blocking() -> Vec<char> {
|
||||
if unsafe{KBD.is_none()} {
|
||||
let xns = xous_names::XousNames::new().unwrap();
|
||||
let kbd = keyboard::Keyboard::new(&xns).unwrap();
|
||||
unsafe{KBD = Some(kbd)};
|
||||
}
|
||||
match send_message(unsafe{KBD.as_ref().unwrap().conn()},
|
||||
Message::new_blocking_scalar(
|
||||
9, // BlockingKeyboardListener
|
||||
0, 0, 0, 0
|
||||
)
|
||||
) {
|
||||
Ok(xous::Result::Scalar2(k1, k2)) => {
|
||||
let mut ret = Vec::<char>::new();
|
||||
if let Some(c) = core::char::from_u32(k1 as u32) {
|
||||
ret.push(c)
|
||||
}
|
||||
if let Some(c) = core::char::from_u32(k2 as u32) {
|
||||
ret.push(c)
|
||||
}
|
||||
ret
|
||||
}
|
||||
Ok(_) | Err(_) => panic!("internal error: Incorrect return type")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[export_name = "rust_getchar"]
|
||||
pub unsafe extern "C" fn rust_getchar() -> c_char {
|
||||
log::info!("rust_getchar called");
|
||||
let mut chr = 0 as c_char;
|
||||
let kbhit = get_keys_blocking();
|
||||
for k in kbhit {
|
||||
log::info!("got key character: {}", k);
|
||||
chr = k as i8;
|
||||
return chr;
|
||||
//break;
|
||||
}
|
||||
log::info!("libc_getchar cleanup FIXME");
|
||||
//kbd.drop(); ?????
|
||||
return chr;
|
||||
}
|
||||
|
||||
/*
|
||||
/// Call this from your Rust init routine, before using get_keys_blocking()
|
||||
pub fn init_kbd() {
|
||||
let xns = xous_names::XousNames::new().unwrap();
|
||||
let kbd = keyboard::Keyboard::new(&xns).unwrap();
|
||||
KBD_CONN.store(kbd.conn(), Ordering::SeqCst);
|
||||
unsafe{KBD = Some(kbd)};
|
||||
}*/
|
||||
|
||||
extern "C" {
|
||||
pub fn add_one(a: i32) -> i32;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,38 +47,39 @@ impl Into<usize> for KeyMap {
|
|||
}
|
||||
}
|
||||
|
||||
// Opcodes are pinned down to allow for unsafe FFI extraction of key hits
|
||||
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
||||
pub(crate) enum Opcode {
|
||||
/// set which keyboard mapping is present
|
||||
SelectKeyMap, //(KeyMap),
|
||||
GetKeyMap,
|
||||
SelectKeyMap = 0, //(KeyMap),
|
||||
GetKeyMap = 1,
|
||||
|
||||
/// request for ScanCodes
|
||||
RegisterListener,
|
||||
RegisterListener = 2,
|
||||
|
||||
/// request for raw keyups/downs
|
||||
RegisterRawListener,
|
||||
RegisterRawListener = 3,
|
||||
|
||||
/// set repeat delay, rate; both in ms
|
||||
SetRepeat, //(u32, u32),
|
||||
SetRepeat = 4, //(u32, u32),
|
||||
|
||||
/// set chording interval (how long to wait for all keydowns to happen before interpreting as a chord), in ms (for braille keyboards)
|
||||
SetChordInterval, //(u32),
|
||||
SetChordInterval = 5, //(u32),
|
||||
|
||||
/// used by host mode emulation and debug UART to inject keys
|
||||
InjectKey, //(char),
|
||||
InjectKey = 6, //(char),
|
||||
|
||||
/// used by the interrupt handler to transfer results to the main loop
|
||||
HandlerTrigger,
|
||||
HandlerTrigger = 7,
|
||||
|
||||
/// used to turn keyboard vibrate on and off
|
||||
Vibe,
|
||||
Vibe = 8,
|
||||
|
||||
/// a blocking key listener - blocks until a key is hit
|
||||
BlockingKeyListener,
|
||||
BlockingKeyListener = 9,
|
||||
|
||||
/// Suspend/resume callback
|
||||
SuspendResume,
|
||||
SuspendResume = 10,
|
||||
}
|
||||
|
||||
// this structure is used to register a keyboard listener. Currently, we only accept
|
||||
|
|
|
|||
|
|
@ -92,6 +92,8 @@ impl Keyboard {
|
|||
Ok(_) | Err(_) => panic!("internal error: Incorrect return type")
|
||||
}
|
||||
}
|
||||
/// Reveal the connection ID for use with unsafe FFI calls
|
||||
pub fn conn(&self) -> xous::CID { self.conn }
|
||||
|
||||
#[cfg(not(any(target_os = "none", target_os = "xous")))]
|
||||
pub fn hostmode_inject_key(&self, c: char) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue