Skip to content

Commit

Permalink
Patch up LCD_CAM example (esp-rs#1701)
Browse files Browse the repository at this point in the history
Co-authored-by: Dominic Fischer <git@dominicfischer.me>
  • Loading branch information
Dominaezzz and Dominic Fischer authored Jun 20, 2024
1 parent 13d6b51 commit eee20de
Showing 1 changed file with 54 additions and 61 deletions.
115 changes: 54 additions & 61 deletions examples/src/bin/lcd_i8080.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,75 +118,68 @@ fn main() -> ! {
const CMD_DOCA: u8 = 0xE8; // Display Output Ctrl Adjust
const CMD_CSCON: u8 = 0xF0; // Command Set Control

i8080.send(CMD_CSCON, 0, &[0xC3]).unwrap(); // Enable extension command 2 part I
i8080.send(CMD_CSCON, 0, &[0x96]).unwrap(); // Enable extension command 2 part II
i8080.send(CMD_INVCTR, 0, &[0x01]).unwrap(); // 1-dot inversion
i8080
.send(
CMD_DFUNCTR,
0,
&[
0x80, // Display Function Control //Bypass
0x22, /* Source Output Scan from S1 to S960, Gate Output scan from G1 to
* G480, scan cycle=2 */
0x3B,
],
)
.unwrap(); // LCD Drive Line=8*(59+1)
i8080
.send(
CMD_DOCA,
0,
&[
0x40, 0x8A, 0x00, 0x00, 0x29, // Source eqaulizing period time= 22.5 us
0x19, // Timing for "Gate start"=25 (Tclk)
0xA5, // Timing for "Gate End"=37 (Tclk), Gate driver EQ function ON
0x33,
],
)
.unwrap();
i8080.send(CMD_PWCTR2, 0, &[0x06]).unwrap(); // Power control2 //VAP(GVDD)=3.85+( vcom+vcom offset), VAN(GVCL)=-3.85+(
// vcom+vcom offset)
i8080.send(CMD_PWCTR3, 0, &[0xA7]).unwrap(); // Power control 3 //Source driving current level=low, Gamma driving current
// level=High
i8080.send(CMD_VMCTR, 0, &[0x18]).unwrap(); // VCOM Control //VCOM=0.9
// This is here mostly to workaround https://github.com/esp-rs/esp-hal/issues/1532
let mut send_cmd = |cmd: u8, data: &[u8]| {
let buf = &mut tx_buffer[0..data.len()];
buf.copy_from_slice(data);
i8080.send(cmd, 0, buf).unwrap();
};

send_cmd(CMD_CSCON, &[0xC3]); // Enable extension command 2 part I
send_cmd(CMD_CSCON, &[0x96]); // Enable extension command 2 part II
send_cmd(CMD_INVCTR, &[0x01]); // 1-dot inversion
send_cmd(
CMD_DFUNCTR,
&[
0x80, // Display Function Control //Bypass
0x22, /* Source Output Scan from S1 to S960, Gate Output scan from G1 to
* G480, scan cycle=2 */
0x3B,
],
); // LCD Drive Line=8*(59+1)
send_cmd(
CMD_DOCA,
&[
0x40, 0x8A, 0x00, 0x00, 0x29, // Source eqaulizing period time= 22.5 us
0x19, // Timing for "Gate start"=25 (Tclk)
0xA5, // Timing for "Gate End"=37 (Tclk), Gate driver EQ function ON
0x33,
],
);
send_cmd(CMD_PWCTR2, &[0x06]); // Power control2 //VAP(GVDD)=3.85+( vcom+vcom offset), VAN(GVCL)=-3.85+(
// vcom+vcom offset)
send_cmd(CMD_PWCTR3, &[0xA7]); // Power control 3 //Source driving current level=low, Gamma driving current
// level=High
send_cmd(CMD_VMCTR, &[0x18]); // VCOM Control //VCOM=0.9
delay.delay_micros(120_000);
i8080
.send(
CMD_GMCTRP1,
0,
&[
0xF0, 0x09, 0x0B, 0x06, 0x04, 0x15, 0x2F, 0x54, 0x42, 0x3C, 0x17, 0x14, 0x18,
0x1B,
],
)
.unwrap();
i8080
.send(
CMD_GMCTRN1,
0,
&[
0xE0, 0x09, 0x0B, 0x06, 0x04, 0x03, 0x2B, 0x43, 0x42, 0x3B, 0x16, 0x14, 0x17,
0x1B,
],
)
.unwrap();
send_cmd(
CMD_GMCTRP1,
&[
0xF0, 0x09, 0x0B, 0x06, 0x04, 0x15, 0x2F, 0x54, 0x42, 0x3C, 0x17, 0x14, 0x18, 0x1B,
],
);
send_cmd(
CMD_GMCTRN1,
&[
0xE0, 0x09, 0x0B, 0x06, 0x04, 0x03, 0x2B, 0x43, 0x42, 0x3B, 0x16, 0x14, 0x17, 0x1B,
],
);
delay.delay_micros(120_000);
i8080.send(CMD_CSCON, 0, &[0x3C]).unwrap(); // Command Set control // Disable extension command 2 partI
i8080.send(CMD_CSCON, 0, &[0x69]).unwrap(); // Command Set control // Disable
// extension command 2 partII
send_cmd(CMD_CSCON, &[0x3C]); // Command Set control // Disable extension command 2 partI
send_cmd(CMD_CSCON, &[0x69]); // Command Set control // Disable
// extension command 2 partII

i8080.send(0x11, 0, &[]).unwrap(); // ExitSleepMode
send_cmd(0x11, &[]); // ExitSleepMode
delay.delay_micros(130_000);
i8080.send(0x38, 0, &[]).unwrap(); // ExitIdleMode
i8080.send(0x29, 0, &[]).unwrap(); // SetDisplayOn
send_cmd(0x38, &[]); // ExitIdleMode
send_cmd(0x29, &[]); // SetDisplayOn

i8080.send(0x21, 0, &[]).unwrap(); // SetInvertMode(ColorInversion::Inverted)
send_cmd(0x21, &[]); // SetInvertMode(ColorInversion::Inverted)

// let madctl = SetAddressMode::from(options);
// i8080.send(madctl)?;
// send_cmd(madctl)?;

i8080.send(0x3A, 0, &[0x55]).unwrap(); // RGB565
send_cmd(0x3A, &[0x55]); // RGB565
}

let width = 320u16;
Expand Down

0 comments on commit eee20de

Please sign in to comment.