From e0b6d96fbd4674dce93ee73168c99de144b78cff Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 23 Dec 2024 01:21:44 +0800 Subject: [PATCH] cleanup USB integration at the service level --- services/usb-cramium/src/hw.rs | 14 +++++++++++--- services/usb-cramium/src/main.rs | 3 +-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/services/usb-cramium/src/hw.rs b/services/usb-cramium/src/hw.rs index 4e669168c..2a9602af4 100644 --- a/services/usb-cramium/src/hw.rs +++ b/services/usb-cramium/src/hw.rs @@ -4,7 +4,7 @@ use std::collections::VecDeque; use std::sync::atomic::compiler_fence; use std::sync::atomic::{AtomicPtr, Ordering}; -use cramium_hal::usb::driver::{CRG_UDC_ERDPLO_EHB, CorigineWrapper, CrgEvent, EventTrbS}; +use cramium_hal::usb::driver::{CRG_UDC_ERDPLO_EHB, CorigineWrapper, EventTrbS}; use cramium_hal::usb::utra::*; use num_traits::*; use usb_cramium::HIDReport; @@ -149,7 +149,10 @@ pub(crate) fn composite_handler(_irq_no: usize, arg: *mut usize) { // actually store the data or pass it on to userspace crate::println!("keyboard LEDs: {:?}", l); } - Err(e) => crate::println!("KEYB ERR: {:?}", e), + Err(e) => match e { + UsbError::WouldBlock => {} + _ => crate::println!("KEYB ERR: {:?}", e), + }, }; // u2f report handler match class.device::, _>().read_report() { @@ -169,7 +172,10 @@ pub(crate) fn composite_handler(_irq_no: usize, arg: *mut usize) { buf.try_send(usb.conn, Opcode::IrqFidoRx.to_u32().unwrap()) .expect("couldn't send FIDO packet to userspace: maybe we need to implement a timeout/retry mechanism?"); } - Err(e) => crate::println!("U2F ERR: {:?}", e), + Err(e) => match e { + UsbError::WouldBlock => {} + _ => crate::println!("U2F ERR: {:?}", e), + }, } } { @@ -276,6 +282,8 @@ impl<'a> CramiumUsb<'a> { .manufacturer("Kosagi") .product("Precursor") .serial_number(&serial_number) + // this is *required* by the corigine stack + .max_packet_size_0(64) .build(); CramiumUsb { diff --git a/services/usb-cramium/src/main.rs b/services/usb-cramium/src/main.rs index cce5f002c..56ac6c527 100644 --- a/services/usb-cramium/src/main.rs +++ b/services/usb-cramium/src/main.rs @@ -118,11 +118,10 @@ pub(crate) fn main_hw() -> ! { log::info!("IRQ1 csr: {:x} -> {:x}", utra::irqarray1::HW_IRQARRAY1_BASE, unsafe { irq_csr.base() as usize }); - let h_op: usize = Opcode::UsbIrqHandler.to_usize().unwrap(); log::info!("making hw object"); let mut corigine_usb = - unsafe { CorigineUsb::new(cid, h_op, ifram_range.as_ptr() as usize, usb.clone(), irq_csr.clone()) }; + unsafe { CorigineUsb::new(ifram_range.as_ptr() as usize, usb.clone(), irq_csr.clone()) }; log::info!("reset.."); corigine_usb.reset(); // initial reset of the core; we want some time to pass before doing the next items