Map keyboard to bépo
This commit is contained in:
51
src/main.rs
51
src/main.rs
@@ -9,7 +9,10 @@
|
||||
#![feature(
|
||||
riscv_ext_intrinsics,
|
||||
str_from_raw_parts,
|
||||
arbitrary_self_types_pointers
|
||||
arbitrary_self_types_pointers,
|
||||
derive_const,
|
||||
const_cmp,
|
||||
const_trait_impl
|
||||
)]
|
||||
|
||||
use core::sync::atomic::AtomicBool;
|
||||
@@ -21,7 +24,7 @@ use log::info;
|
||||
use crate::{
|
||||
cursor::{clear_cursor, draw_cursor},
|
||||
io::init_log,
|
||||
keymap::map_keycode,
|
||||
keymap::{KeyType, ModifierType, map_keycode},
|
||||
pci::{PciDeviceIterator, scan_virtio_devices},
|
||||
riscv::enable_supervisor_interrupt,
|
||||
scheduler::{SCHEDULER, idle},
|
||||
@@ -75,23 +78,24 @@ compile_error! {"This kernel implementation assume endianness is little-endian.
|
||||
#[derive(Debug, Clone, Copy, Default)]
|
||||
pub struct KeyboardState {
|
||||
// ctrl_modifier: bool,
|
||||
maj_modifier: bool,
|
||||
pub shift_modifier: bool,
|
||||
pub alt_gr_modifier: bool,
|
||||
}
|
||||
|
||||
impl KeyboardState {
|
||||
pub const fn new() -> Self {
|
||||
Self {
|
||||
// ctrl_modifier: false,
|
||||
maj_modifier: false,
|
||||
shift_modifier: false,
|
||||
alt_gr_modifier: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static mut KBD_STATE: KeyboardState = KeyboardState::new();
|
||||
static mut KBD_QUEUE: Virtqueue = unsafe { core::mem::zeroed() };
|
||||
pub static mut KBD_DRIVER: VirtioPciDriver = unsafe {
|
||||
pub static mut KBD_DRIVER: VirtioPciDriver<KeyboardState> = unsafe {
|
||||
VirtioPciDriver::new(
|
||||
|event| {
|
||||
|state, event| {
|
||||
let mut kbd_buffer = FILE_SYSTEM.open("/dev/input/keyboard".as_ref()).unwrap();
|
||||
kbd_buffer
|
||||
.write(core::mem::transmute::<
|
||||
@@ -102,25 +106,29 @@ pub static mut KBD_DRIVER: VirtioPciDriver = unsafe {
|
||||
|
||||
if event.is_key() {
|
||||
let event = event.as_key_event();
|
||||
if event.value == EventCodeValue::Pressed {
|
||||
#[allow(clippy::single_match)]
|
||||
match map_keycode(event.code, KBD_STATE.maj_modifier) {
|
||||
keymap::KeyType::Ascii(c) => {
|
||||
let mut buf = [0; 4];
|
||||
let to_send = c.encode_utf8(&mut buf);
|
||||
for c in to_send.as_bytes() {
|
||||
println!("key: {}", c);
|
||||
TTY0.buffer.borrow_mut().push(*c);
|
||||
}
|
||||
#[allow(clippy::single_match)]
|
||||
match map_keycode(event.code, state) {
|
||||
KeyType::Ascii(c) if event.value == EventCodeValue::Pressed => {
|
||||
let mut buf = [0; 4];
|
||||
let to_send = c.encode_utf8(&mut buf);
|
||||
for c in to_send.as_bytes() {
|
||||
TTY0.buffer.borrow_mut().push(*c);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
println!("event: {:#?}", event);
|
||||
KeyType::Modifier(ModifierType::Shift) => {
|
||||
state.shift_modifier = !state.shift_modifier;
|
||||
}
|
||||
KeyType::Modifier(ModifierType::AltGr) => {
|
||||
state.alt_gr_modifier = !state.alt_gr_modifier;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
println!("event: {:#?}", event);
|
||||
} else {
|
||||
// println!("key pressed, {:#?}", event);
|
||||
}
|
||||
},
|
||||
KeyboardState::new(),
|
||||
&mut KBD_QUEUE,
|
||||
)
|
||||
};
|
||||
@@ -128,9 +136,9 @@ pub static mut KBD_DRIVER: VirtioPciDriver = unsafe {
|
||||
pub static mut MOUSE_POSITION: (u16, u16) = (0, 0);
|
||||
|
||||
static mut MOUSE_QUEUE: Virtqueue = unsafe { core::mem::zeroed() };
|
||||
pub static mut MOUSE_DRIVER: VirtioPciDriver = unsafe {
|
||||
pub static mut MOUSE_DRIVER: VirtioPciDriver<()> = unsafe {
|
||||
VirtioPciDriver::new(
|
||||
|event| {
|
||||
|_, event| {
|
||||
if event.is_relative() {
|
||||
let event = event.as_relative_event();
|
||||
|
||||
@@ -153,6 +161,7 @@ pub static mut MOUSE_DRIVER: VirtioPciDriver = unsafe {
|
||||
// println!("mouse moved, {:#?}", event);
|
||||
}
|
||||
},
|
||||
(),
|
||||
&mut MOUSE_QUEUE,
|
||||
)
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user