mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-25 10:23:23 +00:00
Remove virtio-input-decoder dependence
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
2437fba0d9
commit
2d605e04d1
@ -12,8 +12,9 @@ aster-frame = { path = "../../../framework/aster-frame" }
|
||||
aster-util = { path = "../../libs/aster-util" }
|
||||
aster-rights = { path = "../../libs/aster-rights" }
|
||||
component = { path = "../../libs/comp-sys/component" }
|
||||
virtio-input-decoder = "0.1.4"
|
||||
int-to-c-enum = { path = "../../libs/int-to-c-enum" }
|
||||
log = "0.4"
|
||||
ascii = { version = "1.1", default-features = false, features = ["alloc"] }
|
||||
|
||||
[features]
|
||||
|
||||
|
128
services/comps/input/src/key.rs
Normal file
128
services/comps/input/src/key.rs
Normal file
@ -0,0 +1,128 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use int_to_c_enum::TryFromInt;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, TryFromInt)]
|
||||
#[repr(u16)]
|
||||
pub enum Key {
|
||||
Reserved = 0,
|
||||
ESC = 1,
|
||||
One = 2,
|
||||
Two = 3,
|
||||
Three = 4,
|
||||
Four = 5,
|
||||
Five = 6,
|
||||
Six = 7,
|
||||
Seven = 8,
|
||||
Eight = 9,
|
||||
Nine = 10,
|
||||
Zero = 11,
|
||||
Minus = 12,
|
||||
Equal = 13,
|
||||
BackSpace = 14,
|
||||
Tab = 15,
|
||||
Q = 16,
|
||||
W = 17,
|
||||
E = 18,
|
||||
R = 19,
|
||||
T = 20,
|
||||
Y = 21,
|
||||
U = 22,
|
||||
I = 23,
|
||||
O = 24,
|
||||
P = 25,
|
||||
/// Symbol: [
|
||||
LeftBrace = 26,
|
||||
/// Symbol: ]
|
||||
RightBrace = 27,
|
||||
Enter = 28,
|
||||
LeftCtrl = 29,
|
||||
A = 30,
|
||||
S = 31,
|
||||
D = 32,
|
||||
F = 33,
|
||||
G = 34,
|
||||
H = 35,
|
||||
J = 36,
|
||||
K = 37,
|
||||
L = 38,
|
||||
/// Symbol: ;
|
||||
SemiColon = 39,
|
||||
/// Symbol: '
|
||||
Apostrophe = 40,
|
||||
/// Symbol: `
|
||||
Grave = 41,
|
||||
LeftShift = 42,
|
||||
/// Symbol: \
|
||||
BackSlash = 43,
|
||||
Z = 44,
|
||||
X = 45,
|
||||
C = 46,
|
||||
V = 47,
|
||||
B = 48,
|
||||
N = 49,
|
||||
M = 50,
|
||||
Comma = 51,
|
||||
Dot = 52,
|
||||
// Symbol: /
|
||||
Slash = 53,
|
||||
RightShift = 54,
|
||||
/// Keypad asterisk, Symbol: *
|
||||
KpAsterisk = 55,
|
||||
LeftAlt = 56,
|
||||
Space = 57,
|
||||
Capslock = 58,
|
||||
F1 = 59,
|
||||
F2 = 60,
|
||||
F3 = 61,
|
||||
F4 = 62,
|
||||
F5 = 63,
|
||||
F6 = 64,
|
||||
F7 = 65,
|
||||
F8 = 66,
|
||||
F9 = 67,
|
||||
F10 = 68,
|
||||
NumLock = 69,
|
||||
ScrollLock = 70,
|
||||
Kp7 = 71,
|
||||
Kp8 = 72,
|
||||
Kp9 = 73,
|
||||
KpMinus = 74,
|
||||
Kp4 = 75,
|
||||
Kp5 = 76,
|
||||
Kp6 = 77,
|
||||
KpPlus = 78,
|
||||
Kp1 = 79,
|
||||
Kp2 = 80,
|
||||
Kp3 = 81,
|
||||
Kp0 = 82,
|
||||
KpDot = 83,
|
||||
|
||||
F11 = 87,
|
||||
F12 = 88,
|
||||
|
||||
KpEnter = 96,
|
||||
RightCtrl = 97,
|
||||
KpSlash = 98,
|
||||
|
||||
RightAlt = 100,
|
||||
LineFeed = 101,
|
||||
Home = 102,
|
||||
Up = 103,
|
||||
PageUp = 104,
|
||||
Left = 105,
|
||||
Right = 106,
|
||||
End = 107,
|
||||
Down = 108,
|
||||
PageDown = 109,
|
||||
Insert = 110,
|
||||
Delete = 111,
|
||||
|
||||
LeftMeta = 125,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum KeyStatus {
|
||||
Pressed,
|
||||
Released,
|
||||
}
|
@ -6,6 +6,9 @@
|
||||
#![feature(fn_traits)]
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
pub mod key;
|
||||
|
||||
use core::any::Any;
|
||||
use core::fmt::Debug;
|
||||
|
||||
@ -18,11 +21,18 @@ use component::ComponentInitError;
|
||||
|
||||
use aster_frame::sync::SpinLock;
|
||||
use spin::Once;
|
||||
use virtio_input_decoder::DecodeType;
|
||||
|
||||
use key::Key;
|
||||
use key::KeyStatus;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum InputEvent {
|
||||
KeyBoard(Key, KeyStatus),
|
||||
}
|
||||
|
||||
pub trait InputDevice: Send + Sync + Any + Debug {
|
||||
fn handle_irq(&self) -> Option<()>;
|
||||
fn register_callbacks(&self, function: &'static (dyn Fn(DecodeType) + Send + Sync));
|
||||
fn register_callbacks(&self, function: &'static (dyn Fn(InputEvent) + Send + Sync));
|
||||
}
|
||||
|
||||
pub fn register_device(name: String, device: Arc<dyn InputDevice>) {
|
||||
|
Reference in New Issue
Block a user