Skip to main content

Uart

Struct Uart 

Source
pub struct Uart;
Expand description

UART 驱动结构体

Implementations§

Source§

impl Uart

Source

pub const fn new() -> Self

创建一个新的 UART 实例

Source

pub fn init() -> Result<()>

初始化 UART 硬件

配置波特率 38.4K,8 数据位,启用 FIFO,禁用中断。 返回 Ok(()) 表示成功,Err(UartError::InitFailed) 表示失败。

Source

pub fn put_char_sync(c: u8) -> Result<()>

同步输出字符,用于 panic 处理

参考 xv6 的 uartputc_sync 实现,轮询发送空闲并带有超时。 在系统崩溃时确保输出,避免无限等待。

Source

pub fn put_char(c: u8)

向 UART 输出单个字符

阻塞直到发送器准备就绪,轮询 LSR 寄存器直到 TX_IDLE 标志置位。

Source

pub fn put_str(s: &str)

向 UART 输出字符串

Source

pub fn try_get_char() -> Option<u8>

尝试从 UART 读取字符

如果有字符可用则返回 Some(c),否则返回 None

Trait Implementations§

Source§

impl Clone for Uart

Source§

fn clone(&self) -> Uart

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Uart

Source§

impl Debug for Uart

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Uart

§

impl RefUnwindSafe for Uart

§

impl Send for Uart

§

impl Sync for Uart

§

impl Unpin for Uart

§

impl UnsafeUnpin for Uart

§

impl UnwindSafe for Uart

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.