WIP gallery app
This commit is contained in:
9
user-apps/gallery/Cargo.toml
Normal file
9
user-apps/gallery/Cargo.toml
Normal file
@@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "gallery"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
abi = { path = "../../abi" }
|
||||
embedded-graphics = "0.8.1"
|
||||
tinybmp = "0.6.0"
|
||||
28
user-apps/gallery/build.rs
Normal file
28
user-apps/gallery/build.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
//! This build script copies the `memory.x` file from the crate root into
|
||||
//! a directory where the linker can always find it at build time.
|
||||
//! For many projects this is optional, as the linker always searches the
|
||||
//! project root directory -- wherever `Cargo.toml` is. However, if you
|
||||
//! are using a workspace or have a more complicated build setup, this
|
||||
//! build script becomes required. Additionally, by requesting that
|
||||
//! Cargo re-run the build script whenever `memory.x` is changed,
|
||||
//! updating `memory.x` ensures a rebuild of the application with the
|
||||
//! new memory settings.
|
||||
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn main() {
|
||||
// Put `memory.x` in our output directory and ensure it's
|
||||
// on the linker search path.
|
||||
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
|
||||
File::create(out.join("memory.x"))
|
||||
.unwrap()
|
||||
.write_all(include_bytes!("../memory.x"))
|
||||
.unwrap();
|
||||
println!("cargo:rustc-link-search={}", out.display());
|
||||
|
||||
println!("cargo:rerun-if-changed=memory.x");
|
||||
println!("cargo:rustc-link-arg-bins=-Tmemory.x");
|
||||
}
|
||||
56
user-apps/gallery/src/main.rs
Normal file
56
user-apps/gallery/src/main.rs
Normal file
@@ -0,0 +1,56 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
extern crate alloc;
|
||||
use abi::{
|
||||
KeyCode, KeyState, Rng,
|
||||
display::{Display, SCREEN_HEIGHT, SCREEN_WIDTH},
|
||||
file_len, get_key, list_dir, lock_display, print, read_file, sleep,
|
||||
};
|
||||
use alloc::{format, vec::Vec};
|
||||
use core::panic::PanicInfo;
|
||||
use embedded_graphics::{Drawable, image::Image, prelude::*};
|
||||
use tinybmp::Bmp;
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(info: &PanicInfo) -> ! {
|
||||
print(&format!(
|
||||
"user panic: {} @ {:?}",
|
||||
info.message(),
|
||||
info.location(),
|
||||
));
|
||||
loop {}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "Rust" fn _start() {
|
||||
main()
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
print("Starting Gallery app");
|
||||
let mut display = Display;
|
||||
|
||||
let file = "/images/ferriseyes_tiny.bmp";
|
||||
|
||||
let mut bmp_buf = [0_u8; 3_000];
|
||||
let read = read_file(file, 0, &mut bmp_buf);
|
||||
let bmp = Bmp::from_slice(&bmp_buf[..read]).unwrap();
|
||||
|
||||
// ensure all draws show up at once
|
||||
lock_display(true);
|
||||
Image::new(&bmp, Point::new(10, 20))
|
||||
.draw(&mut display)
|
||||
.unwrap();
|
||||
lock_display(false);
|
||||
|
||||
loop {
|
||||
let event = get_key();
|
||||
if event.state != KeyState::Idle {
|
||||
match event.key {
|
||||
KeyCode::Esc => return,
|
||||
_ => (),
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user