-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
187 additions
and
665 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
pub mod virtio; | ||
pub mod virtio; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,75 @@ | ||
use crate::drivers::bus::virtio::VirtioHal; | ||
use crate::{ | ||
gui::{Button, Component}, | ||
gui::{move_rect, reset}, | ||
sync::UPIntrFreeCell, | ||
syscall::PAD, | ||
}; | ||
use alloc::{string::ToString, sync::Arc}; | ||
use alloc::sync::Arc; | ||
use core::any::Any; | ||
use embedded_graphics::{ | ||
prelude::{Point, Size}, | ||
text::Text, | ||
}; | ||
use virtio_drivers::{VirtIOHeader, VirtIOInput}; | ||
use crate::drivers::bus::virtio::VirtioHal; | ||
use virtio_input_decoder::{Decoder, Key, KeyType}; | ||
|
||
use super::GPU_DEVICE; | ||
|
||
const VIRTIO5: usize = 0x10005000; | ||
const VIRTIO6: usize = 0x10006000; | ||
|
||
struct VirtIOINPUT(UPIntrFreeCell<VirtIOInput<'static, VirtioHal>>); | ||
struct VirtIOInputWrapper(UPIntrFreeCell<VirtIOInput<'static, VirtioHal>>); | ||
|
||
pub trait INPUTDevice: Send + Sync + Any { | ||
pub trait InputDevice: Send + Sync + Any { | ||
fn handle_irq(&self); | ||
} | ||
|
||
lazy_static::lazy_static!( | ||
pub static ref KEYBOARD_DEVICE: Arc<dyn INPUTDevice> = Arc::new(VirtIOINPUT::new(VIRTIO5)); | ||
pub static ref MOUSE_DEVICE: Arc<dyn INPUTDevice> = Arc::new(VirtIOINPUT::new(VIRTIO6)); | ||
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)); | ||
); | ||
|
||
impl VirtIOINPUT { | ||
impl VirtIOInputWrapper { | ||
pub fn new(addr: usize) -> Self { | ||
Self(unsafe { | ||
UPIntrFreeCell::new(VirtIOInput::<VirtioHal>::new(&mut *(addr as *mut VirtIOHeader)).unwrap()) | ||
UPIntrFreeCell::new( | ||
VirtIOInput::<VirtioHal>::new(&mut *(addr as *mut VirtIOHeader)).unwrap(), | ||
) | ||
}) | ||
} | ||
} | ||
|
||
impl INPUTDevice for VirtIOINPUT { | ||
impl InputDevice for VirtIOInputWrapper { | ||
fn handle_irq(&self) { | ||
let mut input = self.0.exclusive_access(); | ||
input.ack_interrupt(); | ||
let event = input.pop_pending_event().unwrap(); | ||
let dtype = match Decoder::decode( | ||
event.event_type as usize, | ||
event.code as usize, | ||
event.value as usize, | ||
) { | ||
Ok(dtype) => dtype, | ||
Err(_) => return, | ||
}; | ||
match dtype { | ||
virtio_input_decoder::DecodeType::Key(key, r#type) => { | ||
println!("{:?} {:?}", key, r#type); | ||
if r#type == KeyType::Press { | ||
let mut inner = PAD.exclusive_access(); | ||
let a = inner.as_ref().unwrap(); | ||
match key.to_char() { | ||
Ok(mut k) => { | ||
if k == '\r' { | ||
a.repaint(k.to_string() + "\n") | ||
} else { | ||
a.repaint(k.to_string()) | ||
while let Some(event) = input.pop_pending_event() { | ||
let dtype = match Decoder::decode( | ||
event.event_type as usize, | ||
event.code as usize, | ||
event.value as usize, | ||
) { | ||
Ok(dtype) => dtype, | ||
Err(_) => break, | ||
}; | ||
match dtype { | ||
virtio_input_decoder::DecodeType::Key(key, r#type) => { | ||
if r#type == KeyType::Press { | ||
match key { | ||
Key::C | Key::MouseLeft => { | ||
reset(); | ||
} | ||
Key::W => { | ||
move_rect(0, -10); | ||
} | ||
Key::S => { | ||
move_rect(0, 10); | ||
} | ||
Key::A => { | ||
move_rect(-10, 0); | ||
} | ||
Key::D => { | ||
move_rect(10, 0); | ||
} | ||
_ => {} | ||
} | ||
Err(_) => {} | ||
} | ||
} | ||
_ => {} | ||
} | ||
virtio_input_decoder::DecodeType::Mouse(mouse) => println!("{:?}", mouse), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
pub mod block; | ||
pub mod bus; | ||
pub mod chardev; | ||
pub mod gpu; | ||
pub mod input; | ||
pub mod bus; | ||
pub mod plic; | ||
|
||
pub use block::BLOCK_DEVICE; | ||
pub use bus::*; | ||
pub use chardev::UART; | ||
pub use gpu::*; | ||
pub use input::*; | ||
pub use bus::*; |
Oops, something went wrong.