From d1128b8b4c210acbc48ead1303adb1e7c360359a Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Sun, 6 Sep 2026 19:19:49 +0800 Subject: refactor: uart --- kernel/src/io/output/serial/uart_16550.rs | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'kernel/src/io') diff --git a/kernel/src/io/output/serial/uart_16550.rs b/kernel/src/io/output/serial/uart_16550.rs index 3ecce1b..acdebda 100644 --- a/kernel/src/io/output/serial/uart_16550.rs +++ b/kernel/src/io/output/serial/uart_16550.rs @@ -5,11 +5,11 @@ use uart_16550::{ #[repr(u16)] // TODO: parse & validate via acpi alors scratch -pub enum SerialPortAddress { +enum SerialPortAddress { COM1 = 0x3F8, - Com2 = 0x2F8, - Com3 = 0x3E8, - Com4 = 0x2E8, + COM2 = 0x2F8, + COM3 = 0x3E8, + COM4 = 0x2E8, } impl From for u16 { @@ -22,14 +22,6 @@ pub struct Uart16550 { pub coms: [Option>; 4], } -#[inline(always)] -fn init_port( - cfg: &mut Option, - addr: SerialPortAddress, -) -> Result>, Uart16550TtyError> { - cfg.take().map(|c| unsafe { Uart16550Tty::new_port(addr.into(), c) }).transpose() -} - impl Uart16550 { /// # Safety /// @@ -40,17 +32,26 @@ impl Uart16550 { /// /// [`NUM_REGISTERS`]: crate::spec::NUM_REGISTERS pub unsafe fn init( + // TODO: more type safe mut config: [Option; 4], ) -> Result> { unsafe { Ok(Self { coms: [ init_port(&mut config[0], SerialPortAddress::COM1)?, - init_port(&mut config[1], SerialPortAddress::Com2)?, - init_port(&mut config[2], SerialPortAddress::Com3)?, - init_port(&mut config[3], SerialPortAddress::Com4)?, + init_port(&mut config[1], SerialPortAddress::COM2)?, + init_port(&mut config[2], SerialPortAddress::COM3)?, + init_port(&mut config[3], SerialPortAddress::COM4)?, ], }) } } } + +#[inline(always)] +unsafe fn init_port( + cfg: &mut Option, + addr: SerialPortAddress, +) -> Result>, Uart16550TtyError> { + cfg.take().map(|c| unsafe { Uart16550Tty::new_port(addr.into(), c) }).transpose() +} -- cgit v1.2.3