From b0901daa85d95a4020056a030c6aecb02df22d1e Mon Sep 17 00:00:00 2001 From: Iakabos <46475652+Iakabos@users.noreply.github.com> Date: Sun, 19 Jul 2020 17:18:08 -0700 Subject: [PATCH] display: Add configuration options for OLED displays (#3084) Add user-configurable contrast, vcomh (affects "smearing"), and invert options for SSD1306/SH1106 type OLED displays. Signed-off-by: James Esau --- config/example-extras.cfg | 12 ++++++++++-- klippy/extras/display/uc1701.py | 9 ++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/config/example-extras.cfg b/config/example-extras.cfg index 6ab4398b..f5f6bdb4 100644 --- a/config/example-extras.cfg +++ b/config/example-extras.cfg @@ -1831,8 +1831,16 @@ # optional. The cs_pin and a0_pin parameters must be provided when # using an uc1701 display. #contrast: 40 -# The contrast to set when using a uc1701 type display. The value may -# range from 0 to 63. Default is 40. +# The contrast to set when using a uc1701 or SSD1306/SH1106 type display +# For UC1701 the value may range from 0 to 63. Default is 40. +# For SSD1306/SH1106 the value may range from 0 to 256. Default is 239. +#vcomh: 0 +# Set the Vcomh value on SSD1306/SH1106 displays. This value is +# associated with a "smearing" effect on some OLED displays. +# The value may range from 0 to 63. Default is 0. +#invert: FALSE +# TRUE inverts the pixels on certain OLED (SSD1306/SH1106) displays +# The default is FALSE #cs_pin: #dc_pin: #spi_bus: diff --git a/klippy/extras/display/uc1701.py b/klippy/extras/display/uc1701.py index bcca8a5e..1c491dd3 100644 --- a/klippy/extras/display/uc1701.py +++ b/klippy/extras/display/uc1701.py @@ -202,6 +202,9 @@ class SSD1306(DisplayBase): io_bus = io.spi self.reset = ResetHelper(config.get("reset_pin", None), io_bus) DisplayBase.__init__(self, io, columns) + self.contrast = config.getint('contrast', 239, minval=0, maxval=255) + self.vcomh = config.getint('vcomh', 0, minval=0, maxval=63) + self.invert = config.getboolean('invert', False) def init(self): self.reset.init() init_cmds = [ @@ -215,12 +218,12 @@ class SSD1306(DisplayBase): 0xA1, # Set Segment re-map 0xC8, # Set COM output scan direction 0xDA, 0x12, # Set COM pins hardware configuration - 0x81, 0xEF, # Set contrast control + 0x81, self.contrast, # Set contrast control 0xD9, 0xA1, # Set pre-charge period - 0xDB, 0x00, # Set VCOMH deselect level + 0xDB, self.vcomh, # Set VCOMH deselect level 0x2E, # Deactivate scroll 0xA4, # Output ram to display - 0xA6, # Normal display + 0xA7 if self.invert else 0xA6, # Set normal/invert 0xAF, # Display on ] self.send(init_cmds)