A personal rust firmware for the Badger 2040 W
at c686e7ad8974a5d279b0dd9841c8abfb44db8d4d 65 lines 1.8 kB view raw
1use core::sync::atomic::{AtomicBool, AtomicU8}; 2 3use embedded_graphics::prelude::Point; 4 5pub static CURRENT_IMAGE: AtomicU8 = AtomicU8::new(0); 6pub static CHANGE_IMAGE: AtomicBool = AtomicBool::new(true); 7 8static NUMBER_OF_IMAGES: u8 = 2; 9static FERRIS_IMG: &[u8; 15722] = include_bytes!("../images/ferris_w_a_knife.bmp"); 10static REPO_IMG: &[u8; 11262] = include_bytes!("../images/repo.bmp"); 11 12pub enum DisplayImage { 13 Ferris = 0, 14 Repo = 1, 15} 16 17pub fn get_current_image() -> DisplayImage { 18 DisplayImage::from_u8(CURRENT_IMAGE.load(core::sync::atomic::Ordering::Relaxed)).unwrap() 19} 20 21impl DisplayImage { 22 pub fn from_u8(value: u8) -> Option<Self> { 23 match value { 24 0 => Some(Self::Ferris), 25 1 => Some(Self::Repo), 26 _ => None, 27 } 28 } 29 30 pub fn as_u8(&self) -> u8 { 31 match self { 32 Self::Ferris => 0, 33 Self::Repo => 1, 34 } 35 } 36 37 pub fn image(&self) -> &'static [u8] { 38 match self { 39 Self::Ferris => FERRIS_IMG, 40 Self::Repo => REPO_IMG, 41 } 42 } 43 44 pub fn next(&self) -> Self { 45 let image_count = self.as_u8(); 46 let next_image = (image_count + 1) % NUMBER_OF_IMAGES; 47 DisplayImage::from_u8(next_image).unwrap() 48 } 49 50 pub fn previous(&self) -> Self { 51 let image_count = self.as_u8(); 52 if image_count == 0 { 53 return DisplayImage::from_u8(NUMBER_OF_IMAGES - 1).unwrap(); 54 } 55 let previous_image = (image_count - 1) % NUMBER_OF_IMAGES; 56 DisplayImage::from_u8(previous_image).unwrap() 57 } 58 59 pub fn image_location(&self) -> Point { 60 match self { 61 Self::Ferris => Point::new(150, 26), 62 Self::Repo => Point::new(190, 26), 63 } 64 } 65}