Merge branch 'main' into u2f

This commit is contained in:
bunnie 2022-06-05 18:47:02 +08:00
commit c3615f2fff
7 changed files with 81 additions and 18 deletions

View file

@ -3,7 +3,7 @@
<device schemaVersion="1.1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="CMSIS-SVD.xsd" > <device schemaVersion="1.1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="CMSIS-SVD.xsd" >
<vendor>litex</vendor> <vendor>litex</vendor>
<name>SOC</name> <name>SOC</name>
<description><![CDATA[Litex SoC 2022-05-06 03:38:23]]></description> <description><![CDATA[Litex SoC 2022-05-30 17:10:53]]></description>
<addressUnitBits>8</addressUnitBits> <addressUnitBits>8</addressUnitBits>
<width>32</width> <width>32</width>
@ -1222,10 +1222,10 @@ register to disable individual events.]]></description>
<register> <register>
<name>GIT_GITREV</name> <name>GIT_GITREV</name>
<description><![CDATA[First 32-bits of the git revision. This documentation was built from git rev <description><![CDATA[First 32-bits of the git revision. This documentation was built from git rev
``df6ac783``, so this value is 3748317059, which should be enough to check out ``010b3183``, so this value is 17510787, which should be enough to check out the
the exact git version used to build this firmware.]]></description> exact git version used to build this firmware.]]></description>
<addressOffset>0x0014</addressOffset> <addressOffset>0x0014</addressOffset>
<resetValue>0xdf6ac783</resetValue> <resetValue>0x10b3183</resetValue>
<size>32</size> <size>32</size>
<fields> <fields>
<field> <field>
@ -1242,7 +1242,7 @@ the exact git version used to build this firmware.]]></description>
is ``1``, then the repository this was built from has one additional commit is ``1``, then the repository this was built from has one additional commit
beyond the tag indicated in `MAJOR`, `MINOR`, and `REVISION`.]]></description> beyond the tag indicated in `MAJOR`, `MINOR`, and `REVISION`.]]></description>
<addressOffset>0x0018</addressOffset> <addressOffset>0x0018</addressOffset>
<resetValue>0x12</resetValue> <resetValue>0x16</resetValue>
<size>32</size> <size>32</size>
<fields> <fields>
<field> <field>
@ -3577,7 +3577,7 @@ inject too fast.]]></description>
<name>SEED1</name> <name>SEED1</name>
<description><![CDATA[Bits 32-63 of `SEED_SEED`. Seed used for the build]]></description> <description><![CDATA[Bits 32-63 of `SEED_SEED`. Seed used for the build]]></description>
<addressOffset>0x0000</addressOffset> <addressOffset>0x0000</addressOffset>
<resetValue>0x4616d7dd</resetValue> <resetValue>0x65ce43e3</resetValue>
<size>32</size> <size>32</size>
<fields> <fields>
<field> <field>
@ -3592,7 +3592,7 @@ inject too fast.]]></description>
<name>SEED0</name> <name>SEED0</name>
<description><![CDATA[Bits 0-31 of `SEED_SEED`.]]></description> <description><![CDATA[Bits 0-31 of `SEED_SEED`.]]></description>
<addressOffset>0x0004</addressOffset> <addressOffset>0x0004</addressOffset>
<resetValue>0x3c6bc921</resetValue> <resetValue>0x28aafeae</resetValue>
<size>32</size> <size>32</size>
<fields> <fields>
<field> <field>
@ -7129,7 +7129,6 @@ of the PLL]]></description>
<constant name="CONFIG_BUS_STANDARD" value="WISHBONE" /> <constant name="CONFIG_BUS_STANDARD" value="WISHBONE" />
<constant name="CONFIG_BUS_DATA_WIDTH" value="32" /> <constant name="CONFIG_BUS_DATA_WIDTH" value="32" />
<constant name="CONFIG_BUS_ADDRESS_WIDTH" value="32" /> <constant name="CONFIG_BUS_ADDRESS_WIDTH" value="32" />
<constant name="CONFIG_BUS_BURSTING" value="0" />
<constant name="APP_UART_INTERRUPT" value="4" /> <constant name="APP_UART_INTERRUPT" value="4" />
<constant name="AUDIO_INTERRUPT" value="14" /> <constant name="AUDIO_INTERRUPT" value="14" />
<constant name="BTEVENTS_INTERRUPT" value="7" /> <constant name="BTEVENTS_INTERRUPT" value="7" />

View file

@ -74,6 +74,9 @@ pub(crate) enum Opcode {
/// used to turn keyboard vibrate on and off /// used to turn keyboard vibrate on and off
Vibe, Vibe,
/// a blocking key listener - blocks until a key is hit
BlockingKeyListener,
/// Suspend/resume callback /// Suspend/resume callback
SuspendResume, SuspendResume,
} }

