mirror of
https://github.com/rcore-os/rCore-Tutorial-v3.git
synced 2024-11-22 01:16:26 +04:00
in gui app, can recv keyboard and mouse info
This commit is contained in:
parent
39ba7253b0
commit
6d10d3e3a3
@ -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),
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user