firmware for my Touchscreen E-Paper Input Module for Framework Laptop 16
1use core::mem::MaybeUninit;
2use crate::{syscall, SafeOption};
3use crate::input_common::Event;
4use crate::syscall::SyscallNumber;
5
6#[repr(usize)]
7#[derive(Copy, Clone, Debug, Eq, PartialEq)]
8#[cfg_attr(feature = "defmt", derive(defmt::Format))]
9pub enum InputSyscall {
10 NextEvent = 0,
11 SetTouchEnabled = 1,
12 HasEvent = 2,
13}
14
15impl TryFrom<usize> for InputSyscall {
16 type Error = ();
17
18 fn try_from(value: usize) -> Result<Self, Self::Error> {
19 match value {
20 x if x == InputSyscall::NextEvent as usize => Ok(InputSyscall::NextEvent),
21 x if x == InputSyscall::SetTouchEnabled as usize => Ok(InputSyscall::SetTouchEnabled),
22 x if x == InputSyscall::HasEvent as usize => Ok(InputSyscall::HasEvent),
23 _ => Err(()),
24 }
25 }
26}
27
28pub fn next_event() -> Option<Event> {
29 let mut event: MaybeUninit<SafeOption<Event>> = MaybeUninit::uninit();
30
31 unsafe {
32 syscall!(
33 SyscallNumber::Input,
34 in InputSyscall::NextEvent,
35 in event.as_mut_ptr(),
36 );
37
38 event.assume_init().into()
39 }
40}
41
42pub fn set_touch_enabled(enabled: bool) {
43 unsafe {
44 syscall!(
45 SyscallNumber::Input,
46 in InputSyscall::SetTouchEnabled,
47 in enabled,
48 );
49 }
50}
51
52pub fn has_event() -> bool {
53 let mut has_event: usize;
54
55 unsafe {
56 syscall!(
57 SyscallNumber::Input,
58 out has_event in InputSyscall::HasEvent,
59 );
60 }
61
62 has_event != 0
63}