Move serial driver to arch::x86_64::dev::serial

This commit is contained in:
2025-02-28 23:03:12 +00:00
parent 394e932b9c
commit ad5edb57db
8 changed files with 94 additions and 31 deletions
+20 -14
View File
@@ -1,32 +1,36 @@
/* use core::{
use core::{
pin::Pin,
task::{Context, Poll},
};
use crossbeam::queue::ArrayQueue;
use futures_util::{Stream, StreamExt, task::AtomicWaker};
use pc_keyboard::{
DecodedKey, HandleControl, KeyCode, Keyboard, ScancodeSet1,
layouts::{self, Uk105Key},
};
use spin::{Lazy, Mutex, Once};
// static KBD_QUEUE: Once<ArrayQueue<u8>> = Once::new();
// static WAKER: AtomicWaker = AtomicWaker::new();
static KBD_QUEUE: Once<ArrayQueue<u8>> = Once::new();
static WAKER: AtomicWaker = AtomicWaker::new();
pub static KEYBOARD: Lazy<Mutex<Keyboard<Uk105Key, ScancodeSet1>>> = Lazy::new(|| {
Mutex::new(Keyboard::new(
ScancodeSet1::new(),
// TODO: Expose an API to change the default KB layout.
layouts::Uk105Key,
HandleControl::Ignore,
))
});
pub static KEYBOARD: Lazy<Mutex<Keyboard<Uk105Key, ScancodeSet1>>> =
Lazy::new(|| {
Mutex::new(Keyboard::new(
ScancodeSet1::new(),
// TODO: Expose an API to change the default KB layout.
layouts::Uk105Key,
HandleControl::Ignore,
))
});
pub static SCANCODE_STREAM: Lazy<Mutex<ScancodeStream>> =
Lazy::new(|| Mutex::new(ScancodeStream::new()));
pub fn add_scancode(scancode: u8) {
if let Some(queue) = KBD_QUEUE.get() {
if queue.push(scancode).is_err() {
// println!("WARNING: scancode queue full; dropping keyboard input");
// println!("WARNING: scancode queue full; dropping keyboard
// input");
} else {
WAKER.wake();
}
@@ -59,7 +63,10 @@ impl Default for ScancodeStream {
impl Stream for ScancodeStream {
type Item = u8;
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
fn poll_next(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Option<Self::Item>> {
let queue = KBD_QUEUE.get().unwrap();
if let Some(scancode) = queue.pop() {
@@ -200,4 +207,3 @@ impl core::fmt::Display for KeyStroke {
}
}
}
*/