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
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.
TransBytesError
UartInfo
Immutable information reported by a concrete UART before it is split.
UartParts
Independently owned task-side and hard-IRQ endpoints.

Enums§

ConfigError
DataBits
Parity
RxFlag
SerialDirection
StopBits
TransferError

Traits§

IrqRxSink
Non-blocking destination for samples drained by a UART hard-IRQ endpoint.
PollingUart
Allocation-free polling interface used by early consoles.
SplitUart
Converts a concrete UART into disjoint runtime endpoints.
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