Skip to main content

image/
main.rs

1//! The example shows how to read an image from ROM and draw it on the screen.
2//!
3//! Since we don't specify in advance the image size, we'll need an allocator
4//! to dynamically allocate the required memory. A proper solution would be
5//! to find a third-party allocator (like wee_alloc) and use that.
6//! However, to keep the example simple, we instead enable std. It significantly
7//! increases the binary size but it's good enough for simple apps.
8
9#![allow(static_mut_refs)]
10#![no_main]
11use firefly_rust as ff;
12use std::cell::OnceCell;
13
14static mut IMAGE: OnceCell<ff::FileBuf> = OnceCell::new();
15
16#[unsafe(no_mangle)]
17extern "C" fn boot() {
18    let file = ff::load_file_buf("img").unwrap();
19    unsafe {
20        IMAGE.set(file).ok().unwrap();
21    }
22}
23
24#[unsafe(no_mangle)]
25extern "C" fn update() {
26    ff::clear_screen(ff::Color::White);
27    let image = unsafe { IMAGE.get().unwrap() };
28    let image: ff::Image = (image).into();
29    ff::draw_image(&image, ff::Point { x: 60, y: 60 });
30}