Add TearingMode

This commit is contained in:
Sofia 2026-05-13 17:44:32 +03:00
parent 1cdd390440
commit 854efe3d0f
2 changed files with 25 additions and 0 deletions

View File

@ -119,6 +119,8 @@ pub enum Command {
PTLAR = 0x30, PTLAR = 0x30,
VSCRDEF = 0x33, VSCRDEF = 0x33,
ColorMode = 0x3A, ColorMode = 0x3A,
TearingOff = 0x34,
TearingOn = 0x35,
MADCTL = 0x36, MADCTL = 0x36,
VSCSAD = 0x37, VSCSAD = 0x37,
// MadCTLMY = 0x80, // MadCTLMY = 0x80,
@ -188,6 +190,12 @@ pub struct SetAddressMode {
pub refresh_order: RefreshOrder, pub refresh_order: RefreshOrder,
} }
pub enum TearingMode {
Off,
Horizontal,
HorizontalAndVertical,
}
impl SetAddressMode { impl SetAddressMode {
pub fn into_madctl(&self) -> u8 { pub fn into_madctl(&self) -> u8 {
let mut result = 0; let mut result = 0;
@ -296,6 +304,21 @@ impl<'d, DM: DriverMode, T: DelayNs> Display<'d, DM, T> {
self.write(Writeable::Data(&[mode & 0x77])); self.write(Writeable::Data(&[mode & 0x77]));
} }
pub fn set_tearing(&mut self, tearing: TearingMode) {
let cmd = match tearing {
TearingMode::Off => Command::TearingOff,
TearingMode::Horizontal => Command::TearingOn,
TearingMode::HorizontalAndVertical => Command::TearingOn,
};
self.write(Writeable::Command(cmd));
match tearing {
TearingMode::Off => {}
TearingMode::Horizontal => self.write(Writeable::Data(&[0])),
TearingMode::HorizontalAndVertical => self.write(Writeable::Data(&[1])),
}
}
fn set_columns(&mut self, start: u16, end: u16) { fn set_columns(&mut self, start: u16, end: u16) {
let [start1, start2] = start.to_be_bytes(); let [start1, start2] = start.to_be_bytes();
let [end1, end2] = end.to_be_bytes(); let [end1, end2] = end.to_be_bytes();

View File

@ -94,6 +94,8 @@ fn main() -> ! {
color_order: display::ColorOrder::Bgr, color_order: display::ColorOrder::Bgr,
..Default::default() ..Default::default()
}); });
display.set_tearing(display::TearingMode::Horizontal);
display.draw_rect( display.draw_rect(
Position::new(0, 0), Position::new(0, 0),
Position::new(32, 32), Position::new(32, 32),