better function names

This commit is contained in:
husky 2022-04-19 00:11:39 -07:00
parent 9ede9b1299
commit 1afb95eafb
Signed by: MlCROSOFT
GPG Key ID: E00F7FA3381F0647
1 changed files with 16 additions and 16 deletions

View File

@ -58,14 +58,14 @@ pub struct SerialPorts {
} }
#[cfg(any(target_arch="x86", target_arch="x86_64"))] #[cfg(any(target_arch="x86", target_arch="x86_64"))]
fn outb(port: u16, data: u8) { fn command(port: u16, data: u8) {
unsafe { unsafe {
asm!("out dx, al", in("al") data, in("dx") port); asm!("out dx, al", in("al") data, in("dx") port);
} }
} }
#[cfg(any(target_arch="x86", target_arch="x86_64"))] #[cfg(any(target_arch="x86", target_arch="x86_64"))]
fn inb(port: u16) -> u8 { fn read(port: u16) -> u8 {
let mut data: u8; let mut data: u8;
unsafe { unsafe {
asm!("in al, dx", out("al") data, in("dx") port); asm!("in al, dx", out("al") data, in("dx") port);
@ -75,17 +75,17 @@ fn inb(port: u16) -> u8 {
impl Port { impl Port {
fn is_transmit_empty(&self) -> bool { fn is_transmit_empty(&self) -> bool {
let status = inb(self.base as u16 + serial_offsets::LINE_STATUS as u16); let status = read(self.base as u16 + serial_offsets::LINE_STATUS as u16);
status & 0x20 == 0x20 status & 0x20 == 0x20
} }
pub fn transmit(&self, data: u8) { pub fn transmit(&self, data: u8) {
while !self.is_transmit_empty() {} while !self.is_transmit_empty() {}
outb(self.base as u16 + serial_offsets::DATA as u16, data); command(self.base as u16 + serial_offsets::DATA as u16, data);
} }
fn is_recv_full(&self) -> bool { fn is_recv_full(&self) -> bool {
let status = inb(self.base as u16 + serial_offsets::LINE_STATUS as u16); let status = read(self.base as u16 + serial_offsets::LINE_STATUS as u16);
status & 0x01 == 0x01 status & 0x01 == 0x01
} }
@ -100,7 +100,7 @@ impl Port {
} else { } else {
while !self.is_recv_full() {} while !self.is_recv_full() {}
} }
inb(self.base as u16 + serial_offsets::DATA as u16) read(self.base as u16 + serial_offsets::DATA as u16)
} }
pub fn transrecv(&self, data: u8) -> u8 { pub fn transrecv(&self, data: u8) -> u8 {
@ -111,22 +111,22 @@ impl Port {
pub fn test_port(port: potential_serial_ports) -> bool { pub fn test_port(port: potential_serial_ports) -> bool {
let mut port: u16 = port as u16; let mut port: u16 = port as u16;
outb(port + serial_offsets::INTERRUPT_ID as u16, 0x00); // disable interrupts command(port + serial_offsets::INTERRUPT_ID as u16, 0x00); // disable interrupts
outb(port + serial_offsets::LINE_CTRL as u16, 0x80); // enable DLAB command(port + serial_offsets::LINE_CTRL as u16, 0x80); // enable DLAB
outb(port + serial_offsets::DATA as u16, 0x03); // set divisor to 3 (lo byte) command(port + serial_offsets::DATA as u16, 0x03); // set divisor to 3 (lo byte)
outb(port + serial_offsets::LINE_CTRL as u16, 0x03); // set divisor to 3 (hi byte) command(port + serial_offsets::LINE_CTRL as u16, 0x03); // set divisor to 3 (hi byte)
outb(port + serial_offsets::FIFO_CTRL as u16, 0xC7); // enable FIFO, clear them, with 14-byte threshold command(port + serial_offsets::FIFO_CTRL as u16, 0xC7); // enable FIFO, clear them, with 14-byte threshold
outb(port + serial_offsets::MODEM_CTRL as u16, 0x0B); // IRQs enabled, RTS/DSR set command(port + serial_offsets::MODEM_CTRL as u16, 0x0B); // IRQs enabled, RTS/DSR set
outb(port + serial_offsets::MODEM_CTRL as u16, 0x1E); // loopback mode command(port + serial_offsets::MODEM_CTRL as u16, 0x1E); // loopback mode
// test serial // test serial
outb(port + serial_offsets::DATA as u16, 0xAE); command(port + serial_offsets::DATA as u16, 0xAE);
// check if we received the correct byte // check if we received the correct byte
if inb(port + serial_offsets::DATA as u16) != 0xAE { if read(port + serial_offsets::DATA as u16) != 0xAE {
return false; return false;
} else { } else {
// set stuffz idk // set stuffz idk
outb(port + serial_offsets::MODEM_CTRL as u16, 0x0F); command(port + serial_offsets::MODEM_CTRL as u16, 0x0F);
return true; return true;
} }
} }