24
24
SOFTWARE.
25
25
"""
26
26
27
- __version__ = '1.1.0 '
27
+ __version__ = '1.1.1 '
28
28
29
29
from micropython import const
30
- import time
31
30
import framebuf
32
31
33
32
# commands
56
55
REG_CMD = const (0x80 )
57
56
REG_DATA = const (0x40 )
58
57
59
-
60
58
class SSD1327 :
61
- def __init__ (self , width , height , external_vcc ):
59
+ def __init__ (self , width = 128 , height = 128 ):
62
60
self .width = width
63
61
self .height = height
64
- self .external_vcc = external_vcc
65
62
self .buffer = bytearray (self .width * self .height // 2 )
66
63
self .framebuf = framebuf .FrameBuffer (self .buffer , self .width , self .height , framebuf .GS4_HMSB )
64
+
65
+ self .col_addr = ((128 - self .width ) // 4 , 63 - ((128 - self .width ) // 4 ))
66
+ # 96x96 (8, 55)
67
+ # 128x128 (0, 63)
68
+
69
+ self .row_addr = (0 , self .height - 1 )
70
+ # 96x96 (0, 95)
71
+ # 128x128 (0, 127)
72
+
73
+ self .offset = 128 - self .height
74
+ # 96x96 32
75
+ # 128x128 0
76
+
67
77
self .poweron ()
68
78
self .init_display ()
69
79
@@ -73,7 +83,7 @@ def init_display(self):
73
83
SET_DISP , # Display off
74
84
# Resolution and layout
75
85
SET_DISP_START_LINE , 0x00 ,
76
- SET_DISP_OFFSET , 0x00 , # Set vertical offset by COM from 0~127
86
+ SET_DISP_OFFSET , self . offset , # Set vertical offset by COM from 0~127
77
87
# Set re-map
78
88
# Enable column address re-map
79
89
# Disable nibble re-map
@@ -94,20 +104,13 @@ def init_display(self):
94
104
SET_GRAYSCALE_LINEAR , # Use linear greyscale lookup table
95
105
SET_CONTRAST , 0x7f , # Medium brightness
96
106
SET_DISP_MODE , # Normal, not inverted
97
- # 96x96:
98
- # SET_ROW_ADDR, 0 95,
99
- # SET_COL_ADDR, 8, 55,
100
- # 128x128:
101
- # SET_ROW_ADDR, 0 127,
102
- # SET_COL_ADDR, 0, 63,
103
- SET_ROW_ADDR , 0x00 , self .height - 1 ,
104
- SET_COL_ADDR , ((128 - self .width ) // 4 ), 63 - ((128 - self .width ) // 4 ),
105
-
107
+ SET_COL_ADDR , self .col_addr [0 ], self .col_addr [1 ],
108
+ SET_ROW_ADDR , self .row_addr [0 ], self .row_addr [1 ],
106
109
SET_SCROLL_DEACTIVATE ,
107
110
SET_DISP | 0x01 ): # Display on
108
111
self .write_cmd (cmd )
109
112
self .fill (0 )
110
- self .show ( )
113
+ self .write_data ( self . buffer )
111
114
112
115
def poweroff (self ):
113
116
self .write_cmd (SET_FN_SELECT_A )
@@ -123,16 +126,24 @@ def contrast(self, contrast):
123
126
self .write_cmd (SET_CONTRAST )
124
127
self .write_cmd (contrast ) # 0-255
125
128
129
+ def rotate (self , rotate ):
130
+ self .poweroff ()
131
+ self .write_cmd (SET_DISP_OFFSET )
132
+ self .write_cmd (self .height if rotate else self .offset )
133
+ self .write_cmd (SET_SEG_REMAP )
134
+ self .write_cmd (0x42 if rotate else 0x51 )
135
+ self .poweron ()
136
+
126
137
def invert (self , invert ):
127
138
self .write_cmd (SET_DISP_MODE | (invert & 1 ) << 1 | (invert & 1 )) # 0xA4=Normal, 0xA7=Inverted
128
139
129
140
def show (self ):
130
141
self .write_cmd (SET_COL_ADDR )
131
- self .write_cmd (( 128 - self .width ) // 4 )
132
- self .write_cmd (63 - (( 128 - self .width ) // 4 ) )
142
+ self .write_cmd (self .col_addr [ 0 ] )
143
+ self .write_cmd (self .col_addr [ 1 ] )
133
144
self .write_cmd (SET_ROW_ADDR )
134
- self .write_cmd (0x00 )
135
- self .write_cmd (self .height - 1 )
145
+ self .write_cmd (self . row_addr [ 0 ] )
146
+ self .write_cmd (self .row_addr [ 1 ] )
136
147
self .write_data (self .buffer )
137
148
138
149
def fill (self , col ):
@@ -141,44 +152,43 @@ def fill(self, col):
141
152
def pixel (self , x , y , col ):
142
153
self .framebuf .pixel (x , y , col )
143
154
155
+ def line (self , x1 , y1 , x2 , y2 , col ):
156
+ self .framebuf .line (x1 , y1 , x2 , y2 , col )
157
+
144
158
def scroll (self , dx , dy ):
145
159
self .framebuf .scroll (dx , dy )
146
160
# software scroll
147
161
148
162
def text (self , string , x , y , col = 15 ):
149
163
self .framebuf .text (string , x , y , col )
150
164
165
+ def write_cmd (self ):
166
+ raise NotImplementedError
167
+
168
+ def write_data (self ):
169
+ raise NotImplementedError
170
+
151
171
152
172
class SSD1327_I2C (SSD1327 ):
153
- def __init__ (self , width , height , i2c , addr = 0x3c , external_vcc = False ):
173
+ def __init__ (self , width , height , i2c , addr = 0x3c ):
154
174
self .i2c = i2c
155
175
self .addr = addr
156
176
self .cmd_arr = bytearray ([REG_CMD , 0 ]) # Co=1, D/C#=0
157
177
self .data_list = [bytes ((REG_DATA ,)), None ]
158
- super ().__init__ (width , height , external_vcc )
178
+ super ().__init__ (width , height )
159
179
160
180
def write_cmd (self , cmd ):
161
181
self .cmd_arr [1 ] = cmd
162
182
self .i2c .writeto (self .addr , self .cmd_arr )
163
183
164
- def write_data (self , buf ):
165
- self .data_list [1 ] = buf
184
+ def write_data (self , data_buf ):
185
+ self .data_list [1 ] = data_buf
166
186
self .i2c .writevto (self .addr , self .data_list )
167
187
168
188
169
189
class SEEED_OLED_96X96 (SSD1327_I2C ):
170
190
def __init__ (self , i2c ):
171
191
super ().__init__ (96 , 96 , i2c )
172
- self .write_cmd (SET_DISP_OFFSET )
173
- self .write_cmd (0x20 ) # Set vertical offset by COM from 0~127
174
-
175
- def rotate (self , rotate ):
176
- self .poweroff ()
177
- self .write_cmd (SET_DISP_OFFSET )
178
- self .write_cmd (0x60 if rotate else 0x20 ) # 0x20=0 degrees, 0x60=180 degrees
179
- self .write_cmd (SET_SEG_REMAP )
180
- self .write_cmd (0x42 if rotate else 0x51 ) # 0x51=0 degrees, 0x42=180 degrees
181
- self .poweron ()
182
192
183
193
def lookup (self , table ):
184
194
# GS0 has no pre-charge and current drive
0 commit comments