Compare commits

..

2 Commits

@ -18,12 +18,10 @@ const TEXT_DISPLAY_POINTER : *mut u8 = (BASE_POINTER + TEXT_DISPLAY_OFFSET)
const KEYBOARD_POINTER: *mut u32 = (BASE_POINTER + KEYBOARD_OFFSET) as *mut u32; const KEYBOARD_POINTER: *mut u32 = (BASE_POINTER + KEYBOARD_OFFSET) as *mut u32;
const SCREEN_POINTER: *mut u32 = (BASE_POINTER + SCREEN_OFFSET) as *mut u32; const SCREEN_POINTER: *mut u32 = (BASE_POINTER + SCREEN_OFFSET) as *mut u32;
pub struct Screen {} pub struct Screen {}
impl Screen { impl Screen {
#[inline] #[inline]
pub fn clear() { pub fn clear() {}
}
#[inline] #[inline]
pub fn turn_pixel_on(x: u8, y: u8) { pub fn turn_pixel_on(x: u8, y: u8) {
unsafe { unsafe {
@ -57,6 +55,17 @@ impl TextDisplay {
} }
} }
} }
impl core::fmt::Write for TextDisplay {
#[inline]
fn write_str(&mut self, s: &str) -> core::fmt::Result {
for ch in s.bytes() {
unsafe {
write_volatile(TEXT_DISPLAY_POINTER, ch);
}
}
return Ok(());
}
}
pub struct NumberDisplay {} pub struct NumberDisplay {}
impl NumberDisplay { impl NumberDisplay {

@ -5,7 +5,7 @@ edition = "2021"
[dependencies] [dependencies]
riscv = "0.12.1" riscv = "0.12.1"
riscv-rt = "0.13.0" riscv-rt = { version = "0.13.0", features=["single-hart"] }
lwcpu = { path = "../lwcpu" } lwcpu = { path = "../lwcpu" }
# https://docs.rust-embedded.org/book/unsorted/speed-vs-size.html # https://docs.rust-embedded.org/book/unsorted/speed-vs-size.html

@ -12,7 +12,7 @@ extract: build
size: extract size: extract
cargo size --release -- -A cargo size --release -- -A
disassemble: build disassemble: extract
riscv32-elf-objdump -Cd "target/riscv32i-unknown-none-elf/release/${NAME}" | less riscv32-elf-objdump -Cd "target/riscv32i-unknown-none-elf/release/${NAME}" | less
clean: clean:

@ -1,8 +1,8 @@
#![no_std] #![no_std]
#![no_main] #![no_main]
use core::panic::PanicInfo; use core::{fmt::Write, panic::PanicInfo};
use lwcpu::{self, NumberDisplay, Screen, TextDisplay}; use lwcpu::{NumberDisplay, Screen, TextDisplay};
use riscv_rt::entry; use riscv_rt::entry;
#[panic_handler] #[panic_handler]
@ -11,16 +11,15 @@ fn panic_handler(_info: &PanicInfo) -> ! {
loop {} loop {}
} }
const HELLO_WORLD: &[u8; 13] = b" Hello world!"; const HELLO_WORLD: &str = " Hello world!";
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
let mut text = TextDisplay{};
for i in 0..31 { for i in 0..31 {
Screen::set_line(i, 1 << i); Screen::set_line(i, 1 << i);
} }
loop { loop {
for ch in HELLO_WORLD { let _ = text.write_str(HELLO_WORLD);
TextDisplay::put_char(*ch);
}
} }
} }

Loading…
Cancel
Save