From 2d97e0e2189c4dd6d5810c772467fad9e7cccf9c Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Mon, 2 Dec 2019 10:12:34 -0500 Subject: [PATCH] uc1701: Add support for rst_pin Add support for an optional uc1701 rst_pin. Use the same reset pin code handling with the SSD1306 code. Signed-off-by: Kevin O'Connor --- config/example-extras.cfg | 6 +++-- klippy/extras/display/uc1701.py | 40 ++++++++++++++++++++------------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/config/example-extras.cfg b/config/example-extras.cfg index c5a2712c..9d58d5ba 100644 --- a/config/example-extras.cfg +++ b/config/example-extras.cfg @@ -1671,8 +1671,10 @@ # provided when using an st7920 display. #cs_pin: #a0_pin: -# The pins connected to an uc1701 type lcd. These parameters must be -# provided when using an uc1701 display. +#rst_pin: +# The pins connected to an uc1701 type lcd. The rst_pin is +# optional. The cs_pin and a0_pin parameters must be provided when +# using an uc1701 display. #rs_pin: #cs_pin: #a0_pin: diff --git a/klippy/extras/display/uc1701.py b/klippy/extras/display/uc1701.py index 09bad920..6f018bfd 100644 --- a/klippy/extras/display/uc1701.py +++ b/klippy/extras/display/uc1701.py @@ -133,12 +133,34 @@ class I2C: cmds.insert(0, hdr) self.i2c.i2c_write(cmds, reqclock=BACKGROUND_PRIORITY_CLOCK) +# Helper code for toggling a reset pin on startup +class ResetHelper: + def __init__(self, pin_desc, io_bus): + self.mcu_reset = None + if pin_desc is None: + return + self.mcu_reset = extras.bus.MCU_bus_digital_out( + io_bus.get_mcu(), pin_desc, io_bus.get_command_queue()) + def init(self): + if self.mcu_reset is None: + return + mcu = self.mcu_reset.get_mcu() + curtime = mcu.get_printer().get_reactor().monotonic() + print_time = mcu.estimated_print_time(curtime) + minclock = mcu.print_time_to_clock(print_time + .100) + self.mcu_reset.update_digital_out(0, minclock=minclock) + minclock = mcu.print_time_to_clock(print_time + .200) + self.mcu_reset.update_digital_out(1, minclock=minclock) + # The UC1701 is a "4-wire" SPI display device class UC1701(DisplayBase): def __init__(self, config): - DisplayBase.__init__(self, SPI4wire(config, "a0_pin")) + io = SPI4wire(config, "a0_pin") + DisplayBase.__init__(self, io) self.contrast = config.getint('contrast', 40, minval=0, maxval=63) + self.reset = ResetHelper(config.get("rst_pin", None), io.spi) def init(self): + self.reset.init() init_cmds = [0xE2, # System reset 0x40, # Set display to start at line 0 0xA0, # Set SEG direction @@ -160,7 +182,6 @@ class UC1701(DisplayBase): self.send([0xA5]) # display all self.send([0xA4]) # normal display self.flush() - logging.info("uc1701 initialized") # The ST7567 is a "4-wire" SPI display device class ST7567(DisplayBase): @@ -205,21 +226,10 @@ class SSD1306(DisplayBase): else: io = SPI4wire(config, "dc_pin") io_bus = io.spi - self.mcu_reset = None - reset_pin_desc = config.get("reset_pin", None) - if reset_pin_desc is not None: - self.mcu_reset = extras.bus.MCU_bus_digital_out( - io_bus.get_mcu(), reset_pin_desc, io_bus.get_command_queue()) + self.reset = ResetHelper(config.get("reset_pin", None), io_bus) DisplayBase.__init__(self, io, columns) def init(self): - if self.mcu_reset is not None: - mcu = self.mcu_reset.get_mcu() - curtime = mcu.get_printer().get_reactor().monotonic() - print_time = mcu.estimated_print_time(curtime) - minclock = mcu.print_time_to_clock(print_time + .100) - self.mcu_reset.update_digital_out(0, minclock=minclock) - minclock = mcu.print_time_to_clock(print_time + .200) - self.mcu_reset.update_digital_out(1, minclock=minclock) + self.reset.init() init_cmds = [ 0xAE, # Display off 0xD5, 0x80, # Set oscillator frequency