Skip to content

fix for https://github.com/adafruit/circuitpython/issues/4956 #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 9, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 41 additions & 18 deletions adafruit_displayio_sh1107.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

"""

import sys
import displayio
from micropython import const

Expand Down Expand Up @@ -65,23 +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 sys.implementation.version[0] < 7:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmmm .. it seems like this lib is also used on standard python3 (is in pypi) where sys.implementation.version is currently 3. I guess this means that python3 also keeps using the old behavior, which is fine for now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont even think that oleds are supported in blinka? or this special oled method

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, but it's in pypi. https://pypi.org/project/adafruit-circuitpython-displayio-sh1107/

I think it's fine, since 3<7 so this doesn't change anything on blinka.

_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):
Expand Down Expand Up @@ -112,7 +135,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,
Expand Down
5 changes: 4 additions & 1 deletion examples/displayio_sh1107_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@
# 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()
Expand Down