in gui app, can recv keyboard and mouse info

This commit is contained in:
Yu Chen 2022-06-20 23:57:11 +08:00
parent 39ba7253b0
commit 6d10d3e3a3
2 changed files with 7 additions and 3 deletions

View File

@ -16,6 +16,7 @@ pub const VIRT_UART: usize = 0x1000_0000;
use crate::drivers::block::BLOCK_DEVICE;
use crate::drivers::chardev::{CharDevice, UART};
use crate::drivers::plic::{IntrTargetPriority, PLIC};
use crate::drivers::{KEYBOARD_DEVICE, MOUSE_DEVICE};
pub fn device_init() {
use riscv::register::sie;
@ -25,7 +26,8 @@ pub fn device_init() {
let machine = IntrTargetPriority::Machine;
plic.set_threshold(hart_id, supervisor, 0);
plic.set_threshold(hart_id, machine, 1);
for intr_src_id in [8usize, 10] {
//irq nums: 5 keyboard, 6 mouse, 8 block, 10 uart
for intr_src_id in [5usize, 6, 8 , 10] {
plic.enable(hart_id, supervisor, intr_src_id);
plic.set_priority(intr_src_id, 1);
}
@ -38,6 +40,8 @@ pub fn irq_handler() {
let mut plic = unsafe { PLIC::new(VIRT_PLIC) };
let intr_src_id = plic.claim(0, IntrTargetPriority::Supervisor);
match intr_src_id {
5 => KEYBOARD_DEVICE.handle_irq(),
6 => MOUSE_DEVICE.handle_irq(),
8 => BLOCK_DEVICE.handle_irq(),
10 => UART.handle_irq(),
_ => panic!("unsupported IRQ {}", intr_src_id),

View File

@ -21,7 +21,7 @@ const VIRTIO6: usize = 0x10006000;
struct VirtIOINPUT(UPIntrFreeCell<VirtIOInput<'static>>);
pub trait INPUTDevice: Send + Sync + Any {
fn handler_interrupt(&self);
fn handle_irq(&self);
}
lazy_static::lazy_static!(
@ -38,7 +38,7 @@ impl VirtIOINPUT {
}
impl INPUTDevice for VirtIOINPUT {
fn handler_interrupt(&self) {
fn handle_irq(&self) {
let mut input = self.0.exclusive_access();
input.ack_interrupt();
let event = input.pop_pending_event().unwrap();