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)] 32pub enum RefreshBlockMode { 33 NonBlocking, 34 BlockAcknowledge, 35 BlockFinish, 36} 37 38#[repr(C)] 39#[derive(Copy, Clone)] 40pub struct ProgramFunctionTable { 41 pub write_image: extern "C" fn(&[u8; IMAGE_BYTES]), 42 pub refresh: extern "C" fn(bool, RefreshBlockMode), 43 pub next_event: extern "C" fn() -> SafeOption<Event>, 44 pub set_touch_enabled: unsafe extern "C" fn(bool), 45 pub serial_number: extern "C" fn() -> &'static [u8; 16] 46} 47 48impl ProgramFunctionTable { 49 pub fn serial_number_str(&self) -> &'static str { 50 unsafe { core::str::from_utf8_unchecked((self.serial_number)()) } 51 } 52} 53 54#[repr(C)] 55#[derive(Copy, Clone, Debug, Eq, PartialEq, defmt::Format)] 56pub enum Event { 57 Null, 58 Touch(TouchEvent), 59 RefreshFinished, 60} 61 62#[repr(u8)] 63#[derive(Copy, Clone, Debug, Eq, PartialEq, defmt::Format)] 64pub enum TouchEventType { 65 Down, 66 Up, 67 Move, 68} 69 70#[repr(C)] 71#[derive(Copy, Clone, Debug, Eq, PartialEq, defmt::Format)] 72pub struct TouchEvent { 73 pub ev_type: TouchEventType, 74 pub x: u16, 75 pub y: u16, 76} 77 78impl TouchEvent { 79 pub const fn new() -> Self { 80 Self { 81 ev_type: TouchEventType::Down, 82 x: u16::MAX, 83 y: u16::MAX, 84 } 85 } 86 87 #[cfg(feature = "embedded-graphics")] 88 pub fn eg_point(&self) -> embedded_graphics::prelude::Point { 89 embedded_graphics::prelude::Point::new(self.x as i32, self.y as i32) 90 } 91} 92 93impl Display for TouchEvent { 94 fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { 95 let ty = match self.ev_type { 96 TouchEventType::Down => "Down", 97 TouchEventType::Up => "Up", 98 TouchEventType::Move => "Move", 99 }; 100 write!(f, "{ty} @ ({}, {})", self.x, self.y) 101 } 102}