From e231ac74221fcfa6e26ace1027d322c7fe111e38 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Wed, 21 Nov 2018 13:43:48 -0500 Subject: [PATCH] uc1701: Add support for SSD1306 displays Signed-off-by: Kevin O'Connor --- config/example-extras.cfg | 15 ++++++++++----- klippy/extras/display/display.py | 2 +- klippy/extras/display/uc1701.py | 29 ++++++++++++++++++++++++++++- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/config/example-extras.cfg b/config/example-extras.cfg index a86759f0..e79ec469 100644 --- a/config/example-extras.cfg +++ b/config/example-extras.cfg @@ -863,11 +863,12 @@ # Support for a display attached to the micro-controller. #[display] #lcd_type: -# The type of LCD chip in use. This may be "hd44780" (which is -# used in "RepRapDiscount 2004 Smart Controller" type displays), -# "st7920" (which is used in "RepRapDiscount 12864 Full Graphic -# Smart Controller" type displays) or "uc1701" (which is used in -# "MKS Mini 12864" type displays). This parameter must be provided. +# The type of LCD chip in use. This may be "hd44780" (which is used +# in "RepRapDiscount 2004 Smart Controller" type displays), "st7920" +# (which is used in "RepRapDiscount 12864 Full Graphic Smart +# Controller" type displays), "uc1701" (which is used in "MKS Mini +# 12864" type displays), or "ssd1306". This parameter must be +# provided. #rs_pin: #e_pin: #d4_pin: @@ -885,6 +886,10 @@ #a0_pin # The pins connected to an uc1701 type lcd. These parameters must be # provided when using an uc1701 display. +#cs_pin: +#dc_pin +# The pins connected to an ssd1306 type lcd. These parameters must +# be provided when using an ssd1306 display. #menu_root: # Entry point for menu, root menu container name. If this parameter # is not provided then default menu root is used. When provided diff --git a/klippy/extras/display/display.py b/klippy/extras/display/display.py index b3cffa7b..c58bf65f 100644 --- a/klippy/extras/display/display.py +++ b/klippy/extras/display/display.py @@ -11,7 +11,7 @@ import menu LCD_chips = { 'st7920': st7920.ST7920, 'hd44780': hd44780.HD44780, - 'uc1701' : uc1701.UC1701 + 'uc1701' : uc1701.UC1701, 'ssd1306': uc1701.SSD1306, } M73_TIMEOUT = 5. diff --git a/klippy/extras/display/uc1701.py b/klippy/extras/display/uc1701.py index ba564395..6b42cdef 100644 --- a/klippy/extras/display/uc1701.py +++ b/klippy/extras/display/uc1701.py @@ -12,6 +12,7 @@ BACKGROUND_PRIORITY_CLOCK = 0x7fffffff00000000 TextGlyphs = { 'right_arrow': '\x1a', 'degrees': '\xf8' } class UC1701: + DATA_PIN_NAME = "a0_pin" CURRENT_BUF, OLD_BUF = 0, 1 EMPTY_CHAR = (0, 32, 255) def __init__(self, config): @@ -20,7 +21,7 @@ class UC1701: mcu = self.spi.get_mcu() # Create a0 pin ppins = config.get_printer().lookup_object('pins') - a0_pin_params = ppins.lookup_pin(config.get('a0_pin')) + a0_pin_params = ppins.lookup_pin(config.get(self.DATA_PIN_NAME)) if a0_pin_params['chip'] != mcu: raise ppins.error("uc1701 all pins must be on same mcu") self.a0_oid = mcu.create_oid() @@ -158,3 +159,29 @@ class UC1701: page[:] = zeros def get_dimensions(self): return (16, 4) + +# The SSD1306 (in 4-wire SPI mode) differs from UC1701 only in display init +class SSD1306(UC1701): + DATA_PIN_NAME = "dc_pin" + def init(self): + init_cmds = [ + 0xAE, # Display off + 0xD5, 0x80, # Set oscillator frequency + 0xA8, 0x3f, # Set multiplex ratio + 0xD3, 0x00, # Set display offset + 0x40, # Set display start line + 0x8D, 0x14, # Charge pump setting + 0x20, 0x02, # Set Memory addressing mode + 0xA1, # Set Segment re-map + 0xC8, # Set COM output scan direction + 0xDA, 0x12, # Set COM pins hardware configuration + 0x81, 0xEF, # Set contrast control + 0xD9, 0xA1, # Set pre-charge period + 0xDB, 0x00, # Set VCOMH deselect level + 0x2E, # Deactivate scroll + 0xA4, # Output ram to display + 0xA6, # Normal display + 0xAF, # Display on + ] + self.send(init_cmds) + self.flush()