ps2-mouse

Crates.iops2-mouse
lib.rsps2-mouse
version0.1.4
sourcesrc
created_at2020-05-01 19:20:57.171493
updated_at2021-06-03 00:08:23.919483
descriptionThis crate provides basic access to a ps2 mouse in x86 environments.
homepage
repositoryhttps://github.com/rust-osdev/ps2-mouse
max_upload_size
id236346
size29,224
(RKennedy9064)

documentation

https://docs.rs/ps2-mouse

README

Build Status Docs.rs Badge

ps2 mouse

This crate provides a basic interface for interacting with a ps2 mouse.

Basic Example

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());
    }
}
Commit count: 25

cargo fmt