use crate::interface::Interface;
#[macro_use]
pub(crate) mod macros;
mod set_address_mode;
pub use set_address_mode::*;
mod set_pixel_format;
pub use set_pixel_format::*;
mod set_column_address;
pub use set_column_address::*;
mod set_page_address;
pub use set_page_address::*;
mod set_scroll_area;
pub use set_scroll_area::*;
mod set_scroll_start;
pub use set_scroll_start::*;
mod set_tearing_effect;
pub use set_tearing_effect::*;
mod set_invert_mode;
pub use set_invert_mode::*;
pub trait DcsCommand {
fn instruction(&self) -> u8;
fn fill_params_buf(&self, buffer: &mut [u8]) -> usize;
}
pub trait InterfaceExt: Interface {
fn write_command(
&mut self,
command: impl DcsCommand,
) -> impl core::future::Future<Output = Result<(), Self::Error>> {
async move {
let mut param_bytes: [u8; 16] = [0; 16];
let n = command.fill_params_buf(&mut param_bytes);
self.write_raw(command.instruction(), ¶m_bytes[..n])
.await
}
}
fn write_raw(
&mut self,
instruction: u8,
param_bytes: &[u8],
) -> impl core::future::Future<Output = Result<(), Self::Error>> {
async move { self.send_command(instruction, param_bytes).await }
}
}
impl<T: Interface> InterfaceExt for T {}
dcs_basic_command!(
SoftReset,
0x01
);
dcs_basic_command!(
EnterSleepMode,
0x10
);
dcs_basic_command!(
ExitSleepMode,
0x11
);
dcs_basic_command!(
EnterPartialMode,
0x12
);
dcs_basic_command!(
EnterNormalMode,
0x13
);
dcs_basic_command!(
SetDisplayOff,
0x28
);
dcs_basic_command!(
SetDisplayOn,
0x29
);
dcs_basic_command!(
ExitIdleMode,
0x38
);
dcs_basic_command!(
EnterIdleMode,
0x39
);
dcs_basic_command!(
WriteMemoryStart,
0x2C
);