firmware for my Touchscreen E-Paper Input Module for Framework Laptop 16
1use core::fmt::{Display, Formatter};
2
3#[repr(C)]
4#[cfg_attr(feature = "defmt", derive(defmt::Format))]
5#[derive(Copy, Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
6pub enum Event {
7 Touch(TouchEvent),
8 RefreshFinished,
9}
10
11#[repr(u8)]
12#[cfg_attr(feature = "defmt", derive(defmt::Format))]
13#[derive(Copy, Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
14pub enum TouchEventType {
15 Down,
16 Up,
17 Move,
18}
19
20#[repr(C)]
21#[cfg_attr(feature = "defmt", derive(defmt::Format))]
22#[derive(Copy, Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
23pub struct TouchEvent {
24 pub ev_type: TouchEventType,
25 pub x: u16,
26 pub y: u16,
27}
28
29impl TouchEvent {
30 pub const fn new() -> Self {
31 Self {
32 ev_type: TouchEventType::Down,
33 x: u16::MAX,
34 y: u16::MAX,
35 }
36 }
37
38 #[cfg(feature = "embedded-graphics")]
39 pub fn eg_point(&self) -> embedded_graphics::prelude::Point {
40 embedded_graphics::prelude::Point::new(self.x as i32, self.y as i32)
41 }
42}
43
44impl Display for TouchEvent {
45 fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
46 let ty = match self.ev_type {
47 TouchEventType::Down => "Down",
48 TouchEventType::Up => "Up",
49 TouchEventType::Move => "Move",
50 };
51 write!(f, "{ty} @ ({}, {})", self.x, self.y)
52 }
53}