From cb17edcab817540882e1940baaf89d2ba7ced7a5 Mon Sep 17 00:00:00 2001 From: Austin Blake Date: Tue, 20 May 2025 11:14:56 -0500 Subject: [PATCH 1/3] Add function to adjust gamma. Include constants that seem to work well on test device. --- src/lib.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 06bbb7b..dc6e98f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -245,6 +245,16 @@ where self.set_address_window(sx, sy, ex, ey)?; self.write_pixels_buffered(colors) } + + pub fn adjust_gamma(&mut self, pos: &[u8;16], neg: &[u8;16]) -> Result<(), ()> { + self.write_command(Instruction::GMCTRP1, pos)?; + self.write_command(Instruction::GMCTRN1, neg) + } +} + +pub mod gamma { + pub const POS: &[u8;16] = &[0x10, 0x0E, 0x02, 0x03, 0x0E, 0x07, 0x02, 0x07, 0x0A, 0x12, 0x27, 0x37, 0x00, 0x0D, 0x0E, 0x10]; + pub const NEG: &[u8;16] = &[0x10, 0x0E, 0x03, 0x03, 0x0F, 0x06, 0x02, 0x08, 0x0A, 0x13, 0x26, 0x36, 0x00, 0x0D, 0x0E, 0x10]; } #[cfg(feature = "graphics")] From 2063202997c85100c52b151d03ad6662e9c3a338 Mon Sep 17 00:00:00 2001 From: Austin Blake Date: Wed, 21 May 2025 15:34:21 -0500 Subject: [PATCH 2/3] Move magic values for gamma from code to comment --- src/lib.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index dc6e98f..bb2ff1c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -246,17 +246,21 @@ where self.write_pixels_buffered(colors) } + /// + /// Allows adjusting gamma correction on the display. + /// + /// Takes in an array `pos` for positive polarity correction and an array `neg` for negative polarity correction. + /// + /// The following values worked well on an ST7735S test device: + /// pos: &[0x10, 0x0E, 0x02, 0x03, 0x0E, 0x07, 0x02, 0x07, 0x0A, 0x12, 0x27, 0x37, 0x00, 0x0D, 0x0E, 0x10] + /// neg: &[0x10, 0x0E, 0x03, 0x03, 0x0F, 0x06, 0x02, 0x08, 0x0A, 0x13, 0x26, 0x36, 0x00, 0x0D, 0x0E, 0x10] + /// pub fn adjust_gamma(&mut self, pos: &[u8;16], neg: &[u8;16]) -> Result<(), ()> { self.write_command(Instruction::GMCTRP1, pos)?; self.write_command(Instruction::GMCTRN1, neg) } } -pub mod gamma { - pub const POS: &[u8;16] = &[0x10, 0x0E, 0x02, 0x03, 0x0E, 0x07, 0x02, 0x07, 0x0A, 0x12, 0x27, 0x37, 0x00, 0x0D, 0x0E, 0x10]; - pub const NEG: &[u8;16] = &[0x10, 0x0E, 0x03, 0x03, 0x0F, 0x06, 0x02, 0x08, 0x0A, 0x13, 0x26, 0x36, 0x00, 0x0D, 0x0E, 0x10]; -} - #[cfg(feature = "graphics")] extern crate embedded_graphics_core; #[cfg(feature = "graphics")] From ff3ac6b294a4cee8742595410dfb349f8b41a532 Mon Sep 17 00:00:00 2001 From: Austin Blake Date: Tue, 27 May 2025 16:06:53 -0500 Subject: [PATCH 3/3] Remove leading & trailing lines from comment --- src/lib.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index bb2ff1c..a05dab4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -246,7 +246,6 @@ where self.write_pixels_buffered(colors) } - /// /// Allows adjusting gamma correction on the display. /// /// Takes in an array `pos` for positive polarity correction and an array `neg` for negative polarity correction. @@ -254,7 +253,6 @@ where /// The following values worked well on an ST7735S test device: /// pos: &[0x10, 0x0E, 0x02, 0x03, 0x0E, 0x07, 0x02, 0x07, 0x0A, 0x12, 0x27, 0x37, 0x00, 0x0D, 0x0E, 0x10] /// neg: &[0x10, 0x0E, 0x03, 0x03, 0x0F, 0x06, 0x02, 0x08, 0x0A, 0x13, 0x26, 0x36, 0x00, 0x0D, 0x0E, 0x10] - /// pub fn adjust_gamma(&mut self, pos: &[u8;16], neg: &[u8;16]) -> Result<(), ()> { self.write_command(Instruction::GMCTRP1, pos)?; self.write_command(Instruction::GMCTRN1, neg)