41
41
except ImportError :
42
42
import adafruit_framebuf as framebuf
43
43
44
+ try :
45
+ from digitalio import DigitalInOut
46
+ from busio import I2C , SPI
47
+ from typing import Optional
48
+ except ImportError :
49
+ pass
50
+
44
51
__version__ = "0.0.0-auto.0"
45
52
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_SSD1305.git"
46
53
@@ -72,15 +79,23 @@ class _SSD1305(framebuf.FrameBuffer):
72
79
"""Base class for SSD1305 display driver"""
73
80
74
81
# pylint: disable-msg=too-many-arguments
75
- def __init__ (self , buffer , width , height , * , external_vcc , reset ):
82
+ def __init__ (
83
+ self ,
84
+ buffer : memoryview ,
85
+ width : int ,
86
+ height : int ,
87
+ * ,
88
+ external_vcc : bool ,
89
+ reset : Optional [DigitalInOut ]
90
+ ):
76
91
super ().__init__ (buffer , width , height )
77
92
self .width = width
78
93
self .height = height
79
94
self .external_vcc = external_vcc
80
95
# reset may be None if not needed
81
96
self .reset_pin = reset
82
97
if self .reset_pin :
83
- self .reset_pin .switch_to_output (value = 0 )
98
+ self .reset_pin .switch_to_output (value = False )
84
99
self .pages = self .height // 8
85
100
self ._column_offset = 0
86
101
if self .height == 32 :
@@ -91,7 +106,7 @@ def __init__(self, buffer, width, height, *, external_vcc, reset):
91
106
self .poweron ()
92
107
self .init_display ()
93
108
94
- def init_display (self ):
109
+ def init_display (self ) -> None :
95
110
"""Base class to initialize display"""
96
111
for cmd in (
97
112
SET_DISP | 0x00 , # off
@@ -135,39 +150,39 @@ def init_display(self):
135
150
self .fill (0 )
136
151
self .show ()
137
152
138
- def poweroff (self ):
153
+ def poweroff (self ) -> None :
139
154
"""Turn off the display (nothing visible)"""
140
155
self .write_cmd (SET_DISP | 0x00 )
141
156
142
- def contrast (self , contrast ) :
157
+ def contrast (self , contrast : int ) -> None :
143
158
"""Adjust the contrast"""
144
159
self .write_cmd (SET_CONTRAST )
145
160
self .write_cmd (contrast )
146
161
147
- def invert (self , invert ) :
162
+ def invert (self , invert : bool ) -> None :
148
163
"""Invert all pixels on the display"""
149
164
self .write_cmd (SET_NORM_INV | (invert & 1 ))
150
165
151
- def write_framebuf (self ):
166
+ def write_framebuf (self ) -> None :
152
167
"""Derived class must implement this"""
153
168
raise NotImplementedError
154
169
155
- def write_cmd (self , cmd ) :
170
+ def write_cmd (self , cmd : int ) -> None :
156
171
"""Derived class must implement this"""
157
172
raise NotImplementedError
158
173
159
- def poweron (self ):
174
+ def poweron (self ) -> None :
160
175
"Reset device and turn on the display."
161
176
if self .reset_pin :
162
- self .reset_pin .value = 1
177
+ self .reset_pin .value = True
163
178
time .sleep (0.001 )
164
- self .reset_pin .value = 0
179
+ self .reset_pin .value = False
165
180
time .sleep (0.010 )
166
- self .reset_pin .value = 1
181
+ self .reset_pin .value = True
167
182
time .sleep (0.010 )
168
183
self .write_cmd (SET_DISP | 0x01 )
169
184
170
- def show (self ):
185
+ def show (self ) -> None :
171
186
"""Update the display"""
172
187
xpos0 = 0
173
188
xpos1 = self .width - 1
@@ -197,7 +212,14 @@ class SSD1305_I2C(_SSD1305):
197
212
"""
198
213
199
214
def __init__ (
200
- self , width , height , i2c , * , addr = 0x3C , external_vcc = False , reset = None
215
+ self ,
216
+ width : int ,
217
+ height : int ,
218
+ i2c : I2C ,
219
+ * ,
220
+ addr : int = 0x3C ,
221
+ external_vcc : bool = False ,
222
+ reset : Optional [DigitalInOut ] = None
201
223
):
202
224
self .i2c_device = i2c_device .I2CDevice (i2c , addr )
203
225
self .addr = addr
@@ -217,14 +239,14 @@ def __init__(
217
239
reset = reset ,
218
240
)
219
241
220
- def write_cmd (self , cmd ) :
242
+ def write_cmd (self , cmd : int ) -> None :
221
243
"""Send a command to the SPI device"""
222
244
self .temp [0 ] = 0x80 # Co=1, D/C#=0
223
245
self .temp [1 ] = cmd
224
246
with self .i2c_device :
225
247
self .i2c_device .write (self .temp )
226
248
227
- def write_framebuf (self ):
249
+ def write_framebuf (self ) -> None :
228
250
"""Blast out the frame buffer using a single I2C transaction to support
229
251
hardware I2C interfaces."""
230
252
with self .i2c_device :
@@ -248,20 +270,20 @@ class SSD1305_SPI(_SSD1305):
248
270
# Disable should be reconsidered when refactor can be tested.
249
271
def __init__ (
250
272
self ,
251
- width ,
252
- height ,
253
- spi ,
254
- dc ,
255
- reset ,
256
- cs ,
273
+ width : int ,
274
+ height : int ,
275
+ spi : SPI ,
276
+ dc : DigitalInOut ,
277
+ reset : DigitalInOut ,
278
+ cs : DigitalInOut ,
257
279
* ,
258
- external_vcc = False ,
259
- baudrate = 8000000 ,
260
- polarity = 0 ,
261
- phase = 0
280
+ external_vcc : bool = False ,
281
+ baudrate : int = 8000000 ,
282
+ polarity : int = 0 ,
283
+ phase : int = 0
262
284
):
263
285
self .rate = 10 * 1024 * 1024
264
- dc .switch_to_output (value = 0 )
286
+ dc .switch_to_output (value = False )
265
287
self .spi_device = spi_device .SPIDevice (
266
288
spi , cs , baudrate = baudrate , polarity = polarity , phase = phase
267
289
)
@@ -275,14 +297,14 @@ def __init__(
275
297
reset = reset ,
276
298
)
277
299
278
- def write_cmd (self , cmd ) :
300
+ def write_cmd (self , cmd : int ) -> None :
279
301
"""Send a command to the SPI device"""
280
- self .dc_pin .value = 0
302
+ self .dc_pin .value = False
281
303
with self .spi_device as spi :
282
304
spi .write (bytearray ([cmd ]))
283
305
284
- def write_framebuf (self ):
306
+ def write_framebuf (self ) -> None :
285
307
"""write to the frame buffer via SPI"""
286
- self .dc_pin .value = 1
308
+ self .dc_pin .value = True
287
309
with self .spi_device as spi :
288
310
spi .write (self .buffer )
0 commit comments