Skip to content

Commit

Permalink
Refactor serial (#336)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinc authored May 6, 2022
1 parent ed8cbf4 commit df4711e
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/sys/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,25 @@ lazy_static! {
}

pub struct Serial {
pub port: SerialPort,
port: SerialPort
}

impl Serial {
fn new(addr: u16) -> Self {
let mut port = unsafe { SerialPort::new(addr) };
port.init();
Self { port }
Self {
port: unsafe { SerialPort::new(addr) }
}
}

fn init(&mut self) {
self.port.init();
}

fn read_byte(&mut self) -> u8 {
self.port.receive()
}

pub fn write_byte(&mut self, byte: u8) {
fn write_byte(&mut self, byte: u8) {
self.port.send(byte);
}
}
Expand Down Expand Up @@ -73,11 +81,12 @@ pub fn print_fmt(args: fmt::Arguments) {
}

pub fn init() {
SERIAL.lock().init();
sys::idt::set_irq_handler(4, interrupt_handler);
}

fn interrupt_handler() {
let b = SERIAL.lock().port.receive();
let b = SERIAL.lock().read_byte();
let c = match b as char {
'\r' => '\n',
'\x7F' => '\x08', // Delete => Backspace
Expand Down

0 comments on commit df4711e

Please sign in to comment.