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]
11#![no_std]
12use core::cell::OnceCell;
13use firefly_rust as ff;
14
15static mut IMAGE: OnceCell<ff::ImageBuf> = OnceCell::new();
16
17#[unsafe(no_mangle)]
18extern "C" fn boot() {
19    let file = ff::load_file_buf("img").unwrap();
20    unsafe {
21        IMAGE.set(file.into()).ok().unwrap();
22    }
23}
24
25#[unsafe(no_mangle)]
26extern "C" fn update() {
27    ff::clear_screen(ff::Color::White);
28    let image = unsafe { IMAGE.get().unwrap() };
29    ff::draw_image(image, ff::Point { x: 60, y: 60 });
30}