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