32
32
from micropython import const
33
33
from adafruit_bus_device import spi_device
34
34
35
+ try :
36
+ from typing import Optional
37
+ from digitalio import DigitalInOut
38
+ from busio import SPI
39
+ except ImportError :
40
+ pass
41
+
35
42
try :
36
43
import framebuf
37
44
except ImportError :
@@ -81,8 +88,15 @@ class ST7565(framebuf.FrameBuffer):
81
88
CMD_SET_STATIC_REG = const (0x00 )
82
89
83
90
def __init__ (
84
- self , spi , dc_pin , cs_pin , reset_pin = None , * , contrast = 0 , baudrate = 1000000
85
- ):
91
+ self ,
92
+ spi : SPI ,
93
+ dc_pin : DigitalInOut ,
94
+ cs_pin : DigitalInOut ,
95
+ reset_pin : Optional [DigitalInOut ] = None ,
96
+ * ,
97
+ contrast : int = 0 ,
98
+ baudrate : int = 1000000
99
+ ) -> None :
86
100
self ._dc_pin = dc_pin
87
101
dc_pin .switch_to_output (value = False )
88
102
@@ -127,7 +141,7 @@ def __init__(
127
141
# Contrast
128
142
self .contrast = contrast
129
143
130
- def reset (self ):
144
+ def reset (self ) -> None :
131
145
"""Reset the display"""
132
146
if self ._reset_pin :
133
147
# Toggle RST low to reset.
@@ -136,13 +150,13 @@ def reset(self):
136
150
self ._reset_pin .value = True
137
151
time .sleep (0.5 )
138
152
139
- def write_cmd (self , cmd ) :
153
+ def write_cmd (self , cmd : int ) -> None :
140
154
"""Send a command to the SPI device"""
141
155
self ._dc_pin .value = False
142
156
with self .spi_device as spi :
143
157
spi .write (bytearray ([cmd ])) # pylint: disable=no-member
144
158
145
- def show (self ):
159
+ def show (self ) -> None :
146
160
"""write out the frame buffer via SPI"""
147
161
for page in self .pagemap :
148
162
# Home cursor on the page
@@ -163,12 +177,12 @@ def show(self):
163
177
spi .write (self .buffer [row_start :row_stop ]) # pylint: disable=no-member
164
178
165
179
@property
166
- def invert (self ):
180
+ def invert (self ) -> bool :
167
181
"""Whether the display is inverted, cached value"""
168
182
return self ._invert
169
183
170
184
@invert .setter
171
- def invert (self , val ) :
185
+ def invert (self , val : bool ) -> None :
172
186
"""Set invert on or normal display on"""
173
187
self ._invert = val
174
188
if val :
@@ -177,12 +191,12 @@ def invert(self, val):
177
191
self .write_cmd (self .CMD_SET_DISP_NORMAL )
178
192
179
193
@property
180
- def contrast (self ):
194
+ def contrast (self ) -> int :
181
195
"""The cached contrast value"""
182
196
return self ._contrast
183
197
184
198
@contrast .setter
185
- def contrast (self , val ) :
199
+ def contrast (self , val : int ) -> None :
186
200
"""Set contrast to specified value (should be 0-127)."""
187
201
self ._contrast = max (0 , min (val , 0x7F )) # Clamp to values 0-0x7f
188
202
self .write_cmd (self .CMD_SET_VOLUME_FIRST )
0 commit comments