firmware for my Touchscreen E-Paper Input Module for Framework Laptop 16
0

Configure Feed

Select the types of activity you want to include in your feed.

1#![no_std] 2 3use core::fmt::{Display, Formatter}; 4pub use tp370pgh01::IMAGE_BYTES; 5 6/// Option type with stable ABI. 7#[repr(C)] 8pub enum SafeOption<T> { 9 None, 10 Some(T), 11} 12 13impl<T> From<Option<T>> for SafeOption<T> { 14 fn from(value: Option<T>) -> Self { 15 match value { 16 None => SafeOption::None, 17 Some(v) => SafeOption::Some(v), 18 } 19 } 20} 21 22impl<T> From<SafeOption<T>> for Option<T> { 23 fn from(value: SafeOption<T>) -> Self { 24 match value { 25 SafeOption::None => None, 26 SafeOption::Some(v) => Some(v), 27 } 28 } 29} 30 31#[repr(C)] 32#[derive(Copy, Clone)] 33pub struct ProgramFunctionTable { 34 pub write_image: extern "C" fn(&[u8; IMAGE_BYTES]), 35 pub refresh: extern "C" fn(bool, bool), 36 pub next_touch_event: extern "C" fn() -> SafeOption<TouchEvent>, 37 pub set_touch_enabled: unsafe extern "C" fn(bool), 38} 39 40#[repr(u8)] 41#[derive(Copy, Clone, Debug, defmt::Format)] 42pub enum TouchEventType { 43 Down, 44 Up, 45 Move, 46} 47 48#[repr(C)] 49#[derive(Copy, Clone, Debug, defmt::Format)] 50pub struct TouchEvent { 51 pub ev_type: TouchEventType, 52 pub x: u16, 53 pub y: u16, 54} 55 56impl TouchEvent { 57 pub const fn new() -> Self { 58 Self { 59 ev_type: TouchEventType::Down, 60 x: u16::MAX, 61 y: u16::MAX, 62 } 63 } 64 65 #[cfg(feature = "embedded-graphics")] 66 pub fn eg_point(&self) -> embedded_graphics::prelude::Point { 67 embedded_graphics::prelude::Point::new(self.x as i32, self.y as i32) 68 } 69} 70 71impl Display for TouchEvent { 72 fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { 73 let ty = match self.ev_type { 74 TouchEventType::Down => "Down", 75 TouchEventType::Up => "Up", 76 TouchEventType::Move => "Move", 77 }; 78 write!(f, "{ty} @ ({}, {})", self.x, self.y) 79 } 80}