Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rust-osdev/ps2-mouse
Library to manage a PS2 mouse
https://github.com/rust-osdev/ps2-mouse
Last synced: 15 days ago
JSON representation
Library to manage a PS2 mouse
- Host: GitHub
- URL: https://github.com/rust-osdev/ps2-mouse
- Owner: rust-osdev
- License: apache-2.0
- Created: 2020-05-01T16:38:47.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-08-30T13:57:00.000Z (over 3 years ago)
- Last Synced: 2024-12-01T01:16:43.128Z (28 days ago)
- Language: Rust
- Size: 24.4 KB
- Stars: 10
- Watchers: 4
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: Changelog.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
[![Build Status](https://github.com/rust-osdev/ps2-mouse/workflows/Build/badge.svg)](https://github.com/rust-osdev/ps2-mouse/actions?query=workflow%3ABuild) [![Docs.rs Badge](https://docs.rs/ps2-mouse/badge.svg)](https://docs.rs/ps2-mouse/)
# ps2 mouse
This crate provides a basic interface for interacting with a ps2 mouse.## Basic Example
```rust
use ps2_mouse::{Mouse, MouseState};
use spinning_top::Spinlock;
use x86_64::instructions::port::PortReadOnly;pub static MOUSE: Lazy> = 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());
}
}
```