Compare commits

..

No commits in common. '28f3838463778b169c78facb8c3f96776418d668' and '82e28a2a76e61b6217a720d3635f1099874ecf1a' have entirely different histories.

@ -18,10 +18,12 @@ const TEXT_DISPLAY_POINTER: *mut u8 = (BASE_POINTER + TEXT_DISPLAY_OFFSET) as *m
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 {
@ -55,17 +57,6 @@ 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 = { version = "0.13.0", features=["single-hart"] } riscv-rt = "0.13.0"
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: extract disassemble: build
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::{fmt::Write, panic::PanicInfo}; use core::panic::PanicInfo;
use lwcpu::{NumberDisplay, Screen, TextDisplay}; use lwcpu::{self, NumberDisplay, Screen, TextDisplay};
use riscv_rt::entry; use riscv_rt::entry;
#[panic_handler] #[panic_handler]
@ -11,15 +11,16 @@ fn panic_handler(_info: &PanicInfo) -> ! {
loop {} loop {}
} }
const HELLO_WORLD: &str = " Hello world!"; const HELLO_WORLD: &[u8; 13] = b" 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 {
let _ = text.write_str(HELLO_WORLD); for ch in HELLO_WORLD {
TextDisplay::put_char(*ch);
}
} }
} }

Loading…
Cancel
Save