#![no_std] use port_input_device::{InputDevice, InputEvent, Key}; const UART_VA: usize = 0x20000; const UART_LSR_OFFSET: usize = 5; pub struct UartInputDevice; impl UartInputDevice { pub fn new() -> Self { Self } fn read_byte(&self) -> Option { let lsr = unsafe { core::ptr::read_volatile((UART_VA + UART_LSR_OFFSET) as *const u8) }; if lsr & 1 != 0 { Some(unsafe { core::ptr::read_volatile(UART_VA as *const u8) }) } else { None } } fn byte_to_key(byte: u8) -> Key { match byte { b'w' | b'W' => Key::Up, b's' | b'S' => Key::Down, b'a' | b'A' => Key::Left, b'd' | b'D' => Key::Right, b'\r' | b'\n' => Key::Enter, 0x1B => Key::Escape, c => Key::Char(c), } } } impl InputDevice for UartInputDevice { fn poll(&mut self) -> Option { let byte = self.read_byte()?; Some(InputEvent::KeyDown(Self::byte_to_key(byte))) } fn has_event(&self) -> bool { let lsr = unsafe { core::ptr::read_volatile((UART_VA + UART_LSR_OFFSET) as *const u8) }; lsr & 1 != 0 } }