···55use core::fmt::{Display, Formatter};
6677#[repr(u8)]
88-#[derive(Copy, Clone, Debug, Eq, PartialEq)]
88+#[derive(Copy, Clone, Debug, Eq, PartialEq, strum::FromRepr)]
99pub enum SerialCommand {
1010 /// Refresh the screen. Must be followed by exactly 12480 bytes of image data.
1111 RefreshNormal = 0,
1212 /// Fast refresh the screen. Must be followed by exactly 12480 bytes of image data.
1313 RefreshFast = 1,
14141515+ MaybeRefreshNormal = 2,
1616+ MaybeRefreshFast = 3,
1717+1518 /// Enter Host App mode. In this mode, events will not be processed by the builtin UI and can
1619 /// instead be retrieved by host programs using the [SerialCommand::NextEvent] command. This
1720 /// mode should be used by all host programs writing images to the display.
1818- EnterHostApp = 2,
2121+ EnterHostApp = 4,
1922 /// Exit Host App mode (see [SerialCommand::EnterHostApp]).
2020- ExitHostApp = 3,
2323+ ExitHostApp = 5,
21242225 /// Get the next event. Only works in Host App mode.
2323- NextEvent = 4,
2626+ NextEvent = 6,
24272528 /// Disable touch. Touch events will no longer be added to the event queue. Only works in Host
2629 /// App mode.
2727- DisableTouch = 5,
3030+ DisableTouch = 7,
2831 /// Enable touch.
2929- EnableTouch = 6,
3232+ EnableTouch = 8,
30333134 /// Get the program slot that will be used to store the next uploaded program. This command is
3235 /// only available when not in Host App mode.
3333- GetProgramSlot = 7,
3636+ GetProgramSlot = 9,
3437 /// Upload a program. The program will be stored in the slot returned by the previous
3538 /// GetProgramSlot call. The program uploaded must be linked correctly for the
3639 /// slot. Only available when not in Host App mode.
3737- UploadProgram = 8,
3838-}
3939-4040-impl TryFrom<u8> for SerialCommand {
4141- type Error = ();
4242-4343- fn try_from(value: u8) -> Result<Self, Self::Error> {
4444- match value {
4545- x if x == SerialCommand::RefreshNormal as u8 => Ok(SerialCommand::RefreshNormal),
4646- x if x == SerialCommand::RefreshFast as u8 => Ok(SerialCommand::RefreshFast),
4747- x if x == SerialCommand::EnterHostApp as u8 => Ok(SerialCommand::EnterHostApp),
4848- x if x == SerialCommand::ExitHostApp as u8 => Ok(SerialCommand::ExitHostApp),
4949- x if x == SerialCommand::NextEvent as u8 => Ok(SerialCommand::NextEvent),
5050- x if x == SerialCommand::DisableTouch as u8 => Ok(SerialCommand::DisableTouch),
5151- x if x == SerialCommand::EnableTouch as u8 => Ok(SerialCommand::EnableTouch),
5252- x if x == SerialCommand::GetProgramSlot as u8 => Ok(SerialCommand::GetProgramSlot),
5353- x if x == SerialCommand::UploadProgram as u8 => Ok(SerialCommand::UploadProgram),
5454-5555- _ => Err(()),
5656- }
5757- }
4040+ UploadProgram = 10,
5841}
59426043#[repr(u8)]
6161-#[derive(Copy, Clone, Debug, Eq, PartialEq)]
4444+#[derive(Copy, Clone, Debug, Eq, PartialEq, strum::FromRepr)]
6245pub enum Response {
6346 UnknownCommand = 0x00,
6447 IncorrectMode = 0x01,
···8770 Response::ProgramSlotsFull => write!(f, "No program slot is available"),
8871 Response::NoProgramSlot => write!(f, "Call GetProgramSlot before UploadProgram"),
8972 Response::Ack => write!(f, "Success"),
9090- }
9191- }
9292-}
9393-9494-impl TryFrom<u8> for Response {
9595- type Error = ();
9696-9797- fn try_from(value: u8) -> Result<Self, Self::Error> {
9898- match value {
9999- x if x == Response::UnknownCommand as u8 => Ok(Response::UnknownCommand),
100100- x if x == Response::IncorrectMode as u8 => Ok(Response::IncorrectMode),
101101- x if x == Response::ProgramSlotsFull as u8 => Ok(Response::ProgramSlotsFull),
102102- x if x == Response::NoProgramSlot as u8 => Ok(Response::NoProgramSlot),
103103- x if x == Response::Ack as u8 => Ok(Response::Ack),
104104-105105- _ => Err(()),
10673 }
10774 }
10875}