Expand description
§Some Serial - 嵌入式串口驱动集合
本库提供统一的串口驱动接口,支持多种硬件平台:
- ARM PL011 UART
- NS16550/16450 UART(IO Port、MMIO 和 DesignWare APB 版本)
§特性
- 🏗️ 统一抽象接口 - 驱动层只提供 UART 寄存器语义,运行期队列由 OS runtime 提供
- 🛡️ 无标准库设计 (
no_std) - 适用于裸机和嵌入式系统 - 📦 模块化架构 - 每个驱动独立模块,按需选择
- 🔒 类型安全 - 使用 Rust 类型系统确保内存安全
- ⚡ 高性能 - 零拷贝数据传输,直接硬件访问
§支持的驱动
§ARM PL011 UART
- 广泛用于 ARM Cortex-A、Cortex-M、Cortex-R 系列
- 支持 FIFO、中断、回环等完整功能
§NS16550/16450 UART
- 经典 PC 串口控制器,广泛兼容
- 支持 IO Port(x86_64)、MMIO(通用)和 DesignWare APB 访问方式
- 支持 16 字节 FIFO 缓冲
§快速开始
use core::ptr::NonNull;
use some_serial::{Config, PollingUart as _, UartPort as _, ns16550::Ns16550, pl011::Pl011};
// 选择合适的驱动
#[cfg(target_arch = "aarch64")]
let mut uart = Pl011::new(NonNull::new(0x9000000 as *mut u8).unwrap(), 24_000_000);
#[cfg(not(target_arch = "aarch64"))]
let mut uart = Ns16550::new_mmio(NonNull::new(0x9000000 as *mut u8).unwrap(), 1_843_200, 1);
// 配置串口
let config = Config::new()
.baudrate(115200)
.data_bits(some_serial::DataBits::Eight)
.stop_bits(some_serial::StopBits::One)
.parity(some_serial::Parity::None);
uart.startup(&config).unwrap();
while !uart.poll_status().tx_ready() {
core::hint::spin_loop();
}
uart.write_byte(b'h');Modules§
Structs§
- Config
- IrqRx
Batch - Fixed-capacity RX data extracted by one UART hard-IRQ pass.
- Polling
Event - RxError
Flags - RX error state reported by the IRQ endpoint while buffering samples.
- RxSample
- One hardware receive sample. Runtime channel policy is intentionally absent.
- Serial
Event Set - Stable event classes exchanged between a UART and its runtime.
- Serial
IrqEvent - Stable event produced by an IRQ-owned UART endpoint.
- Serial
IrqReport - Complete value returned by one UART hard-IRQ pass.
- Serial
Parts - Independently owned task, hard-IRQ, and emergency-TX endpoints.
- Trans
Bytes Error - Uart
Emergency Access - Proof that fatal output permanently owns one UART register block.
- Uart
Info - Immutable information reported by a concrete UART before it is split.
- Uart
Register Gate - Non-blocking exclusion for aliases of one UART register block.
- Uart
Register Guard - Move-only proof that the caller exclusively owns UART register access.
Enums§
Constants§
- IRQ_
RX_ BATCH_ CAPACITY - Maximum number of normalized RX samples returned by one hard-IRQ pass.
Traits§
- Polling
Uart - Allocation-free polling interface used by early consoles.
- Split
Uart - Converts a concrete UART into disjoint runtime endpoints.
- Uart
Emergency Tx - Raw panic/emergency-only TX endpoint.
- UartIrq
- UART hard-IRQ endpoint owned by the registered IRQ callback.
- Uart
Port - UART data/control endpoint owned by one runtime maintenance task.