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