playdate_rs_sys/
lib.rs

1#![no_std]
2#![allow(non_upper_case_globals)]
3#![allow(non_camel_case_types)]
4#![allow(non_snake_case)]
5
6#[cfg(not(all(target_arch = "arm", target_os = "none")))]
7include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
8
9#[cfg(all(target_arch = "arm", target_os = "none"))]
10include!("./thumbv7em_bindings.rs");
11
12#[repr(transparent)]
13#[derive(Debug, PartialEq, Eq, Hash, Default)]
14pub struct LCDColor(u64);
15
16impl LCDColor {
17    /// Convert the LCDColor to a LCDSolidColor
18    pub fn as_solid_color(&self) -> Option<LCDSolidColor> {
19        match self.0 {
20            0 => Some(LCDSolidColor::Black),
21            1 => Some(LCDSolidColor::White),
22            2 => Some(LCDSolidColor::Clear),
23            3 => Some(LCDSolidColor::XOR),
24            _ => None,
25        }
26    }
27
28    /// Convert the LCDColor to a LCDPattern
29    ///
30    /// # Safety
31    ///
32    /// This function is unsafe because it casts the LCDColor into a raw pointer and dereferences it.
33    /// The caller must ensure that the pointer is valid before calling this method.
34    pub unsafe fn as_pattern(&self) -> Option<LCDPattern> {
35        match self.0 {
36            x if x <= 3 => None,
37            _ => Some(unsafe { *(self.0 as *const LCDPattern) }),
38        }
39    }
40}
41
42impl From<LCDSolidColor> for LCDColor {
43    fn from(value: LCDSolidColor) -> Self {
44        LCDColor(value as _)
45    }
46}
47
48impl From<&LCDPattern> for LCDColor {
49    fn from(value: &LCDPattern) -> Self {
50        LCDColor(value as *const LCDPattern as _)
51    }
52}