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 SCREEN_POINTER: *mut u32 = (BASE_POINTER + SCREEN_OFFSET) as *mut u32;
pub struct Screen {}
impl Screen {
#[inline]
pub fn clear() {
}
pub fn clear() {}
#[inline]
pub fn turn_pixel_on(x: u8, y: u8) {
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 {}
impl NumberDisplay {

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

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

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

Loading…
Cancel
Save