From 35af764be761ea1de1681d5ccb342ffa63d9dab6 Mon Sep 17 00:00:00 2001 From: lady ada Date: Thu, 8 Jul 2021 22:52:09 -0400 Subject: [PATCH 1/8] release-dependent fix for sh110x addressing --- adafruit_displayio_sh1107.py | 60 ++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/adafruit_displayio_sh1107.py b/adafruit_displayio_sh1107.py index 11593c3..297e839 100644 --- a/adafruit_displayio_sh1107.py +++ b/adafruit_displayio_sh1107.py @@ -28,6 +28,7 @@ import displayio from micropython import const +import os __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_SH1107.git" @@ -65,24 +66,45 @@ # Sequence from sh1107 framebuf driver formatted for displayio init -_INIT_SEQUENCE = ( - b"\xae\x00" # display off, sleep mode - b"\xdc\x01\x00" # display start line = 0 (POR = 0) - b"\x81\x01\x2f" # contrast setting = 0x2f - b"\x21\x00" # vertical (column) addressing mode (POR=0x20) - b"\xa0\x00" # segment remap = 1 (POR=0, down rotation) - b"\xcf\x00" # common output scan direction = 15 (0 to n-1 (POR=0)) - b"\xa8\x01\x7f" # multiplex ratio = 128 (POR) - b"\xd3\x01\x60" # set display offset mode = 0x60 - b"\xd5\x01\x51" # divide ratio/oscillator: divide by 2, fOsc (POR) - b"\xd9\x01\x22" # pre-charge/dis-charge period mode: 2 DCLKs/2 DCLKs (POR) - b"\xdb\x01\x35" # VCOM deselect level = 0.770 (POR) - b"\xb0\x00" # set page address = 0 (POR) - b"\xa4\x00" # entire display off, retain RAM, normal status (POR) - b"\xa6\x00" # normal (not reversed) display - b"\xaf\x00" # DISPLAY_ON -) - +# we fixed sh110x addressing in 7, so we have slightly different setups +if int(os.uname().release.split('.')[0]) < 7: + _INIT_SEQUENCE = ( + b"\xae\x00" # display off, sleep mode + b"\xdc\x01\x00" # display start line = 0 (POR = 0) + b"\x81\x01\x2f" # contrast setting = 0x2f + b"\x21\x00" # vertical (column) addressing mode (POR=0x20) + b"\xa0\x00" # segment remap = 1 (POR=0, down rotation) + b"\xcf\x00" # common output scan direction = 15 (0 to n-1 (POR=0)) + b"\xa8\x01\x7f" # multiplex ratio = 128 (POR) + b"\xd3\x01\x60" # set display offset mode = 0x60 + b"\xd5\x01\x51" # divide ratio/oscillator: divide by 2, fOsc (POR) + b"\xd9\x01\x22" # pre-charge/dis-charge period mode: 2 DCLKs/2 DCLKs (POR) + b"\xdb\x01\x35" # VCOM deselect level = 0.770 (POR) + b"\xb0\x00" # set page address = 0 (POR) + b"\xa4\x00" # entire display off, retain RAM, normal status (POR) + b"\xa6\x00" # normal (not reversed) display + b"\xaf\x00" # DISPLAY_ON + ) + _PIXELS_IN_ROW = True +else: + _INIT_SEQUENCE = ( + b"\xae\x00" # display off, sleep mode + b"\xdc\x01\x00" # set display start line 0 + b"\x81\x01\x4f" # contrast setting = 0x2f + b"\x20\x00" # vertical (column) addressing mode (POR=0x20) + b"\xa0\x00" # segment remap = 1 (POR=0, down rotation) + b"\xc0\x00" # common output scan direction = 15 (0 to n-1 (POR=0)) + b"\xa8\x01\x3f" # multiplex ratio = 128 (POR) + b"\xd3\x01\x60" # set display offset mode = 0x60 + #b"\xd5\x01\x51" # divide ratio/oscillator: divide by 2, fOsc (POR) + b"\xd9\x01\x22" # pre-charge/dis-charge period mode: 2 DCLKs/2 DCLKs (POR) + b"\xdb\x01\x35" # VCOM deselect level = 0.770 (POR) + #b"\xb0\x00" # set page address = 0 (POR) + b"\xa4\x00" # entire display off, retain RAM, normal status (POR) + b"\xa6\x00" # normal (not reversed) display + b"\xaf\x00" # DISPLAY_ON + ) + _PIXELS_IN_ROW = False class SH1107(displayio.Display): """ @@ -112,7 +134,7 @@ def __init__( **kwargs, color_depth=1, grayscale=True, - pixels_in_byte_share_row=True, # in vertical (column) mode + pixels_in_byte_share_row=_PIXELS_IN_ROW, # in vertical (column) mode data_as_commands=True, # every byte will have a command byte preceeding set_vertical_scroll=0xD3, # TBD -- not sure about this one! brightness_command=0x81, From 6fb814511875f98d5e1ce783b2ca436e1c37ce0f Mon Sep 17 00:00:00 2001 From: lady ada Date: Thu, 8 Jul 2021 22:53:42 -0400 Subject: [PATCH 2/8] fix for https://github.com/adafruit/circuitpython/issues/4956#issuecomment-876811048 --- adafruit_displayio_sh1107.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_displayio_sh1107.py b/adafruit_displayio_sh1107.py index 297e839..ca5d7de 100644 --- a/adafruit_displayio_sh1107.py +++ b/adafruit_displayio_sh1107.py @@ -28,7 +28,7 @@ import displayio from micropython import const -import os +import sys __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_SH1107.git" @@ -67,7 +67,7 @@ # Sequence from sh1107 framebuf driver formatted for displayio init # we fixed sh110x addressing in 7, so we have slightly different setups -if int(os.uname().release.split('.')[0]) < 7: +if sys.implementation.version[0] < 7: _INIT_SEQUENCE = ( b"\xae\x00" # display off, sleep mode b"\xdc\x01\x00" # display start line = 0 (POR = 0) From da751d65f27ed0ea43b1e8303f87160418fe032f Mon Sep 17 00:00:00 2001 From: lady ada Date: Thu, 8 Jul 2021 22:56:49 -0400 Subject: [PATCH 3/8] featherwing has a rotation of 90 (its vertical!) --- examples/displayio_sh1107_simpletest.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/displayio_sh1107_simpletest.py b/examples/displayio_sh1107_simpletest.py index c0f17df..58faa4c 100644 --- a/examples/displayio_sh1107_simpletest.py +++ b/examples/displayio_sh1107_simpletest.py @@ -27,9 +27,10 @@ # SH1107 is vertically oriented 64x128 WIDTH = 128 HEIGHT = 64 +ROTATION = 90 BORDER = 2 -display = adafruit_displayio_sh1107.SH1107(display_bus, width=WIDTH, height=HEIGHT) +display = adafruit_displayio_sh1107.SH1107(display_bus, width=WIDTH, height=HEIGHT, rotation=ROTATION) # Make the display context splash = displayio.Group() From c6a5ed218b9126ecde1c2a7920d0e376e024f1a6 Mon Sep 17 00:00:00 2001 From: lady ada Date: Thu, 8 Jul 2021 22:57:20 -0400 Subject: [PATCH 4/8] fix import --- adafruit_displayio_sh1107.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_displayio_sh1107.py b/adafruit_displayio_sh1107.py index ca5d7de..ef6520f 100644 --- a/adafruit_displayio_sh1107.py +++ b/adafruit_displayio_sh1107.py @@ -26,9 +26,9 @@ """ +import sys import displayio from micropython import const -import sys __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_SH1107.git" From 6f42d81517c934c1a3ac9d6d5e6efdc0eb7f4223 Mon Sep 17 00:00:00 2001 From: lady ada Date: Thu, 8 Jul 2021 22:57:52 -0400 Subject: [PATCH 5/8] blickblack --- adafruit_displayio_sh1107.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/adafruit_displayio_sh1107.py b/adafruit_displayio_sh1107.py index ef6520f..cc2e871 100644 --- a/adafruit_displayio_sh1107.py +++ b/adafruit_displayio_sh1107.py @@ -96,16 +96,17 @@ b"\xc0\x00" # common output scan direction = 15 (0 to n-1 (POR=0)) b"\xa8\x01\x3f" # multiplex ratio = 128 (POR) b"\xd3\x01\x60" # set display offset mode = 0x60 - #b"\xd5\x01\x51" # divide ratio/oscillator: divide by 2, fOsc (POR) + # b"\xd5\x01\x51" # divide ratio/oscillator: divide by 2, fOsc (POR) b"\xd9\x01\x22" # pre-charge/dis-charge period mode: 2 DCLKs/2 DCLKs (POR) b"\xdb\x01\x35" # VCOM deselect level = 0.770 (POR) - #b"\xb0\x00" # set page address = 0 (POR) + # b"\xb0\x00" # set page address = 0 (POR) b"\xa4\x00" # entire display off, retain RAM, normal status (POR) b"\xa6\x00" # normal (not reversed) display b"\xaf\x00" # DISPLAY_ON ) _PIXELS_IN_ROW = False + class SH1107(displayio.Display): """ SSD1107 driver for use with DisplayIO From 86ccffb9d57d4337bc8aa94506d77ec2ab7f4733 Mon Sep 17 00:00:00 2001 From: lady ada Date: Thu, 8 Jul 2021 22:59:59 -0400 Subject: [PATCH 6/8] moreso --- examples/displayio_sh1107_simpletest.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/displayio_sh1107_simpletest.py b/examples/displayio_sh1107_simpletest.py index 58faa4c..d83889d 100644 --- a/examples/displayio_sh1107_simpletest.py +++ b/examples/displayio_sh1107_simpletest.py @@ -30,7 +30,9 @@ ROTATION = 90 BORDER = 2 -display = adafruit_displayio_sh1107.SH1107(display_bus, width=WIDTH, height=HEIGHT, rotation=ROTATION) +display = adafruit_displayio_sh1107.SH1107( + display_bus, width=WIDTH, height=HEIGHT, rotation=ROTATION +) # Make the display context splash = displayio.Group() From e98d07f1b3a9e4ff2ed1c233470db1604991611b Mon Sep 17 00:00:00 2001 From: lady ada Date: Fri, 9 Jul 2021 11:18:29 -0400 Subject: [PATCH 7/8] tweak rotation --- adafruit_displayio_sh1107.py | 11 +++++++---- examples/displayio_sh1107_simpletest.py | 3 +-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/adafruit_displayio_sh1107.py b/adafruit_displayio_sh1107.py index cc2e871..db6b6cd 100644 --- a/adafruit_displayio_sh1107.py +++ b/adafruit_displayio_sh1107.py @@ -26,9 +26,9 @@ """ -import sys import displayio from micropython import const +import sys __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_SH1107.git" @@ -86,6 +86,7 @@ b"\xaf\x00" # DISPLAY_ON ) _PIXELS_IN_ROW = True + _ROTATION_OFFSET = 0 else: _INIT_SEQUENCE = ( b"\xae\x00" # display off, sleep mode @@ -96,16 +97,16 @@ b"\xc0\x00" # common output scan direction = 15 (0 to n-1 (POR=0)) b"\xa8\x01\x3f" # multiplex ratio = 128 (POR) b"\xd3\x01\x60" # set display offset mode = 0x60 - # b"\xd5\x01\x51" # divide ratio/oscillator: divide by 2, fOsc (POR) + #b"\xd5\x01\x51" # divide ratio/oscillator: divide by 2, fOsc (POR) b"\xd9\x01\x22" # pre-charge/dis-charge period mode: 2 DCLKs/2 DCLKs (POR) b"\xdb\x01\x35" # VCOM deselect level = 0.770 (POR) - # b"\xb0\x00" # set page address = 0 (POR) + #b"\xb0\x00" # set page address = 0 (POR) b"\xa4\x00" # entire display off, retain RAM, normal status (POR) b"\xa6\x00" # normal (not reversed) display b"\xaf\x00" # DISPLAY_ON ) _PIXELS_IN_ROW = False - + _ROTATION_OFFSET = 90 class SH1107(displayio.Display): """ @@ -125,6 +126,7 @@ def __init__( self, bus, display_offset=DISPLAY_OFFSET_ADAFRUIT_FEATHERWING_OLED_4650, + rotation=0, **kwargs ): init_sequence = bytearray(_INIT_SEQUENCE) @@ -140,6 +142,7 @@ def __init__( set_vertical_scroll=0xD3, # TBD -- not sure about this one! brightness_command=0x81, single_byte_bounds=True, + rotation=(rotation + _ROTATION_OFFSET) % 360, # for sh1107 use column and page addressing. # lower column command = 0x00 - 0x0F # upper column command = 0x10 - 0x17 diff --git a/examples/displayio_sh1107_simpletest.py b/examples/displayio_sh1107_simpletest.py index d83889d..1f7c79c 100644 --- a/examples/displayio_sh1107_simpletest.py +++ b/examples/displayio_sh1107_simpletest.py @@ -27,11 +27,10 @@ # SH1107 is vertically oriented 64x128 WIDTH = 128 HEIGHT = 64 -ROTATION = 90 BORDER = 2 display = adafruit_displayio_sh1107.SH1107( - display_bus, width=WIDTH, height=HEIGHT, rotation=ROTATION + display_bus, width=WIDTH, height=HEIGHT, rotation=0 ) # Make the display context From 6c6ce2e0838f92c6341353b5a461fd2a51316182 Mon Sep 17 00:00:00 2001 From: lady ada Date: Fri, 9 Jul 2021 11:24:00 -0400 Subject: [PATCH 8/8] lint --- adafruit_displayio_sh1107.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/adafruit_displayio_sh1107.py b/adafruit_displayio_sh1107.py index db6b6cd..fef9177 100644 --- a/adafruit_displayio_sh1107.py +++ b/adafruit_displayio_sh1107.py @@ -26,9 +26,9 @@ """ +import sys import displayio from micropython import const -import sys __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_SH1107.git" @@ -97,10 +97,10 @@ b"\xc0\x00" # common output scan direction = 15 (0 to n-1 (POR=0)) b"\xa8\x01\x3f" # multiplex ratio = 128 (POR) b"\xd3\x01\x60" # set display offset mode = 0x60 - #b"\xd5\x01\x51" # divide ratio/oscillator: divide by 2, fOsc (POR) + # b"\xd5\x01\x51" # divide ratio/oscillator: divide by 2, fOsc (POR) b"\xd9\x01\x22" # pre-charge/dis-charge period mode: 2 DCLKs/2 DCLKs (POR) b"\xdb\x01\x35" # VCOM deselect level = 0.770 (POR) - #b"\xb0\x00" # set page address = 0 (POR) + # b"\xb0\x00" # set page address = 0 (POR) b"\xa4\x00" # entire display off, retain RAM, normal status (POR) b"\xa6\x00" # normal (not reversed) display b"\xaf\x00" # DISPLAY_ON @@ -108,6 +108,7 @@ _PIXELS_IN_ROW = False _ROTATION_OFFSET = 90 + class SH1107(displayio.Display): """ SSD1107 driver for use with DisplayIO