View file

@ -69,6 +69,29 @@ impl Keyboard {
_ => Err(xous::Error::InternalError) _ => Err(xous::Error::InternalError)
} }
} }
/// Blocks until a key is hit. Does not block the keyboard server, just the caller.
/// Returns a `Vec::<char>`, as the user can press more than one key at a time.
/// The specific order of a simultaneous key hit event is not defined.
pub fn get_keys_blocking(&self) -> Vec<char> {
match send_message(self.conn,
Message::new_blocking_scalar(
Opcode::BlockingKeyListener.to_usize().unwrap(),
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")
}
}
#[cfg(not(any(target_os = "none", target_os = "xous")))] #[cfg(not(any(target_os = "none", target_os = "xous")))]
pub fn hostmode_inject_key(&self, c: char) { pub fn hostmode_inject_key(&self, c: char) {

View file

@ -9,7 +9,7 @@ use log::info;
use num_traits::*; use num_traits::*;
use xous_ipc::Buffer; use xous_ipc::Buffer;
use xous::{CID, msg_scalar_unpack, msg_blocking_scalar_unpack}; use xous::{CID, msg_scalar_unpack, msg_blocking_scalar_unpack, MessageSender};
#[cfg(any(target_os = "none", target_os = "xous"))] #[cfg(any(target_os = "none", target_os = "xous"))]
mod implementation { mod implementation {
use utralib::generated::*; use utralib::generated::*;
@ -764,6 +764,8 @@ fn main() -> ! {
}*/ }*/
let mut esc_index: Option<usize> = None; let mut esc_index: Option<usize> = None;
let mut esc_chars = [0u8; 16]; let mut esc_chars = [0u8; 16];
// storage for any blocking listeners
let mut blocking_listener = Vec::<MessageSender>::new();
log::trace!("starting main loop"); log::trace!("starting main loop");
loop { loop {
@ -779,6 +781,11 @@ fn main() -> ! {
if ena != 0 { vibe = true } if ena != 0 { vibe = true }
else { vibe = false } else { vibe = false }
}), }),
Some(Opcode::BlockingKeyListener) => {
// by simply storing the sender address and not returning a value,
// the sender will remain blocked until the return value is generated
blocking_listener.push(msg.sender);
},
Some(Opcode::RegisterListener) => { Some(Opcode::RegisterListener) => {
let buffer = unsafe{Buffer::from_memory_message(msg.body.memory_message().unwrap())}; let buffer = unsafe{Buffer::from_memory_message(msg.body.memory_message().unwrap())};
let kr = buffer.as_flat::<KeyboardRegistration, _>().unwrap(); let kr = buffer.as_flat::<KeyboardRegistration, _>().unwrap();
@ -893,6 +900,11 @@ fn main() -> ! {
).unwrap(); ).unwrap();
} }
} }
for listener in blocking_listener.drain(..) {
// we must unblock anyways once the key is hit; even if the key is invalid,
// send the invalid key. The receiving library function will clean this up into a nil-response vector.
xous::return_scalar2(listener, key as u32 as usize, 0).unwrap();
}
}), }),
Some(Opcode::HandlerTrigger) => { Some(Opcode::HandlerTrigger) => {
let rawstates = kbd.update(); let rawstates = kbd.update();
@ -927,6 +939,32 @@ fn main() -> ! {
}; };
// send keys, if any // send keys, if any
// handle the blocking listeners
if kc.len() > 0 {
for listener in blocking_listener.drain(..) {
xous::return_scalar2(
listener,
if kc.len() >= 1 {
kc[0] as u32 as usize
} else {
0
},
if kc.len() >= 2 {
kc[1] as u32 as usize
} else {
0
},
).unwrap();
if kc.len() > 2 {
log::warn!(
"Extra keys in multi-hit event went unreported: only 2 of {} total keys reported out of {:?}",
kc.len(),
&kc,
);
}
}
}
// handle the true async listeners
if kc.len() > 0 && listener_conn.is_some() && listener_op.is_some() { if kc.len() > 0 && listener_conn.is_some() && listener_op.is_some() {
if vibe { if vibe {
llio.vibe(llio::VibePattern::Short).unwrap(); llio.vibe(llio::VibePattern::Short).unwrap();

View file

@ -41,6 +41,6 @@ rand_chacha = "0.3.1"
utralib = { path = "../../utralib"} utralib = { path = "../../utralib"}
[features] [features]
keyboard = [] # handy for debugging composite device issues emukbd = [] # handy for debugging composite device issues
mjolnir = [] # the big hammer for debugging Spinal USB issues. A raw memory dump of config and descriptor space. Use with care. mjolnir = [] # the big hammer for debugging Spinal USB issues. A raw memory dump of config and descriptor space. Use with care.
default = ["keyboard"] default = ["emukbd"]

View file

@ -142,7 +142,7 @@ fn main() -> ! {
let usb_alloc = UsbBusAllocator::new(usbdev); let usb_alloc = UsbBusAllocator::new(usbdev);
#[cfg(any(target_os = "none", target_os = "xous"))] #[cfg(any(target_os = "none", target_os = "xous"))]
let clock = EmbeddedClock::new(); let clock = EmbeddedClock::new();
#[cfg(all(any(target_os = "none", target_os = "xous"), feature="keyboard"))] #[cfg(all(any(target_os = "none", target_os = "xous"), feature="emukbd"))]
let mut composite = UsbHidClassBuilder::new() let mut composite = UsbHidClassBuilder::new()
.add_interface( .add_interface(
NKROBootKeyboardInterface::default_config(&clock), NKROBootKeyboardInterface::default_config(&clock),
@ -151,7 +151,7 @@ fn main() -> ! {
FidoInterface::default_config() FidoInterface::default_config()
) )
.build(&usb_alloc); .build(&usb_alloc);
#[cfg(all(any(target_os = "none", target_os = "xous"), not(feature="keyboard")))] #[cfg(all(any(target_os = "none", target_os = "xous"), not(feature="emukbd")))]
let mut composite = UsbHidClassBuilder::new() let mut composite = UsbHidClassBuilder::new()
.add_interface( .add_interface(
FidoInterface::default_config() FidoInterface::default_config()
@ -164,7 +164,7 @@ fn main() -> ! {
.product("Precursor") .product("Precursor")
.serial_number(&serial_number) .serial_number(&serial_number)
.build(); .build();
#[cfg(all(any(target_os = "none", target_os = "xous"), feature="keyboard"))] #[cfg(all(any(target_os = "none", target_os = "xous"), feature="emukbd"))]
{ {
let keyboard = composite.interface::<NKROBootKeyboardInterface<'_, _, _,>, _>(); let keyboard = composite.interface::<NKROBootKeyboardInterface<'_, _, _,>, _>();
keyboard.write_report(&Vec::<Keyboard>::new()).ok(); keyboard.write_report(&Vec::<Keyboard>::new()).ok();
@ -246,7 +246,7 @@ fn main() -> ! {
Some(Opcode::UsbIrqHandler) => { Some(Opcode::UsbIrqHandler) => {
#[cfg(any(target_os = "none", target_os = "xous"))] #[cfg(any(target_os = "none", target_os = "xous"))]
if usb_dev.poll(&mut [&mut composite]) { if usb_dev.poll(&mut [&mut composite]) {
#[cfg(feature="keyboard")] #[cfg(feature="emukbd")]
{ {
let keyboard = composite.interface::<NKROBootKeyboardInterface<'_, _, _,>, _>(); let keyboard = composite.interface::<NKROBootKeyboardInterface<'_, _, _,>, _>();
match keyboard.read_report() { match keyboard.read_report() {
@ -361,7 +361,7 @@ fn main() -> ! {
codes.push(Keyboard::from_primitive(code2 as u8)); codes.push(Keyboard::from_primitive(code2 as u8));
} }
let auto_up = if autoup == 1 {true} else {false}; let auto_up = if autoup == 1 {true} else {false};
#[cfg(feature="keyboard")] #[cfg(feature="emukbd")]
{ {
let keyboard = composite.interface::<NKROBootKeyboardInterface<'_, _, _,>, _>(); let keyboard = composite.interface::<NKROBootKeyboardInterface<'_, _, _,>, _>();
keyboard.write_report(&codes).ok(); keyboard.write_report(&codes).ok();
@ -397,7 +397,7 @@ fn main() -> ! {
KeyMap::Dvorak => mappings::char_to_hid_code_dvorak(ch), KeyMap::Dvorak => mappings::char_to_hid_code_dvorak(ch),
_ => mappings::char_to_hid_code_us101(ch), _ => mappings::char_to_hid_code_us101(ch),
}; };
#[cfg(feature="keyboard")] #[cfg(feature="emukbd")]
{ {
let keyboard = composite.interface::<NKROBootKeyboardInterface<'_, _, _,>, _>(); let keyboard = composite.interface::<NKROBootKeyboardInterface<'_, _, _,>, _>();
keyboard.write_report(&codes).ok(); keyboard.write_report(&codes).ok();

View file

@ -194,7 +194,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
pkgs.push(app); pkgs.push(app);
} }
generate_app_menus(&apps); generate_app_menus(&apps);
renode_image(false, &hw_pkgs, &[], None, None)? renode_image(false, &pkgs, &[], None, None)?
} }
Some("renode-test") => { Some("renode-test") => {
let mut args = env::args(); let mut args = env::args();