#x86-64 #mouse #ps2 #basic #port #set

nightly 无 std ps2-mouse

此包提供了在 x86 环境中对 PS2 鼠标的简单访问

5 个版本

0.1.4 2021 年 6 月 3 日
0.1.3 2020 年 10 月 31 日
0.1.2 2020 年 5 月 21 日
0.1.1 2020 年 5 月 5 日
0.1.0 2020 年 5 月 1 日

#240 in 无标准库

MIT/Apache

15KB
296

Build Status Docs.rs Badge

ps2 鼠标

此包提供了一个与 PS2 鼠标交互的基本接口。

基本示例

use ps2_mouse::{Mouse, MouseState};
use spinning_top::Spinlock;
use x86_64::instructions::port::PortReadOnly;

pub static MOUSE: Lazy<Spinlock<Mouse>> = Lazy::new(|| Spinlock::new(Mouse::new()));

// Initialize the mouse and set the on complete event.
fn init_mouse() {
    MOUSE.lock().init().unwrap();
    MOUSE.lock().set_on_complete(on_complete);
}

// This will be fired when a packet is finished being processed.
fn on_complete(mouse_state: MouseState) {
    println!("{:?}", mouse_state);
}

// An example interrupt based on https://os.phil-opp.com/hardware-interrupts/. The ps2 mouse is configured to fire
// interrupts at PIC offset 12.
extern "x86-interrupt" fn mouse_interrupt_handler(_stack_frame: &mut InterruptStackFrame) {
    let mut port = PortReadOnly::new(0x60);
    let packet = unsafe { port.read() };
    MOUSE.lock().process_packet(packet);

    unsafe {
        PICS.lock()
            .notify_end_of_interrupt(InterruptIndex::Mouse.into());
    }
}

依赖项

~560KB
~11K SLoC