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

Configure Feed

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

at f6676c82689a4e7314b93c8eb98ddd08152fe708 96 lines 3.4 kB view raw
1#![no_std] 2 3pub use eepy_sys::input_common::Event; 4 5use core::fmt::{Display, Formatter}; 6 7#[repr(u8)] 8#[derive(Copy, Clone, Debug, Eq, PartialEq, strum::FromRepr)] 9pub enum SerialCommand { 10 /// Refresh the screen. Must be followed by exactly 12480 bytes of image data. 11 RefreshNormal = 0, 12 /// Fast refresh the screen. Must be followed by exactly 12480 bytes of image data. 13 RefreshFast = 1, 14 15 MaybeRefreshNormal = 2, 16 MaybeRefreshFast = 3, 17 18 /// Enter Host App mode. In this mode, events will not be processed by the builtin UI and can 19 /// instead be retrieved by host programs using the [SerialCommand::NextEvent] command. This 20 /// mode should be used by all host programs writing images to the display. 21 EnterHostApp = 4, 22 /// Exit Host App mode (see [SerialCommand::EnterHostApp]). 23 ExitHostApp = 5, 24 25 /// Get the next event. Only works in Host App mode. 26 NextEvent = 6, 27 28 /// Disable touch. Touch events will no longer be added to the event queue. Only works in Host 29 /// App mode. 30 DisableTouch = 7, 31 /// Enable touch. 32 EnableTouch = 8, 33 34 /// Get the program slot that will be used to store the next uploaded program. This command is 35 /// only available when not in Host App mode. 36 GetProgramSlot = 9, 37 /// Upload a program. The program will be stored in the slot returned by the previous 38 /// GetProgramSlot call. The program uploaded must be linked correctly for the 39 /// slot. Only available when not in Host App mode. 40 UploadProgram = 10, 41} 42 43#[repr(u8)] 44#[derive(Copy, Clone, Debug, Eq, PartialEq, strum::FromRepr)] 45pub enum Response { 46 UnknownCommand = 0x00, 47 IncorrectMode = 0x01, 48 ProgramSlotsFull = 0x02, 49 NoProgramSlot = 0x03, 50 Ack = 0xff, 51} 52 53impl From<Response> for Result<(), SerialError> { 54 fn from(value: Response) -> Self { 55 match value { 56 Response::UnknownCommand => Err(SerialError::UnknownCommand), 57 Response::IncorrectMode => Err(SerialError::IncorrectMode), 58 Response::ProgramSlotsFull => Err(SerialError::ProgramSlotsFull), 59 Response::NoProgramSlot => Err(SerialError::NoProgramSlot), 60 Response::Ack => Ok(()), 61 } 62 } 63} 64 65impl Display for Response { 66 fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { 67 match self { 68 Response::UnknownCommand => write!(f, "Invalid command"), 69 Response::IncorrectMode => write!(f, "Incorrect mode"), 70 Response::ProgramSlotsFull => write!(f, "No program slot is available"), 71 Response::NoProgramSlot => write!(f, "Call GetProgramSlot before UploadProgram"), 72 Response::Ack => write!(f, "Success"), 73 } 74 } 75} 76 77#[derive(Copy, Clone, Debug, Eq, PartialEq)] 78pub enum SerialError { 79 UnknownCommand, 80 IncorrectMode, 81 ProgramSlotsFull, 82 NoProgramSlot, 83} 84 85impl Display for SerialError { 86 fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { 87 match self { 88 SerialError::UnknownCommand => write!(f, "Invalid command"), 89 SerialError::IncorrectMode => write!(f, "Incorrect mode"), 90 SerialError::ProgramSlotsFull => write!(f, "No program slot is available"), 91 SerialError::NoProgramSlot => write!(f, "Call GetProgramSlot before UploadProgram"), 92 } 93 } 94} 95 96impl core::error::Error for SerialError {}