Decode input events in inputdev_event.rs

This commit is contained in:
Yifan Wu 2023-01-12 00:21:57 -08:00
parent 4430e86d5a
commit f0cecc4940
9 changed files with 67 additions and 67 deletions

View file

@ -13,10 +13,8 @@ buddy_system_allocator = "0.6"
bitflags = "1.2.1"
xmas-elf = "0.7.0"
volatile = "0.3"
#virtio-drivers = { git = "https://github.com/rcore-os/virtio-drivers", rev = "4ee80e5" }
virtio-drivers = { git = "https://github.com/rcore-os/virtio-drivers", rev = "70b5850" }
virtio-drivers = { git = "https://github.com/rcore-os/virtio-drivers", rev = "4ee80e5" }
easy-fs = { path = "../easy-fs" }
#virtio-input-decoder = "0.1.4"
embedded-graphics = "0.7.1"
tinybmp = "0.3.1"

View file

@ -16,41 +16,20 @@ struct VirtIOInputInner {
struct VirtIOInputWrapper {
inner: UPIntrFreeCell<VirtIOInputInner>,
//condvars: BTreeMap<u16, Condvar>,
//condvar: Arc::<Condvar> ,
condvar: Condvar,
}
pub trait InputDevice: Send + Sync + Any {
fn read_event(&self) -> u64;
fn handle_irq(&self);
// fn events(&self) -> &VecDeque<u64>;
fn is_empty(&self) -> bool;
}
lazy_static::lazy_static!(
pub static ref KEYBOARD_DEVICE: Arc<dyn InputDevice> = Arc::new(VirtIOInputWrapper::new(VIRTIO5));
pub static ref MOUSE_DEVICE: Arc<dyn InputDevice> = Arc::new(VirtIOInputWrapper::new(VIRTIO6));
// pub static ref INPUT_CONDVAR: Arc::<Condvar> = Arc::new(Condvar::new());
);
// from virtio-drivers/src/input.rs
//const QUEUE_SIZE: u16 = 32;
// pub fn read_input_event() -> u64 {
// loop {
// //let mut inner = self.inner.exclusive_access();
// let kb=KEYBOARD_DEVICE.clone();
// let evs = kb.events();
// if let Some(event) = evs.pop_front() {
// return event;
// } else {
// let task_cx_ptr = INPUT_CONDVAR.clone().wait_no_sched();
// drop(inner);
// schedule(task_cx_ptr);
// }
// }
// }
impl VirtIOInputWrapper {
pub fn new(addr: usize) -> Self {
let inner = VirtIOInputInner {
@ -59,17 +38,8 @@ impl VirtIOInputWrapper {
},
events: VecDeque::new(),
};
// let mut condvars = BTreeMap::new();
// let channels = QUEUE_SIZE;
// for i in 0..channels {
// let condvar = Condvar::new();
// condvars.insert(i, condvar);
// }
Self {
inner: unsafe { UPIntrFreeCell::new(inner) },
//condvar: INPUT_CONDVAR.clone(),
condvar: Condvar::new(),
}
}
@ -93,29 +63,20 @@ impl InputDevice for VirtIOInputWrapper {
}
}
// fn events(&self) -> &VecDeque<u64> {
// &self.inner.exclusive_access().events
// }
fn handle_irq(&self) {
let mut count = 0;
let mut result = 0;
let mut key = 0;
self.inner.exclusive_session(|inner| {
inner.virtio_input.ack_interrupt();
while let Some((token, event)) = inner.virtio_input.pop_pending_event() {
while let Some(event) = inner.virtio_input.pop_pending_event() {
count += 1;
key = token;
result = (event.event_type as u64) << 48
| (event.code as u64) << 32
| (event.value) as u64;
inner.events.push_back(result);
// for test
//println!("[KERN] inputdev_handle_irq: event: {:x}", result);
}
});
if count > 0 {
//self.condvars.get(&key).unwrap().signal();
self.condvar.signal();
};
}

View file

@ -29,7 +29,6 @@ mod trap;
use crate::drivers::chardev::CharDevice;
use crate::drivers::chardev::UART;
//use syscall::create_desktop; //for test
core::arch::global_asm!(include_str!("entry.asm"));
@ -59,7 +58,6 @@ pub fn rust_main() -> ! {
UART.init();
println!("KERN: init gpu");
let _gpu = GPU_DEVICE.clone();
//let _input_condvar = INPUT_CONDVAR.clone();
println!("KERN: init keyboard");
let _keyboard = KEYBOARD_DEVICE.clone();
println!("KERN: init mouse");