Skip to content

Commit

Permalink
refactor(console): extract Console::read
Browse files Browse the repository at this point in the history
  • Loading branch information
mkroening committed Dec 12, 2024
1 parent c86d541 commit 976579b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 14 deletions.
5 changes: 0 additions & 5 deletions src/arch/aarch64/kernel/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ impl SerialPort {
}
}

#[allow(dead_code)]
pub fn read(&mut self) -> Option<u8> {
None
}

pub fn init(&self, _baudrate: u32) {
// We don't do anything here (yet).
}
Expand Down
7 changes: 0 additions & 7 deletions src/arch/x86_64/kernel/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,11 @@ impl SerialPort {
}
}

#[allow(dead_code)]
#[cfg(feature = "shell")]
pub fn read(&mut self) -> Option<u8> {
self.buffer.pop_front()
}

#[allow(dead_code)]
#[cfg(not(feature = "shell"))]
pub fn read(&mut self) -> Option<u8> {
None
}

pub fn send(&mut self, buf: &[u8]) {
match &mut self.inner {
SerialInner::Uhyve(s) => {
Expand Down
8 changes: 8 additions & 0 deletions src/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ impl Console {
pub fn write(&mut self, buf: &[u8]) {
arch::output_message_buf(buf);
}

#[cfg(feature = "shell")]
pub fn read(&mut self) -> Option<u8> {
crate::arch::kernel::COM1
.lock()
.as_mut()
.map(|s| s.read())?
}
}

/// A collection of methods that are required to format
Expand Down
3 changes: 1 addition & 2 deletions src/shell.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use simple_shell::*;

use crate::arch::kernel::COM1;
use crate::interrupts::print_statistics;

fn read() -> Option<u8> {
COM1.lock().as_mut().map(|s| s.read())?
crate::console::CONSOLE.lock().read()
}

pub(crate) fn init() {
Expand Down

0 comments on commit 976579b

Please sign in to comment.