uc1701: Add support for SSD1306 displays

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2018-11-21 13:43:48 -05:00
parent a00d7b418f
commit e231ac7422
3 changed files with 39 additions and 7 deletions

View File

@ -863,11 +863,12 @@
# Support for a display attached to the micro-controller. # Support for a display attached to the micro-controller.
#[display] #[display]
#lcd_type: #lcd_type:
# The type of LCD chip in use. This may be "hd44780" (which is # The type of LCD chip in use. This may be "hd44780" (which is used
# used in "RepRapDiscount 2004 Smart Controller" type displays), # in "RepRapDiscount 2004 Smart Controller" type displays), "st7920"
# "st7920" (which is used in "RepRapDiscount 12864 Full Graphic # (which is used in "RepRapDiscount 12864 Full Graphic Smart
# Smart Controller" type displays) or "uc1701" (which is used in # Controller" type displays), "uc1701" (which is used in "MKS Mini
# "MKS Mini 12864" type displays). This parameter must be provided. # 12864" type displays), or "ssd1306". This parameter must be
# provided.
#rs_pin: #rs_pin:
#e_pin: #e_pin:
#d4_pin: #d4_pin:
@ -885,6 +886,10 @@
#a0_pin #a0_pin
# The pins connected to an uc1701 type lcd. These parameters must be # The pins connected to an uc1701 type lcd. These parameters must be
# provided when using an uc1701 display. # 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: #menu_root:
# Entry point for menu, root menu container name. If this parameter # Entry point for menu, root menu container name. If this parameter
# is not provided then default menu root is used. When provided # is not provided then default menu root is used. When provided

View File

@ -11,7 +11,7 @@ import menu
LCD_chips = { LCD_chips = {
'st7920': st7920.ST7920, 'hd44780': hd44780.HD44780, 'st7920': st7920.ST7920, 'hd44780': hd44780.HD44780,
'uc1701' : uc1701.UC1701 'uc1701' : uc1701.UC1701, 'ssd1306': uc1701.SSD1306,
} }
M73_TIMEOUT = 5. M73_TIMEOUT = 5.

View File

@ -12,6 +12,7 @@ BACKGROUND_PRIORITY_CLOCK = 0x7fffffff00000000
TextGlyphs = { 'right_arrow': '\x1a', 'degrees': '\xf8' } TextGlyphs = { 'right_arrow': '\x1a', 'degrees': '\xf8' }
class UC1701: class UC1701:
DATA_PIN_NAME = "a0_pin"
CURRENT_BUF, OLD_BUF = 0, 1 CURRENT_BUF, OLD_BUF = 0, 1
EMPTY_CHAR = (0, 32, 255) EMPTY_CHAR = (0, 32, 255)
def __init__(self, config): def __init__(self, config):
@ -20,7 +21,7 @@ class UC1701:
mcu = self.spi.get_mcu() mcu = self.spi.get_mcu()
# Create a0 pin # Create a0 pin
ppins = config.get_printer().lookup_object('pins') 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: if a0_pin_params['chip'] != mcu:
raise ppins.error("uc1701 all pins must be on same mcu") raise ppins.error("uc1701 all pins must be on same mcu")
self.a0_oid = mcu.create_oid() self.a0_oid = mcu.create_oid()
@ -158,3 +159,29 @@ class UC1701:
page[:] = zeros page[:] = zeros
def get_dimensions(self): def get_dimensions(self):
return (16, 4) 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()