From 23426557993b50bd87cc314ce7a8d2aa08e88daf Mon Sep 17 00:00:00 2001 From: Grant Miller Date: Fri, 28 Aug 2020 14:32:16 -0500 Subject: [PATCH 1/5] Simplify reset and reduce delays --- src/lib.rs | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b7c1794..e484736 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -91,9 +91,22 @@ where height: HEIGHT, }; - ili9341.hard_reset(delay).map_err(Error::OutputPin)?; + // Do hardware reset by holding reset low for at least 10us + ili9341.reset.set_low().map_err(Error::OutputPin)?; + delay.delay_ms(1); + // Set high for normal operation + ili9341.reset.set_high().map_err(Error::OutputPin)?; + + // Wait 5ms after reset before sending commands + // and 120ms before sending Sleep Out + delay.delay_ms(5); + + // Do software reset ili9341.command(Command::SoftwareReset, &[])?; - delay.delay_ms(200); + + // Wait 5ms after reset before sending commands + // and 120ms before sending Sleep Out + delay.delay_ms(120); ili9341.command(Command::PowerControlA, &[0x39, 0x2c, 0x00, 0x34, 0x02])?; ili9341.command(Command::PowerControlB, &[0x00, 0xc1, 0x30])?; @@ -125,26 +138,17 @@ where 0x0f, ], )?; + ili9341.command(Command::SleepOut, &[])?; - delay.delay_ms(120); + + // Wait 5ms after Sleep Out before sending commands + delay.delay_ms(5); + ili9341.command(Command::DisplayOn, &[])?; Ok(ili9341) } - fn hard_reset>(&mut self, delay: &mut DELAY) -> Result<(), PinE> { - // set high if previously low - self.reset.set_high()?; - delay.delay_ms(200); - // set low for reset - self.reset.set_low()?; - delay.delay_ms(200); - // set high for normal operation - self.reset.set_high()?; - delay.delay_ms(200); - Ok(()) - } - fn command(&mut self, cmd: Command, args: &[u8]) -> Result<(), Error> { self.interface .send_commands(U8Iter(&mut once(cmd as u8))) From bc1282b0ca4457f2706e0c0c22633ca2284bb500 Mon Sep 17 00:00:00 2001 From: Grant Miller Date: Fri, 28 Aug 2020 14:38:49 -0500 Subject: [PATCH 2/5] Remove extended commands --- src/lib.rs | 42 ------------------------------------------ 1 file changed, 42 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e484736..596cdde 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -108,36 +108,9 @@ where // and 120ms before sending Sleep Out delay.delay_ms(120); - ili9341.command(Command::PowerControlA, &[0x39, 0x2c, 0x00, 0x34, 0x02])?; - ili9341.command(Command::PowerControlB, &[0x00, 0xc1, 0x30])?; - ili9341.command(Command::DriverTimingControlA, &[0x85, 0x00, 0x78])?; - ili9341.command(Command::DriverTimingControlB, &[0x00, 0x00])?; - ili9341.command(Command::PowerOnSequenceControl, &[0x64, 0x03, 0x12, 0x81])?; - ili9341.command(Command::PumpRatioControl, &[0x20])?; - ili9341.command(Command::PowerControl1, &[0x23])?; - ili9341.command(Command::PowerControl2, &[0x10])?; - ili9341.command(Command::VCOMControl1, &[0x3e, 0x28])?; - ili9341.command(Command::VCOMControl2, &[0x86])?; ili9341.command(Command::MemoryAccessControl, &[0x48])?; ili9341.command(Command::PixelFormatSet, &[0x55])?; - ili9341.command(Command::FrameControlNormal, &[0x00, 0x18])?; - ili9341.command(Command::DisplayFunctionControl, &[0x08, 0x82, 0x27])?; - ili9341.command(Command::Enable3G, &[0x00])?; ili9341.command(Command::GammaSet, &[0x01])?; - ili9341.command( - Command::PositiveGammaCorrection, - &[ - 0x0f, 0x31, 0x2b, 0x0c, 0x0e, 0x08, 0x4e, 0xf1, 0x37, 0x07, 0x10, 0x03, 0x0e, 0x09, - 0x00, - ], - )?; - ili9341.command( - Command::NegativeGammaCorrection, - &[ - 0x00, 0x0e, 0x14, 0x03, 0x11, 0x07, 0x31, 0xc1, 0x48, 0x08, 0x0f, 0x0c, 0x31, 0x36, - 0x0f, - ], - )?; ili9341.command(Command::SleepOut, &[])?; @@ -272,24 +245,9 @@ mod graphics; #[derive(Clone, Copy)] enum Command { SoftwareReset = 0x01, - PowerControlA = 0xcb, - PowerControlB = 0xcf, - DriverTimingControlA = 0xe8, - DriverTimingControlB = 0xea, - PowerOnSequenceControl = 0xed, - PumpRatioControl = 0xf7, - PowerControl1 = 0xc0, - PowerControl2 = 0xc1, - VCOMControl1 = 0xc5, - VCOMControl2 = 0xc7, MemoryAccessControl = 0x36, PixelFormatSet = 0x3a, - FrameControlNormal = 0xb1, - DisplayFunctionControl = 0xb6, - Enable3G = 0xf2, GammaSet = 0x26, - PositiveGammaCorrection = 0xe0, - NegativeGammaCorrection = 0xe1, SleepOut = 0x11, DisplayOn = 0x29, ColumnAddressSet = 0x2a, From 780a5f0c25329a5afff2ef5af035780f18143843 Mon Sep 17 00:00:00 2001 From: Grant Miller Date: Fri, 28 Aug 2020 14:39:37 -0500 Subject: [PATCH 3/5] Remove gamma set command, 0x01 is the default --- src/lib.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 596cdde..fda0f4b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -110,7 +110,6 @@ where ili9341.command(Command::MemoryAccessControl, &[0x48])?; ili9341.command(Command::PixelFormatSet, &[0x55])?; - ili9341.command(Command::GammaSet, &[0x01])?; ili9341.command(Command::SleepOut, &[])?; @@ -247,7 +246,6 @@ enum Command { SoftwareReset = 0x01, MemoryAccessControl = 0x36, PixelFormatSet = 0x3a, - GammaSet = 0x26, SleepOut = 0x11, DisplayOn = 0x29, ColumnAddressSet = 0x2a, From 427127fe2ddd97218b170f3578fc3aedff17f663 Mon Sep 17 00:00:00 2001 From: Grant Miller Date: Fri, 28 Aug 2020 15:28:31 -0500 Subject: [PATCH 4/5] Use `set_orientation` in initialization --- src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index fda0f4b..682b04d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -108,7 +108,8 @@ where // and 120ms before sending Sleep Out delay.delay_ms(120); - ili9341.command(Command::MemoryAccessControl, &[0x48])?; + ili9341.set_orientation(Orientation::Portrait)?; + ili9341.command(Command::PixelFormatSet, &[0x55])?; ili9341.command(Command::SleepOut, &[])?; From 61531412cf240ada4da2f001199c20226984561f Mon Sep 17 00:00:00 2001 From: Grant Miller Date: Fri, 28 Aug 2020 15:26:46 -0500 Subject: [PATCH 5/5] Add comment to pixel format set --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index 682b04d..9b52a2d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -110,6 +110,7 @@ where ili9341.set_orientation(Orientation::Portrait)?; + // Set pixel format to 16 bits per pixel ili9341.command(Command::PixelFormatSet, &[0x55])?; ili9341.command(Command::SleepOut, &[])?;