···11+#![no_std]
22+33+#[repr(u8)]
44+pub enum SerialCommand {
55+ /// Refresh the screen. Must be followed by exactly 12480 bytes of image data.
66+ RefreshNormal = 0,
77+ /// Fast refresh the screen. Must be followed by exactly 12480 bytes of image data.
88+ RefreshFast = 1,
99+1010+ /// Enter Host App mode. In this mode, events will not be processed by the builtin UI and can
1111+ /// instead be retrieved by host programs using the [SerialCommand::NextEvent] command. This
1212+ /// mode should be used by all host programs writing images to the display.
1313+ EnterHostApp = 2,
1414+ /// Exit Host App mode (see [SerialCommand::EnterHostApp]).
1515+ ExitHostApp = 3,
1616+1717+ /// Get the next event. Only works in Host App mode.
1818+ NextEvent = 4,
1919+2020+ /// Disable touch. Touch events will no longer be added to the event queue. Only works in Host
2121+ /// App mode.
2222+ DisableTouch = 5,
2323+ /// Enable touch.
2424+ EnableTouch = 6,
2525+2626+ /// Get the program slot that will be used to store the next uploaded program. This command is
2727+ /// only available when not in Host App mode.
2828+ GetProgramSlot = 7,
2929+ /// Upload a program. The program will be stored in the slot returned by the previous
3030+ /// GetProgramSlot call. The host program should
3131+ UploadProgram = 8,
3232+}
3333+3434+impl TryFrom<u8> for SerialCommand {
3535+ type Error = ();
3636+3737+ fn try_from(value: u8) -> Result<Self, Self::Error> {
3838+ match value {
3939+ x if x == SerialCommand::RefreshNormal as u8 => Ok(SerialCommand::RefreshNormal),
4040+ x if x == SerialCommand::RefreshFast as u8 => Ok(SerialCommand::RefreshFast),
4141+ x if x == SerialCommand::EnterHostApp as u8 => Ok(SerialCommand::EnterHostApp),
4242+ x if x == SerialCommand::ExitHostApp as u8 => Ok(SerialCommand::ExitHostApp),
4343+ x if x == SerialCommand::NextEvent as u8 => Ok(SerialCommand::NextEvent),
4444+ x if x == SerialCommand::DisableTouch as u8 => Ok(SerialCommand::DisableTouch),
4545+ x if x == SerialCommand::EnableTouch as u8 => Ok(SerialCommand::EnableTouch),
4646+ x if x == SerialCommand::GetProgramSlot as u8 => Ok(SerialCommand::GetProgramSlot),
4747+ x if x == SerialCommand::UploadProgram as u8 => Ok(SerialCommand::UploadProgram),
4848+4949+ _ => Err(()),
5050+ }
5151+ }
5252+}
5353+5454+#[repr(u8)]
5555+pub enum Response {
5656+ UnknownCommand = 0x00,
5757+ IncorrectMode = 0x01,
5858+ ProgramSlotsFull = 0x02,
5959+ NoProgramSlot = 0x03,
6060+ Ack = 0xff,
6161+}
6262+6363+impl TryFrom<u8> for Response {
6464+ type Error = ();
6565+6666+ fn try_from(value: u8) -> Result<Self, Self::Error> {
6767+ match value {
6868+ x if x == Response::UnknownCommand as u8 => Ok(Response::UnknownCommand),
6969+ x if x == Response::IncorrectMode as u8 => Ok(Response::IncorrectMode),
7070+ x if x == Response::ProgramSlotsFull as u8 => Ok(Response::ProgramSlotsFull),
7171+ x if x == Response::NoProgramSlot as u8 => Ok(Response::NoProgramSlot),
7272+ x if x == Response::Ack as u8 => Ok(Response::Ack),
7373+7474+ _ => Err(()),
7575+ }
7676+ }
7777+}
···55#[cfg(feature = "rp2040")]
66pub mod rp2040;
7788-use defmt::trace;
98use embedded_hal::digital::{InputPin, OutputPin, PinState};
1091110/// A trait for pin types that allows running a closure with the pin configured as an input.
···157156 self.sck.set_low()?;
158157 self.delay.delay_read_after_sck_low();
159158 }
160160-161161- trace!("read byte {}", byte);
162159163160 self.cs.set_high()?;
164161 self.delay.delay_read_after_byte();