use std::{cell::UnsafeCell, mem::MaybeUninit}; use embedded_graphics::pixelcolor::Rgb565; use tinybmp::Bmp; thread_local! { pub static HUMIDITY_ICON: UnsafeCell>> = const { UnsafeCell::new(MaybeUninit::zeroed()) }; pub static TEMPERATURE_ICON: UnsafeCell>> = const { UnsafeCell::new(MaybeUninit::zeroed()) }; pub static VOC_ICON: UnsafeCell>> = const { UnsafeCell::new(MaybeUninit::zeroed()) }; pub static CO2_ICON: UnsafeCell>> = const { UnsafeCell::new(MaybeUninit::zeroed()) }; } macro_rules! load_image { ($stat:expr, $path:expr) => { $stat .with(|x| *x.get() = MaybeUninit::new(Bmp::from_slice(include_bytes!($path)).unwrap())); }; } #[macro_export] macro_rules! get_image { ($image:expr) => { unsafe { &*std::mem::transmute::<*mut MaybeUninit>, *mut Bmp>( $image.with(|g| g.get()), ) } }; } pub fn prepare_images() { unsafe { load_image!(HUMIDITY_ICON, "../assets/humidity-icon.bmp"); load_image!(TEMPERATURE_ICON, "../assets/temperature-icon.bmp"); load_image!(VOC_ICON, "../assets/voc-icon.bmp"); load_image!(CO2_ICON, "../assets/co2-icon.bmp"); } }