Skip to content

Commit 41a2d9c

Browse files
committed
Graphical console
1 parent 19bc552 commit 41a2d9c

16 files changed

Lines changed: 2360 additions & 0 deletions

File tree

Cargo.lock

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[workspace]
22
resolver = "2"
33
members = [
4+
"crates/console",
45
"crates/device-tree",
56
"crates/display-client",
67
"crates/display-proto",

crates/console/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.elf

crates/console/Cargo.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "console"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
bytemuck = "1.21.0"
8+
libm = "0.2.11"
9+
unicode-segmentation = "1.12"
10+
linked_list_allocator = "0.10"
11+
12+
display-client = { path = "../display-client" }
13+
lz4 = { path = "../lz4" }
14+
ulib = { path = "../ulib" }
15+
16+
[dev-dependencies]
17+
ulib = { path = "../ulib", features = ["test"] }

crates/console/build.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn main() {
2+
let crate_root = std::env::var("CARGO_MANIFEST_DIR").unwrap();
3+
println!("cargo::rerun-if-changed=../ulib/script.ld");
4+
println!("cargo::rustc-link-arg-bins=-T{crate_root}/../ulib/script.ld");
5+
println!("cargo::rustc-link-arg-bins=-n");
6+
}

crates/console/build.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
3+
set -ex
4+
5+
BIN="console"
6+
TARGET=aarch64-unknown-none-softfloat
7+
PROFILE=${PROFILE-"release"}
8+
9+
cargo rustc --profile="${PROFILE}" \
10+
--target=${TARGET} -- \
11+
-C relocation-model=static
12+
13+
if test "$PROFILE" = "dev" ; then
14+
BINARY=../../target/${TARGET}/debug/${BIN}
15+
else
16+
BINARY=../../target/${TARGET}/${PROFILE}/${BIN}
17+
fi
18+
19+
cp "${BINARY}" "${BIN}".elf
7.54 KB
Binary file not shown.

crates/console/src/color.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
pub const fn rgba(r: u8, g: u8, b: u8, a: u8) -> u32 {
2+
u32::from_be_bytes([a, r, g, b])
3+
}
4+
5+
pub const fn de_rgba(color: u32) -> (u8, u8, u8, u8) {
6+
let [a, r, g, b] = color.to_be_bytes();
7+
(r, g, b, a)
8+
}
9+
10+
pub fn blend(one: u32, two: u32) -> u32 {
11+
let [a, r, g, b] = one.to_be_bytes().map(u32::from);
12+
if a == 255 {
13+
return one;
14+
}
15+
let [_bg_a, bg_r, bg_g, bg_b] = two.to_be_bytes().map(u32::from);
16+
// TODO: blend in linear space?
17+
let (r, g, b) = (
18+
(r * a + bg_r * (255 - a)) / 255,
19+
(g * a + bg_g * (255 - a)) / 255,
20+
(b * a + bg_b * (255 - a)) / 255,
21+
);
22+
u32::from_be_bytes([a, r, g, b].map(|b| b as u8))
23+
}

0 commit comments

Comments
 (0)