gif need psram
This commit is contained in:
9
user-apps/gif/Cargo.toml
Normal file
9
user-apps/gif/Cargo.toml
Normal file
@@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "gif"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
abi = { path = "../../abi" }
|
||||
embedded-graphics = "0.8.1"
|
||||
tinygif = "0.0.4"
|
||||
28
user-apps/gif/build.rs
Normal file
28
user-apps/gif/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");
|
||||
}
|
||||
64
user-apps/gif/src/main.rs
Normal file
64
user-apps/gif/src/main.rs
Normal file
@@ -0,0 +1,64 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
extern crate alloc;
|
||||
use abi::{
|
||||
display::{Display, lock_display},
|
||||
fs::read_file,
|
||||
get_key, get_ms,
|
||||
keyboard::{KeyCode, KeyState},
|
||||
print, sleep,
|
||||
};
|
||||
use alloc::format;
|
||||
use core::panic::PanicInfo;
|
||||
use embedded_graphics::{image::ImageDrawable, pixelcolor::Rgb565};
|
||||
use tinygif::{Gif, Header};
|
||||
|
||||
#[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 Gif app");
|
||||
let mut display = Display;
|
||||
|
||||
static mut BUF: [u8; 256] = [0_u8; 256];
|
||||
|
||||
read_file("/gif/bad_apple.gif", 0, unsafe { &mut BUF[0..6] });
|
||||
|
||||
let gif_header = Header::parse(unsafe { &BUF[0..6] });
|
||||
|
||||
let image = Gif::<Rgb565>::from_slice().unwrap();
|
||||
|
||||
loop {
|
||||
for frame in image.frames() {
|
||||
let start = get_ms();
|
||||
|
||||
frame.draw(&mut display).unwrap();
|
||||
|
||||
sleep(((frame.delay_centis as u64) * 10).saturating_sub(start));
|
||||
|
||||
let event = get_key();
|
||||
if event.state != KeyState::Idle {
|
||||
match event.key {
|
||||
KeyCode::Esc => return,
|
||||
_ => (),
|
||||
};
|
||||
};
|
||||
|
||||
lock_display(true);
|
||||
lock_display(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user