2626
2727"""
2828
29+ import sys
2930import displayio
3031from micropython import const
3132
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
87112class 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
0 commit comments