35
35
SET_DISP_START_LINE = const (0x40 )
36
36
SET_SEG_REMAP = const (0xA0 )
37
37
SET_MUX_RATIO = const (0xA8 )
38
+ SET_IREF_SELECT = const (0xAD )
38
39
SET_COM_OUT_DIR = const (0xC0 )
39
40
SET_DISP_OFFSET = const (0xD3 )
40
41
SET_COM_PIN_CFG = const (0xDA )
@@ -96,24 +97,22 @@ def init_display(self):
96
97
# 64, 48: 0x80 0x12
97
98
# 64, 32: 0x80 0x12
98
99
for cmd in (
99
- SET_DISP | 0x00 , # off
100
+ SET_DISP , # off
100
101
# address setting
101
102
SET_MEM_ADDR ,
102
103
0x10 # Page Addressing Mode
103
104
if self .page_addressing
104
105
else 0x00 , # Horizontal Addressing Mode
105
106
# resolution and layout
106
- SET_DISP_START_LINE | 0x00 ,
107
+ SET_DISP_START_LINE ,
107
108
SET_SEG_REMAP | 0x01 , # column addr 127 mapped to SEG0
108
109
SET_MUX_RATIO ,
109
110
self .height - 1 ,
110
111
SET_COM_OUT_DIR | 0x08 , # scan from COM[N] to COM0
111
112
SET_DISP_OFFSET ,
112
113
0x00 ,
113
114
SET_COM_PIN_CFG ,
114
- 0x02
115
- if (self .height == 32 or self .height == 16 ) and (self .width != 64 )
116
- else 0x12 ,
115
+ 0x02 if self .width > 2 * self .height else 0x12 ,
117
116
# timing and driving scheme
118
117
SET_DISP_CLK_DIV ,
119
118
0x80 ,
@@ -126,21 +125,20 @@ def init_display(self):
126
125
0xFF , # maximum
127
126
SET_ENTIRE_ON , # output follows RAM contents
128
127
SET_NORM_INV , # not inverted
128
+ SET_IREF_SELECT ,
129
+ 0x30 , # enable internal IREF during display on
129
130
# charge pump
130
131
SET_CHARGE_PUMP ,
131
132
0x10 if self .external_vcc else 0x14 ,
132
- SET_DISP | 0x01 ,
133
- ): # on
133
+ SET_DISP | 0x01 , # display on
134
+ ):
134
135
self .write_cmd (cmd )
135
- if self .width == 72 :
136
- self .write_cmd (0xAD )
137
- self .write_cmd (0x30 )
138
136
self .fill (0 )
139
137
self .show ()
140
138
141
139
def poweroff (self ):
142
140
"""Turn off the display (nothing visible)"""
143
- self .write_cmd (SET_DISP | 0x00 )
141
+ self .write_cmd (SET_DISP )
144
142
self ._power = False
145
143
146
144
def contrast (self , contrast ):
@@ -152,6 +150,13 @@ def invert(self, invert):
152
150
"""Invert all pixels on the display"""
153
151
self .write_cmd (SET_NORM_INV | (invert & 1 ))
154
152
153
+ def rotate (self , rotate ):
154
+ """Rotate the display 0 or 180 degrees"""
155
+ self .write_cmd (SET_COM_OUT_DIR | ((rotate & 1 ) << 3 ))
156
+ self .write_cmd (SET_SEG_REMAP | (rotate & 1 ))
157
+ # com output (vertical mirror) is changed immediately
158
+ # you need to call show() for the seg remap to be visible
159
+
155
160
def write_framebuf (self ):
156
161
"""Derived class must implement this"""
157
162
raise NotImplementedError
@@ -177,14 +182,11 @@ def show(self):
177
182
if not self .page_addressing :
178
183
xpos0 = 0
179
184
xpos1 = self .width - 1
180
- if self .width == 64 :
181
- # displays with width of 64 pixels are shifted by 32
182
- xpos0 += 32
183
- xpos1 += 32
184
- if self .width == 72 :
185
- # displays with width of 72 pixels are shifted by 28
186
- xpos0 += 28
187
- xpos1 += 28
185
+ if self .width != 128 :
186
+ # narrow displays use centered columns
187
+ col_offset = (128 - self .width ) // 2
188
+ xpos0 += col_offset
189
+ xpos1 += col_offset
188
190
self .write_cmd (SET_COL_ADDR )
189
191
self .write_cmd (xpos0 )
190
192
self .write_cmd (xpos1 )
0 commit comments