Skip to content

Commit 980127d

Browse files
authored
Merge pull request #7 from ladyada/main
fix for adafruit/circuitpython#4956
2 parents f268b81 + 6c6ce2e commit 980127d

File tree

2 files changed

+48
-19
lines changed

2 files changed

+48
-19
lines changed

adafruit_displayio_sh1107.py

+45-18
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
2727
"""
2828

29+
import sys
2930
import displayio
3031
from micropython import const
3132

@@ -65,23 +66,47 @@
6566

6667

6768
# Sequence from sh1107 framebuf driver formatted for displayio init
68-
_INIT_SEQUENCE = (
69-
b"\xae\x00" # display off, sleep mode
70-
b"\xdc\x01\x00" # display start line = 0 (POR = 0)
71-
b"\x81\x01\x2f" # contrast setting = 0x2f
72-
b"\x21\x00" # vertical (column) addressing mode (POR=0x20)
73-
b"\xa0\x00" # segment remap = 1 (POR=0, down rotation)
74-
b"\xcf\x00" # common output scan direction = 15 (0 to n-1 (POR=0))
75-
b"\xa8\x01\x7f" # multiplex ratio = 128 (POR)
76-
b"\xd3\x01\x60" # set display offset mode = 0x60
77-
b"\xd5\x01\x51" # divide ratio/oscillator: divide by 2, fOsc (POR)
78-
b"\xd9\x01\x22" # pre-charge/dis-charge period mode: 2 DCLKs/2 DCLKs (POR)
79-
b"\xdb\x01\x35" # VCOM deselect level = 0.770 (POR)
80-
b"\xb0\x00" # set page address = 0 (POR)
81-
b"\xa4\x00" # entire display off, retain RAM, normal status (POR)
82-
b"\xa6\x00" # normal (not reversed) display
83-
b"\xaf\x00" # DISPLAY_ON
84-
)
69+
# we fixed sh110x addressing in 7, so we have slightly different setups
70+
if sys.implementation.version[0] < 7:
71+
_INIT_SEQUENCE = (
72+
b"\xae\x00" # display off, sleep mode
73+
b"\xdc\x01\x00" # display start line = 0 (POR = 0)
74+
b"\x81\x01\x2f" # contrast setting = 0x2f
75+
b"\x21\x00" # vertical (column) addressing mode (POR=0x20)
76+
b"\xa0\x00" # segment remap = 1 (POR=0, down rotation)
77+
b"\xcf\x00" # common output scan direction = 15 (0 to n-1 (POR=0))
78+
b"\xa8\x01\x7f" # multiplex ratio = 128 (POR)
79+
b"\xd3\x01\x60" # set display offset mode = 0x60
80+
b"\xd5\x01\x51" # divide ratio/oscillator: divide by 2, fOsc (POR)
81+
b"\xd9\x01\x22" # pre-charge/dis-charge period mode: 2 DCLKs/2 DCLKs (POR)
82+
b"\xdb\x01\x35" # VCOM deselect level = 0.770 (POR)
83+
b"\xb0\x00" # set page address = 0 (POR)
84+
b"\xa4\x00" # entire display off, retain RAM, normal status (POR)
85+
b"\xa6\x00" # normal (not reversed) display
86+
b"\xaf\x00" # DISPLAY_ON
87+
)
88+
_PIXELS_IN_ROW = True
89+
_ROTATION_OFFSET = 0
90+
else:
91+
_INIT_SEQUENCE = (
92+
b"\xae\x00" # display off, sleep mode
93+
b"\xdc\x01\x00" # set display start line 0
94+
b"\x81\x01\x4f" # contrast setting = 0x2f
95+
b"\x20\x00" # vertical (column) addressing mode (POR=0x20)
96+
b"\xa0\x00" # segment remap = 1 (POR=0, down rotation)
97+
b"\xc0\x00" # common output scan direction = 15 (0 to n-1 (POR=0))
98+
b"\xa8\x01\x3f" # multiplex ratio = 128 (POR)
99+
b"\xd3\x01\x60" # set display offset mode = 0x60
100+
# b"\xd5\x01\x51" # divide ratio/oscillator: divide by 2, fOsc (POR)
101+
b"\xd9\x01\x22" # pre-charge/dis-charge period mode: 2 DCLKs/2 DCLKs (POR)
102+
b"\xdb\x01\x35" # VCOM deselect level = 0.770 (POR)
103+
# b"\xb0\x00" # set page address = 0 (POR)
104+
b"\xa4\x00" # entire display off, retain RAM, normal status (POR)
105+
b"\xa6\x00" # normal (not reversed) display
106+
b"\xaf\x00" # DISPLAY_ON
107+
)
108+
_PIXELS_IN_ROW = False
109+
_ROTATION_OFFSET = 90
85110

86111

87112
class SH1107(displayio.Display):
@@ -102,6 +127,7 @@ def __init__(
102127
self,
103128
bus,
104129
display_offset=DISPLAY_OFFSET_ADAFRUIT_FEATHERWING_OLED_4650,
130+
rotation=0,
105131
**kwargs
106132
):
107133
init_sequence = bytearray(_INIT_SEQUENCE)
@@ -112,11 +138,12 @@ def __init__(
112138
**kwargs,
113139
color_depth=1,
114140
grayscale=True,
115-
pixels_in_byte_share_row=True, # in vertical (column) mode
141+
pixels_in_byte_share_row=_PIXELS_IN_ROW, # in vertical (column) mode
116142
data_as_commands=True, # every byte will have a command byte preceeding
117143
set_vertical_scroll=0xD3, # TBD -- not sure about this one!
118144
brightness_command=0x81,
119145
single_byte_bounds=True,
146+
rotation=(rotation + _ROTATION_OFFSET) % 360,
120147
# for sh1107 use column and page addressing.
121148
# lower column command = 0x00 - 0x0F
122149
# upper column command = 0x10 - 0x17

examples/displayio_sh1107_simpletest.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
HEIGHT = 64
3030
BORDER = 2
3131

32-
display = adafruit_displayio_sh1107.SH1107(display_bus, width=WIDTH, height=HEIGHT)
32+
display = adafruit_displayio_sh1107.SH1107(
33+
display_bus, width=WIDTH, height=HEIGHT, rotation=0
34+
)
3335

3436
# Make the display context
3537
splash = displayio.Group()

0 commit comments

Comments
 (0)