| Crates.io | polished_ps2 |
| lib.rs | polished_ps2 |
| version | 0.1.1 |
| created_at | 2025-06-12 08:26:19.188972+00 |
| updated_at | 2025-06-12 20:25:33.768469+00 |
| description | Low-level routines for initializing and managing the PS/2 controller and keyboard on x86 systems. |
| homepage | |
| repository | https://codeberg.org/ofluffydev/polished |
| max_upload_size | |
| id | 1709535 |
| size | 20,279 |
ps2)This crate provides low-level routines for initializing and managing the PS/2 controller and keyboard on x86 systems. It is designed for use in operating system kernels or bootloaders written in Rust, where direct hardware access is required.
The ps2 library offers safe(ish) Rust abstractions over the raw I/O port operations needed to:
serial_logging crate.All hardware access is performed in unsafe blocks, as is required for direct port I/O on x86 hardware.
serial_logging crate to log each major step and hardware response for debugging.outb and inb functions for port I/O, wrapped in unsafe Rust for explicitness.If using as part of a workspace (as in Polished OS), add to your Cargo.toml:
[dependencies]
ps2 = { path = "../ps2" }
Call the ps2_init() function early in your kernel or bootloader initialization sequence, after setting up basic memory and logging:
ps2::ps2_init();
This will:
All functions that perform hardware access are marked unsafe internally. The public API (ps2_init) is safe to call, but must only be used in a context where direct hardware access is permitted (i.e., kernel mode, not in userland or standard OS processes).
// In your kernel's main.rs or initialization code:
extern crate ps2;
fn main() {
// ...other early setup...
ps2::ps2_init();
// ...continue kernel boot...
}
core::arch::asm!) for inb and outb operations.0xFF) and enable scanning (0xF4) commands, and checks for proper acknowledgments.serial_logging crate for debugging.The PS/2 controller is a legacy hardware interface used to connect keyboards and mice to x86 PCs. It communicates with devices using a simple serial protocol and is managed by the system firmware and operating system. Here’s how it works in the context of OS development:
| Feature | PS/2 Keyboard | USB Keyboard |
|---|---|---|
| Connection | Legacy 6-pin mini-DIN port | USB port (Type-A, Type-C, etc.) |
| Communication | Serial protocol via I/O ports | Packet-based USB protocol |
| Interrupt Handling | Hardware IRQ (IRQ1) | Polled or interrupt via USB stack |
| Initialization | Direct port I/O, simple commands | Requires USB stack and enumeration |
| Hotplug Support | No (must be connected at boot) | Yes (can be plugged/unplugged live) |
| OS Complexity | Simple, handled in kernel/firmware | Requires USB host controller driver |
| Latency | Very low, direct interrupt | Slightly higher, USB stack overhead |
| Legacy Support | Supported in BIOS/UEFI and early OS | May require special drivers in early boot |
This crate is licensed under the zlib License. See the root LICENSE file for details.
For questions or contributions, see the main Polished OS repository.