mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 22:37:49 +00:00
Refactor: Move interrupt wakers/operations into separate modules
This commit is contained in:
@@ -1,11 +1,38 @@
|
||||
use crate::{interrupts, print};
|
||||
use crate::{print, println, task::interrupt_wake};
|
||||
use conquer_once::spin::OnceCell;
|
||||
use core::future::Future;
|
||||
use core::{
|
||||
pin::Pin,
|
||||
task::{Context, Poll},
|
||||
};
|
||||
use crossbeam_queue::ArrayQueue;
|
||||
use futures_util::task::AtomicWaker;
|
||||
use pc_keyboard::{layouts, DecodedKey, HandleControl, Keyboard, ScancodeSet1};
|
||||
|
||||
static WAKER: AtomicWaker = AtomicWaker::new();
|
||||
static SCANCODE_QUEUE: OnceCell<ArrayQueue<u8>> = OnceCell::uninit();
|
||||
|
||||
pub fn init() {
|
||||
SCANCODE_QUEUE
|
||||
.try_init_once(|| ArrayQueue::new(10))
|
||||
.expect("failed to init scancode queue");
|
||||
}
|
||||
|
||||
/// Called by the keyboard interrupt handler
|
||||
///
|
||||
/// Must not block (including spinlocks).
|
||||
pub(crate) fn keyboard_scancode(scancode: u8) {
|
||||
let scancode_queue = SCANCODE_QUEUE
|
||||
.try_get()
|
||||
.expect("scancode queue not initialized");
|
||||
if let Err(_) = scancode_queue.push(scancode) {
|
||||
println!("WARNING: dropping keyboard input");
|
||||
}
|
||||
if let Some(waker) = WAKER.take() {
|
||||
interrupt_wake(waker);
|
||||
}
|
||||
}
|
||||
|
||||
fn next_scancode() -> impl Future<Output = u8> {
|
||||
NextScancode
|
||||
}
|
||||
@@ -16,7 +43,7 @@ impl Future for NextScancode {
|
||||
type Output = u8;
|
||||
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<u8> {
|
||||
let scancodes = interrupts::SCANCODE_QUEUE
|
||||
let scancodes = SCANCODE_QUEUE
|
||||
.try_get()
|
||||
.expect("scancode queue not initialized");
|
||||
// fast path
|
||||
@@ -24,7 +51,7 @@ impl Future for NextScancode {
|
||||
return Poll::Ready(scancode);
|
||||
}
|
||||
|
||||
interrupts::KEYBOARD_INTERRUPT_WAKER.register(&cx.waker());
|
||||
WAKER.register(&cx.waker());
|
||||
match scancodes.pop() {
|
||||
Ok(scancode) => Poll::Ready(scancode),
|
||||
Err(crossbeam_queue::PopError) => Poll::Pending,
|
||||
@@ -32,7 +59,7 @@ impl Future for NextScancode {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn print_keypresses() {
|
||||
pub async fn keyboard_task() {
|
||||
let mut keyboard = Keyboard::new(layouts::Us104Key, ScancodeSet1, HandleControl::Ignore);
|
||||
|
||||
loop {
|
||||
|
||||
Reference in New Issue
Block a user