Skip to main content

Crate some_serial

Crate some_serial 

Source
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§

ns16550
NS16550/16450 UART 驱动模块
pl011

Structs§

Config
IrqRxBatch
Fixed-capacity RX data extracted by one UART hard-IRQ pass.
PollingEvent
RxErrorFlags
RX error state reported by the IRQ endpoint while buffering samples.
RxSample
One hardware receive sample. Runtime channel policy is intentionally absent.
SerialEventSet
Stable event classes exchanged between a UART and its runtime.
SerialIrqEvent
Stable event produced by an IRQ-owned UART endpoint.
SerialIrqReport
Complete value returned by one UART hard-IRQ pass.
SerialParts
Independently owned task, hard-IRQ, and emergency-TX endpoints.
TransBytesError
UartEmergencyAccess
Proof that fatal output permanently owns one UART register block.
UartInfo
Immutable information reported by a concrete UART before it is split.
UartRegisterGate
Non-blocking exclusion for aliases of one UART register block.
UartRegisterGuard
Move-only proof that the caller exclusively owns UART register access.

Enums§

ConfigError
DataBits
Parity
RxFlag
SerialDirection
StopBits
TransferError

Constants§

IRQ_RX_BATCH_CAPACITY
Maximum number of normalized RX samples returned by one hard-IRQ pass.

Traits§

PollingUart
Allocation-free polling interface used by early consoles.
SplitUart
Converts a concrete UART into disjoint runtime endpoints.
UartEmergencyTx
Raw panic/emergency-only TX endpoint.
UartIrq
UART hard-IRQ endpoint owned by the registered IRQ callback.
UartPort
UART data/control endpoint owned by one runtime maintenance task.

Type Aliases§

SerialEvent