3 个版本 (破坏性更新)
使用旧的 Rust 2015
| 0.3.0 | 2020 年 5 月 20 日 |
|---|---|
| 0.2.0 | 2015 年 11 月 12 日 |
| 0.1.0 | 2015 年 11 月 8 日 |
#1530 in 嵌入式开发
1,834 每月下载量
在 4 个包中使用了 (2 直接)
8KB
79 行
cpuio: inb、outb 等指令的 Rust 封装
警告:与低级 outb、outw 和 outl 函数的接口已更改以匹配 Linux。请将这些三个函数的参数顺序反转。
此库旨在在裸机上运行,并且它只依赖于 core 库。
要使用此库,将其添加到您的 Cargo.toml 文件中,并调用 cpuio::Port::new 来创建一个端口,确保指定 u8、u16 或 u32,具体取决于端口支持的数据大小。
extern crate cpuio;
use cpuio::Port;
fn main() {
// Create a port pointing at 0x60, the address of the PS/2 keyboard
// port on x86 hardware. This is an unsafe operation because many
// ports can be used to reconfigure your underlying hardware, and
// it's the responsiblity of the port creator to make sure it's
// used safely.
let mut keyboard: Port<u8> = unsafe { Port::new(0x60) };
// Read a single scancode from a PS/2 keyboard. If you run this as
// an ordinary user, it will fail with a SIGSEGV.
println!("scancode: {}", keyboard.read());
}
Port::new 构造函数可用作 const fn,允许您在编译时配置端口。
还有一个 UnsafePort 类型,它与上述类型相同,只是 read 和 write 被显式标记为 unsafe。在单个端口操作可能损坏内存或导致未定义行为时,最好使用 UnsafePort。
许可
根据您的选择,此库受 Apache 许可证 2.0 版 或 MIT 许可证 许可。